diff options
| author | bors <bors@rust-lang.org> | 2021-11-15 06:55:01 +0000 |
|---|---|---|
| committer | bors <bors@rust-lang.org> | 2021-11-15 06:55:01 +0000 |
| commit | d5a0c7cb036032288a4a5443b54ba061ec12ee26 (patch) | |
| tree | d723172ea55478cc6290b7bd35aca9625e6c8b74 /src | |
| parent | 42054811104bb005ded241ea8846ba7383921c46 (diff) | |
| parent | 829a5288ec5e33f10e6f5fe2dc891a037d125e6c (diff) | |
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 https://github.com/rust-lang/rust/issues/89856 Thanks to `@estebank` for guiding me.
Diffstat (limited to 'src')
| -rw-r--r-- | src/test/ui/typeck/issue-89856.rs | 8 | ||||
| -rw-r--r-- | src/test/ui/typeck/issue-89856.stderr | 16 |
2 files changed, 24 insertions, 0 deletions
diff --git a/src/test/ui/typeck/issue-89856.rs b/src/test/ui/typeck/issue-89856.rs new file mode 100644 index 00000000000..b021e349e35 --- /dev/null +++ b/src/test/ui/typeck/issue-89856.rs @@ -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] +} diff --git a/src/test/ui/typeck/issue-89856.stderr b/src/test/ui/typeck/issue-89856.stderr new file mode 100644 index 00000000000..4cb46a34a07 --- /dev/null +++ b/src/test/ui/typeck/issue-89856.stderr @@ -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`. |
