diff options
author | Josh Stone <cuviper@gmail.com> | 2023-08-17 15:40:09 -0700 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-08-17 15:40:09 -0700 |
commit | 5861815559f93dbd43431756e0256329f18ea47a (patch) | |
tree | 1dfd2c564da7e92f65527f813d7547edbb2938f3 /tests/ui/suggestions | |
parent | 7ea4de9632ab0e29e34e5250f367992a0e862519 (diff) | |
parent | 1c73248b67167dd18c9bd01bf541f5ea35be66d8 (diff) |
Rollup merge of #114931 - Urgau:revert-114052, r=compiler-errors
Revert PR #114052 to fix invalid suggestion
This PR reverts https://github.com/rust-lang/rust/pull/114052 to fix the invalid suggestion produced by the PR.
Unfortunately the invalid suggestion cannot be improved from the current position where it's emitted since we lack enough information (is an assignment?, left or right?, ...) to be able to fix it here. Furthermore the previous wasn't wrong, just suboptimal, contrary to the current one which is just wrong.
Added a regression test and commented out some code instead of removing it so we can use it later.
Reopens https://github.com/rust-lang/rust/issues/114050
Fixes https://github.com/rust-lang/rust/issues/114925
Diffstat (limited to 'tests/ui/suggestions')
-rw-r--r-- | tests/ui/suggestions/copied-and-cloned.fixed | 18 | ||||
-rw-r--r-- | tests/ui/suggestions/copied-and-cloned.rs | 16 | ||||
-rw-r--r-- | tests/ui/suggestions/copied-and-cloned.stderr | 37 |
3 files changed, 55 insertions, 16 deletions
diff --git a/tests/ui/suggestions/copied-and-cloned.fixed b/tests/ui/suggestions/copied-and-cloned.fixed index 77159d5075a..4cecf9e26f9 100644 --- a/tests/ui/suggestions/copied-and-cloned.fixed +++ b/tests/ui/suggestions/copied-and-cloned.fixed @@ -2,6 +2,16 @@ fn expect<T>(_: T) {} +struct Issue114925 { + x: Option<String>, +} + +fn issue_114925(lol: &mut Issue114925, x: Option<&String>) { + lol.x = x.clone().cloned(); + //~^ ERROR mismatched types + //~| HELP use `Option::cloned` to clone the value inside the `Option` +} + fn main() { let x = Some(&()); expect::<Option<()>>(x.copied()); @@ -24,10 +34,10 @@ fn main() { let s = String::new(); let x = Some(s.clone()); let y = Some(&s); - println!("{}", x.as_ref() == y); + println!("{}", x == y.cloned()); //~^ ERROR mismatched types - //~| HELP use `Option::as_ref` to convert `Option<String>` to `Option<&String>` - + //~| HELP use `Option::cloned` to clone the value inside the `Option` + //FIXME(#114050) ~| HELP use `Option::as_ref` to convert `Option<String>` to `Option<&String>` let mut s = (); let x = Some(s); @@ -42,4 +52,6 @@ fn main() { println!("{}", x == y.cloned()); //~^ ERROR mismatched types //~| HELP use `Option::cloned` to clone the value inside the `Option` + + issue_114925(&mut Issue114925 { x: None }, None); } diff --git a/tests/ui/suggestions/copied-and-cloned.rs b/tests/ui/suggestions/copied-and-cloned.rs index c506494ee14..a79928c50d5 100644 --- a/tests/ui/suggestions/copied-and-cloned.rs +++ b/tests/ui/suggestions/copied-and-cloned.rs @@ -2,6 +2,16 @@ fn expect<T>(_: T) {} +struct Issue114925 { + x: Option<String>, +} + +fn issue_114925(lol: &mut Issue114925, x: Option<&String>) { + lol.x = x.clone(); + //~^ ERROR mismatched types + //~| HELP use `Option::cloned` to clone the value inside the `Option` +} + fn main() { let x = Some(&()); expect::<Option<()>>(x); @@ -26,8 +36,8 @@ fn main() { let y = Some(&s); println!("{}", x == y); //~^ ERROR mismatched types - //~| HELP use `Option::as_ref` to convert `Option<String>` to `Option<&String>` - + //~| HELP use `Option::cloned` to clone the value inside the `Option` + //FIXME(#114050) ~| HELP use `Option::as_ref` to convert `Option<String>` to `Option<&String>` let mut s = (); let x = Some(s); @@ -42,4 +52,6 @@ fn main() { println!("{}", x == y); //~^ ERROR mismatched types //~| HELP use `Option::cloned` to clone the value inside the `Option` + + issue_114925(&mut Issue114925 { x: None }, None); } diff --git a/tests/ui/suggestions/copied-and-cloned.stderr b/tests/ui/suggestions/copied-and-cloned.stderr index f8712d0a39e..87b0624d48b 100644 --- a/tests/ui/suggestions/copied-and-cloned.stderr +++ b/tests/ui/suggestions/copied-and-cloned.stderr @@ -1,5 +1,20 @@ error[E0308]: mismatched types - --> $DIR/copied-and-cloned.rs:7:26 + --> $DIR/copied-and-cloned.rs:10:13 + | +LL | lol.x = x.clone(); + | ----- ^^^^^^^^^ expected `Option<String>`, found `Option<&String>` + | | + | expected due to the type of this binding + | + = note: expected enum `Option<String>` + found enum `Option<&String>` +help: use `Option::cloned` to clone the value inside the `Option` + | +LL | lol.x = x.clone().cloned(); + | +++++++++ + +error[E0308]: mismatched types + --> $DIR/copied-and-cloned.rs:17:26 | LL | expect::<Option<()>>(x); | -------------------- ^ expected `Option<()>`, found `Option<&()>` @@ -19,7 +34,7 @@ LL | expect::<Option<()>>(x.copied()); | +++++++++ error[E0308]: mismatched types - --> $DIR/copied-and-cloned.rs:11:30 + --> $DIR/copied-and-cloned.rs:21:30 | LL | expect::<Result<(), ()>>(x); | ------------------------ ^ expected `Result<(), ()>`, found `Result<&(), _>` @@ -39,7 +54,7 @@ LL | expect::<Result<(), ()>>(x.copied()); | +++++++++ error[E0308]: mismatched types - --> $DIR/copied-and-cloned.rs:16:30 + --> $DIR/copied-and-cloned.rs:26:30 | LL | expect::<Option<String>>(x); | ------------------------ ^ expected `Option<String>`, found `Option<&String>` @@ -59,7 +74,7 @@ LL | expect::<Option<String>>(x.cloned()); | +++++++++ error[E0308]: mismatched types - --> $DIR/copied-and-cloned.rs:20:34 + --> $DIR/copied-and-cloned.rs:30:34 | LL | expect::<Result<String, ()>>(x); | ---------------------------- ^ expected `Result<String, ()>`, found `Result<&String, _>` @@ -79,20 +94,20 @@ LL | expect::<Result<String, ()>>(x.cloned()); | +++++++++ error[E0308]: mismatched types - --> $DIR/copied-and-cloned.rs:27:25 + --> $DIR/copied-and-cloned.rs:37:25 | LL | println!("{}", x == y); | ^ expected `Option<String>`, found `Option<&String>` | = note: expected enum `Option<String>` found enum `Option<&String>` -help: use `Option::as_ref` to convert `Option<String>` to `Option<&String>` +help: use `Option::cloned` to clone the value inside the `Option` | -LL | println!("{}", x.as_ref() == y); - | +++++++++ +LL | println!("{}", x == y.cloned()); + | +++++++++ error[E0308]: mismatched types - --> $DIR/copied-and-cloned.rs:35:25 + --> $DIR/copied-and-cloned.rs:45:25 | LL | println!("{}", x == y); | ^ expected `Option<()>`, found `Option<&mut ()>` @@ -105,7 +120,7 @@ LL | println!("{}", x == y.copied()); | +++++++++ error[E0308]: mismatched types - --> $DIR/copied-and-cloned.rs:42:25 + --> $DIR/copied-and-cloned.rs:52:25 | LL | println!("{}", x == y); | ^ expected `Option<String>`, found `Option<&mut String>` @@ -117,6 +132,6 @@ help: use `Option::cloned` to clone the value inside the `Option` LL | println!("{}", x == y.cloned()); | +++++++++ -error: aborting due to 7 previous errors +error: aborting due to 8 previous errors For more information about this error, try `rustc --explain E0308`. |