1
Fork 0

Attach Applicability to multipart_suggestion and span_suggestions

This commit is contained in:
Vitaly _Vi Shukela 2018-09-15 15:03:02 +03:00
parent 2f5cb6dbdc
commit 4b05128114
No known key found for this signature in database
GPG key ID: C097221D6E03DF68
4 changed files with 14 additions and 7 deletions

View file

@ -801,7 +801,7 @@ fn compare_synthetic_generics<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
.span_to_snippet(trait_m.generics.span) .span_to_snippet(trait_m.generics.span)
.ok()?; .ok()?;
err.multipart_suggestion( err.multipart_suggestion_with_applicability(
"try changing the `impl Trait` argument to a generic parameter", "try changing the `impl Trait` argument to a generic parameter",
vec![ vec![
// replace `impl Trait` with `T` // replace `impl Trait` with `T`
@ -811,6 +811,7 @@ fn compare_synthetic_generics<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
// of the generics, but it works for the common case // of the generics, but it works for the common case
(generics_span, new_generics), (generics_span, new_generics),
], ],
Applicability::Unspecified,
); );
Some(()) Some(())
})(); })();
@ -872,7 +873,7 @@ fn compare_synthetic_generics<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
.span_to_snippet(bounds) .span_to_snippet(bounds)
.ok()?; .ok()?;
err.multipart_suggestion( err.multipart_suggestion_with_applicability(
"try removing the generic parameter and using `impl Trait` instead", "try removing the generic parameter and using `impl Trait` instead",
vec![ vec![
// delete generic parameters // delete generic parameters
@ -880,6 +881,7 @@ fn compare_synthetic_generics<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
// replace param usage with `impl Trait` // replace param usage with `impl Trait`
(span, format!("impl {}", bounds)), (span, format!("impl {}", bounds)),
], ],
Applicability::Unspecified,
); );
Some(()) Some(())
})(); })();

View file

@ -132,9 +132,11 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
let expr_text = print::to_string(print::NO_ANN, |s| s.print_expr(expr)); let expr_text = print::to_string(print::NO_ANN, |s| s.print_expr(expr));
let suggestions = compatible_variants.iter() let suggestions = compatible_variants.iter()
.map(|v| format!("{}({})", v, expr_text)).collect::<Vec<_>>(); .map(|v| format!("{}({})", v, expr_text)).collect::<Vec<_>>();
err.span_suggestions(expr.span, err.span_suggestions_with_applicability(expr.span,
"try using a variant of the expected type", "try using a variant of the expected type",
suggestions); suggestions,
Applicability::Unspecified,
);
} }
} }

View file

@ -464,10 +464,12 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
is_assign, is_assign,
) { ) {
(Ok(l), Ok(r), false) => { (Ok(l), Ok(r), false) => {
err.multipart_suggestion(msg, vec![ err.multipart_suggestion_with_applicability(msg, vec![
(lhs_expr.span, format!("{}.to_owned()", l)), (lhs_expr.span, format!("{}.to_owned()", l)),
(rhs_expr.span, format!("&{}", r)), (rhs_expr.span, format!("&{}", r)),
]); ],
Applicability::Unspecified,
);
} }
_ => { _ => {
err.help(msg); err.help(msg);

View file

@ -996,9 +996,10 @@ pub fn expand_preparsed_format_args(ecx: &mut ExtCtxt,
)); ));
} }
if suggestions.len() > 0 { if suggestions.len() > 0 {
diag.multipart_suggestion( diag.multipart_suggestion_with_applicability(
"format specifiers use curly braces", "format specifiers use curly braces",
suggestions, suggestions,
Applicability::Unspecified,
); );
} }
}}; }};