-
Notifications
You must be signed in to change notification settings - Fork 12.9k
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
Tracking Issue for RFC: Supertrait Item Shadowing #89151
Comments
@rust-lang/libs-api — this change is relevant to our ability to add things like |
For the Iterator/Itertools case it would be necessary to shadow based on the explicit import of Currently the RFC only concerns itself with traits being brought into scope via generics or trait objects, not via the prelude.
So the scope of this issue would have to be widened a bit. |
This is correct, the RFC explicitly only concerns itself with generics and trait objects. Similar concerns to what the RFC covers however also apply to the case where both supertrait and subtrait are |
Well, the std prelude (which is what causes #88967) isn't an explicit glob import either, it's fully implicit. |
Ah, I thought you were talking about a prelude in Itertools. |
I remember looking at the method resolution logic (excluding auto(de)ref) in the compiler a couple of years ago, and not liking what I've seen. Treating methods from generic parameter bounds as inherent (bad idea, IMO), treating I wish that area got some principled common vision (and corresponding bugfixing) before new features are added. |
@petrochenkov did any of that resolution restructuring happen? I think there has gotten some interest recently |
I re-read the RFC with the // core
trait Iterator {
#[unstable]
fn intersperse(self, element: Self::Item) -> Intersperse<Self>;
}
// itertools
trait Itertools: Iterator {
fn intersperse(self, element: Self::Item) -> Intersperse<Self>;
} Today, Most uses of this method look like this: // Implicit prelude import
use core::iter::Iterator;
// Explicit trait import
use itertools::Itertools;
// Actual use which causes an ambiguity error.
let text = lines.intersperse("\n").collect(); This would not work with the RFC as proposed since no generic bounds are in use. Instead we would need one of the proposed alternatives, specifically "Always resolving in favor of the subtrait". Essentially, if there is ambiguity between a supertrait and subtrait method, we should always resolve the ambiguity by selecting the subtrait method. @rust-lang/types What are your thoughts on this? @rust-lang/libs-api would like to know if this is likely to move forward since this affects future development of the |
My personal preference would be to always resolve in favor of the sub trait, linting when defining a sub trait if the trait has an item with the same name as the super trait. I believe always shadowing super traits is fairly straightforward to implement and linting the definition of the sub trait is as well. I consider this behavior to be part of the area where the responsibilities of t-types and t-lang overlap. T-lang is responsible for the vibe while T-types has to sign off that it works well with the general design of the type system and its implementation in rustc. Nominating this for t-lang to decide whether "always prefering methods from subtraits" is acceptable to them and to decide whether this needs any additional FCP/RFC to be implemented. |
We discussed this in the @rust-lang/lang triage meeting and we felt we didn't have sufficient context to evaluate precisely what is being proposed, so we'd love to see a short RFC about this. What I think would be really useful is to highlight the examples of where this "does the right thing" but also any edge cases. Basically what are the arguments against this? Off the top of my head...
|
I wrote an RFC: rust-lang/rfcs#3624 |
This is a tracking issue for:
The feature gate for the issue is
#![feature(supertrait_item_shadowing)]
.About tracking issues
Tracking issues are used to record the overall progress of implementation. They are also used as hubs connecting to other relevant issues, e.g., bugs or open design questions. A tracking issue is however not meant for large scale discussion, questions, or bug reports about a feature. Instead, open a dedicated issue for the specific matter and add the relevant feature gate label.
Steps
supertrait_item_shadowing
(v2) #125782Unresolved Questions
TODO.
Related
supertrait_item_shadowing
(v2) #125782The text was updated successfully, but these errors were encountered: