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

impl Trait for Trait should yield a coherence violation #24015

Closed
nikomatsakis opened this issue Apr 3, 2015 · 2 comments · Fixed by #24056
Closed

impl Trait for Trait should yield a coherence violation #24015

nikomatsakis opened this issue Apr 3, 2015 · 2 comments · Fixed by #24056
Labels
I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️

Comments

@nikomatsakis
Copy link
Contributor

Since the compiler now supplies an implementation of the trait for itself, something like http://is.gd/Id71IX:

trait Foo { fn dummy(&self) { } }
impl Foo for Foo { }
fn main() { }```

ought to be reported as overlap. Instead we get an error later when we find an ambiguity:

:2:1: 2:21 error: internal compiler error: coherence failed to report ambiguity: cannot locate the impl of the trait Foo for the type Foo
:2 impl Foo for Foo { }
^~~~~~~~~~~~~~~~~~~~
note: the compiler unexpectedly panicked. this is a bug.
note: we would appreciate a bug report: https://github.com/rust-lang/rust/blob/master/CONTRIBUTING.md#bug-reports
note: run with RUST_BACKTRACE=1 for a backtrace
thread 'rustc' panicked at 'Box', /home/rustbuild/src/rust-buildbot/slave/nightly-dist-rustc-linux/build/src/libsyntax/diagnostic.rs:130

@nikomatsakis nikomatsakis added the I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️ label Apr 3, 2015
@nikomatsakis
Copy link
Contributor Author

triage: I-Nominated

@nikomatsakis
Copy link
Contributor Author

(I'm not really sure how much to care about this; but it may be worth fixing since it's quite confusing.)

nikomatsakis added a commit to nikomatsakis/rust that referenced this issue Apr 6, 2015
`Trait`, prefer the object. Also give a nice error for attempts to
manually `impl Trait for Trait`, since they will be ineffectual.

Fixes rust-lang#24015.

Fixes rust-lang#24051.
Fixes rust-lang#24037.
Fixes rust-lang#23853.
Fixes rust-lang#21942.
cc rust-lang#21756.
bors added a commit that referenced this issue Apr 6, 2015
If we find a blanket impl for `Trait` but we're matching on an object `Trait`, prefer the object (I think we could perhaps go either way, but this seems safer). Also give a nice error for attempts to manually `impl Trait for Trait`, since they will be ineffectual.

This fixes the problems around ambiguity ICEs relating to `Any` and `MarkerTrait` that were cropping up all over the place. There may still be similar ICEs reported in #21756 that this PR does not address.

Fixes #24015.

Fixes #24051.
Fixes #24037.
Fixes #23853.
Fixes #21942.
cc #21756.

cc @alexcrichton (this fixes crates.io)
r? @aturon
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant