add test for Result<&T, _> where T; Deref

This commit is contained in:
Lzu Tao 2024-07-13 00:54:00 +00:00
parent 5e1cabe982
commit 9c1a9e03d5
2 changed files with 25 additions and 1 deletions

View File

@ -12,3 +12,7 @@ pub fn bar(arg: Option<&Vec<i32>>) -> &[i32] {
pub fn barzz<'a>(arg: Option<&'a Vec<i32>>, v: &'a [i32]) -> &'a [i32] {
arg.unwrap_or(v) //~ ERROR 13:19: 13:20: mismatched types [E0308]
}
pub fn convert_result(arg: Result<&Vec<i32>, ()>) -> &[i32] {
arg.unwrap_or(&[]) //~ ERROR 17:19: 17:22: mismatched types [E0308]
}

View File

@ -61,6 +61,26 @@ help: use `Option::map_or` to deref inner value of `Option`
LL | arg.map_or(v, |v| v)
| ~~~~~~~~~~~~~~~~
error: aborting due to 3 previous errors
error[E0308]: mismatched types
--> $DIR/transforming-option-ref-issue-127545.rs:17:19
|
LL | arg.unwrap_or(&[])
| --------- ^^^ expected `&Vec<i32>`, found `&[_; 0]`
| |
| arguments to this method are incorrect
|
= note: expected reference `&Vec<i32>`
found reference `&[_; 0]`
help: the return type of this call is `&[_; 0]` due to the type of the argument passed
--> $DIR/transforming-option-ref-issue-127545.rs:17:5
|
LL | arg.unwrap_or(&[])
| ^^^^^^^^^^^^^^---^
| |
| this argument influences the return type of `unwrap_or`
note: method defined here
--> $SRC_DIR/core/src/result.rs:LL:COL
error: aborting due to 4 previous errors
For more information about this error, try `rustc --explain E0308`.