Skip to content

Commit 73fa217

Browse files
committed
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 <[email protected]>
1 parent baaa3b6 commit 73fa217

File tree

17 files changed

+40
-40
lines changed

17 files changed

+40
-40
lines changed

compiler/rustc_borrowck/src/diagnostics/mutability_errors.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -237,7 +237,7 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, 'tcx> {
237237
err.span_suggestion_verbose(
238238
span,
239239
"consider changing this to be mutable",
240-
" mut ".into(),
240+
" mut ",
241241
Applicability::MaybeIncorrect,
242242
);
243243
}

compiler/rustc_builtin_macros/src/deriving/default.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -235,7 +235,7 @@ fn validate_default_attribute(
235235
.span_suggestion_hidden(
236236
attr.span,
237237
"try using `#[default]`",
238-
"#[default]".into(),
238+
"#[default]",
239239
Applicability::MaybeIncorrect,
240240
)
241241
.emit();

compiler/rustc_errors/src/diagnostic.rs

+7-7
Original file line numberDiff line numberDiff line change
@@ -605,7 +605,7 @@ impl Diagnostic {
605605
&mut self,
606606
sp: Span,
607607
msg: impl Into<DiagnosticMessage>,
608-
suggestion: String,
608+
suggestion: impl ToString,
609609
applicability: Applicability,
610610
) -> &mut Self {
611611
self.span_suggestion_with_style(
@@ -623,13 +623,13 @@ impl Diagnostic {
623623
&mut self,
624624
sp: Span,
625625
msg: impl Into<DiagnosticMessage>,
626-
suggestion: String,
626+
suggestion: impl ToString,
627627
applicability: Applicability,
628628
style: SuggestionStyle,
629629
) -> &mut Self {
630630
self.push_suggestion(CodeSuggestion {
631631
substitutions: vec![Substitution {
632-
parts: vec![SubstitutionPart { snippet: suggestion, span: sp }],
632+
parts: vec![SubstitutionPart { snippet: suggestion.to_string(), span: sp }],
633633
}],
634634
msg: msg.into(),
635635
style,
@@ -643,7 +643,7 @@ impl Diagnostic {
643643
&mut self,
644644
sp: Span,
645645
msg: impl Into<DiagnosticMessage>,
646-
suggestion: String,
646+
suggestion: impl ToString,
647647
applicability: Applicability,
648648
) -> &mut Self {
649649
self.span_suggestion_with_style(
@@ -711,7 +711,7 @@ impl Diagnostic {
711711
&mut self,
712712
sp: Span,
713713
msg: impl Into<DiagnosticMessage>,
714-
suggestion: String,
714+
suggestion: impl ToString,
715715
applicability: Applicability,
716716
) -> &mut Self {
717717
self.span_suggestion_with_style(
@@ -734,7 +734,7 @@ impl Diagnostic {
734734
&mut self,
735735
sp: Span,
736736
msg: impl Into<DiagnosticMessage>,
737-
suggestion: String,
737+
suggestion: impl ToString,
738738
applicability: Applicability,
739739
) -> &mut Self {
740740
self.span_suggestion_with_style(
@@ -755,7 +755,7 @@ impl Diagnostic {
755755
&mut self,
756756
sp: Span,
757757
msg: impl Into<DiagnosticMessage>,
758-
suggestion: String,
758+
suggestion: impl ToString,
759759
applicability: Applicability,
760760
) -> &mut Self {
761761
self.span_suggestion_with_style(

compiler/rustc_errors/src/diagnostic_builder.rs

+5-5
Original file line numberDiff line numberDiff line change
@@ -477,7 +477,7 @@ impl<'a, G: EmissionGuarantee> DiagnosticBuilder<'a, G> {
477477
&mut self,
478478
sp: Span,
479479
msg: impl Into<DiagnosticMessage>,
480-
suggestion: String,
480+
suggestion: impl ToString,
481481
applicability: Applicability,
482482
) -> &mut Self);
483483
forward!(pub fn span_suggestions(
@@ -497,28 +497,28 @@ impl<'a, G: EmissionGuarantee> DiagnosticBuilder<'a, G> {
497497
&mut self,
498498
sp: Span,
499499
msg: impl Into<DiagnosticMessage>,
500-
suggestion: String,
500+
suggestion: impl ToString,
501501
applicability: Applicability,
502502
) -> &mut Self);
503503
forward!(pub fn span_suggestion_verbose(
504504
&mut self,
505505
sp: Span,
506506
msg: impl Into<DiagnosticMessage>,
507-
suggestion: String,
507+
suggestion: impl ToString,
508508
applicability: Applicability,
509509
) -> &mut Self);
510510
forward!(pub fn span_suggestion_hidden(
511511
&mut self,
512512
sp: Span,
513513
msg: impl Into<DiagnosticMessage>,
514-
suggestion: String,
514+
suggestion: impl ToString,
515515
applicability: Applicability,
516516
) -> &mut Self);
517517
forward!(pub fn tool_only_span_suggestion(
518518
&mut self,
519519
sp: Span,
520520
msg: impl Into<DiagnosticMessage>,
521-
suggestion: String,
521+
suggestion: impl ToString,
522522
applicability: Applicability,
523523
) -> &mut Self);
524524

compiler/rustc_expand/src/config.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -511,7 +511,7 @@ pub fn parse_cfg<'a>(meta_item: &'a MetaItem, sess: &Session) -> Option<&'a Meta
511511
err.span_suggestion(
512512
span,
513513
"expected syntax is",
514-
suggestion.into(),
514+
suggestion,
515515
Applicability::HasPlaceholders,
516516
);
517517
}

compiler/rustc_infer/src/infer/error_reporting/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -2198,7 +2198,7 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
21982198
err.span_suggestion(
21992199
span.with_hi(before_close).shrink_to_hi(),
22002200
msg,
2201-
",".into(),
2201+
",",
22022202
Applicability::MachineApplicable,
22032203
);
22042204
} else {

compiler/rustc_lint/src/array_into_iter.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,7 @@ impl<'tcx> LateLintPass<'tcx> for ArrayIntoIter {
129129
diag.span_suggestion(
130130
call.ident.span,
131131
"use `.iter()` instead of `.into_iter()` to avoid ambiguity",
132-
"iter".into(),
132+
"iter",
133133
Applicability::MachineApplicable,
134134
);
135135
if self.for_expr_span == expr.span {

compiler/rustc_lint/src/context.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -738,7 +738,7 @@ pub trait LintContext: Sized {
738738
db.span_suggestion_verbose(
739739
span.shrink_to_hi(),
740740
"insert whitespace here to avoid this being parsed as a prefix in Rust 2021",
741-
" ".into(),
741+
" ",
742742
Applicability::MachineApplicable,
743743
);
744744
}

compiler/rustc_lint/src/non_fmt_panic.rs

+5-5
Original file line numberDiff line numberDiff line change
@@ -176,7 +176,7 @@ fn check_panic<'tcx>(cx: &LateContext<'tcx>, f: &'tcx hir::Expr<'tcx>, arg: &'tc
176176
l.span_suggestion_verbose(
177177
arg_span.shrink_to_lo(),
178178
"add a \"{}\" format string to Display the message",
179-
"\"{}\", ".into(),
179+
"\"{}\", ",
180180
fmt_applicability,
181181
);
182182
} else if suggest_debug {
@@ -186,7 +186,7 @@ fn check_panic<'tcx>(cx: &LateContext<'tcx>, f: &'tcx hir::Expr<'tcx>, arg: &'tc
186186
"add a \"{{:?}}\" format string to use the Debug implementation of `{}`",
187187
ty,
188188
),
189-
"\"{:?}\", ".into(),
189+
"\"{:?}\", ",
190190
fmt_applicability,
191191
);
192192
}
@@ -266,13 +266,13 @@ fn check_panic_str<'tcx>(
266266
l.span_suggestion(
267267
arg.span.shrink_to_hi(),
268268
&format!("add the missing argument{}", pluralize!(n_arguments)),
269-
", ...".into(),
269+
", ...",
270270
Applicability::HasPlaceholders,
271271
);
272272
l.span_suggestion(
273273
arg.span.shrink_to_lo(),
274274
"or add a \"{}\" format string to use the message literally",
275-
"\"{}\", ".into(),
275+
"\"{}\", ",
276276
Applicability::MachineApplicable,
277277
);
278278
}
@@ -297,7 +297,7 @@ fn check_panic_str<'tcx>(
297297
l.span_suggestion(
298298
arg.span.shrink_to_lo(),
299299
"add a \"{}\" format string to use the message literally",
300-
"\"{}\", ".into(),
300+
"\"{}\", ",
301301
Applicability::MachineApplicable,
302302
);
303303
}

compiler/rustc_parse/src/lexer/mod.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -612,14 +612,14 @@ impl<'a> StringReader<'a> {
612612
err.span_suggestion_verbose(
613613
prefix_span,
614614
"use `br` for a raw byte string",
615-
"br".to_string(),
615+
"br",
616616
Applicability::MaybeIncorrect,
617617
);
618618
} else if expn_data.is_root() {
619619
err.span_suggestion_verbose(
620620
prefix_span.shrink_to_hi(),
621621
"consider inserting whitespace here",
622-
" ".into(),
622+
" ",
623623
Applicability::MaybeIncorrect,
624624
);
625625
}

compiler/rustc_parse/src/parser/expr.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -1771,7 +1771,7 @@ impl<'a> Parser<'a> {
17711771
.span_suggestion(
17721772
token.span,
17731773
"must have an integer part",
1774-
pprust::token_to_string(token).into(),
1774+
pprust::token_to_string(token),
17751775
Applicability::MachineApplicable,
17761776
)
17771777
.emit();
@@ -2324,7 +2324,7 @@ impl<'a> Parser<'a> {
23242324
.span_suggestion_short(
23252325
span,
23262326
msg,
2327-
sugg.into(),
2327+
sugg,
23282328
// Has been misleading, at least in the past (closed Issue #48492).
23292329
Applicability::MaybeIncorrect,
23302330
)
@@ -2828,7 +2828,7 @@ impl<'a> Parser<'a> {
28282828
e.span_suggestion(
28292829
self.prev_token.span.shrink_to_hi(),
28302830
"try adding a comma",
2831-
",".into(),
2831+
",",
28322832
Applicability::MachineApplicable,
28332833
);
28342834
}

compiler/rustc_parse/src/parser/item.rs

+5-5
Original file line numberDiff line numberDiff line change
@@ -332,7 +332,7 @@ impl<'a> Parser<'a> {
332332
err.span_suggestion_short(
333333
sp,
334334
&msg,
335-
" struct ".into(),
335+
" struct ",
336336
Applicability::MaybeIncorrect, // speculative
337337
);
338338
Err(err)
@@ -532,13 +532,13 @@ impl<'a> Parser<'a> {
532532
.span_suggestion(
533533
span,
534534
"add a trait here",
535-
" Trait ".into(),
535+
" Trait ",
536536
Applicability::HasPlaceholders,
537537
)
538538
.span_suggestion(
539539
span.to(self.token.span),
540540
"for an inherent impl, drop this `for`",
541-
"".into(),
541+
"",
542542
Applicability::MaybeIncorrect,
543543
)
544544
.emit();
@@ -1459,7 +1459,7 @@ impl<'a> Parser<'a> {
14591459
err.span_suggestion(
14601460
sp,
14611461
"missing comma here",
1462-
",".into(),
1462+
",",
14631463
Applicability::MachineApplicable,
14641464
);
14651465
}
@@ -1498,7 +1498,7 @@ impl<'a> Parser<'a> {
14981498
err.span_suggestion(
14991499
sp,
15001500
"try adding a comma",
1501-
",".into(),
1501+
",",
15021502
Applicability::MachineApplicable,
15031503
);
15041504
err.emit();

compiler/rustc_parse/src/parser/mod.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -802,7 +802,7 @@ impl<'a> Parser<'a> {
802802
.span_suggestion_verbose(
803803
self.prev_token.span.shrink_to_hi().until(self.token.span),
804804
&msg,
805-
" @ ".to_string(),
805+
" @ ",
806806
Applicability::MaybeIncorrect,
807807
)
808808
.emit();
@@ -818,7 +818,7 @@ impl<'a> Parser<'a> {
818818
.span_suggestion_short(
819819
sp,
820820
&format!("missing `{}`", token_str),
821-
token_str.into(),
821+
token_str,
822822
Applicability::MaybeIncorrect,
823823
)
824824
.emit();

compiler/rustc_parse/src/parser/pat.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -606,7 +606,7 @@ impl<'a> Parser<'a> {
606606
.span_suggestion(
607607
mutref_span,
608608
"try switching the order",
609-
"ref mut".into(),
609+
"ref mut",
610610
Applicability::MachineApplicable,
611611
)
612612
.emit();

compiler/rustc_resolve/src/build_reduced_graph.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -851,7 +851,7 @@ impl<'a, 'b> BuildReducedGraphVisitor<'a, 'b> {
851851
.span_suggestion(
852852
item.span,
853853
"rename the `self` crate to be able to import it",
854-
"extern crate self as name;".into(),
854+
"extern crate self as name;",
855855
Applicability::HasPlaceholders,
856856
)
857857
.emit();

src/tools/clippy/clippy_lints/src/functions/must_use.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ fn check_needless_must_use(
108108
diag.span_suggestion(
109109
attr.span,
110110
"remove the attribute",
111-
"".into(),
111+
"",
112112
Applicability::MachineApplicable,
113113
);
114114
},

src/tools/clippy/clippy_lints/src/needless_pass_by_value.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -241,7 +241,7 @@ impl<'tcx> LateLintPass<'tcx> for NeedlessPassByValue {
241241
|x| Cow::from(format!("change `{}` to", x)),
242242
)
243243
.as_ref(),
244-
suggestion.into(),
244+
suggestion,
245245
Applicability::Unspecified,
246246
);
247247
}
@@ -271,7 +271,7 @@ impl<'tcx> LateLintPass<'tcx> for NeedlessPassByValue {
271271
|x| Cow::from(format!("change `{}` to", x))
272272
)
273273
.as_ref(),
274-
suggestion.into(),
274+
suggestion,
275275
Applicability::Unspecified,
276276
);
277277
}

0 commit comments

Comments
 (0)