-
Notifications
You must be signed in to change notification settings - Fork 12.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
where
clause not honored in trait impl
body
#20414
Comments
Per theme in trait Foo {
fn foo_fn(self);
}
struct NoData;
impl NoData where NoData: Foo {
fn any_fn(self) {
self.foo_fn()
}
}
fn main() { }
|
A variant that uses a function instead of a method.
Error:
|
cc @jroesch |
It seems to me that the bug with the In fact, it seems the original is falling into the same hole since trait Foo {
fn answer(&mut self) -> u8;
}
struct Newtype<'a, T: 'a> {
value: &'a mut T,
}
// impl<'a, T> Foo for Newtype<'a, T> { fn answer(&mut self) -> u8 { 0 } }
fn stuff<'a, T>(this: &'a mut T) -> u8 where Newtype<'a, T>: Foo {
let newtype: Newtype<'a, T> = Newtype{value: this};
newtype.answer()
}
fn main() {} Uncommenting the
which is #20413. |
My particular use-case is cross-crate: I have one crate defining The two non-generic examples don't have this possibility, because the type has no generic parameters and thus there is no opportunity for impls from another crate. Also, a modified version of your example, which only implements
|
…n event context. The code right now is super nasty, since it is not currently possible to implement TelnetChannel for all T where Carrier<T> implements ChannelHandler. This is an explicit feature of the `where` clause, and a Rust issue is open for this. (rust-lang/rust#20414)
I ran into an issue which is very similar (I believe). Here it goes:
This is rejected but I think it should compile. The error message is:
|
@sellibitze There is currently a bug with method call style syntax. You can rewrite this code to use UFCS:
That worked for me here: http://is.gd/hqeprS. |
@jroesch: Hey, that worked for my use-case too. Weird! I'll add this workaround to the OP for now. |
My original example and @sellibitze's now compile successfully under the latest nightly. rustc 1.0.0-nightly (ea6f65c5f 2015-01-06 19:47:08 +0000)
binary: rustc
commit-hash: ea6f65c5f1a3f84e010d2cef02a0160804e9567a
commit-date: 2015-01-06 19:47:08 +0000
host: x86_64-apple-darwin
release: 1.0.0-nightly Probably fixed by #20608? |
@Twisol yeah method resolution uses slightly different code then function calls, and there was a bug lurking in the method call code that had been resolved for function calls. Glad everything it is working. I think we can close this one out, but we need someone with repository rights to do so. |
Temporarily reopened while awaiting a test case PR. |
Add test for issue #20414 Reviewed-by: alexcrichton
Labeling as E-needstest per @bstrie's comment |
@nikomatsakis We should have a regression now as per: #20800. I should of marked it as closes this issue. |
k |
Even though I've stipulated in the
where
clause thatNewtype<'a, T>
must implementFoo
for this impl to apply, I can't callanswer
on aNewtype<'a, T>
within the impl body.Workaround
Per @jroesch below, this can be worked around by using
Foo::answer(&mut newtype)
instead ofnewtype.answer()
.Test case
The text was updated successfully, but these errors were encountered: