Fill in suggestions Applicability according to @estebank
Also fix some formatting along the way.
This commit is contained in:
parent
c61f4a7144
commit
2b77760944
16 changed files with 69 additions and 46 deletions
|
|
@ -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();
|
||||
|
|
|
|||
|
|
@ -426,7 +426,7 @@ impl<'a, 'gcx, 'tcx> MirBorrowckCtxt<'a, 'gcx, 'tcx> {
|
|||
span,
|
||||
&format!("consider removing the `{}`", to_remove),
|
||||
suggestion,
|
||||
Applicability::Unspecified,
|
||||
Applicability::MachineApplicable,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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,
|
||||
);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -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,
|
||||
);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -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();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
|
|
|
|||
|
|
@ -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),
|
||||
|
|
|
|||
|
|
@ -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(())
|
||||
})();
|
||||
|
|
|
|||
|
|
@ -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,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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() {
|
||||
|
|
|
|||
|
|
@ -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,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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,
|
||||
);
|
||||
}
|
||||
_ => {
|
||||
|
|
|
|||
|
|
@ -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();
|
||||
|
|
|
|||
|
|
@ -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,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
|
|
|
|||
|
|
@ -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,
|
||||
);
|
||||
}
|
||||
}};
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue