Type mismatch in a associated type bound don't point at said associated type
Open
Nobody has claimed this yet.
A-associated-items
A-diagnostics
D-imprecise-spans
T-compiler
- Dominant language
- Rust
- Stars
- 119k
- Forks
- 16.1k
- PR merge metrics
- PR metrics pending
Description
struct Foo;
trait Bar: TryFrom<(), Error = i32> {}
impl Bar for Foo {}
impl TryFrom<()> for Foo {
type Error = ();
fn try_from(_: ()) -> Result<Self, Self::Error> {
todo!()
}
}
Current output:
error[E0271]: type mismatch resolving `<Foo as TryFrom<()>>::Error == i32`
--> src/lib.rs:4:14
|
4 | impl Bar for Foo {}
| ^^^ expected `i32`, found `()`
|
note: required by a bound in `Bar`
--> src/lib.rs:2:24
|
2 | trait Bar: TryFrom<(), Error = i32> {}
| ^^^^^^^^^^^ required by this bound in `Bar`
Desired output:
error[E0271]: type mismatch resolving `<Foo as TryFrom<()>>::Error == i32`
--> src/lib.rs:4:14
|
6 | type Error = ();
| ^^ expected `i32`, found `()`
|
note: required by a bound in `Bar`
--> src/lib.rs:2:24
|
2 | trait Bar: TryFrom<(), Error = i32> {}
| ^^^^^^^^^^^ required by this bound in `Bar`
note: required for this impl
--> src/lib.rs:4:14
|
4 | impl Bar for Foo {}
| ^^^^^^^^^^^^^^^^
|
Similar:
struct Foo;
trait Bar: TryFrom<(), Error = i32> {}
impl Bar for Foo {}
error[E0271]: type mismatch resolving `<Foo as TryFrom<()>>::Error == i32`
--> src/lib.rs:4:14
|
4 | impl Bar for Foo {}
| ^^^ expected `i32`, found `Infallible`
|
note: required by a bound in `Bar`
--> src/lib.rs:2:24
|
2 | trait Bar: TryFrom<(), Error = i32> {}
| ^^^^^^^^^^^ required by this bound in `Bar`
error[E0277]: the trait bound `Foo: TryFrom<()>` is not satisfied
--> src/lib.rs:4:14
|
4 | impl Bar for Foo {}
| ^^^ the trait `From<()>` is not implemented for `Foo`
|
= note: required for `()` to implement `Into<Foo>`
= note: required for `Foo` to implement `TryFrom<()>`
note: required by a bound in `Bar`
--> src/lib.rs:2:12
|
2 | trait Bar: TryFrom<(), Error = i32> {}
| ^^^^^^^^^^^^^^^^^^^^^^^^ required by this bound in `Bar`
E0271 should probably be dropped in favor of E0277 here.
@rustbot label +A-diagnostics +A-associated-items +T-compiler +D-imprecise-spans
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Reproduce the diagnostics from the Rust examples in src/lib.rs and compare the E0271 and E0277 output with the desired spans and notes. The work is done when the associated type definition is highlighted for the mismatch and the similar case no longer reports the inappropriate E0271 diagnostic.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- rust
- Domain
- compilers
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Clearly specified
- Newbie friendliness
- 45/100