Repository navigation
Inconsistency in whether methods of shadowed traits are usable #31379
Description
Activity
cc @rust-lang/lang
- addedI-needs-decisionIssue: In need of a decision.Issue: In need of a decision.
on Feb 3, 2016 Nominating for discussion at meeting. Clearly we should be consistent. I'm inclined to think that they should not be available, ever.
I'm inclined to think that they should not be available, ever.
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?
Is there a reason to shadow traits by name? What happens here is that it must find a method named
.into_iter()among the imported traits, and that name has not been shadowed in any way, so it should be callable.Is there a reason to shadow traits by name? What happens here is that it must find a method named .into_iter() among the imported traits, and that name has not been shadowed in any way, so it should be callable.
Well, that's the question, isn't it. Imagine then that
trait Tdid have aninto_itermethod -- would you prefer an ambiguity error here, or success?Ambiguity error if
Twas implemented forOption<i32>in the example (and this error is already implemented). Otherwise it doesn't interfere in any way.Another more challenging example might be:
mod foo { use path1::Trait; fn bar() { use path2::Trait; } }
should the methods from
path1::Traitbe available, given that it is shadowed bypath2::Trait?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.
Discussed in @rust-lang/lang meeting and settled on "methods from shadowed traits should be unavailable".
triage: P-medium
- addedP-mediumMedium priorityMedium priorityand removedI-needs-decisionIssue: In need of a decision.Issue: In need of a decision.
on Feb 25, 2016 This interpretation is shadowing of items from prelude and globs
We also want methods from
path1::Traitto be unavailable (from your more challenging example), right?- added a commit that references this issue
on Mar 25, 2016 - addedA-const-evalArea: Constant evaluation, covers all const contexts (static, const fn, ...)Area: Constant evaluation, covers all const contexts (static, const fn, ...)
on Dec 1, 2024
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?