diff options
| author | threadexception <hannes.gaumann@outlook.de> | 2021-11-06 10:31:46 +0100 |
|---|---|---|
| committer | threadexception <hannes.gaumann@outlook.de> | 2021-11-13 15:17:44 +0100 |
| commit | 829a5288ec5e33f10e6f5fe2dc891a037d125e6c (patch) | |
| tree | 9e9e6b90ad9a6559a656793349dfd257f5106d03 /src | |
| parent | 0d1754e8bf6942b4c1d24d7c923438782129ba5a (diff) | |
Implement diagnostic for String conversion
Co-authored-by: Esteban Kuber <estebank@users.noreply.github.com>
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`. |
