Skip to content

Commit 70a4b54

Browse files
committed
Add regression test for issue 127545
1 parent 0ca92de commit 70a4b54

File tree

2 files changed

+53
-0
lines changed

2 files changed

+53
-0
lines changed
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
// Regression test for <https://github.com/rust-lang/rust/issues/127545>.
2+
#![crate_type = "lib"]
3+
4+
pub fn bar(arg: Option<&Vec<i32>>) -> &[i32] {
5+
arg.unwrap_or(&[]) //~ ERROR 5:19: 5:22: mismatched types [E0308]
6+
}
7+
8+
pub fn barzz<'a>(arg: Option<&'a Vec<i32>>, v: &'a [i32]) -> &'a [i32] {
9+
arg.unwrap_or(v) //~ ERROR 9:19: 9:20: mismatched types [E0308]
10+
}
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
error[E0308]: mismatched types
2+
--> $DIR/transforming-option-ref-issue-127545.rs:5:19
3+
|
4+
LL | arg.unwrap_or(&[])
5+
| --------- ^^^ expected `&Vec<i32>`, found `&[_; 0]`
6+
| |
7+
| arguments to this method are incorrect
8+
|
9+
= note: expected reference `&Vec<i32>`
10+
found reference `&[_; 0]`
11+
help: the return type of this call is `&[_; 0]` due to the type of the argument passed
12+
--> $DIR/transforming-option-ref-issue-127545.rs:5:5
13+
|
14+
LL | arg.unwrap_or(&[])
15+
| ^^^^^^^^^^^^^^---^
16+
| |
17+
| this argument influences the return type of `unwrap_or`
18+
note: method defined here
19+
--> $SRC_DIR/core/src/option.rs:LL:COL
20+
21+
error[E0308]: mismatched types
22+
--> $DIR/transforming-option-ref-issue-127545.rs:9:19
23+
|
24+
LL | arg.unwrap_or(v)
25+
| --------- ^ expected `&Vec<i32>`, found `&[i32]`
26+
| |
27+
| arguments to this method are incorrect
28+
|
29+
= note: expected reference `&Vec<i32>`
30+
found reference `&'a [i32]`
31+
help: the return type of this call is `&'a [i32]` due to the type of the argument passed
32+
--> $DIR/transforming-option-ref-issue-127545.rs:9:5
33+
|
34+
LL | arg.unwrap_or(v)
35+
| ^^^^^^^^^^^^^^-^
36+
| |
37+
| this argument influences the return type of `unwrap_or`
38+
note: method defined here
39+
--> $SRC_DIR/core/src/option.rs:LL:COL
40+
41+
error: aborting due to 2 previous errors
42+
43+
For more information about this error, try `rustc --explain E0308`.

0 commit comments

Comments
 (0)