-
Notifications
You must be signed in to change notification settings - Fork 13.3k
No error despite of multiple applicable methods in scope #26080
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
Comments
Edit: Found a good reproduction, I think this explains the situation. I'm still surprised that this is allowed, but the methods in question have different self type -- struct Type;
trait A {
fn foo(&self) -> bool { false }
}
trait B : Sized {
fn foo(self) -> bool { true }
}
impl A for Type { }
impl B for Type { }
fn main() {
println!("{}", Type.foo()); // This will call B::foo -- it will prefer `self`.
} |
UFCS is not used here (that would be We might want to make k autoderefs be ambiguous with k autoderefs + autoref, but this is of course a breaking change (an annotatable one, through) and somebody may be relying on it. |
@michas2 It may be that it's a known "feature" of method look up priorities, yours and my example both use the fact that the methods use It's confusing but perhaps not a bug like I thought! As @arielb1 says, using the |
triage: I-nominated |
triage: still an issue. |
Triage: still reproduces, not something that I think we're likely to change? |
Triage: still reproduces Do we still consider this a bug? |
Given the following code:
buf
is of typeRingBuf
.RingBuf
does not provide.bytes()
, but it implements bothBuf
andRead
, which both provide a.bytes()
implementation.According to https://doc.rust-lang.org/book/ufcs.html the compiler should complain. But it simply chooses to take the implementation of
Read
, which return the "wrong" result type.(Without the "use Read" line rust chooses the implementation of
Buf
, which return the "correct" type.)(I am using Rust 1.0.0.)
The text was updated successfully, but these errors were encountered: