1
Fork 0

Rollup merge of #81737 - camelid:typeck-structure-sugg, r=lcnr

typeck: Emit structured suggestions for tuple struct syntax

And tuple variant syntax, but that didn't fit in the subject :)

Now the fact that these are suggestions is exposed both to the layout
engine and to IDEs and rustfix for automatic application.
This commit is contained in:
Jonas Schievink 2021-02-06 17:01:47 +01:00 committed by GitHub
commit f631410159
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 18 additions and 13 deletions

View file

@ -1460,28 +1460,33 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
),
);
err.span_label(field.ident.span, "field does not exist");
err.span_label(
err.span_suggestion(
ty_span,
format!(
"`{adt}::{variant}` is a tuple {kind_name}, \
use the appropriate syntax: `{adt}::{variant}(/* fields */)`",
&format!(
"`{adt}::{variant}` is a tuple {kind_name}, use the appropriate syntax",
adt = ty,
variant = variant.ident,
kind_name = kind_name
),
format!(
"{adt}::{variant}(/* fields */)",
adt = ty,
variant = variant.ident,
),
Applicability::HasPlaceholders,
);
}
_ => {
err.span_label(variant.ident.span, format!("`{adt}` defined here", adt = ty));
err.span_label(field.ident.span, "field does not exist");
err.span_label(
err.span_suggestion(
ty_span,
format!(
"`{adt}` is a tuple {kind_name}, \
use the appropriate syntax: `{adt}(/* fields */)`",
&format!(
"`{adt}` is a tuple {kind_name}, use the appropriate syntax",
adt = ty,
kind_name = kind_name
kind_name = kind_name,
),
format!("{adt}(/* fields */)", adt = ty),
Applicability::HasPlaceholders,
);
}
},