-
Notifications
You must be signed in to change notification settings - Fork 12.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Rollup merge of #104261 - compiler-errors:formal-and-expected-differ,…
… r=estebank More accurately report error when formal and expected signature types differ Fixes #104242
- Loading branch information
Showing
4 changed files
with
77 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
25 changes: 25 additions & 0 deletions
25
src/test/ui/argument-suggestions/formal-and-expected-differ.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
pub trait Foo { | ||
type T; | ||
} | ||
|
||
impl Foo for i32 { | ||
type T = f32; | ||
} | ||
|
||
pub struct U<T1, T2>(T1, S<T2>) | ||
where | ||
T1: Foo<T = T2>; | ||
|
||
pub struct S<T>(T); | ||
|
||
fn main() { | ||
// The error message here isn't great -- it has to do with the fact that the | ||
// `expected_inputs_for_expected_output` deduced inputs differs from the inputs | ||
// that we infer from the constraints of the signature. | ||
// | ||
// I am not really sure what the best way of presenting this error message is, | ||
// since right now it just suggests changing `3u32` <=> `3f32` back and forth. | ||
let _: U<_, u32> = U(1, S(3u32)); | ||
//~^ ERROR mismatched types | ||
//~| ERROR mismatched types | ||
} |
30 changes: 30 additions & 0 deletions
30
src/test/ui/argument-suggestions/formal-and-expected-differ.stderr
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
error[E0308]: mismatched types | ||
--> $DIR/formal-and-expected-differ.rs:22:29 | ||
| | ||
LL | let _: U<_, u32> = U(1, S(3u32)); | ||
| - ^^^^^^^ expected `f32`, found `u32` | ||
| | | ||
| arguments to this struct are incorrect | ||
| | ||
= note: expected struct `S<f32>` | ||
found struct `S<u32>` | ||
note: tuple struct defined here | ||
--> $DIR/formal-and-expected-differ.rs:9:12 | ||
| | ||
LL | pub struct U<T1, T2>(T1, S<T2>) | ||
| ^ | ||
|
||
error[E0308]: mismatched types | ||
--> $DIR/formal-and-expected-differ.rs:22:24 | ||
| | ||
LL | let _: U<_, u32> = U(1, S(3u32)); | ||
| --------- ^^^^^^^^^^^^^ expected `u32`, found `f32` | ||
| | | ||
| expected due to this | ||
| | ||
= note: expected struct `U<_, u32>` | ||
found struct `U<i32, f32>` | ||
|
||
error: aborting due to 2 previous errors | ||
|
||
For more information about this error, try `rustc --explain E0308`. |