use structured suggestions for nonexistent fields
This commit is contained in:
parent
79d8a0fcef
commit
dfc326d0e2
18 changed files with 50 additions and 35 deletions
|
@ -3415,8 +3415,12 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
|
||||||
if let Some(suggested_field_name) =
|
if let Some(suggested_field_name) =
|
||||||
Self::suggest_field_name(def.non_enum_variant(),
|
Self::suggest_field_name(def.non_enum_variant(),
|
||||||
&field.as_str(), vec![]) {
|
&field.as_str(), vec![]) {
|
||||||
err.span_label(field.span,
|
err.span_suggestion_with_applicability(
|
||||||
format!("did you mean `{}`?", suggested_field_name));
|
field.span,
|
||||||
|
"a field with a similar name exists",
|
||||||
|
suggested_field_name.to_string(),
|
||||||
|
Applicability::MaybeIncorrect,
|
||||||
|
);
|
||||||
} else {
|
} else {
|
||||||
err.span_label(field.span, "unknown field");
|
err.span_label(field.span, "unknown field");
|
||||||
let struct_variant_def = def.non_enum_variant();
|
let struct_variant_def = def.non_enum_variant();
|
||||||
|
@ -3543,8 +3547,12 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
|
||||||
if let Some(field_name) = Self::suggest_field_name(variant,
|
if let Some(field_name) = Self::suggest_field_name(variant,
|
||||||
&field.ident.as_str(),
|
&field.ident.as_str(),
|
||||||
skip_fields.collect()) {
|
skip_fields.collect()) {
|
||||||
err.span_label(field.ident.span,
|
err.span_suggestion_with_applicability(
|
||||||
format!("field does not exist - did you mean `{}`?", field_name));
|
field.ident.span,
|
||||||
|
"a field with a similar name exists",
|
||||||
|
field_name.to_string(),
|
||||||
|
Applicability::MaybeIncorrect,
|
||||||
|
);
|
||||||
} else {
|
} else {
|
||||||
match ty.sty {
|
match ty.sty {
|
||||||
ty::Adt(adt, ..) => {
|
ty::Adt(adt, ..) => {
|
||||||
|
@ -5257,13 +5265,15 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
|
||||||
if let Some(adt_def) = adt_def {
|
if let Some(adt_def) = adt_def {
|
||||||
match adt_def.adt_kind() {
|
match adt_def.adt_kind() {
|
||||||
AdtKind::Enum => {
|
AdtKind::Enum => {
|
||||||
err.note("did you mean to use one of the enum's variants?");
|
err.help("did you mean to use one of the enum's variants?");
|
||||||
},
|
},
|
||||||
AdtKind::Struct |
|
AdtKind::Struct |
|
||||||
AdtKind::Union => {
|
AdtKind::Union => {
|
||||||
err.span_label(
|
err.span_suggestion_with_applicability(
|
||||||
span,
|
span,
|
||||||
format!("did you mean `Self {{ /* fields */ }}`?"),
|
"use curly brackets",
|
||||||
|
String::from("Self { /* fields */ }"),
|
||||||
|
Applicability::HasPlaceholders,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,7 +2,7 @@ error[E0609]: no field `baz` on type `Foo`
|
||||||
--> $DIR/issue-36798.rs:7:7
|
--> $DIR/issue-36798.rs:7:7
|
||||||
|
|
|
|
||||||
LL | f.baz; //~ ERROR no field
|
LL | f.baz; //~ ERROR no field
|
||||||
| ^^^ did you mean `bar`?
|
| ^^^ help: a field with a similar name exists: `bar`
|
||||||
|
|
||||||
error: aborting due to previous error
|
error: aborting due to previous error
|
||||||
|
|
||||||
|
|
|
@ -2,7 +2,7 @@ error[E0560]: struct `submodule::Demo` has no field named `inocently_mispellable
|
||||||
--> $DIR/issue-42599_available_fields_note.rs:16:39
|
--> $DIR/issue-42599_available_fields_note.rs:16:39
|
||||||
|
|
|
|
||||||
LL | Self { secret_integer: 2, inocently_mispellable: () }
|
LL | Self { secret_integer: 2, inocently_mispellable: () }
|
||||||
| ^^^^^^^^^^^^^^^^^^^^^ field does not exist - did you mean `innocently_misspellable`?
|
| ^^^^^^^^^^^^^^^^^^^^^ help: a field with a similar name exists: `innocently_misspellable`
|
||||||
|
|
||||||
error[E0560]: struct `submodule::Demo` has no field named `egregiously_nonexistent_field`
|
error[E0560]: struct `submodule::Demo` has no field named `egregiously_nonexistent_field`
|
||||||
--> $DIR/issue-42599_available_fields_note.rs:21:39
|
--> $DIR/issue-42599_available_fields_note.rs:21:39
|
||||||
|
@ -16,7 +16,7 @@ error[E0609]: no field `inocently_mispellable` on type `submodule::Demo`
|
||||||
--> $DIR/issue-42599_available_fields_note.rs:32:41
|
--> $DIR/issue-42599_available_fields_note.rs:32:41
|
||||||
|
|
|
|
||||||
LL | let innocent_field_misaccess = demo.inocently_mispellable;
|
LL | let innocent_field_misaccess = demo.inocently_mispellable;
|
||||||
| ^^^^^^^^^^^^^^^^^^^^^ did you mean `innocently_misspellable`?
|
| ^^^^^^^^^^^^^^^^^^^^^ help: a field with a similar name exists: `innocently_misspellable`
|
||||||
|
|
||||||
error[E0609]: no field `egregiously_nonexistent_field` on type `submodule::Demo`
|
error[E0609]: no field `egregiously_nonexistent_field` on type `submodule::Demo`
|
||||||
--> $DIR/issue-42599_available_fields_note.rs:35:42
|
--> $DIR/issue-42599_available_fields_note.rs:35:42
|
||||||
|
|
|
@ -2,7 +2,7 @@ error[E0609]: no field `1` on type `Foo`
|
||||||
--> $DIR/ex-E0612.rs:5:6
|
--> $DIR/ex-E0612.rs:5:6
|
||||||
|
|
|
|
||||||
LL | y.1; //~ ERROR no field `1` on type `Foo`
|
LL | y.1; //~ ERROR no field `1` on type `Foo`
|
||||||
| ^ did you mean `0`?
|
| ^ help: a field with a similar name exists: `0`
|
||||||
|
|
||||||
error: aborting due to previous error
|
error: aborting due to previous error
|
||||||
|
|
||||||
|
|
|
@ -2,7 +2,7 @@ error[E0609]: no field `00` on type `Verdict`
|
||||||
--> $DIR/issue-47073-zero-padded-tuple-struct-indices.rs:8:30
|
--> $DIR/issue-47073-zero-padded-tuple-struct-indices.rs:8:30
|
||||||
|
|
|
|
||||||
LL | let _condemned = justice.00;
|
LL | let _condemned = justice.00;
|
||||||
| ^^ did you mean `0`?
|
| ^^ help: a field with a similar name exists: `0`
|
||||||
|
|
||||||
error[E0609]: no field `001` on type `Verdict`
|
error[E0609]: no field `001` on type `Verdict`
|
||||||
--> $DIR/issue-47073-zero-padded-tuple-struct-indices.rs:10:31
|
--> $DIR/issue-47073-zero-padded-tuple-struct-indices.rs:10:31
|
||||||
|
|
|
@ -2,7 +2,7 @@ error[E0560]: struct `NonCopyable` has no field named `p`
|
||||||
--> $DIR/issue-4736.rs:4:26
|
--> $DIR/issue-4736.rs:4:26
|
||||||
|
|
|
|
||||||
LL | let z = NonCopyable{ p: () }; //~ ERROR struct `NonCopyable` has no field named `p`
|
LL | let z = NonCopyable{ p: () }; //~ ERROR struct `NonCopyable` has no field named `p`
|
||||||
| ^ field does not exist - did you mean `0`?
|
| ^ help: a field with a similar name exists: `0`
|
||||||
|
|
||||||
error: aborting due to previous error
|
error: aborting due to previous error
|
||||||
|
|
||||||
|
|
|
@ -4,7 +4,7 @@ error: the `Self` constructor can only be used with tuple or unit structs
|
||||||
LL | let _ = Self;
|
LL | let _ = Self;
|
||||||
| ^^^^
|
| ^^^^
|
||||||
|
|
|
|
||||||
= note: did you mean to use one of the enum's variants?
|
= help: did you mean to use one of the enum's variants?
|
||||||
|
|
||||||
error: the `Self` constructor can only be used with tuple or unit structs
|
error: the `Self` constructor can only be used with tuple or unit structs
|
||||||
--> $DIR/issue-56199.rs:8:17
|
--> $DIR/issue-56199.rs:8:17
|
||||||
|
@ -12,19 +12,19 @@ error: the `Self` constructor can only be used with tuple or unit structs
|
||||||
LL | let _ = Self();
|
LL | let _ = Self();
|
||||||
| ^^^^
|
| ^^^^
|
||||||
|
|
|
|
||||||
= note: did you mean to use one of the enum's variants?
|
= help: did you mean to use one of the enum's variants?
|
||||||
|
|
||||||
error: the `Self` constructor can only be used with tuple or unit structs
|
error: the `Self` constructor can only be used with tuple or unit structs
|
||||||
--> $DIR/issue-56199.rs:15:17
|
--> $DIR/issue-56199.rs:15:17
|
||||||
|
|
|
|
||||||
LL | let _ = Self;
|
LL | let _ = Self;
|
||||||
| ^^^^ did you mean `Self { /* fields */ }`?
|
| ^^^^ help: use curly brackets: `Self { /* fields */ }`
|
||||||
|
|
||||||
error: the `Self` constructor can only be used with tuple or unit structs
|
error: the `Self` constructor can only be used with tuple or unit structs
|
||||||
--> $DIR/issue-56199.rs:17:17
|
--> $DIR/issue-56199.rs:17:17
|
||||||
|
|
|
|
||||||
LL | let _ = Self();
|
LL | let _ = Self();
|
||||||
| ^^^^ did you mean `Self { /* fields */ }`?
|
| ^^^^ help: use curly brackets: `Self { /* fields */ }`
|
||||||
|
|
||||||
error: aborting due to 4 previous errors
|
error: aborting due to 4 previous errors
|
||||||
|
|
||||||
|
|
|
@ -2,7 +2,7 @@ error: the `Self` constructor can only be used with tuple or unit structs
|
||||||
--> $DIR/issue-56835.rs:4:12
|
--> $DIR/issue-56835.rs:4:12
|
||||||
|
|
|
|
||||||
LL | fn bar(Self(foo): Self) {}
|
LL | fn bar(Self(foo): Self) {}
|
||||||
| ^^^^^^^^^ did you mean `Self { /* fields */ }`?
|
| ^^^^^^^^^ help: use curly brackets: `Self { /* fields */ }`
|
||||||
|
|
||||||
error[E0164]: expected tuple struct/variant, found self constructor `Self`
|
error[E0164]: expected tuple struct/variant, found self constructor `Self`
|
||||||
--> $DIR/issue-56835.rs:4:12
|
--> $DIR/issue-56835.rs:4:12
|
||||||
|
|
|
@ -2,7 +2,7 @@ error[E0560]: struct `rmeta_meta::Foo` has no field named `field2`
|
||||||
--> $DIR/rmeta_meta_main.rs:13:19
|
--> $DIR/rmeta_meta_main.rs:13:19
|
||||||
|
|
|
|
||||||
LL | let _ = Foo { field2: 42 }; //~ ERROR struct `rmeta_meta::Foo` has no field named `field2`
|
LL | let _ = Foo { field2: 42 }; //~ ERROR struct `rmeta_meta::Foo` has no field named `field2`
|
||||||
| ^^^^^^ field does not exist - did you mean `field`?
|
| ^^^^^^ help: a field with a similar name exists: `field`
|
||||||
|
|
||||||
error: aborting due to previous error
|
error: aborting due to previous error
|
||||||
|
|
||||||
|
|
|
@ -2,7 +2,7 @@ error[E0560]: struct `A` has no field named `bar`
|
||||||
--> $DIR/struct-fields-hints-no-dupe.rs:10:9
|
--> $DIR/struct-fields-hints-no-dupe.rs:10:9
|
||||||
|
|
|
|
||||||
LL | bar : 42,
|
LL | bar : 42,
|
||||||
| ^^^ field does not exist - did you mean `barr`?
|
| ^^^ help: a field with a similar name exists: `barr`
|
||||||
|
|
||||||
error: aborting due to previous error
|
error: aborting due to previous error
|
||||||
|
|
||||||
|
|
|
@ -2,7 +2,7 @@ error[E0560]: struct `A` has no field named `bar`
|
||||||
--> $DIR/struct-fields-hints.rs:10:9
|
--> $DIR/struct-fields-hints.rs:10:9
|
||||||
|
|
|
|
||||||
LL | bar : 42,
|
LL | bar : 42,
|
||||||
| ^^^ field does not exist - did you mean `car`?
|
| ^^^ help: a field with a similar name exists: `car`
|
||||||
|
|
||||||
error: aborting due to previous error
|
error: aborting due to previous error
|
||||||
|
|
||||||
|
|
|
@ -8,7 +8,8 @@ fn main() {
|
||||||
foo: 0,
|
foo: 0,
|
||||||
bar: 0.5,
|
bar: 0.5,
|
||||||
};
|
};
|
||||||
let x = foo.baa;//~ no field `baa` on type `BuildData`
|
let x = foo.baa; //~ ERROR no field `baa` on type `BuildData`
|
||||||
//~^ did you mean `bar`?
|
//~| HELP a field with a similar name exists
|
||||||
|
//~| SUGGESTION bar
|
||||||
println!("{}", x);
|
println!("{}", x);
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,8 +1,8 @@
|
||||||
error[E0609]: no field `baa` on type `BuildData`
|
error[E0609]: no field `baa` on type `BuildData`
|
||||||
--> $DIR/struct-fields-typo.rs:11:17
|
--> $DIR/struct-fields-typo.rs:11:17
|
||||||
|
|
|
|
||||||
LL | let x = foo.baa;//~ no field `baa` on type `BuildData`
|
LL | let x = foo.baa; //~ ERROR no field `baa` on type `BuildData`
|
||||||
| ^^^ did you mean `bar`?
|
| ^^^ help: a field with a similar name exists: `bar`
|
||||||
|
|
||||||
error: aborting due to previous error
|
error: aborting due to previous error
|
||||||
|
|
||||||
|
|
|
@ -2,7 +2,7 @@ error[E0560]: struct `xc::B` has no field named `aa`
|
||||||
--> $DIR/suggest-private-fields.rs:15:9
|
--> $DIR/suggest-private-fields.rs:15:9
|
||||||
|
|
|
|
||||||
LL | aa: 20,
|
LL | aa: 20,
|
||||||
| ^^ field does not exist - did you mean `a`?
|
| ^^ help: a field with a similar name exists: `a`
|
||||||
|
|
||||||
error[E0560]: struct `xc::B` has no field named `bb`
|
error[E0560]: struct `xc::B` has no field named `bb`
|
||||||
--> $DIR/suggest-private-fields.rs:17:9
|
--> $DIR/suggest-private-fields.rs:17:9
|
||||||
|
@ -16,13 +16,13 @@ error[E0560]: struct `A` has no field named `aa`
|
||||||
--> $DIR/suggest-private-fields.rs:22:9
|
--> $DIR/suggest-private-fields.rs:22:9
|
||||||
|
|
|
|
||||||
LL | aa: 20,
|
LL | aa: 20,
|
||||||
| ^^ field does not exist - did you mean `a`?
|
| ^^ help: a field with a similar name exists: `a`
|
||||||
|
|
||||||
error[E0560]: struct `A` has no field named `bb`
|
error[E0560]: struct `A` has no field named `bb`
|
||||||
--> $DIR/suggest-private-fields.rs:24:9
|
--> $DIR/suggest-private-fields.rs:24:9
|
||||||
|
|
|
|
||||||
LL | bb: 20,
|
LL | bb: 20,
|
||||||
| ^^ field does not exist - did you mean `b`?
|
| ^^ help: a field with a similar name exists: `b`
|
||||||
|
|
||||||
error: aborting due to 4 previous errors
|
error: aborting due to 4 previous errors
|
||||||
|
|
||||||
|
|
|
@ -2,7 +2,7 @@ error[E0609]: no field `0` on type `Point`
|
||||||
--> $DIR/tuple-index-not-tuple.rs:6:12
|
--> $DIR/tuple-index-not-tuple.rs:6:12
|
||||||
|
|
|
|
||||||
LL | origin.0;
|
LL | origin.0;
|
||||||
| ^ did you mean `x`?
|
| ^ help: a field with a similar name exists: `x`
|
||||||
|
|
||||||
error[E0609]: no field `0` on type `Empty`
|
error[E0609]: no field `0` on type `Empty`
|
||||||
--> $DIR/tuple-index-not-tuple.rs:8:11
|
--> $DIR/tuple-index-not-tuple.rs:8:11
|
||||||
|
|
|
@ -2,7 +2,7 @@ error[E0609]: no field `2` on type `Point`
|
||||||
--> $DIR/tuple-index-out-of-bounds.rs:7:12
|
--> $DIR/tuple-index-out-of-bounds.rs:7:12
|
||||||
|
|
|
|
||||||
LL | origin.2;
|
LL | origin.2;
|
||||||
| ^ did you mean `0`?
|
| ^ help: a field with a similar name exists: `0`
|
||||||
|
|
||||||
error[E0609]: no field `2` on type `({integer}, {integer})`
|
error[E0609]: no field `2` on type `({integer}, {integer})`
|
||||||
--> $DIR/tuple-index-out-of-bounds.rs:12:11
|
--> $DIR/tuple-index-out-of-bounds.rs:12:11
|
||||||
|
|
|
@ -9,8 +9,12 @@ impl U {
|
||||||
fn main() {
|
fn main() {
|
||||||
let u = U { principle: 0 };
|
let u = U { principle: 0 };
|
||||||
//~^ ERROR union `U` has no field named `principle`
|
//~^ ERROR union `U` has no field named `principle`
|
||||||
|
//~| HELP a field with a similar name exists
|
||||||
|
//~| SUGGESTION principal
|
||||||
let w = u.principial; //~ ERROR no field `principial` on type `U`
|
let w = u.principial; //~ ERROR no field `principial` on type `U`
|
||||||
//~^ did you mean `principal`?
|
//~| HELP a field with a similar name exists
|
||||||
|
//~| SUGGESTION principal
|
||||||
|
|
||||||
let y = u.calculate; //~ ERROR attempted to take value of method `calculate` on type `U`
|
let y = u.calculate; //~ ERROR attempted to take value of method `calculate` on type `U`
|
||||||
|
//~| HELP maybe a `()` to call it is missing
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,16 +2,16 @@ error[E0560]: union `U` has no field named `principle`
|
||||||
--> $DIR/union-suggest-field.rs:10:17
|
--> $DIR/union-suggest-field.rs:10:17
|
||||||
|
|
|
|
||||||
LL | let u = U { principle: 0 };
|
LL | let u = U { principle: 0 };
|
||||||
| ^^^^^^^^^ field does not exist - did you mean `principal`?
|
| ^^^^^^^^^ help: a field with a similar name exists: `principal`
|
||||||
|
|
||||||
error[E0609]: no field `principial` on type `U`
|
error[E0609]: no field `principial` on type `U`
|
||||||
--> $DIR/union-suggest-field.rs:12:15
|
--> $DIR/union-suggest-field.rs:14:15
|
||||||
|
|
|
|
||||||
LL | let w = u.principial; //~ ERROR no field `principial` on type `U`
|
LL | let w = u.principial; //~ ERROR no field `principial` on type `U`
|
||||||
| ^^^^^^^^^^ did you mean `principal`?
|
| ^^^^^^^^^^ help: a field with a similar name exists: `principal`
|
||||||
|
|
||||||
error[E0615]: attempted to take value of method `calculate` on type `U`
|
error[E0615]: attempted to take value of method `calculate` on type `U`
|
||||||
--> $DIR/union-suggest-field.rs:15:15
|
--> $DIR/union-suggest-field.rs:18:15
|
||||||
|
|
|
|
||||||
LL | let y = u.calculate; //~ ERROR attempted to take value of method `calculate` on type `U`
|
LL | let y = u.calculate; //~ ERROR attempted to take value of method `calculate` on type `U`
|
||||||
| ^^^^^^^^^
|
| ^^^^^^^^^
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue