Skip to content

Add span to E0271 errors pointing at the "found" associated type bound #42390

Description

@chabapok

This code produce next error:

fn foo<F, R>(f: F)
    where F: FnOnce() -> R,
          R: IntoItem<Item=()> 
          { }

trait IntoItem {
    type Item;
}

struct S;

impl IntoItem for S {
    type Item = u32;
}

fn main() {    
    foo(|| S);
}

error:

 35 |     foo(|| S);
    |     ^^^ expected u32, found ()
    |
    = note: expected type `u32`
               found type `()`
    = note: required by `foo`

This is not correct, because expected type of foo is () (see functon signature).
I'm ask to swap "expected" and "found" notes, because is very confused. For rust
beginners this is embarassing (e.g., an error often occurs when works with tokio crate).

It's also incorrect because underlining is on "foo" keyword, but should to argument.

This error might look like this:

35 |     foo(|| S);
   |         ^^^^ expected (), found u32
   |
   = note: expected type `()`
              found type `u32`
   = note: required by `foo`

I suggest making a conclusion about this error easier, such as this:

fn foo(v:u8){ }
fn main(){
    foo(25u16); //expected u8, found u16 <-- this is correct
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-closuresArea: Closures (`|…| { … }`)A-diagnosticsArea: Messages for errors, warnings, and lintsC-enhancementCategory: An issue proposing an enhancement or a PR with one.D-papercutDiagnostics: An error or lint that needs small tweaks.E-hardCall for participation: Hard difficulty. Experience needed to fix: A lot.T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions