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 upTracking issue for allowing overlapping implementations for marker trait #29864
Comments
nikomatsakis
referenced this issue
Nov 16, 2015
Closed
Allow overlapping implementations for marker traits #1268
nikomatsakis
added
B-unstable
T-lang
labels
Nov 18, 2015
This comment has been minimized.
This comment has been minimized.
|
With respect to the second question of whether we should make a more explicit notion of marker trait, I have been pondering this since the RFC discussion. On the one hand, there are a number of places in Rust today where going from nothing to something is a breaking change: adding a private field to a struct, for example. The difference here I think is that:
However, the second point depends a lot on the fate of specialization. If we wind up adopting specialization, and in particular a model that does not require strict subsets, then it would still be possible to adapt existing impls. This makes me a lot less worried. Of course, implementing that form of specialization is tricky, but not (I don't think...) that much trickier than implementing THIS suggestion. The hard part in both cases is the potential for overlap. |
sgrif
added a commit
to diesel-rs/diesel
that referenced
this issue
Nov 25, 2015
sgrif
added a commit
to diesel-rs/diesel
that referenced
this issue
Nov 26, 2015
nrc
added
the
B-RFC-implemented
label
Aug 29, 2016
This comment has been minimized.
This comment has been minimized.
|
@nrc This has the RFC implemented label, but I don't think it has been. If it has, is there a feature gate that I'm missing? If it hasn't been implemented, is there anything I can do to help push this along? It's now been a year since the RFC was accepted. |
nikomatsakis
added
B-RFC-approved
and removed
B-RFC-implemented
labels
Nov 15, 2016
This comment has been minimized.
This comment has been minimized.
|
@sgrif swapped labels |
sgrif
added a commit
to diesel-rs/diesel
that referenced
this issue
Dec 8, 2016
sgrif
added a commit
to diesel-rs/diesel
that referenced
this issue
Dec 8, 2016
sgrif
added a commit
to sgrif/rust
that referenced
this issue
Feb 25, 2017
sgrif
added a commit
to sgrif/rust
that referenced
this issue
Feb 25, 2017
sgrif
added a commit
to sgrif/rust
that referenced
this issue
Feb 25, 2017
sgrif
added a commit
to sgrif/rust
that referenced
this issue
Mar 17, 2017
sgrif
added a commit
to sgrif/rust
that referenced
this issue
Mar 19, 2017
nikomatsakis
added a commit
to sgrif/rust
that referenced
this issue
Apr 3, 2017
bors
added a commit
that referenced
this issue
Apr 3, 2017
bors
added a commit
that referenced
this issue
Apr 4, 2017
frewsxcv
added a commit
to frewsxcv/rust
that referenced
this issue
Apr 4, 2017
frewsxcv
added a commit
to frewsxcv/rust
that referenced
this issue
Apr 15, 2017
frewsxcv
referenced this issue
Apr 15, 2017
Merged
Implement RFC 1268 "Allow overlapping implementations for marker traits" #41309
frewsxcv
added
B-RFC-implemented
and removed
B-RFC-approved
labels
Apr 15, 2017
This comment has been minimized.
This comment has been minimized.
|
Looks like this doesn't work when the overlapping impls are provided by two separate crates, even if both crates have |
This comment has been minimized.
This comment has been minimized.
|
@sgrif interesting, what is the example you have in mind? |
killercup
referenced this issue
May 10, 2017
Merged
Refactor join construction to be much more composeable #879
Mark-Simulacrum
added
the
C-tracking-issue
label
Jul 22, 2017
This comment has been minimized.
This comment has been minimized.
|
One drawback mentioned in the RFC is that this feature makes it a breaking change to add default methods to a trait. Forgive me if this issue was already discussed and resolved, but I didn't see it mentioned in the RFC discussion. Prior to hearing this RFC mentioned, I never thought of "marker traits" (i.e. traits without any items) as anything special or distinct from regular traits, and I would not have expected it to be a breaking change to add default methods to them. Personally, I'd prefer if the user had to opt-in to making a trait a "marker" trait so that they didn't unwittingly cause breakage. |
This comment has been minimized.
This comment has been minimized.
|
One alternative I don't see in the RFC or its discussion thread is doing this only to auto traits, not to all "marker traits". Unless I missed something, all of the motivating examples (including hypotheticals) appear to be auto traits, and afaik you can't add a method to an auto trait anyway so that breaking change issue would just evaporate. |
This comment has been minimized.
This comment has been minimized.
|
Yeah, I'd be totally fine with just doing this on auto traits (whose definition is already unstable). |
This comment has been minimized.
This comment has been minimized.
Vurich
commented
Jan 11, 2018
|
You could explicitly seperate marker and "normal" traits by having marker traits have a different syntax, my suggestion would be: trait MyMarker;Similar to ZSTs. This makes it clearer when you're turning a marker trait into a non-marker trait. |
This comment has been minimized.
This comment has been minimized.
|
@cramertj I would be in favor, I think, of a |
This comment has been minimized.
This comment has been minimized.
|
I also don't believe this is particularly tied to auto traits. |
This comment has been minimized.
This comment has been minimized.
|
@nikomatsakis There's also precedence for semantically meaningful attributes in derives and in |
This comment has been minimized.
This comment has been minimized.
|
I needed this feature for a single trait in a personal project, and turning it on means overlapping is allowed for all of my marker traits. I'd personally like a warning issued for overlapping impls which can then be Also, I assume this is a bug in the current implementation, but order seems to matter: #![feature(overlapping_marker_traits)]
pub trait F {}
impl<T> F for T where T: Copy {}
impl<T> F for T where T: 'static {}Gives the error:
While this (same code, different order) compiles and works as expected: pub trait F {}
impl<T> F for T where T: 'static {}
impl<T> F for T where T: Copy {} |
This comment has been minimized.
This comment has been minimized.
|
Also the error messages when using the above trait aren't great. The errors always indicate that the type needs a This appears to be a problem solely with lifetimes (which is my use case). If |
This comment has been minimized.
This comment has been minimized.
|
That particular example will be complex to make work as desired in any case, due to how region handling is done in rustc at present (e.g., #21974). In general, integrating "or" constraints and region solving is a bit tricky I suppose. I imagine we can do it by making the region checker smarter, which we have to do eventually. |
This comment has been minimized.
This comment has been minimized.
Vurich
commented
Feb 26, 2018
|
No matter what the actual syntax is (either an annotation or |
This comment has been minimized.
This comment has been minimized.
|
A thought in favour of (Inspired by a discussion with the bunny about having something like Edit: Also, using an attribute fits the generally-suggested "do it with a macro or attribute first, then add syntax once we have more experience" procedure. |
This comment has been minimized.
This comment has been minimized.
Vurich
commented
Feb 26, 2018
|
I actually quite like that idea, since it's not an uncommon pattern to have convenience functions in traits and often these will only ever be implemented in the defining crate and it might be a useful tradeoff to allow overlapping implementations at the cost of disallowing consuming crates from overriding the function body. If that was to be allowed, though, I'd prefer the name |
This comment has been minimized.
This comment has been minimized.
|
It seems obvious that we should make a |
scottmcm
referenced this issue
Apr 9, 2018
Closed
Tracking issue for the to_bytes and from_bytes methods of integers #49792
sfackler
referenced this issue
May 9, 2018
Open
Coherence rules are not consistent when applied to auto traits #50551
cramertj
referenced this issue
Jul 31, 2018
Closed
Propagate either feature and enable by default from the facade #1151
This comment has been minimized.
This comment has been minimized.
|
I was just thinking about a way to prevent users from implementing the |
nikomatsakis commentedNov 16, 2015
•
edited
Tracking issue for rust-lang/rfcs#1268.
Status
Known bugs
Prior to stabilization