Skip to content

Commit

Permalink
tests: update tests for more conservative return ty mismatch note
Browse files Browse the repository at this point in the history
  • Loading branch information
jieyouxu committed Jun 16, 2024
1 parent 964cb77 commit a5eff62
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 6 deletions.
11 changes: 10 additions & 1 deletion tests/ui/return/return-ty-mismatch-note.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
// Checks existence of a note for "a caller chooses ty for ty param" upon return ty mismatch.
// Checks existence or absence of a note for "a caller chooses ty for ty param" upon return ty
// mismatch.

fn f<T>() -> (T,) {
(0,) //~ ERROR mismatched types
Expand All @@ -14,6 +15,14 @@ fn h() -> u8 {
0u8
}

// This case was reported in <https://github.com/rust-lang/rust/issues/126547> where it doesn't
// make sense to make the "note caller chooses ty for ty param" note if the found type contains
// the ty param...
fn k<T>(_t: &T) -> T {
_t
//~^ ERROR mismatched types
}

fn main() {
f::<()>();
g::<(), ()>;
Expand Down
21 changes: 17 additions & 4 deletions tests/ui/return/return-ty-mismatch-note.stderr
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
error[E0308]: mismatched types
--> $DIR/return-ty-mismatch-note.rs:4:6
--> $DIR/return-ty-mismatch-note.rs:5:6
|
LL | fn f<T>() -> (T,) {
| - expected this type parameter
Expand All @@ -10,7 +10,7 @@ LL | (0,)
found type `{integer}`

error[E0308]: mismatched types
--> $DIR/return-ty-mismatch-note.rs:8:6
--> $DIR/return-ty-mismatch-note.rs:9:6
|
LL | fn g<U, V>() -> (U, V) {
| - expected this type parameter
Expand All @@ -21,7 +21,7 @@ LL | (0, "foo")
found type `{integer}`

error[E0308]: mismatched types
--> $DIR/return-ty-mismatch-note.rs:8:9
--> $DIR/return-ty-mismatch-note.rs:9:9
|
LL | fn g<U, V>() -> (U, V) {
| - expected this type parameter
Expand All @@ -31,6 +31,19 @@ LL | (0, "foo")
= note: expected type parameter `V`
found reference `&'static str`

error: aborting due to 3 previous errors
error[E0308]: mismatched types
--> $DIR/return-ty-mismatch-note.rs:22:5
|
LL | fn k<T>(_t: &T) -> T {
| - - expected `T` because of return type
| |
| expected this type parameter
LL | _t
| ^^ expected type parameter `T`, found `&T`
|
= note: expected type parameter `_`
found reference `&_`

error: aborting due to 4 previous errors

For more information about this error, try `rustc --explain E0308`.
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ LL | t.clone()
|
= note: expected type parameter `_`
found reference `&_`
= note: the caller chooses a type for `T` which can be different from `&T`
note: `T` does not implement `Clone`, so `&T` was cloned instead
--> $DIR/clone-on-unconstrained-borrowed-type-param.rs:3:5
|
Expand Down

0 comments on commit a5eff62

Please # to comment.