Suggest expressions' fields even if they're not ADTs
This commit is contained in:
parent
e4417cf020
commit
9cf570995c
14 changed files with 80 additions and 6 deletions
|
@ -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,
|
||||
|
|
|
@ -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
|
||||
|
||||
|
|
|
@ -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
|
||||
|
||||
|
|
|
@ -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
|
||||
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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
|
||||
|
||||
|
|
|
@ -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
|
||||
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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
|
||||
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
||||
|
|
|
@ -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
|
||||
|
||||
|
|
|
@ -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
|
||||
|
||||
|
|
|
@ -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
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue