-
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.
Auto merge of #90645 - terrarier2111:master, r=estebank
Implement diagnostic for String conversion This is my first real contribution to rustc, any feedback is highly appreciated. This should fix #89856 Thanks to `@estebank` for guiding me.
- Loading branch information
Showing
3 changed files
with
85 additions
and
36 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
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,8 @@ | ||
fn take_str_maybe(x: Option<&str>) -> Option<&str> { None } | ||
|
||
fn main() { | ||
let string = String::from("Hello, world"); | ||
let option = Some(&string); | ||
take_str_maybe(option); | ||
//~^ ERROR: mismatched types [E0308] | ||
} |
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,16 @@ | ||
error[E0308]: mismatched types | ||
--> $DIR/issue-89856.rs:6:20 | ||
| | ||
LL | take_str_maybe(option); | ||
| ^^^^^^ expected `str`, found struct `String` | ||
| | ||
= note: expected enum `Option<&str>` | ||
found enum `Option<&String>` | ||
help: try converting the passed type into a `&str` | ||
| | ||
LL | take_str_maybe(option.map(|x| &**x)); | ||
| ++++++++++++++ | ||
|
||
error: aborting due to previous error | ||
|
||
For more information about this error, try `rustc --explain E0308`. |