Skip to content

Provide more context when an expected type was a type parameter - #160180

Draft
estebank wants to merge 1 commit into
rust-lang:mainfrom
estebank:issue-67991
Draft

Provide more context when an expected type was a type parameter#160180
estebank wants to merge 1 commit into
rust-lang:mainfrom
estebank:issue-67991

Conversation

@estebank

@estebank estebank commented Jul 29, 2026

Copy link
Copy Markdown
Contributor

This becomes particularly confusing when a type parameter has a default.

  --> $DIR/default-type-parameter.rs:8:17
   |
LL |     fn foo() -> u32 { 0 }
   |                 ^^^ expected `()`, found `u32`
   |
note: type in trait
  --> $DIR/default-type-parameter.rs:2:17
   |
LL |     fn foo() -> T;
   |                 ^
   = note: expected signature `fn() -> ()`
              found signature `fn() -> u32`
note: expected to match this type parameter
  --> $DIR/default-type-parameter.rs:1:13
   |
LL | trait Trait<T = ()> {
   |             ^^^^^^
help: change the output type to match the trait
   |
LL -     fn foo() -> u32 { 0 }
LL +     fn foo() -> () { 0 }

Fix #67991.

This becomes particularly confusing when a type parameter has a default.

```
  --> $DIR/default-type-parameter.rs:8:17
   |
LL |     fn foo() -> u32 { 0 }
   |                 ^^^ expected `()`, found `u32`
   |
note: type in trait
  --> $DIR/default-type-parameter.rs:2:17
   |
LL |     fn foo() -> T;
   |                 ^
   = note: expected signature `fn() -> ()`
              found signature `fn() -> u32`
note: expected to match this type parameter
  --> $DIR/default-type-parameter.rs:1:13
   |
LL | trait Trait<T = ()> {
   |             ^^^^^^
help: change the output type to match the trait
   |
LL -     fn foo() -> u32 { 0 }
LL +     fn foo() -> () { 0 }
```
@rustbot rustbot added S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Jul 29, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Incompatible type error should explain when types come from default type parameters

2 participants