Join GitHub today
GitHub is home to over 31 million developers working together to host and review code, manage projects, and build software together.
Sign upInconsistency in whether methods of shadowed traits are usable #31379
Comments
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
nikomatsakis
added
I-nominated
I-needs-decision
A-const-fn
labels
Feb 3, 2016
This comment has been minimized.
This comment has been minimized.
|
Nominating for discussion at meeting. Clearly we should be consistent. I'm inclined to think that they should not be available, ever. |
This comment has been minimized.
This comment has been minimized.
I'm of the same thoughts as @nikomatsakis. A new "thing" with the same name as another outer "thing" should not inherit/infer/have/etc. any part of that outer thing. This is the case with variable bindings, but—according to the presented opinion—it seems like it needs to be made consistent for trait bindings, right? |
This comment has been minimized.
This comment has been minimized.
|
Is there a reason to shadow traits by name? What happens here is that it must find a method named |
This comment has been minimized.
This comment has been minimized.
Well, that's the question, isn't it. Imagine then that |
This comment has been minimized.
This comment has been minimized.
|
Ambiguity error if |
nikomatsakis
added
the
T-lang
label
Feb 25, 2016
This comment has been minimized.
This comment has been minimized.
|
Another more challenging example might be: mod foo {
use path1::Trait;
fn bar() {
use path2::Trait;
}
}should the methods from |
This comment has been minimized.
This comment has been minimized.
|
My feeling is that the simplest rule is to say that methods come from "traits that are in scope", and shadowed traits are not in scope. This interpretation is shadowing of items from prelude and globs, which seem like they should clearly not count towards method resolution. |
This comment has been minimized.
This comment has been minimized.
|
Discussed in @rust-lang/lang meeting and settled on "methods from shadowed traits should be unavailable". triage: P-medium |
rust-highfive
added
P-medium
and removed
I-nominated
I-needs-decision
labels
Feb 25, 2016
This comment has been minimized.
This comment has been minimized.
We also want methods from |
jseyfried commentedFeb 3, 2016
This compiles:
but this doesn't:
More generally, a shadowed trait's methods are usable if it is shadowed by an item, but not if it is shadowed by an import.
Should methods from shadowed traits be usable?