diff options
| -rw-r--r-- | compiler/rustc_typeck/src/check/expr.rs | 12 | ||||
| -rw-r--r-- | src/test/ui/copy-a-resource.stderr | 4 | ||||
| -rw-r--r-- | src/test/ui/issues/issue-2823.stderr | 4 | ||||
| -rw-r--r-- | src/test/ui/issues/issue-31173.stderr | 4 | ||||
| -rw-r--r-- | src/test/ui/issues/issue-39175.stderr | 4 | ||||
| -rw-r--r-- | src/test/ui/mismatched_types/issue-36053-2.stderr | 4 | ||||
| -rw-r--r-- | src/test/ui/noncopyable-class.stderr | 8 | ||||
| -rw-r--r-- | src/test/ui/suggestions/import-trait-for-method-call.stderr | 4 | ||||
| -rw-r--r-- | src/test/ui/suggestions/mut-borrow-needed-by-trait.stderr | 10 | ||||
| -rw-r--r-- | src/test/ui/suggestions/suggest-using-chars.stderr | 8 | ||||
| -rw-r--r-- | src/test/ui/union/union-derive-clone.mirunsafeck.stderr | 4 | ||||
| -rw-r--r-- | src/test/ui/union/union-derive-clone.thirunsafeck.stderr | 4 | ||||
| -rw-r--r-- | src/test/ui/unique-object-noncopyable.stderr | 8 | ||||
| -rw-r--r-- | src/test/ui/unique-pinned-nocopy.stderr | 8 |
14 files changed, 80 insertions, 6 deletions
diff --git a/compiler/rustc_typeck/src/check/expr.rs b/compiler/rustc_typeck/src/check/expr.rs index 6e97b0bf2ab..a9358835136 100644 --- a/compiler/rustc_typeck/src/check/expr.rs +++ b/compiler/rustc_typeck/src/check/expr.rs @@ -2611,15 +2611,15 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { // up to a depth of three None } else { - // recursively search fields of `candidate_field` if it's a ty::Adt field_path.push(candidate_field.ident(self.tcx).normalize_to_macros_2_0()); let field_ty = candidate_field.ty(self.tcx, subst); - if let Some((nested_fields, subst)) = self.get_field_candidates(span, field_ty) { - for field in nested_fields.iter() { + if matches(candidate_field, field_ty) { + return Some(field_path); + } else if let Some((nested_fields, subst)) = self.get_field_candidates(span, field_ty) { + // recursively search fields of `candidate_field` if it's a ty::Adt + for field in nested_fields { if field.vis.is_accessible_from(id, self.tcx) { - if matches(candidate_field, field_ty) { - return Some(field_path); - } else if let Some(field_path) = self.check_for_nested_field_satisfying( + if let Some(field_path) = self.check_for_nested_field_satisfying( span, matches, field, diff --git a/src/test/ui/copy-a-resource.stderr b/src/test/ui/copy-a-resource.stderr index 128087f1e37..b92449c6e0a 100644 --- a/src/test/ui/copy-a-resource.stderr +++ b/src/test/ui/copy-a-resource.stderr @@ -10,6 +10,10 @@ LL | let _y = x.clone(); = help: items from traits can only be used if the trait is implemented and in scope = note: the following trait defines an item `clone`, perhaps you need to implement it: candidate #1: `Clone` +help: one of the expressions' fields has a method of the same name + | +LL | let _y = x.i.clone(); + | ++ error: aborting due to previous error diff --git a/src/test/ui/issues/issue-2823.stderr b/src/test/ui/issues/issue-2823.stderr index b5a2b2f55a6..208b340d064 100644 --- a/src/test/ui/issues/issue-2823.stderr +++ b/src/test/ui/issues/issue-2823.stderr @@ -10,6 +10,10 @@ LL | let _d = c.clone(); = help: items from traits can only be used if the trait is implemented and in scope = note: the following trait defines an item `clone`, perhaps you need to implement it: candidate #1: `Clone` +help: one of the expressions' fields has a method of the same name + | +LL | let _d = c.x.clone(); + | ++ error: aborting due to previous error diff --git a/src/test/ui/issues/issue-31173.stderr b/src/test/ui/issues/issue-31173.stderr index 68337a715e1..e8797ea7b5b 100644 --- a/src/test/ui/issues/issue-31173.stderr +++ b/src/test/ui/issues/issue-31173.stderr @@ -33,6 +33,10 @@ LL | pub struct TakeWhile<I, P> { which is required by `Cloned<TakeWhile<&mut std::vec::IntoIter<u8>, [closure@$DIR/issue-31173.rs:6:39: 6:43]>>: Iterator` `Cloned<TakeWhile<&mut std::vec::IntoIter<u8>, [closure@$DIR/issue-31173.rs:6:39: 6:43]>>: Iterator` which is required by `&mut Cloned<TakeWhile<&mut std::vec::IntoIter<u8>, [closure@$DIR/issue-31173.rs:6:39: 6:43]>>: Iterator` +help: one of the expressions' fields has a method of the same name + | +LL | .it.collect(); + | +++ error: aborting due to 2 previous errors diff --git a/src/test/ui/issues/issue-39175.stderr b/src/test/ui/issues/issue-39175.stderr index afceae82e68..b19f58d2a38 100644 --- a/src/test/ui/issues/issue-39175.stderr +++ b/src/test/ui/issues/issue-39175.stderr @@ -5,6 +5,10 @@ LL | Command::new("echo").arg("hello").exec(); | ^^^^ method not found in `&mut Command` | = help: items from traits can only be used if the trait is in scope +help: one of the expressions' fields has a method of the same name + | +LL | Command::new("echo").arg("hello").inner.exec(); + | ++++++ help: the following trait is implemented but not in scope; perhaps add a `use` for it: | LL | use std::os::unix::process::CommandExt; diff --git a/src/test/ui/mismatched_types/issue-36053-2.stderr b/src/test/ui/mismatched_types/issue-36053-2.stderr index b11ea97d160..c3c8e5f272e 100644 --- a/src/test/ui/mismatched_types/issue-36053-2.stderr +++ b/src/test/ui/mismatched_types/issue-36053-2.stderr @@ -35,6 +35,10 @@ LL | pub struct Filter<I, P> { which is required by `Filter<Fuse<std::iter::Once<&str>>, [closure@$DIR/issue-36053-2.rs:7:39: 7:48]>: Iterator` `Filter<Fuse<std::iter::Once<&str>>, [closure@$DIR/issue-36053-2.rs:7:39: 7:48]>: Iterator` which is required by `&mut Filter<Fuse<std::iter::Once<&str>>, [closure@$DIR/issue-36053-2.rs:7:39: 7:48]>: Iterator` +help: one of the expressions' fields has a method of the same name + | +LL | once::<&str>("str").fuse().filter(|a: &str| true).iter.count(); + | +++++ error: aborting due to 2 previous errors diff --git a/src/test/ui/noncopyable-class.stderr b/src/test/ui/noncopyable-class.stderr index 0c696163a26..15e22e946da 100644 --- a/src/test/ui/noncopyable-class.stderr +++ b/src/test/ui/noncopyable-class.stderr @@ -10,6 +10,14 @@ LL | let _y = x.clone(); = help: items from traits can only be used if the trait is implemented and in scope = note: the following trait defines an item `clone`, perhaps you need to implement it: candidate #1: `Clone` +help: one of the expressions' fields has a method of the same name + | +LL | let _y = x.i.clone(); + | ++ +help: one of the expressions' fields has a method of the same name + | +LL | let _y = x.j.x.clone(); + | ++++ error: aborting due to previous error diff --git a/src/test/ui/suggestions/import-trait-for-method-call.stderr b/src/test/ui/suggestions/import-trait-for-method-call.stderr index bac8de79872..f220458f321 100644 --- a/src/test/ui/suggestions/import-trait-for-method-call.stderr +++ b/src/test/ui/suggestions/import-trait-for-method-call.stderr @@ -10,6 +10,10 @@ LL | fn finish(&self) -> u64; | ------ the method is available for `DefaultHasher` here | = help: items from traits can only be used if the trait is in scope +help: one of the expressions' fields has a method of the same name + | +LL | h.0.finish() + | ++ help: the following trait is implemented but not in scope; perhaps add a `use` for it: | LL | use std::hash::Hasher; diff --git a/src/test/ui/suggestions/mut-borrow-needed-by-trait.stderr b/src/test/ui/suggestions/mut-borrow-needed-by-trait.stderr index d121932c842..e19bc5a1fd4 100644 --- a/src/test/ui/suggestions/mut-borrow-needed-by-trait.stderr +++ b/src/test/ui/suggestions/mut-borrow-needed-by-trait.stderr @@ -41,6 +41,16 @@ LL | pub struct BufWriter<W: Write> { `&dyn std::io::Write: std::io::Write` which is required by `BufWriter<&dyn std::io::Write>: std::io::Write` = note: this error originates in the macro `writeln` (in Nightly builds, run with -Z macro-backtrace for more info) +help: one of the expressions' fields has a method of the same name + --> $SRC_DIR/core/src/macros/mod.rs:LL:COL + | +LL | $dst.inner.write_fmt($crate::format_args_nl!($($arg)*)) + | ++++++ +help: one of the expressions' fields has a method of the same name + --> $SRC_DIR/core/src/macros/mod.rs:LL:COL + | +LL | $dst.buf.write_fmt($crate::format_args_nl!($($arg)*)) + | ++++ error: aborting due to 3 previous errors diff --git a/src/test/ui/suggestions/suggest-using-chars.stderr b/src/test/ui/suggestions/suggest-using-chars.stderr index 99bcfb08a08..1690309719f 100644 --- a/src/test/ui/suggestions/suggest-using-chars.stderr +++ b/src/test/ui/suggestions/suggest-using-chars.stderr @@ -25,6 +25,10 @@ help: because of the in-memory representation of `&str`, to obtain an `Iterator` | LL | let _ = String::from("bar").chars(); | ~~~~~ +help: one of the expressions' fields has a method of the same name + | +LL | let _ = String::from("bar").vec.iter(); + | ++++ error[E0599]: no method named `iter` found for reference `&String` in the current scope --> $DIR/suggest-using-chars.rs:5:36 @@ -36,6 +40,10 @@ help: because of the in-memory representation of `&str`, to obtain an `Iterator` | LL | let _ = (&String::from("bar")).chars(); | ~~~~~ +help: one of the expressions' fields has a method of the same name + | +LL | let _ = (&String::from("bar")).vec.iter(); + | ++++ error[E0599]: no method named `iter` found for type `{integer}` in the current scope --> $DIR/suggest-using-chars.rs:6:15 diff --git a/src/test/ui/union/union-derive-clone.mirunsafeck.stderr b/src/test/ui/union/union-derive-clone.mirunsafeck.stderr index 148fb504670..44c9d4a8438 100644 --- a/src/test/ui/union/union-derive-clone.mirunsafeck.stderr +++ b/src/test/ui/union/union-derive-clone.mirunsafeck.stderr @@ -42,6 +42,10 @@ help: consider annotating `CloneNoCopy` with `#[derive(Clone, Copy)]` | LL | #[derive(Clone, Copy)] | +help: one of the expressions' fields has a method of the same name + | +LL | let w = u.a.clone(); + | ++ error: aborting due to 2 previous errors diff --git a/src/test/ui/union/union-derive-clone.thirunsafeck.stderr b/src/test/ui/union/union-derive-clone.thirunsafeck.stderr index 148fb504670..44c9d4a8438 100644 --- a/src/test/ui/union/union-derive-clone.thirunsafeck.stderr +++ b/src/test/ui/union/union-derive-clone.thirunsafeck.stderr @@ -42,6 +42,10 @@ help: consider annotating `CloneNoCopy` with `#[derive(Clone, Copy)]` | LL | #[derive(Clone, Copy)] | +help: one of the expressions' fields has a method of the same name + | +LL | let w = u.a.clone(); + | ++ error: aborting due to 2 previous errors diff --git a/src/test/ui/unique-object-noncopyable.stderr b/src/test/ui/unique-object-noncopyable.stderr index 98a9bd07ed2..12917d54114 100644 --- a/src/test/ui/unique-object-noncopyable.stderr +++ b/src/test/ui/unique-object-noncopyable.stderr @@ -23,6 +23,14 @@ LL | | >(Unique<T>, A); which is required by `Box<dyn Foo>: Clone` `dyn Foo: Clone` which is required by `Box<dyn Foo>: Clone` +help: one of the expressions' fields has a method of the same name + | +LL | let _z = y.0.clone(); + | ++ +help: one of the expressions' fields has a method of the same name + | +LL | let _z = y.1.clone(); + | ++ error: aborting due to previous error diff --git a/src/test/ui/unique-pinned-nocopy.stderr b/src/test/ui/unique-pinned-nocopy.stderr index 7af9c684b72..cc9bdd26e11 100644 --- a/src/test/ui/unique-pinned-nocopy.stderr +++ b/src/test/ui/unique-pinned-nocopy.stderr @@ -25,6 +25,14 @@ help: consider annotating `R` with `#[derive(Clone)]` | LL | #[derive(Clone)] | +help: one of the expressions' fields has a method of the same name + | +LL | let _j = i.0.clone(); + | ++ +help: one of the expressions' fields has a method of the same name + | +LL | let _j = i.1.clone(); + | ++ error: aborting due to previous error |
