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:
parent
baaa3b6829
commit
73fa217bc1
17 changed files with 40 additions and 40 deletions
|
@ -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,
|
||||
);
|
||||
}
|
||||
|
|
|
@ -235,7 +235,7 @@ fn validate_default_attribute(
|
|||
.span_suggestion_hidden(
|
||||
attr.span,
|
||||
"try using `#[default]`",
|
||||
"#[default]".into(),
|
||||
"#[default]",
|
||||
Applicability::MaybeIncorrect,
|
||||
)
|
||||
.emit();
|
||||
|
|
|
@ -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(
|
||||
|
|
|
@ -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);
|
||||
|
||||
|
|
|
@ -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,
|
||||
);
|
||||
}
|
||||
|
|
|
@ -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 {
|
||||
|
|
|
@ -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 {
|
||||
|
|
|
@ -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,
|
||||
);
|
||||
}
|
||||
|
|
|
@ -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,
|
||||
);
|
||||
}
|
||||
|
|
|
@ -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,
|
||||
);
|
||||
}
|
||||
|
|
|
@ -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,
|
||||
);
|
||||
}
|
||||
|
|
|
@ -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();
|
||||
|
|
|
@ -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();
|
||||
|
|
|
@ -606,7 +606,7 @@ impl<'a> Parser<'a> {
|
|||
.span_suggestion(
|
||||
mutref_span,
|
||||
"try switching the order",
|
||||
"ref mut".into(),
|
||||
"ref mut",
|
||||
Applicability::MachineApplicable,
|
||||
)
|
||||
.emit();
|
||||
|
|
|
@ -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();
|
||||
|
|
|
@ -108,7 +108,7 @@ fn check_needless_must_use(
|
|||
diag.span_suggestion(
|
||||
attr.span,
|
||||
"remove the attribute",
|
||||
"".into(),
|
||||
"",
|
||||
Applicability::MachineApplicable,
|
||||
);
|
||||
},
|
||||
|
|
|
@ -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,
|
||||
);
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue