-
Notifications
You must be signed in to change notification settings - Fork 13k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add regression test for issue 127545
- Loading branch information
Showing
2 changed files
with
53 additions
and
0 deletions.
There are no files selected for viewing
10 changes: 10 additions & 0 deletions
10
tests/ui/mismatched_types/transforming-option-ref-issue-127545.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
// Regression test for <https://github.com/rust-lang/rust/issues/127545>. | ||
#![crate_type = "lib"] | ||
|
||
pub fn bar(arg: Option<&Vec<i32>>) -> &[i32] { | ||
arg.unwrap_or(&[]) //~ ERROR 5:19: 5:22: mismatched types [E0308] | ||
} | ||
|
||
pub fn barzz<'a>(arg: Option<&'a Vec<i32>>, v: &'a [i32]) -> &'a [i32] { | ||
arg.unwrap_or(v) //~ ERROR 9:19: 9:20: mismatched types [E0308] | ||
} |
43 changes: 43 additions & 0 deletions
43
tests/ui/mismatched_types/transforming-option-ref-issue-127545.stderr
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
error[E0308]: mismatched types | ||
--> $DIR/transforming-option-ref-issue-127545.rs:5: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:5: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:9: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:9: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 2 previous errors | ||
|
||
For more information about this error, try `rustc --explain E0308`. |