Skip to content

Commit 252dc87

Browse files
committed
Add regression test for issue 127545
1 parent 0ca92de commit 252dc87

File tree

2 files changed

+68
-0
lines changed

2 files changed

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

0 commit comments

Comments
 (0)