Add regression test for issue 127545

This commit is contained in:
Lzu Tao 2024-07-11 22:36:45 +00:00
parent b286722878
commit abeb7203e4
2 changed files with 48 additions and 0 deletions

View file

@ -4,3 +4,11 @@
pub fn foo(arg: Option<&Vec<i32>>) -> Option<&[i32]> {
arg //~ ERROR 5:5: 5:8: mismatched types [E0308]
}
pub fn bar(arg: Option<&Vec<i32>>) -> &[i32] {
arg.unwrap_or(&[]) //~ ERROR 9:19: 9:22: mismatched types [E0308]
}
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]
}

View file

@ -14,5 +14,45 @@ LL | arg.map(|v| &**v)
| ++++++++++++++
error: aborting due to 1 previous error
--> $DIR/transforming-option-ref-issue-127545.rs:9: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:9:5
|
LL | arg.unwrap_or(&[])
| ^^^^^^^^^^^^^^---^
| |
| this argument influences the return type of `unwrap_or`
note: method defined here
--> $SRC_DIR/core/src/option.rs:LL:COL
error[E0308]: mismatched types
--> $DIR/transforming-option-ref-issue-127545.rs:13:19
|
LL | arg.unwrap_or(v)
| --------- ^ expected `&Vec<i32>`, found `&[i32]`
| |
| arguments to this method are incorrect
|
= note: expected reference `&Vec<i32>`
found reference `&'a [i32]`
help: the return type of this call is `&'a [i32]` due to the type of the argument passed
--> $DIR/transforming-option-ref-issue-127545.rs:13:5
|
LL | arg.unwrap_or(v)
| ^^^^^^^^^^^^^^-^
| |
| this argument influences the return type of `unwrap_or`
note: method defined here
--> $SRC_DIR/core/src/option.rs:LL:COL
error: aborting due to 3 previous errors
For more information about this error, try `rustc --explain E0308`.