Skip to content

Commit 9c1a9e0

Browse files
committed
add test for Result<&T, _> where T; Deref
1 parent 5e1cabe commit 9c1a9e0

File tree

2 files changed

+25
-1
lines changed

2 files changed

+25
-1
lines changed

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

+4
Original file line numberDiff line numberDiff line change
@@ -12,3 +12,7 @@ pub fn bar(arg: Option<&Vec<i32>>) -> &[i32] {
1212
pub fn barzz<'a>(arg: Option<&'a Vec<i32>>, v: &'a [i32]) -> &'a [i32] {
1313
arg.unwrap_or(v) //~ ERROR 13:19: 13:20: mismatched types [E0308]
1414
}
15+
16+
pub fn convert_result(arg: Result<&Vec<i32>, ()>) -> &[i32] {
17+
arg.unwrap_or(&[]) //~ ERROR 17:19: 17:22: mismatched types [E0308]
18+
}

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

+21-1
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,26 @@ help: use `Option::map_or` to deref inner value of `Option`
6161
LL | arg.map_or(v, |v| v)
6262
| ~~~~~~~~~~~~~~~~
6363

64-
error: aborting due to 3 previous errors
64+
error[E0308]: mismatched types
65+
--> $DIR/transforming-option-ref-issue-127545.rs:17:19
66+
|
67+
LL | arg.unwrap_or(&[])
68+
| --------- ^^^ expected `&Vec<i32>`, found `&[_; 0]`
69+
| |
70+
| arguments to this method are incorrect
71+
|
72+
= note: expected reference `&Vec<i32>`
73+
found reference `&[_; 0]`
74+
help: the return type of this call is `&[_; 0]` due to the type of the argument passed
75+
--> $DIR/transforming-option-ref-issue-127545.rs:17:5
76+
|
77+
LL | arg.unwrap_or(&[])
78+
| ^^^^^^^^^^^^^^---^
79+
| |
80+
| this argument influences the return type of `unwrap_or`
81+
note: method defined here
82+
--> $SRC_DIR/core/src/result.rs:LL:COL
83+
84+
error: aborting due to 4 previous errors
6585

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

0 commit comments

Comments
 (0)