Skip to content

Incomplete diagnostic notes when closure returns conflicting instantiations of generic type #84128

Open
@eggyal

Description

@eggyal

Given the following code (playground):

struct Foo<T>(T);

fn main() {
    || {
        if false {
            return Foo(0);
        }

        Foo(())
    };
}

The current output is:

error[E0308]: mismatched types
 --> src/main.rs:9:13
  |
9 |         Foo(())
  |             ^^ expected integer, found `()`

Ideally the output should look like:

error[E0308]: mismatched types
 --> src/main.rs:9:13
  |
9 |         Foo(())
  |             ^^ expected integer, found `()`
  |
note: return type inferred to be `Foo<{integer}>` here
 --> src/main.rs:6:20
  |
6 |             return Foo(0);
  |                    ^^^^^^

Since #78235, notes have been provided when the returned types are entirely different—but they do not appear when they are the same base type with different generic type parameters. cc @Aaron1011

@rustbot label: A-closures A-diagnostics A-inference C-enhancement D-papercut

Metadata

Metadata

Labels

A-closuresArea: Closures (`|…| { … }`)A-diagnosticsArea: Messages for errors, warnings, and lintsA-inferenceArea: Type inferenceC-enhancementCategory: An issue proposing an enhancement or a PR with one.D-papercutDiagnostics: An error or lint that needs small tweaks.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