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

Provide overlapping types for coherence errors #29962

Merged
merged 1 commit into from
Dec 16, 2015

Conversation

aturon
Copy link
Member

@aturon aturon commented Nov 20, 2015

Currently, a coherence error based on overlapping impls simply mentions
the trait, and points to the two conflicting impls:

error: conflicting implementations for trait `Foo`

With this commit, the error will include all input types to the
trait (including the Self type) after unification between the
overlapping impls. In other words, the error message will provide
feedback with full type details, like:

error: conflicting implementations of trait `Foo<u32>` for type `u8`:

When the Self type for the two impls unify to an inference variable,
it is elided in the output, since "for type _" is just noise in that
case.

Closes #23980

r? @nikomatsakis

impl2_def_id: DefId)
-> bool
/// If there are types that satisfy both impls, returns a `TraitRef`
/// with those types substituted.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So the thing that makes me wary here is that, because of the probe, this trait reference may include unresolved type variables that have since been popped. Basically, it's ok to print it out, but it's not ok to do much else with it, since it contains the equivalent of dangling references. I think instead of using resolve_type_vars_if_possible, we should consider using infer::freshen, which also resolves type variables, but which replaces unresolved type variables with a FreshTy. (Possibly not the best names...) One problem though is that freshen also replaces regions with 'static which, at least if they are printed out, could be pretty confusing.

I guess another, easier, option would be to move the probe call outside of overlapping_impls and into check_if_impls_overlap. Never mind, let's do that instead. :)

@nikomatsakis
Copy link
Contributor

Also, we should add a test for the new message I think. I hate tests that encode error messages, but it seems like there is non-trivial logic here, so we'd like to test that the types we expect are being printed.

@bors
Copy link
Contributor

bors commented Nov 24, 2015

☔ The latest upstream changes (presumably #29960) made this pull request unmergeable. Please resolve the merge conflicts.

@aturon
Copy link
Member Author

aturon commented Dec 4, 2015

Test added. And it turned out the probe wasn't needed anyway, since each invocation was on a fresh infcx.

@aturon aturon force-pushed the coherence-errors branch 3 times, most recently from c95405d to 21bd4dc Compare December 4, 2015 17:58
@nikomatsakis
Copy link
Contributor

@aturon seems good, but travis is unhappy -- still, I see no clear reason why this is the case. Perhaps it is bogus.

@nikomatsakis
Copy link
Contributor

@bors r+

let's see what bors thinks.

@bors
Copy link
Contributor

bors commented Dec 15, 2015

📌 Commit 21bd4dc has been approved by nikomatsakis

@sanxiyn
Copy link
Member

sanxiyn commented Dec 16, 2015

Travis failure is due to test [compile-fail] compile-fail/issue-28568.rs ... FAILED.

@bors
Copy link
Contributor

bors commented Dec 16, 2015

⌛ Testing commit 21bd4dc with merge 3ab1ee8...

@bors
Copy link
Contributor

bors commented Dec 16, 2015

💔 Test failed - auto-mac-64-nopt-t

Currently, a coherence error based on overlapping impls simply mentions
the trait, and points to the two conflicting impls:

```
error: conflicting implementations for trait `Foo`
```

With this commit, the error will include all input types to the
trait (including the `Self` type) after unification between the
overlapping impls. In other words, the error message will provide
feedback with full type details, like:

```
error: conflicting implementations of trait `Foo<u32>` for type `u8`:
```

When the `Self` type for the two impls unify to an inference variable,
it is elided in the output, since "for type `_`" is just noise in that
case.

Closes rust-lang#23980
@aturon
Copy link
Member Author

aturon commented Dec 16, 2015

@bors: r=nmatsakis

@bors
Copy link
Contributor

bors commented Dec 16, 2015

📌 Commit bc33dd7 has been approved by nmatsakis

bors added a commit that referenced this pull request Dec 16, 2015
Currently, a coherence error based on overlapping impls simply mentions
the trait, and points to the two conflicting impls:

```
error: conflicting implementations for trait `Foo`
```

With this commit, the error will include all input types to the
trait (including the `Self` type) after unification between the
overlapping impls. In other words, the error message will provide
feedback with full type details, like:

```
error: conflicting implementations of trait `Foo<u32>` for type `u8`:
```

When the `Self` type for the two impls unify to an inference variable,
it is elided in the output, since "for type `_`" is just noise in that
case.

Closes #23980

r? @nikomatsakis
@bors
Copy link
Contributor

bors commented Dec 16, 2015

⌛ Testing commit bc33dd7 with merge 38da1a4...

@bors bors merged commit bc33dd7 into rust-lang:master Dec 16, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants