-
Notifications
You must be signed in to change notification settings - Fork 12.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Rollup merge of #127596 - tesuji:help-unwrap-or, r=compiler-errors
More suggestion for converting `Option<&Vec<T>>` to `Option<&[T]>` Please review commit-by-commit.
- Loading branch information
Showing
3 changed files
with
61 additions
and
15 deletions.
There are no files selected for viewing
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
6 changes: 6 additions & 0 deletions
6
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,6 @@ | ||
// Regression test for <https://github.com/rust-lang/rust/issues/127545>. | ||
#![crate_type = "lib"] | ||
|
||
pub fn foo(arg: Option<&Vec<i32>>) -> Option<&[i32]> { | ||
arg //~ ERROR 5:5: 5:8: mismatched types [E0308] | ||
} |
18 changes: 18 additions & 0 deletions
18
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,18 @@ | ||
error[E0308]: mismatched types | ||
--> $DIR/transforming-option-ref-issue-127545.rs:5:5 | ||
| | ||
LL | pub fn foo(arg: Option<&Vec<i32>>) -> Option<&[i32]> { | ||
| -------------- expected `Option<&[i32]>` because of return type | ||
LL | arg | ||
| ^^^ expected `Option<&[i32]>`, found `Option<&Vec<i32>>` | ||
| | ||
= note: expected enum `Option<&[i32]>` | ||
found enum `Option<&Vec<i32>>` | ||
help: try using `.map(|v| &**v)` to convert `Option<&Vec<i32>>` to `Option<&[i32]>` | ||
| | ||
LL | arg.map(|v| &**v) | ||
| ++++++++++++++ | ||
|
||
error: aborting due to 1 previous error | ||
|
||
For more information about this error, try `rustc --explain E0308`. |