Skip to content

Commit 939026c

Browse files
committed
tests: update tests for more conservative return ty mismatch note
1 parent bfe6a26 commit 939026c

File tree

3 files changed

+27
-6
lines changed

3 files changed

+27
-6
lines changed

tests/ui/return/return-ty-mismatch-note.rs

+10-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
// Checks existence of a note for "a caller chooses ty for ty param" upon return ty mismatch.
1+
// Checks existence or absence of a note for "a caller chooses ty for ty param" upon return ty
2+
// mismatch.
23

34
fn f<T>() -> (T,) {
45
(0,) //~ ERROR mismatched types
@@ -14,6 +15,14 @@ fn h() -> u8 {
1415
0u8
1516
}
1617

18+
// This case was reported in <https://github.com/rust-lang/rust/issues/126547> where it doesn't
19+
// make sense to make the "note caller chooses ty for ty param" note if the found type contains
20+
// the ty param...
21+
fn k<T>(_t: &T) -> T {
22+
_t
23+
//~^ ERROR mismatched types
24+
}
25+
1726
fn main() {
1827
f::<()>();
1928
g::<(), ()>;

tests/ui/return/return-ty-mismatch-note.stderr

+17-4
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
error[E0308]: mismatched types
2-
--> $DIR/return-ty-mismatch-note.rs:4:6
2+
--> $DIR/return-ty-mismatch-note.rs:5:6
33
|
44
LL | fn f<T>() -> (T,) {
55
| - expected this type parameter
@@ -10,7 +10,7 @@ LL | (0,)
1010
found type `{integer}`
1111

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

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

34-
error: aborting due to 3 previous errors
34+
error[E0308]: mismatched types
35+
--> $DIR/return-ty-mismatch-note.rs:22:5
36+
|
37+
LL | fn k<T>(_t: &T) -> T {
38+
| - - expected `T` because of return type
39+
| |
40+
| expected this type parameter
41+
LL | _t
42+
| ^^ expected type parameter `T`, found `&T`
43+
|
44+
= note: expected type parameter `_`
45+
found reference `&_`
46+
47+
error: aborting due to 4 previous errors
3548

3649
For more information about this error, try `rustc --explain E0308`.

tests/ui/suggestions/clone-on-unconstrained-borrowed-type-param.stderr

-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ LL | t.clone()
1010
|
1111
= note: expected type parameter `_`
1212
found reference `&_`
13-
= note: the caller chooses a type for `T` which can be different from `&T`
1413
note: `T` does not implement `Clone`, so `&T` was cloned instead
1514
--> $DIR/clone-on-unconstrained-borrowed-type-param.rs:3:5
1615
|

0 commit comments

Comments
 (0)