diff options
| author | Vitaly _Vi Shukela <vi0oss@gmail.com> | 2018-09-17 03:16:08 +0300 |
|---|---|---|
| committer | Vitaly _Vi Shukela <vi0oss@gmail.com> | 2018-09-17 03:20:08 +0300 |
| commit | 2b7776094492bcdb9ecf62f5333b719f30ffce1f (patch) | |
| tree | 6d1cae430c70c79ed8aa945f5faf6cf786506e3b | |
| parent | c61f4a71448f817848059e5c0942d14d14c929b6 (diff) | |
| download | rust-2b7776094492bcdb9ecf62f5333b719f30ffce1f.tar.gz rust-2b7776094492bcdb9ecf62f5333b719f30ffce1f.zip | |
Fill in suggestions Applicability according to @estebank
Also fix some formatting along the way.
| -rw-r--r-- | src/librustc_borrowck/borrowck/mod.rs | 9 | ||||
| -rw-r--r-- | src/librustc_mir/borrow_check/move_errors.rs | 2 | ||||
| -rw-r--r-- | src/librustc_mir/borrow_check/mutability_errors.rs | 6 | ||||
| -rw-r--r-- | src/librustc_passes/ast_validation.rs | 2 | ||||
| -rw-r--r-- | src/librustc_passes/loops.rs | 2 | ||||
| -rw-r--r-- | src/librustc_resolve/lib.rs | 2 | ||||
| -rw-r--r-- | src/librustc_typeck/check/cast.rs | 4 | ||||
| -rw-r--r-- | src/librustc_typeck/check/compare_method.rs | 6 | ||||
| -rw-r--r-- | src/librustc_typeck/check/demand.rs | 2 | ||||
| -rw-r--r-- | src/librustc_typeck/check/method/suggest.rs | 12 | ||||
| -rw-r--r-- | src/librustc_typeck/check/mod.rs | 21 | ||||
| -rw-r--r-- | src/librustc_typeck/check/op.rs | 17 | ||||
| -rw-r--r-- | src/libsyntax/config.rs | 5 | ||||
| -rw-r--r-- | src/libsyntax/ext/tt/macro_rules.rs | 8 | ||||
| -rw-r--r-- | src/libsyntax/parse/parser.rs | 11 | ||||
| -rw-r--r-- | 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 9971d602f3f..ed84e9a64f5 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 5bba05a7b21..52d051ebe7b 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 8a31d7c91b9..a078aa59a7d 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 9e97b297f30..f6ace57f5e0 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 cf8967ab283..677345396c1 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 0b77c0d895b..6820fd727db 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 5d9802839eb..7fa50fd4f48 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 75b9d283160..a192068d28f 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 13f3bdbb10f..5348312637c 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 453a7e1e72f..2e878956ede 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 3b1f81a9eba..dcec21c9eef 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::<Vec<_>>(); 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 f029ae2d954..6ebb1676bf6 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 c3917488b98..63e719a0d4e 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 75f46f2e02c..bbe49d409ea 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 458a5c6473f..18287189539 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 b4ad777e6d7..1adbbbe2446 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, ); } }}; |
