errors: span_suggestion takes impl ToString

Change `span_suggestion` (and variants) to take `impl ToString` rather
than `String` for the suggested code, as this simplifies the
requirements on the diagnostic derive.

Signed-off-by: David Wood <david.wood@huawei.com>
This commit is contained in:
David Wood 2022-04-26 06:17:33 +01:00
parent baaa3b6829
commit 73fa217bc1
17 changed files with 40 additions and 40 deletions

View file

@ -237,7 +237,7 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, 'tcx> {
err.span_suggestion_verbose(
span,
"consider changing this to be mutable",
" mut ".into(),
" mut ",
Applicability::MaybeIncorrect,
);
}

View file

@ -235,7 +235,7 @@ fn validate_default_attribute(
.span_suggestion_hidden(
attr.span,
"try using `#[default]`",
"#[default]".into(),
"#[default]",
Applicability::MaybeIncorrect,
)
.emit();

View file

@ -605,7 +605,7 @@ impl Diagnostic {
&mut self,
sp: Span,
msg: impl Into<DiagnosticMessage>,
suggestion: String,
suggestion: impl ToString,
applicability: Applicability,
) -> &mut Self {
self.span_suggestion_with_style(
@ -623,13 +623,13 @@ impl Diagnostic {
&mut self,
sp: Span,
msg: impl Into<DiagnosticMessage>,
suggestion: String,
suggestion: impl ToString,
applicability: Applicability,
style: SuggestionStyle,
) -> &mut Self {
self.push_suggestion(CodeSuggestion {
substitutions: vec![Substitution {
parts: vec![SubstitutionPart { snippet: suggestion, span: sp }],
parts: vec![SubstitutionPart { snippet: suggestion.to_string(), span: sp }],
}],
msg: msg.into(),
style,
@ -643,7 +643,7 @@ impl Diagnostic {
&mut self,
sp: Span,
msg: impl Into<DiagnosticMessage>,
suggestion: String,
suggestion: impl ToString,
applicability: Applicability,
) -> &mut Self {
self.span_suggestion_with_style(
@ -711,7 +711,7 @@ impl Diagnostic {
&mut self,
sp: Span,
msg: impl Into<DiagnosticMessage>,
suggestion: String,
suggestion: impl ToString,
applicability: Applicability,
) -> &mut Self {
self.span_suggestion_with_style(
@ -734,7 +734,7 @@ impl Diagnostic {
&mut self,
sp: Span,
msg: impl Into<DiagnosticMessage>,
suggestion: String,
suggestion: impl ToString,
applicability: Applicability,
) -> &mut Self {
self.span_suggestion_with_style(
@ -755,7 +755,7 @@ impl Diagnostic {
&mut self,
sp: Span,
msg: impl Into<DiagnosticMessage>,
suggestion: String,
suggestion: impl ToString,
applicability: Applicability,
) -> &mut Self {
self.span_suggestion_with_style(

View file

@ -477,7 +477,7 @@ impl<'a, G: EmissionGuarantee> DiagnosticBuilder<'a, G> {
&mut self,
sp: Span,
msg: impl Into<DiagnosticMessage>,
suggestion: String,
suggestion: impl ToString,
applicability: Applicability,
) -> &mut Self);
forward!(pub fn span_suggestions(
@ -497,28 +497,28 @@ impl<'a, G: EmissionGuarantee> DiagnosticBuilder<'a, G> {
&mut self,
sp: Span,
msg: impl Into<DiagnosticMessage>,
suggestion: String,
suggestion: impl ToString,
applicability: Applicability,
) -> &mut Self);
forward!(pub fn span_suggestion_verbose(
&mut self,
sp: Span,
msg: impl Into<DiagnosticMessage>,
suggestion: String,
suggestion: impl ToString,
applicability: Applicability,
) -> &mut Self);
forward!(pub fn span_suggestion_hidden(
&mut self,
sp: Span,
msg: impl Into<DiagnosticMessage>,
suggestion: String,
suggestion: impl ToString,
applicability: Applicability,
) -> &mut Self);
forward!(pub fn tool_only_span_suggestion(
&mut self,
sp: Span,
msg: impl Into<DiagnosticMessage>,
suggestion: String,
suggestion: impl ToString,
applicability: Applicability,
) -> &mut Self);

View file

@ -511,7 +511,7 @@ pub fn parse_cfg<'a>(meta_item: &'a MetaItem, sess: &Session) -> Option<&'a Meta
err.span_suggestion(
span,
"expected syntax is",
suggestion.into(),
suggestion,
Applicability::HasPlaceholders,
);
}

View file

@ -2198,7 +2198,7 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
err.span_suggestion(
span.with_hi(before_close).shrink_to_hi(),
msg,
",".into(),
",",
Applicability::MachineApplicable,
);
} else {

View file

@ -129,7 +129,7 @@ impl<'tcx> LateLintPass<'tcx> for ArrayIntoIter {
diag.span_suggestion(
call.ident.span,
"use `.iter()` instead of `.into_iter()` to avoid ambiguity",
"iter".into(),
"iter",
Applicability::MachineApplicable,
);
if self.for_expr_span == expr.span {

View file

@ -738,7 +738,7 @@ pub trait LintContext: Sized {
db.span_suggestion_verbose(
span.shrink_to_hi(),
"insert whitespace here to avoid this being parsed as a prefix in Rust 2021",
" ".into(),
" ",
Applicability::MachineApplicable,
);
}

View file

@ -176,7 +176,7 @@ fn check_panic<'tcx>(cx: &LateContext<'tcx>, f: &'tcx hir::Expr<'tcx>, arg: &'tc
l.span_suggestion_verbose(
arg_span.shrink_to_lo(),
"add a \"{}\" format string to Display the message",
"\"{}\", ".into(),
"\"{}\", ",
fmt_applicability,
);
} else if suggest_debug {
@ -186,7 +186,7 @@ fn check_panic<'tcx>(cx: &LateContext<'tcx>, f: &'tcx hir::Expr<'tcx>, arg: &'tc
"add a \"{{:?}}\" format string to use the Debug implementation of `{}`",
ty,
),
"\"{:?}\", ".into(),
"\"{:?}\", ",
fmt_applicability,
);
}
@ -266,13 +266,13 @@ fn check_panic_str<'tcx>(
l.span_suggestion(
arg.span.shrink_to_hi(),
&format!("add the missing argument{}", pluralize!(n_arguments)),
", ...".into(),
", ...",
Applicability::HasPlaceholders,
);
l.span_suggestion(
arg.span.shrink_to_lo(),
"or add a \"{}\" format string to use the message literally",
"\"{}\", ".into(),
"\"{}\", ",
Applicability::MachineApplicable,
);
}
@ -297,7 +297,7 @@ fn check_panic_str<'tcx>(
l.span_suggestion(
arg.span.shrink_to_lo(),
"add a \"{}\" format string to use the message literally",
"\"{}\", ".into(),
"\"{}\", ",
Applicability::MachineApplicable,
);
}

View file

@ -612,14 +612,14 @@ impl<'a> StringReader<'a> {
err.span_suggestion_verbose(
prefix_span,
"use `br` for a raw byte string",
"br".to_string(),
"br",
Applicability::MaybeIncorrect,
);
} else if expn_data.is_root() {
err.span_suggestion_verbose(
prefix_span.shrink_to_hi(),
"consider inserting whitespace here",
" ".into(),
" ",
Applicability::MaybeIncorrect,
);
}

View file

@ -1771,7 +1771,7 @@ impl<'a> Parser<'a> {
.span_suggestion(
token.span,
"must have an integer part",
pprust::token_to_string(token).into(),
pprust::token_to_string(token),
Applicability::MachineApplicable,
)
.emit();
@ -2324,7 +2324,7 @@ impl<'a> Parser<'a> {
.span_suggestion_short(
span,
msg,
sugg.into(),
sugg,
// Has been misleading, at least in the past (closed Issue #48492).
Applicability::MaybeIncorrect,
)
@ -2828,7 +2828,7 @@ impl<'a> Parser<'a> {
e.span_suggestion(
self.prev_token.span.shrink_to_hi(),
"try adding a comma",
",".into(),
",",
Applicability::MachineApplicable,
);
}

View file

@ -332,7 +332,7 @@ impl<'a> Parser<'a> {
err.span_suggestion_short(
sp,
&msg,
" struct ".into(),
" struct ",
Applicability::MaybeIncorrect, // speculative
);
Err(err)
@ -532,13 +532,13 @@ impl<'a> Parser<'a> {
.span_suggestion(
span,
"add a trait here",
" Trait ".into(),
" Trait ",
Applicability::HasPlaceholders,
)
.span_suggestion(
span.to(self.token.span),
"for an inherent impl, drop this `for`",
"".into(),
"",
Applicability::MaybeIncorrect,
)
.emit();
@ -1459,7 +1459,7 @@ impl<'a> Parser<'a> {
err.span_suggestion(
sp,
"missing comma here",
",".into(),
",",
Applicability::MachineApplicable,
);
}
@ -1498,7 +1498,7 @@ impl<'a> Parser<'a> {
err.span_suggestion(
sp,
"try adding a comma",
",".into(),
",",
Applicability::MachineApplicable,
);
err.emit();

View file

@ -802,7 +802,7 @@ impl<'a> Parser<'a> {
.span_suggestion_verbose(
self.prev_token.span.shrink_to_hi().until(self.token.span),
&msg,
" @ ".to_string(),
" @ ",
Applicability::MaybeIncorrect,
)
.emit();
@ -818,7 +818,7 @@ impl<'a> Parser<'a> {
.span_suggestion_short(
sp,
&format!("missing `{}`", token_str),
token_str.into(),
token_str,
Applicability::MaybeIncorrect,
)
.emit();

View file

@ -606,7 +606,7 @@ impl<'a> Parser<'a> {
.span_suggestion(
mutref_span,
"try switching the order",
"ref mut".into(),
"ref mut",
Applicability::MachineApplicable,
)
.emit();

View file

@ -851,7 +851,7 @@ impl<'a, 'b> BuildReducedGraphVisitor<'a, 'b> {
.span_suggestion(
item.span,
"rename the `self` crate to be able to import it",
"extern crate self as name;".into(),
"extern crate self as name;",
Applicability::HasPlaceholders,
)
.emit();

View file

@ -108,7 +108,7 @@ fn check_needless_must_use(
diag.span_suggestion(
attr.span,
"remove the attribute",
"".into(),
"",
Applicability::MachineApplicable,
);
},

View file

@ -241,7 +241,7 @@ impl<'tcx> LateLintPass<'tcx> for NeedlessPassByValue {
|x| Cow::from(format!("change `{}` to", x)),
)
.as_ref(),
suggestion.into(),
suggestion,
Applicability::Unspecified,
);
}
@ -271,7 +271,7 @@ impl<'tcx> LateLintPass<'tcx> for NeedlessPassByValue {
|x| Cow::from(format!("change `{}` to", x))
)
.as_ref(),
suggestion.into(),
suggestion,
Applicability::Unspecified,
);
}