diff options
| author | bors <bors@rust-lang.org> | 2021-09-06 07:58:24 +0000 |
|---|---|---|
| committer | bors <bors@rust-lang.org> | 2021-09-06 07:58:24 +0000 |
| commit | d19d864e79531ad702e4f44b2635da6c50cc5eb0 (patch) | |
| tree | 2b750bf335f2e0d0c4856020bce6ceae1cfa2c1f /compiler | |
| parent | b2d9bcda7ec267dbabfaef67f7af344ef71e002c (diff) | |
| parent | 2226977a875c149effeb7d6b85bce5a5ba0c440c (diff) | |
Auto merge of #88631 - camelid:sugg-span, r=davidtwco
Improve structured tuple struct suggestion Previously, the span was just for the constructor name, which meant it would result in syntactically-invalid code when applied. Now, the span is for the entire expression. I also changed it to use `span_suggestion_verbose`, for two reasons: 1. Now that the suggestion span has been corrected, the output is a bit cluttered and hard to read. Putting the suggestion its own window creates more space. 2. It's easier to see what's being suggested, since now the version after the suggestion is applied is shown. r? `@davidtwco`
Diffstat (limited to 'compiler')
| -rw-r--r-- | compiler/rustc_typeck/src/check/expr.rs | 16 |
1 files changed, 10 insertions, 6 deletions
diff --git a/compiler/rustc_typeck/src/check/expr.rs b/compiler/rustc_typeck/src/check/expr.rs index 64594a82ec0..d578fac4cdb 100644 --- a/compiler/rustc_typeck/src/check/expr.rs +++ b/compiler/rustc_typeck/src/check/expr.rs @@ -1236,6 +1236,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { variant, fields, base_expr.is_none(), + expr.span, ); if let Some(base_expr) = base_expr { // If check_expr_struct_fields hit an error, do not attempt to populate @@ -1283,6 +1284,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { variant: &'tcx ty::VariantDef, ast_fields: &'tcx [hir::ExprField<'tcx>], check_completeness: bool, + expr_span: Span, ) -> bool { let tcx = self.tcx; @@ -1334,7 +1336,9 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { ident, }); } else { - self.report_unknown_field(adt_ty, variant, field, ast_fields, kind_name, span); + self.report_unknown_field( + adt_ty, variant, field, ast_fields, kind_name, expr_span, + ); } tcx.ty_error() @@ -1467,7 +1471,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { field: &hir::ExprField<'_>, skip_fields: &[hir::ExprField<'_>], kind_name: &str, - ty_span: Span, + expr_span: Span, ) { if variant.is_recovered() { self.set_tainted_by_errors(); @@ -1510,8 +1514,8 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { ), ); err.span_label(field.ident.span, "field does not exist"); - err.span_suggestion( - ty_span, + err.span_suggestion_verbose( + expr_span, &format!( "`{adt}::{variant}` is a tuple {kind_name}, use the appropriate syntax", adt = ty, @@ -1528,8 +1532,8 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { _ => { err.span_label(variant.ident.span, format!("`{adt}` defined here", adt = ty)); err.span_label(field.ident.span, "field does not exist"); - err.span_suggestion( - ty_span, + err.span_suggestion_verbose( + expr_span, &format!( "`{adt}` is a tuple {kind_name}, use the appropriate syntax", adt = ty, |
