Skip to content

Commit abeb720

Browse files
committed
Add regression test for issue 127545
1 parent b286722 commit abeb720

File tree

2 files changed

+48
-0
lines changed

2 files changed

+48
-0
lines changed

Diff for: tests/ui/mismatched_types/transforming-option-ref-issue-127545.rs

+8
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,11 @@
44
pub fn foo(arg: Option<&Vec<i32>>) -> Option<&[i32]> {
55
arg //~ ERROR 5:5: 5:8: mismatched types [E0308]
66
}
7+
8+
pub fn bar(arg: Option<&Vec<i32>>) -> &[i32] {
9+
arg.unwrap_or(&[]) //~ ERROR 9:19: 9:22: mismatched types [E0308]
10+
}
11+
12+
pub fn barzz<'a>(arg: Option<&'a Vec<i32>>, v: &'a [i32]) -> &'a [i32] {
13+
arg.unwrap_or(v) //~ ERROR 13:19: 13:20: mismatched types [E0308]
14+
}

Diff for: tests/ui/mismatched_types/transforming-option-ref-issue-127545.stderr

+40
Original file line numberDiff line numberDiff line change
@@ -14,5 +14,45 @@ LL | arg.map(|v| &**v)
1414
| ++++++++++++++
1515

1616
error: aborting due to 1 previous error
17+
--> $DIR/transforming-option-ref-issue-127545.rs:9:19
18+
|
19+
LL | arg.unwrap_or(&[])
20+
| --------- ^^^ expected `&Vec<i32>`, found `&[_; 0]`
21+
| |
22+
| arguments to this method are incorrect
23+
|
24+
= note: expected reference `&Vec<i32>`
25+
found reference `&[_; 0]`
26+
help: the return type of this call is `&[_; 0]` due to the type of the argument passed
27+
--> $DIR/transforming-option-ref-issue-127545.rs:9:5
28+
|
29+
LL | arg.unwrap_or(&[])
30+
| ^^^^^^^^^^^^^^---^
31+
| |
32+
| this argument influences the return type of `unwrap_or`
33+
note: method defined here
34+
--> $SRC_DIR/core/src/option.rs:LL:COL
35+
36+
error[E0308]: mismatched types
37+
--> $DIR/transforming-option-ref-issue-127545.rs:13:19
38+
|
39+
LL | arg.unwrap_or(v)
40+
| --------- ^ expected `&Vec<i32>`, found `&[i32]`
41+
| |
42+
| arguments to this method are incorrect
43+
|
44+
= note: expected reference `&Vec<i32>`
45+
found reference `&'a [i32]`
46+
help: the return type of this call is `&'a [i32]` due to the type of the argument passed
47+
--> $DIR/transforming-option-ref-issue-127545.rs:13:5
48+
|
49+
LL | arg.unwrap_or(v)
50+
| ^^^^^^^^^^^^^^-^
51+
| |
52+
| this argument influences the return type of `unwrap_or`
53+
note: method defined here
54+
--> $SRC_DIR/core/src/option.rs:LL:COL
55+
56+
error: aborting due to 3 previous errors
1757

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

0 commit comments

Comments
 (0)