From 2b7776094492bcdb9ecf62f5333b719f30ffce1f Mon Sep 17 00:00:00 2001 From: Vitaly _Vi Shukela Date: Mon, 17 Sep 2018 03:16:08 +0300 Subject: [PATCH] Fill in suggestions Applicability according to @estebank Also fix some formatting along the way. --- src/librustc_borrowck/borrowck/mod.rs | 9 ++++++-- src/librustc_mir/borrow_check/move_errors.rs | 2 +- .../borrow_check/mutability_errors.rs | 6 +++--- src/librustc_passes/ast_validation.rs | 2 +- src/librustc_passes/loops.rs | 2 +- src/librustc_resolve/lib.rs | 2 +- src/librustc_typeck/check/cast.rs | 4 ++-- src/librustc_typeck/check/compare_method.rs | 6 +++--- src/librustc_typeck/check/demand.rs | 2 +- src/librustc_typeck/check/method/suggest.rs | 12 +++++++---- src/librustc_typeck/check/mod.rs | 21 +++++++++++++------ src/librustc_typeck/check/op.rs | 17 ++++++++------- src/libsyntax/config.rs | 5 +++-- src/libsyntax/ext/tt/macro_rules.rs | 8 +++---- src/libsyntax/parse/parser.rs | 11 +++++----- src/libsyntax_ext/format.rs | 6 +++--- 16 files changed, 69 insertions(+), 46 deletions(-) diff --git a/src/librustc_borrowck/borrowck/mod.rs b/src/librustc_borrowck/borrowck/mod.rs index 9971d602f3f1..ed84e9a64f53 100644 --- a/src/librustc_borrowck/borrowck/mod.rs +++ b/src/librustc_borrowck/borrowck/mod.rs @@ -1250,6 +1250,11 @@ impl<'a, 'tcx> BorrowckCtxt<'a, 'tcx> { let_span, "use a mutable reference instead", replace_str, + // I believe this can be machine applicable, + // but if there are multiple attempted uses of an immutable + // reference, I don't know how rustfix handles it, it might + // attempt fixing them multiple times. + // @estebank Applicability::Unspecified, ); } @@ -1308,7 +1313,7 @@ impl<'a, 'tcx> BorrowckCtxt<'a, 'tcx> { "consider removing the `&mut`, as it is an \ immutable binding to a mutable reference", snippet, - Applicability::Unspecified, + Applicability::MachineApplicable, ); } else { db.span_suggestion_with_applicability( @@ -1345,7 +1350,7 @@ impl<'a, 'tcx> BorrowckCtxt<'a, 'tcx> { use the `move` keyword", cmt_path_or_string), suggestion, - Applicability::Unspecified, + Applicability::MachineApplicable, ) .emit(); self.signal_error(); diff --git a/src/librustc_mir/borrow_check/move_errors.rs b/src/librustc_mir/borrow_check/move_errors.rs index 5bba05a7b21a..52d051ebe7ba 100644 --- a/src/librustc_mir/borrow_check/move_errors.rs +++ b/src/librustc_mir/borrow_check/move_errors.rs @@ -426,7 +426,7 @@ impl<'a, 'gcx, 'tcx> MirBorrowckCtxt<'a, 'gcx, 'tcx> { span, &format!("consider removing the `{}`", to_remove), suggestion, - Applicability::Unspecified, + Applicability::MachineApplicable, ); } } diff --git a/src/librustc_mir/borrow_check/mutability_errors.rs b/src/librustc_mir/borrow_check/mutability_errors.rs index 8a31d7c91b94..a078aa59a7d5 100644 --- a/src/librustc_mir/borrow_check/mutability_errors.rs +++ b/src/librustc_mir/borrow_check/mutability_errors.rs @@ -232,7 +232,7 @@ impl<'a, 'gcx, 'tcx> MirBorrowckCtxt<'a, 'gcx, 'tcx> { local_decl.source_info.span, "consider changing this to be mutable", format!("mut {}", local_decl.name.unwrap()), - Applicability::Unspecified, + Applicability::MachineApplicable, ); } @@ -263,7 +263,7 @@ impl<'a, 'gcx, 'tcx> MirBorrowckCtxt<'a, 'gcx, 'tcx> { upvar_ident.span, "consider changing this to be mutable", format!("mut {}", upvar_ident.name), - Applicability::Unspecified, + Applicability::MachineApplicable, ); } } @@ -358,7 +358,7 @@ impl<'a, 'gcx, 'tcx> MirBorrowckCtxt<'a, 'gcx, 'tcx> { err_help_span, &format!("consider changing this to be a mutable {}", pointer_desc), suggested_code, - Applicability::Unspecified, + Applicability::MachineApplicable, ); } diff --git a/src/librustc_passes/ast_validation.rs b/src/librustc_passes/ast_validation.rs index 9e97b297f307..f6ace57f5e0f 100644 --- a/src/librustc_passes/ast_validation.rs +++ b/src/librustc_passes/ast_validation.rs @@ -184,7 +184,7 @@ impl<'a> AstValidator<'a> { if let Ok(snippet) = self.session.source_map().span_to_snippet(span) { err.span_suggestion_with_applicability( span, "consider adding parentheses", format!("({})", snippet), - Applicability::Unspecified, + Applicability::MachineApplicable, ); } diff --git a/src/librustc_passes/loops.rs b/src/librustc_passes/loops.rs index cf8967ab2832..677345396c12 100644 --- a/src/librustc_passes/loops.rs +++ b/src/librustc_passes/loops.rs @@ -147,7 +147,7 @@ impl<'a, 'hir> Visitor<'hir> for CheckLoopVisitor<'a, 'hir> { without a value inside this `{}` loop", kind.name()), "break".to_string(), - Applicability::Unspecified, + Applicability::MaybeIncorrect, ) .emit(); } diff --git a/src/librustc_resolve/lib.rs b/src/librustc_resolve/lib.rs index 0b77c0d895bd..6820fd727dbe 100644 --- a/src/librustc_resolve/lib.rs +++ b/src/librustc_resolve/lib.rs @@ -3303,7 +3303,7 @@ impl<'a, 'crateloader: 'a> Resolver<'a, 'crateloader> { sp, "did you mean to use `;` here instead?", ";".to_string(), - Applicability::Unspecified, + Applicability::MaybeIncorrect, ); } break; diff --git a/src/librustc_typeck/check/cast.rs b/src/librustc_typeck/check/cast.rs index 5d9802839eb6..7fa50fd4f487 100644 --- a/src/librustc_typeck/check/cast.rs +++ b/src/librustc_typeck/check/cast.rs @@ -332,7 +332,7 @@ impl<'a, 'gcx, 'tcx> CastCheck<'tcx> { err.span_suggestion_with_applicability(self.cast_span, "try casting to a reference instead", format!("&{}{}", mtstr, s), - Applicability::Unspecified, + Applicability::MachineApplicable, ); } Err(_) => { @@ -353,7 +353,7 @@ impl<'a, 'gcx, 'tcx> CastCheck<'tcx> { err.span_suggestion_with_applicability(self.cast_span, "try casting to a `Box` instead", format!("Box<{}>", s), - Applicability::Unspecified, + Applicability::MachineApplicable, ); } Err(_) => span_help!(err, self.cast_span, "did you mean `Box<{}>`?", tstr), diff --git a/src/librustc_typeck/check/compare_method.rs b/src/librustc_typeck/check/compare_method.rs index 75b9d2831600..a192068d28f2 100644 --- a/src/librustc_typeck/check/compare_method.rs +++ b/src/librustc_typeck/check/compare_method.rs @@ -326,7 +326,7 @@ fn compare_predicate_entailment<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, impl_err_span, "consider change the type to match the mutability in trait", format!("{}", trait_err_str), - Applicability::Unspecified, + Applicability::MachineApplicable, ); } } @@ -811,7 +811,7 @@ fn compare_synthetic_generics<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, // of the generics, but it works for the common case (generics_span, new_generics), ], - Applicability::Unspecified, + Applicability::MaybeIncorrect, ); Some(()) })(); @@ -881,7 +881,7 @@ fn compare_synthetic_generics<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, // replace param usage with `impl Trait` (span, format!("impl {}", bounds)), ], - Applicability::Unspecified, + Applicability::MaybeIncorrect, ); Some(()) })(); diff --git a/src/librustc_typeck/check/demand.rs b/src/librustc_typeck/check/demand.rs index 13f3bdbb10f0..5348312637cc 100644 --- a/src/librustc_typeck/check/demand.rs +++ b/src/librustc_typeck/check/demand.rs @@ -135,7 +135,7 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> { err.span_suggestions_with_applicability(expr.span, "try using a variant of the expected type", suggestions, - Applicability::Unspecified, + Applicability::MaybeIncorrect, ); } } diff --git a/src/librustc_typeck/check/method/suggest.rs b/src/librustc_typeck/check/method/suggest.rs index 453a7e1e72f4..2e878956edef 100644 --- a/src/librustc_typeck/check/method/suggest.rs +++ b/src/librustc_typeck/check/method/suggest.rs @@ -258,7 +258,7 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> { format!("{}_{}", snippet, concrete_type), - Applicability::Unspecified, + Applicability::MaybeIncorrect, ); } hir::ExprKind::Path(ref qpath) => { // local binding @@ -290,7 +290,7 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> { .unwrap_or(span)), &msg, format!("{}: {}", snippet, concrete_type), - Applicability::Unspecified, + Applicability::MaybeIncorrect, ); } _ => { @@ -519,8 +519,12 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> { format!("use {};\n{}", self.tcx.item_path_str(*did), additional_newline) }).collect(); - err.span_suggestions_with_applicability(span, &msg, path_strings, - Applicability::Unspecified); + err.span_suggestions_with_applicability( + span, + &msg, + path_strings, + Applicability::MaybeIncorrect, + ); } else { let limit = if candidates.len() == 5 { 5 } else { 4 }; for (i, trait_did) in candidates.iter().take(limit).enumerate() { diff --git a/src/librustc_typeck/check/mod.rs b/src/librustc_typeck/check/mod.rs index 3b1f81a9eba0..dcec21c9eef3 100644 --- a/src/librustc_typeck/check/mod.rs +++ b/src/librustc_typeck/check/mod.rs @@ -3348,8 +3348,12 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> { let base = self.tcx.hir.node_to_pretty_string(base.id); let msg = format!("`{}` is a native pointer; try dereferencing it", base); let suggestion = format!("(*{}).{}", base, field); - err.span_suggestion_with_applicability(field.span, &msg, suggestion, - Applicability::Unspecified); + err.span_suggestion_with_applicability( + field.span, + &msg, + suggestion, + Applicability::MaybeIncorrect, + ); } _ => {} } @@ -4717,8 +4721,12 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> { found: Ty<'tcx>, ) { if let Some((sp, msg, suggestion)) = self.check_ref(expr, found, expected) { - err.span_suggestion_with_applicability(sp, msg, suggestion, - Applicability::Unspecified); + err.span_suggestion_with_applicability( + sp, + msg, + suggestion, + Applicability::MachineApplicable, + ); } else if !self.check_for_cast(err, expr, found, expected) { let methods = self.get_conversion_methods(expr.span, expected, found); if let Ok(expr_text) = self.sess().source_map().span_to_snippet(expr.span) { @@ -4748,10 +4756,11 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> { } }) .collect::>(); if !suggestions.is_empty() { - err.span_suggestions_with_applicability(expr.span, + err.span_suggestions_with_applicability( + expr.span, "try using a conversion method", suggestions, - Applicability::Unspecified, + Applicability::MaybeIncorrect, ); } } diff --git a/src/librustc_typeck/check/op.rs b/src/librustc_typeck/check/op.rs index f029ae2d954e..6ebb1676bf61 100644 --- a/src/librustc_typeck/check/op.rs +++ b/src/librustc_typeck/check/op.rs @@ -444,10 +444,11 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> { err.span_label(expr.span, "`+` can't be used to concatenate two `&str` strings"); match source_map.span_to_snippet(lhs_expr.span) { - Ok(lstring) => err.span_suggestion_with_applicability(lhs_expr.span, + Ok(lstring) => err.span_suggestion_with_applicability( + lhs_expr.span, msg, format!("{}.to_owned()", lstring), - Applicability::Unspecified, + Applicability::MachineApplicable, ), _ => err.help(msg), }; @@ -464,11 +465,13 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> { is_assign, ) { (Ok(l), Ok(r), false) => { - err.multipart_suggestion_with_applicability(msg, vec![ - (lhs_expr.span, format!("{}.to_owned()", l)), - (rhs_expr.span, format!("&{}", r)), - ], - Applicability::Unspecified, + err.multipart_suggestion_with_applicability( + msg, + vec![ + (lhs_expr.span, format!("{}.to_owned()", l)), + (rhs_expr.span, format!("&{}", r)), + ], + Applicability::MachineApplicable, ); } _ => { diff --git a/src/libsyntax/config.rs b/src/libsyntax/config.rs index c3917488b98d..63e719a0d4ef 100644 --- a/src/libsyntax/config.rs +++ b/src/libsyntax/config.rs @@ -124,10 +124,11 @@ impl<'a> StripUnconfigured<'a> { let error = |span, msg, suggestion: &str| { let mut err = self.sess.span_diagnostic.struct_span_err(span, msg); if !suggestion.is_empty() { - err.span_suggestion_with_applicability(span, + err.span_suggestion_with_applicability( + span, "expected syntax is", suggestion.into(), - Applicability::Unspecified, + Applicability::MaybeIncorrect, ); } err.emit(); diff --git a/src/libsyntax/ext/tt/macro_rules.rs b/src/libsyntax/ext/tt/macro_rules.rs index 75f46f2e02c7..bbe49d409ea2 100644 --- a/src/libsyntax/ext/tt/macro_rules.rs +++ b/src/libsyntax/ext/tt/macro_rules.rs @@ -189,10 +189,10 @@ fn generic_extension<'cx>(cx: &'cx mut ExtCtxt, err.note("you might be missing a comma"); } else { err.span_suggestion_short_with_applicability( - comma_span, - "missing comma here", - ", ".to_string(), - Applicability::Unspecified, + comma_span, + "missing comma here", + ", ".to_string(), + Applicability::MachineApplicable, ); } } diff --git a/src/libsyntax/parse/parser.rs b/src/libsyntax/parse/parser.rs index 458a5c6473f9..182871895390 100644 --- a/src/libsyntax/parse/parser.rs +++ b/src/libsyntax/parse/parser.rs @@ -3882,11 +3882,12 @@ impl<'a> Parser<'a> { if self.token == token::CloseDelim(token::Brace) { // If the struct looks otherwise well formed, recover and continue. if let Some(sp) = comma_sp { - err.span_suggestion_short_with_applicability(sp, - "remove this comma", - String::new(), - Applicability::Unspecified, - ); + err.span_suggestion_short_with_applicability( + sp, + "remove this comma", + String::new(), + Applicability::MachineApplicable, + ); } err.emit(); break; diff --git a/src/libsyntax_ext/format.rs b/src/libsyntax_ext/format.rs index b4ad777e6d7b..1adbbbe2446d 100644 --- a/src/libsyntax_ext/format.rs +++ b/src/libsyntax_ext/format.rs @@ -997,9 +997,9 @@ pub fn expand_preparsed_format_args(ecx: &mut ExtCtxt, } if suggestions.len() > 0 { diag.multipart_suggestion_with_applicability( - "format specifiers use curly braces", - suggestions, - Applicability::Unspecified, + "format specifiers use curly braces", + suggestions, + Applicability::MachineApplicable, ); } }};