1
Fork 0

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( err.span_suggestion_verbose(
span, span,
"consider changing this to be mutable", "consider changing this to be mutable",
" mut ".into(), " mut ",
Applicability::MaybeIncorrect, Applicability::MaybeIncorrect,
); );
} }

View file

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

View file

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

View file

@ -477,7 +477,7 @@ impl<'a, G: EmissionGuarantee> DiagnosticBuilder<'a, G> {
&mut self, &mut self,
sp: Span, sp: Span,
msg: impl Into<DiagnosticMessage>, msg: impl Into<DiagnosticMessage>,
suggestion: String, suggestion: impl ToString,
applicability: Applicability, applicability: Applicability,
) -> &mut Self); ) -> &mut Self);
forward!(pub fn span_suggestions( forward!(pub fn span_suggestions(
@ -497,28 +497,28 @@ impl<'a, G: EmissionGuarantee> DiagnosticBuilder<'a, G> {
&mut self, &mut self,
sp: Span, sp: Span,
msg: impl Into<DiagnosticMessage>, msg: impl Into<DiagnosticMessage>,
suggestion: String, suggestion: impl ToString,
applicability: Applicability, applicability: Applicability,
) -> &mut Self); ) -> &mut Self);
forward!(pub fn span_suggestion_verbose( forward!(pub fn span_suggestion_verbose(
&mut self, &mut self,
sp: Span, sp: Span,
msg: impl Into<DiagnosticMessage>, msg: impl Into<DiagnosticMessage>,
suggestion: String, suggestion: impl ToString,
applicability: Applicability, applicability: Applicability,
) -> &mut Self); ) -> &mut Self);
forward!(pub fn span_suggestion_hidden( forward!(pub fn span_suggestion_hidden(
&mut self, &mut self,
sp: Span, sp: Span,
msg: impl Into<DiagnosticMessage>, msg: impl Into<DiagnosticMessage>,
suggestion: String, suggestion: impl ToString,
applicability: Applicability, applicability: Applicability,
) -> &mut Self); ) -> &mut Self);
forward!(pub fn tool_only_span_suggestion( forward!(pub fn tool_only_span_suggestion(
&mut self, &mut self,
sp: Span, sp: Span,
msg: impl Into<DiagnosticMessage>, msg: impl Into<DiagnosticMessage>,
suggestion: String, suggestion: impl ToString,
applicability: Applicability, applicability: Applicability,
) -> &mut Self); ) -> &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( err.span_suggestion(
span, span,
"expected syntax is", "expected syntax is",
suggestion.into(), suggestion,
Applicability::HasPlaceholders, Applicability::HasPlaceholders,
); );
} }

View file

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

View file

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

View file

@ -738,7 +738,7 @@ pub trait LintContext: Sized {
db.span_suggestion_verbose( db.span_suggestion_verbose(
span.shrink_to_hi(), span.shrink_to_hi(),
"insert whitespace here to avoid this being parsed as a prefix in Rust 2021", "insert whitespace here to avoid this being parsed as a prefix in Rust 2021",
" ".into(), " ",
Applicability::MachineApplicable, 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( l.span_suggestion_verbose(
arg_span.shrink_to_lo(), arg_span.shrink_to_lo(),
"add a \"{}\" format string to Display the message", "add a \"{}\" format string to Display the message",
"\"{}\", ".into(), "\"{}\", ",
fmt_applicability, fmt_applicability,
); );
} else if suggest_debug { } 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 `{}`", "add a \"{{:?}}\" format string to use the Debug implementation of `{}`",
ty, ty,
), ),
"\"{:?}\", ".into(), "\"{:?}\", ",
fmt_applicability, fmt_applicability,
); );
} }
@ -266,13 +266,13 @@ fn check_panic_str<'tcx>(
l.span_suggestion( l.span_suggestion(
arg.span.shrink_to_hi(), arg.span.shrink_to_hi(),
&format!("add the missing argument{}", pluralize!(n_arguments)), &format!("add the missing argument{}", pluralize!(n_arguments)),
", ...".into(), ", ...",
Applicability::HasPlaceholders, Applicability::HasPlaceholders,
); );
l.span_suggestion( l.span_suggestion(
arg.span.shrink_to_lo(), arg.span.shrink_to_lo(),
"or add a \"{}\" format string to use the message literally", "or add a \"{}\" format string to use the message literally",
"\"{}\", ".into(), "\"{}\", ",
Applicability::MachineApplicable, Applicability::MachineApplicable,
); );
} }
@ -297,7 +297,7 @@ fn check_panic_str<'tcx>(
l.span_suggestion( l.span_suggestion(
arg.span.shrink_to_lo(), arg.span.shrink_to_lo(),
"add a \"{}\" format string to use the message literally", "add a \"{}\" format string to use the message literally",
"\"{}\", ".into(), "\"{}\", ",
Applicability::MachineApplicable, Applicability::MachineApplicable,
); );
} }

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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