summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorbors <bors@rust-lang.org>2018-12-31 20:56:19 +0000
committerbors <bors@rust-lang.org>2018-12-31 20:56:19 +0000
commit9eac386342c601b14311b435f2b6d314fc817bb5 (patch)
treec7ccb9e9b2497adb98f75085eca41d388463a411 /src
parent6efaef61899f6551914156f69809aa7d5854399d (diff)
parentdfc326d0e212bd644d04906ca21bb012cf970cb4 (diff)
downloadrust-9eac386342c601b14311b435f2b6d314fc817bb5.tar.gz
Auto merge of #57047 - euclio:field-structured-suggestions, r=estebank
use structured suggestions for nonexistent fields r? @estebank
Diffstat (limited to 'src')
-rw-r--r--src/librustc_typeck/check/mod.rs24
-rw-r--r--src/test/ui/did_you_mean/issue-36798.stderr2
-rw-r--r--src/test/ui/did_you_mean/issue-42599_available_fields_note.stderr4
-rw-r--r--src/test/ui/error-codes/ex-E0612.stderr2
-rw-r--r--src/test/ui/issues/issue-47073-zero-padded-tuple-struct-indices.stderr2
-rw-r--r--src/test/ui/issues/issue-4736.stderr2
-rw-r--r--src/test/ui/issues/issue-56199.stderr8
-rw-r--r--src/test/ui/issues/issue-56835.stderr2
-rw-r--r--src/test/ui/rmeta_meta_main.stderr2
-rw-r--r--src/test/ui/structs/struct-fields-hints-no-dupe.stderr2
-rw-r--r--src/test/ui/structs/struct-fields-hints.stderr2
-rw-r--r--src/test/ui/structs/struct-fields-typo.rs5
-rw-r--r--src/test/ui/structs/struct-fields-typo.stderr4
-rw-r--r--src/test/ui/suggestions/suggest-private-fields.stderr6
-rw-r--r--src/test/ui/tuple/tuple-index-not-tuple.stderr2
-rw-r--r--src/test/ui/tuple/tuple-index-out-of-bounds.stderr2
-rw-r--r--src/test/ui/union/union-suggest-field.rs6
-rw-r--r--src/test/ui/union/union-suggest-field.stderr8
18 files changed, 50 insertions, 35 deletions
diff --git a/src/librustc_typeck/check/mod.rs b/src/librustc_typeck/check/mod.rs
index 39beb283285..974df84beef 100644
--- a/src/librustc_typeck/check/mod.rs
+++ b/src/librustc_typeck/check/mod.rs
@@ -3422,8 +3422,12 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
if let Some(suggested_field_name) =
Self::suggest_field_name(def.non_enum_variant(),
&field.as_str(), vec![]) {
- err.span_label(field.span,
- format!("did you mean `{}`?", suggested_field_name));
+ err.span_suggestion_with_applicability(
+ field.span,
+ "a field with a similar name exists",
+ suggested_field_name.to_string(),
+ Applicability::MaybeIncorrect,
+ );
} else {
err.span_label(field.span, "unknown field");
let struct_variant_def = def.non_enum_variant();
@@ -3550,8 +3554,12 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
if let Some(field_name) = Self::suggest_field_name(variant,
&field.ident.as_str(),
skip_fields.collect()) {
- err.span_label(field.ident.span,
- format!("field does not exist - did you mean `{}`?", field_name));
+ err.span_suggestion_with_applicability(
+ field.ident.span,
+ "a field with a similar name exists",
+ field_name.to_string(),
+ Applicability::MaybeIncorrect,
+ );
} else {
match ty.sty {
ty::Adt(adt, ..) => {
@@ -5195,13 +5203,15 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
if let Some(adt_def) = adt_def {
match adt_def.adt_kind() {
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::Union => {
- err.span_label(
+ err.span_suggestion_with_applicability(
span,
- format!("did you mean `Self {{ /* fields */ }}`?"),
+ "use curly brackets",
+ String::from("Self { /* fields */ }"),
+ Applicability::HasPlaceholders,
);
}
}
diff --git a/src/test/ui/did_you_mean/issue-36798.stderr b/src/test/ui/did_you_mean/issue-36798.stderr
index 41dc15c1b81..8273fad4764 100644
--- a/src/test/ui/did_you_mean/issue-36798.stderr
+++ b/src/test/ui/did_you_mean/issue-36798.stderr
@@ -2,7 +2,7 @@ error[E0609]: no field `baz` on type `Foo`
--> $DIR/issue-36798.rs:7:7
|
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
diff --git a/src/test/ui/did_you_mean/issue-42599_available_fields_note.stderr b/src/test/ui/did_you_mean/issue-42599_available_fields_note.stderr
index 808ff1670da..e5dd61c45d6 100644
--- a/src/test/ui/did_you_mean/issue-42599_available_fields_note.stderr
+++ b/src/test/ui/did_you_mean/issue-42599_available_fields_note.stderr
@@ -2,7 +2,7 @@ error[E0560]: struct `submodule::Demo` has no field named `inocently_mispellable
--> $DIR/issue-42599_available_fields_note.rs:16:39
|
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`
--> $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
|
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`
--> $DIR/issue-42599_available_fields_note.rs:35:42
diff --git a/src/test/ui/error-codes/ex-E0612.stderr b/src/test/ui/error-codes/ex-E0612.stderr
index e65e8bd8142..0f498d16439 100644
--- a/src/test/ui/error-codes/ex-E0612.stderr
+++ b/src/test/ui/error-codes/ex-E0612.stderr
@@ -2,7 +2,7 @@ error[E0609]: no field `1` on type `Foo`
--> $DIR/ex-E0612.rs:5:6
|
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
diff --git a/src/test/ui/issues/issue-47073-zero-padded-tuple-struct-indices.stderr b/src/test/ui/issues/issue-47073-zero-padded-tuple-struct-indices.stderr
index 6e8d1ef2f7b..5e1b816defd 100644
--- a/src/test/ui/issues/issue-47073-zero-padded-tuple-struct-indices.stderr
+++ b/src/test/ui/issues/issue-47073-zero-padded-tuple-struct-indices.stderr
@@ -2,7 +2,7 @@ error[E0609]: no field `00` on type `Verdict`
--> $DIR/issue-47073-zero-padded-tuple-struct-indices.rs:8:30
|
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`
--> $DIR/issue-47073-zero-padded-tuple-struct-indices.rs:10:31
diff --git a/src/test/ui/issues/issue-4736.stderr b/src/test/ui/issues/issue-4736.stderr
index eac7e65064d..39c649ba3e0 100644
--- a/src/test/ui/issues/issue-4736.stderr
+++ b/src/test/ui/issues/issue-4736.stderr
@@ -2,7 +2,7 @@ error[E0560]: struct `NonCopyable` has no field named `p`
--> $DIR/issue-4736.rs:4:26
|
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
diff --git a/src/test/ui/issues/issue-56199.stderr b/src/test/ui/issues/issue-56199.stderr
index 9503183deb9..7aaf8e4ac2f 100644
--- a/src/test/ui/issues/issue-56199.stderr
+++ b/src/test/ui/issues/issue-56199.stderr
@@ -4,7 +4,7 @@ error: the `Self` constructor can only be used with tuple or unit structs
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
--> $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();
| ^^^^
|
- = 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
--> $DIR/issue-56199.rs:15:17
|
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
--> $DIR/issue-56199.rs:17:17
|
LL | let _ = Self();
- | ^^^^ did you mean `Self { /* fields */ }`?
+ | ^^^^ help: use curly brackets: `Self { /* fields */ }`
error: aborting due to 4 previous errors
diff --git a/src/test/ui/issues/issue-56835.stderr b/src/test/ui/issues/issue-56835.stderr
index 21ecbf05dc7..f9fdf23af97 100644
--- a/src/test/ui/issues/issue-56835.stderr
+++ b/src/test/ui/issues/issue-56835.stderr
@@ -2,7 +2,7 @@ error: the `Self` constructor can only be used with tuple or unit structs
--> $DIR/issue-56835.rs:4:12
|
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`
--> $DIR/issue-56835.rs:4:12
diff --git a/src/test/ui/rmeta_meta_main.stderr b/src/test/ui/rmeta_meta_main.stderr
index b7d7f89cfbb..bed9076d84c 100644
--- a/src/test/ui/rmeta_meta_main.stderr
+++ b/src/test/ui/rmeta_meta_main.stderr
@@ -2,7 +2,7 @@ error[E0560]: struct `rmeta_meta::Foo` has no field named `field2`
--> $DIR/rmeta_meta_main.rs:13:19
|
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
diff --git a/src/test/ui/structs/struct-fields-hints-no-dupe.stderr b/src/test/ui/structs/struct-fields-hints-no-dupe.stderr
index 105f330463a..1a88f269347 100644
--- a/src/test/ui/structs/struct-fields-hints-no-dupe.stderr
+++ b/src/test/ui/structs/struct-fields-hints-no-dupe.stderr
@@ -2,7 +2,7 @@ error[E0560]: struct `A` has no field named `bar`
--> $DIR/struct-fields-hints-no-dupe.rs:10:9
|
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
diff --git a/src/test/ui/structs/struct-fields-hints.stderr b/src/test/ui/structs/struct-fields-hints.stderr
index d7130305631..3b8a2b5c7ba 100644
--- a/src/test/ui/structs/struct-fields-hints.stderr
+++ b/src/test/ui/structs/struct-fields-hints.stderr
@@ -2,7 +2,7 @@ error[E0560]: struct `A` has no field named `bar`
--> $DIR/struct-fields-hints.rs:10:9
|
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
diff --git a/src/test/ui/structs/struct-fields-typo.rs b/src/test/ui/structs/struct-fields-typo.rs
index b435a0a4777..0e9b2ae5145 100644
--- a/src/test/ui/structs/struct-fields-typo.rs
+++ b/src/test/ui/structs/struct-fields-typo.rs
@@ -8,7 +8,8 @@ fn main() {
foo: 0,
bar: 0.5,
};
- let x = foo.baa;//~ no field `baa` on type `BuildData`
- //~^ did you mean `bar`?
+ let x = foo.baa; //~ ERROR no field `baa` on type `BuildData`
+ //~| HELP a field with a similar name exists
+ //~| SUGGESTION bar
println!("{}", x);
}
diff --git a/src/test/ui/structs/struct-fields-typo.stderr b/src/test/ui/structs/struct-fields-typo.stderr
index 93127ab5beb..c2fab714f7c 100644
--- a/src/test/ui/structs/struct-fields-typo.stderr
+++ b/src/test/ui/structs/struct-fields-typo.stderr
@@ -1,8 +1,8 @@
error[E0609]: no field `baa` on type `BuildData`
--> $DIR/struct-fields-typo.rs:11:17
|
-LL | let x = foo.baa;//~ no field `baa` on type `BuildData`
- | ^^^ did you mean `bar`?
+LL | let x = foo.baa; //~ ERROR no field `baa` on type `BuildData`
+ | ^^^ help: a field with a similar name exists: `bar`
error: aborting due to previous error
diff --git a/src/test/ui/suggestions/suggest-private-fields.stderr b/src/test/ui/suggestions/suggest-private-fields.stderr
index 5f0176473ea..524558e0ec5 100644
--- a/src/test/ui/suggestions/suggest-private-fields.stderr
+++ b/src/test/ui/suggestions/suggest-private-fields.stderr
@@ -2,7 +2,7 @@ error[E0560]: struct `xc::B` has no field named `aa`
--> $DIR/suggest-private-fields.rs:15:9
|
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`
--> $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
|
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`
--> $DIR/suggest-private-fields.rs:24:9
|
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
diff --git a/src/test/ui/tuple/tuple-index-not-tuple.stderr b/src/test/ui/tuple/tuple-index-not-tuple.stderr
index ab9ac4c4142..a1bcdfaedbc 100644
--- a/src/test/ui/tuple/tuple-index-not-tuple.stderr
+++ b/src/test/ui/tuple/tuple-index-not-tuple.stderr
@@ -2,7 +2,7 @@ error[E0609]: no field `0` on type `Point`
--> $DIR/tuple-index-not-tuple.rs:6:12
|
LL | origin.0;
- | ^ did you mean `x`?
+ | ^ help: a field with a similar name exists: `x`
error[E0609]: no field `0` on type `Empty`
--> $DIR/tuple-index-not-tuple.rs:8:11
diff --git a/src/test/ui/tuple/tuple-index-out-of-bounds.stderr b/src/test/ui/tuple/tuple-index-out-of-bounds.stderr
index 86e977a01b7..7d7c5cd7892 100644
--- a/src/test/ui/tuple/tuple-index-out-of-bounds.stderr
+++ b/src/test/ui/tuple/tuple-index-out-of-bounds.stderr
@@ -2,7 +2,7 @@ error[E0609]: no field `2` on type `Point`
--> $DIR/tuple-index-out-of-bounds.rs:7:12
|
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})`
--> $DIR/tuple-index-out-of-bounds.rs:12:11
diff --git a/src/test/ui/union/union-suggest-field.rs b/src/test/ui/union/union-suggest-field.rs
index ad527a97918..b2d8c0efea8 100644
--- a/src/test/ui/union/union-suggest-field.rs
+++ b/src/test/ui/union/union-suggest-field.rs
@@ -9,8 +9,12 @@ impl U {
fn main() {
let u = U { principle: 0 };
//~^ 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`
- //~^ 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`
+ //~| HELP maybe a `()` to call it is missing
}
diff --git a/src/test/ui/union/union-suggest-field.stderr b/src/test/ui/union/union-suggest-field.stderr
index 15464eea4c2..91d6b30ea02 100644
--- a/src/test/ui/union/union-suggest-field.stderr
+++ b/src/test/ui/union/union-suggest-field.stderr
@@ -2,16 +2,16 @@ error[E0560]: union `U` has no field named `principle`
--> $DIR/union-suggest-field.rs:10:17
|
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`
- --> $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`
- | ^^^^^^^^^^ 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`
- --> $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`
| ^^^^^^^^^