diff options
| author | Matthias Krüger <matthias.krueger@famsik.de> | 2023-03-25 03:37:10 +0100 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2023-03-25 03:37:10 +0100 |
| commit | f3d3f350cceb6ce8d20ec4bace032f4a62a43c4e (patch) | |
| tree | b594e48b586c5ce0da813c1bf63b223684294190 /tests | |
| parent | d012d2f96e2959267b14812929b85e17a155f653 (diff) | |
| parent | 64f6e4f21ccd8e0ed1f4bb32abe525b4f6ab87c1 (diff) | |
| download | rust-f3d3f350cceb6ce8d20ec4bace032f4a62a43c4e.tar.gz rust-f3d3f350cceb6ce8d20ec4bace032f4a62a43c4e.zip | |
Rollup merge of #109355 - chenyukang:yukang/fix-108470, r=compiler-errors
Fix bad suggestion for clone/is_some in field init shorthand Fixes #108470
Diffstat (limited to 'tests')
| -rw-r--r-- | tests/ui/suggestions/issue-108470.fixed | 29 | ||||
| -rw-r--r-- | tests/ui/suggestions/issue-108470.rs | 29 | ||||
| -rw-r--r-- | tests/ui/suggestions/issue-108470.stderr | 27 |
3 files changed, 85 insertions, 0 deletions
diff --git a/tests/ui/suggestions/issue-108470.fixed b/tests/ui/suggestions/issue-108470.fixed new file mode 100644 index 00000000000..9d15c4a8fcb --- /dev/null +++ b/tests/ui/suggestions/issue-108470.fixed @@ -0,0 +1,29 @@ +// run-rustfix +#![allow(dead_code)] + +struct Foo { + t: Thing +} + +#[derive(Clone)] +struct Thing; + +fn test_clone() { + let t = &Thing; + let _f = Foo { + t: t.clone() //~ ERROR mismatched types + }; +} + +struct Bar { + t: bool +} + +fn test_is_some() { + let t = Option::<i32>::Some(1); + let _f = Bar { + t: t.is_some() //~ ERROR mismatched types + }; +} + +fn main() {} diff --git a/tests/ui/suggestions/issue-108470.rs b/tests/ui/suggestions/issue-108470.rs new file mode 100644 index 00000000000..bda39085d4d --- /dev/null +++ b/tests/ui/suggestions/issue-108470.rs @@ -0,0 +1,29 @@ +// run-rustfix +#![allow(dead_code)] + +struct Foo { + t: Thing +} + +#[derive(Clone)] +struct Thing; + +fn test_clone() { + let t = &Thing; + let _f = Foo { + t //~ ERROR mismatched types + }; +} + +struct Bar { + t: bool +} + +fn test_is_some() { + let t = Option::<i32>::Some(1); + let _f = Bar { + t //~ ERROR mismatched types + }; +} + +fn main() {} diff --git a/tests/ui/suggestions/issue-108470.stderr b/tests/ui/suggestions/issue-108470.stderr new file mode 100644 index 00000000000..4e561eca734 --- /dev/null +++ b/tests/ui/suggestions/issue-108470.stderr @@ -0,0 +1,27 @@ +error[E0308]: mismatched types + --> $DIR/issue-108470.rs:14:9 + | +LL | t + | ^ expected `Thing`, found `&Thing` + | +help: consider using clone here + | +LL | t: t.clone() + | +++++++++++ + +error[E0308]: mismatched types + --> $DIR/issue-108470.rs:25:9 + | +LL | t + | ^ expected `bool`, found `Option<i32>` + | + = note: expected type `bool` + found enum `Option<i32>` +help: use `Option::is_some` to test if the `Option` has a value + | +LL | t: t.is_some() + | +++++++++++++ + +error: aborting due to 2 previous errors + +For more information about this error, try `rustc --explain E0308`. |
