Skip to content
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

dyn Trait + Send+ Send should equal dyn Trait + Send #47010

Closed
Havvy opened this issue Dec 26, 2017 · 2 comments
Closed

dyn Trait + Send+ Send should equal dyn Trait + Send #47010

Havvy opened this issue Dec 26, 2017 · 2 comments
Labels
A-traits Area: Trait system C-feature-request Category: A feature request, i.e: not implemented / a PR. T-lang Relevant to the language team, which will review and decide on the PR/issue.

Comments

@Havvy
Copy link
Contributor

Havvy commented Dec 26, 2017

For some trait, Trait, the following is a legal type: type Send2 = Trait + Send + Send.

Not only that, but the type is actually distinct from type Send1 = Trait + Send. E.g., you can put inherent methods on both, and call them distinctly. I've a full example of this here.

Unfortunately, this is already in stable Rust, but at the same time, I don't think anybody is actually relying on this corner of the language. It should be an error to have the same trait twice in a trait object (except perhaps via generics), or at least make cases like Send1 and Send2 be equivalent.

@Havvy Havvy changed the title dyn Trait + AutoTrait + AutoTrait is a thing that should not exist dyn Trait + Send+ Send is a thing that should not exist Dec 26, 2017
@kennytm
Copy link
Member

kennytm commented Dec 26, 2017

except perhaps via generics

You can't write type WithSend<T: ?Sized> = T + Send (causes E0404 "not a trait"), so denying it should be safe.

However I'm not sure if these should be considered equivalent, or different, or rejected.

trait X: Send {}

type A = X;
type B = X + Send;

// A == B ?

@kennytm kennytm added A-traits Area: Trait system C-feature-request Category: A feature request, i.e: not implemented / a PR. T-lang Relevant to the language team, which will review and decide on the PR/issue. labels Dec 26, 2017
@petrochenkov
Copy link
Contributor

fn f<T: Write + Send + Send>() {}

is legal, so dyn Write + Send + Send should be legal as well, stating a predicate twice is redundancy, but not an error.

This can also be useful with trait aliases - dyn TraitAlias + Send, where TraitAlias may include Send as well.

Looks like the bounds just need to be "normalized" somehow (e.g. sorted and deduplicated) when lowering from syntactic to semantic form.
This is somewhat similar to #33140.

@Havvy Havvy changed the title dyn Trait + Send+ Send is a thing that should not exist dyn Trait + Send+ Send should equal dyn Trait + Send May 22, 2018
Mark-Simulacrum added a commit to Mark-Simulacrum/rust that referenced this issue Jun 8, 2018
…tsakis

Dedup auto traits in trait objects.

Fixes rust-lang#47010

Note that the test file `run-pass/trait-object-auto-dedup.rs` passes before and after this change. It's the `ui` test that changed from compiling to not compiling. Which does make this a breaking change, but I cannot imagine anybody actually being broken by it.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-traits Area: Trait system C-feature-request Category: A feature request, i.e: not implemented / a PR. T-lang Relevant to the language team, which will review and decide on the PR/issue.
Projects
None yet
Development

No branches or pull requests

3 participants