Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions compiler/rustc_borrowck/src/diagnostics/conflict_errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -535,7 +535,7 @@ impl<'infcx, 'tcx> MirBorrowckCtxt<'_, 'infcx, 'tcx> {
if let Some(pat) = finder.parent_pat {
sugg.insert(0, (pat.span.shrink_to_lo(), "ref ".to_string()));
}
err.multipart_suggestion_verbose(
err.multipart_suggestion(
"borrow this binding in the pattern to avoid moving the value",
sugg,
Applicability::MachineApplicable,
Expand Down Expand Up @@ -1509,7 +1509,7 @@ impl<'infcx, 'tcx> MirBorrowckCtxt<'_, 'infcx, 'tcx> {
} else {
"consider cloning the value if the performance cost is acceptable"
};
err.multipart_suggestion_verbose(msg, sugg, Applicability::MachineApplicable);
err.multipart_suggestion(msg, sugg, Applicability::MachineApplicable);
true
}

Expand Down Expand Up @@ -2759,7 +2759,7 @@ impl<'infcx, 'tcx> MirBorrowckCtxt<'_, 'infcx, 'tcx> {
.chain(finder.closure_call_changes)
.collect();

err.multipart_suggestion_verbose(
err.multipart_suggestion(
"try explicitly passing `&Self` into the closure as an argument",
sugg,
Applicability::MachineApplicable,
Expand Down Expand Up @@ -3347,7 +3347,7 @@ impl<'infcx, 'tcx> MirBorrowckCtxt<'_, 'infcx, 'tcx> {

let addition =
format!("let {}binding = {};\n{}", mutability, s, " ".repeat(p));
err.multipart_suggestion_verbose(
err.multipart_suggestion(
msg,
vec![
(stmt.span.shrink_to_lo(), addition),
Expand Down
6 changes: 1 addition & 5 deletions compiler/rustc_borrowck/src/diagnostics/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1516,11 +1516,7 @@ impl<'infcx, 'tcx> MirBorrowckCtxt<'_, 'infcx, 'tcx> {
)
}
};
err.multipart_suggestion_verbose(
msg,
sugg,
Applicability::MaybeIncorrect,
);
err.multipart_suggestion(msg, sugg, Applicability::MaybeIncorrect);
for error in errors {
if let FulfillmentErrorCode::Select(
SelectionError::Unimplemented,
Expand Down
4 changes: 2 additions & 2 deletions compiler/rustc_borrowck/src/diagnostics/move_errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -375,7 +375,7 @@ impl<'infcx, 'tcx> MirBorrowckCtxt<'_, 'infcx, 'tcx> {
.source_map()
.indentation_before(stmt.span)
.unwrap_or_else(|| " ".to_string());
err.multipart_suggestion_verbose(
err.multipart_suggestion(
"consider cloning the value before moving it into the closure",
vec![
(
Expand Down Expand Up @@ -405,7 +405,7 @@ impl<'infcx, 'tcx> MirBorrowckCtxt<'_, 'infcx, 'tcx> {
.source_map()
.indentation_before(closure_expr.span)
.unwrap_or_else(|| " ".to_string());
err.multipart_suggestion_verbose(
err.multipart_suggestion(
"consider cloning the value before moving it into the closure",
vec![
(
Expand Down
4 changes: 2 additions & 2 deletions compiler/rustc_borrowck/src/diagnostics/mutability_errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1340,7 +1340,7 @@ impl<'infcx, 'tcx> MirBorrowckCtxt<'_, 'infcx, 'tcx> {
return;
}

err.multipart_suggestion_verbose(
err.multipart_suggestion(
format!(
"consider changing this to be a mutable {pointer_desc}{}{extra}",
if is_trait_sig {
Expand All @@ -1365,7 +1365,7 @@ impl<'infcx, 'tcx> MirBorrowckCtxt<'_, 'infcx, 'tcx> {
if self.infcx.tcx.sess.source_map().is_imported(span) {
return;
}
err.multipart_suggestion_verbose(
err.multipart_suggestion(
"consider using `get_mut`",
vec![(span, suggestion)],
Applicability::MaybeIncorrect,
Expand Down
4 changes: 2 additions & 2 deletions compiler/rustc_borrowck/src/diagnostics/region_errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -290,7 +290,7 @@ impl<'infcx, 'tcx> MirBorrowckCtxt<'_, 'infcx, 'tcx> {
});
if suggestions.len() > 0 {
suggestions.dedup();
diag.multipart_suggestion_verbose(
diag.multipart_suggestion(
inline_fluent!("consider restricting the type parameter to the `'static` lifetime"),
suggestions,
Applicability::MaybeIncorrect,
Expand Down Expand Up @@ -902,7 +902,7 @@ impl<'infcx, 'tcx> MirBorrowckCtxt<'_, 'infcx, 'tcx> {
spans_suggs.push((alias_span.shrink_to_hi(), "<'a>".to_string()));
}

diag.multipart_suggestion_verbose(
diag.multipart_suggestion(
format!(
"to declare that the trait object {captures}, you can add a lifetime parameter `'a` in the type alias"
),
Expand Down
20 changes: 2 additions & 18 deletions compiler/rustc_errors/src/diagnostic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -838,25 +838,9 @@ impl<'a, G: EmissionGuarantee> Diag<'a, G> {
}

with_fn! { with_multipart_suggestion,
/// Show a suggestion that has multiple parts to it.
/// In other words, multiple changes need to be applied as part of this suggestion.
pub fn multipart_suggestion(
&mut self,
msg: impl Into<DiagMessage>,
suggestion: Vec<(Span, String)>,
applicability: Applicability,
) -> &mut Self {
self.multipart_suggestion_with_style(
msg,
suggestion,
applicability,
SuggestionStyle::ShowCode,
)
} }

/// Show a suggestion that has multiple parts to it, always as its own subdiagnostic.
/// In other words, multiple changes need to be applied as part of this suggestion.
pub fn multipart_suggestion_verbose(
pub fn multipart_suggestion(
&mut self,
msg: impl Into<DiagMessage>,
suggestion: Vec<(Span, String)>,
Expand All @@ -868,7 +852,7 @@ impl<'a, G: EmissionGuarantee> Diag<'a, G> {
applicability,
SuggestionStyle::ShowAlways,
)
}
} }

/// [`Diag::multipart_suggestion()`] but you can set the [`SuggestionStyle`].
pub fn multipart_suggestion_with_style(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1026,7 +1026,7 @@ impl<'a, 'tcx> WrongNumberOfGenericArgs<'a, 'tcx> {
.collect::<Vec<_>>();

if !suggestions.is_empty() {
err.multipart_suggestion_verbose(
err.multipart_suggestion(
format!(
"replace the generic bound{s} with the associated type{s}",
s = pluralize!(unbound_types.len())
Expand Down
16 changes: 8 additions & 8 deletions compiler/rustc_hir_analysis/src/hir_ty_lowering/dyn_trait.rs
Original file line number Diff line number Diff line change
Expand Up @@ -619,7 +619,7 @@ impl<'tcx> dyn HirTyLowerer<'tcx> + '_ {
tcx.node_span_lint(BARE_TRAIT_OBJECTS, hir_id, span, |lint| {
lint.primary_message("trait objects without an explicit `dyn` are deprecated");
if span.can_be_used_for_suggestions() {
lint.multipart_suggestion_verbose(
lint.multipart_suggestion(
"if this is a dyn-compatible trait, use `dyn`",
sugg,
Applicability::MachineApplicable,
Expand Down Expand Up @@ -684,7 +684,7 @@ impl<'tcx> dyn HirTyLowerer<'tcx> + '_ {
} else {
sugg.push((generics.where_clause_span, format!("<{param}: {}>", rendered_ty)));
}
diag.multipart_suggestion_verbose(
diag.multipart_suggestion(
"you might be missing a type parameter",
sugg,
Applicability::MachineApplicable,
Expand Down Expand Up @@ -795,7 +795,7 @@ impl<'tcx> dyn HirTyLowerer<'tcx> + '_ {
}

// FIXME: Only emit this suggestion if the trait is dyn-compatible.
diag.multipart_suggestion_verbose(
diag.multipart_suggestion(
"you can add the `dyn` keyword if you want a trait object",
sugg,
Applicability::MachineApplicable,
Expand Down Expand Up @@ -881,7 +881,7 @@ impl<'tcx> dyn HirTyLowerer<'tcx> + '_ {
single underlying type",
);

diag.multipart_suggestion_verbose(msg, impl_sugg, Applicability::MachineApplicable);
diag.multipart_suggestion(msg, impl_sugg, Applicability::MachineApplicable);

// Suggest `Box<dyn Trait>` for return type
if is_dyn_compatible {
Expand All @@ -897,7 +897,7 @@ impl<'tcx> dyn HirTyLowerer<'tcx> + '_ {
]
};

diag.multipart_suggestion_verbose(
diag.multipart_suggestion(
"alternatively, you can return an owned trait object",
suggestion,
Applicability::MachineApplicable,
Expand All @@ -912,12 +912,12 @@ impl<'tcx> dyn HirTyLowerer<'tcx> + '_ {
continue;
}
let sugg = self.add_generic_param_suggestion(generics, span, &trait_name);
diag.multipart_suggestion_verbose(
diag.multipart_suggestion(
format!("use a new generic type parameter, constrained by `{trait_name}`"),
sugg,
Applicability::MachineApplicable,
);
diag.multipart_suggestion_verbose(
diag.multipart_suggestion(
"you can also use an opaque type, but users won't be able to specify the type \
parameter when calling the `fn`, having to rely exclusively on type inference",
impl_sugg,
Expand All @@ -941,7 +941,7 @@ impl<'tcx> dyn HirTyLowerer<'tcx> + '_ {
} else {
vec![(span.shrink_to_lo(), dyn_str.to_string())]
};
diag.multipart_suggestion_verbose(
diag.multipart_suggestion(
format!(
"alternatively, use a trait object to accept any type that implements \
`{trait_name}`, accessing its methods at runtime using dynamic dispatch",
Expand Down
6 changes: 3 additions & 3 deletions compiler/rustc_hir_analysis/src/hir_ty_lowering/errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -528,7 +528,7 @@ impl<'tcx> dyn HirTyLowerer<'tcx> + '_ {
}
}
}
err.multipart_suggestion_verbose(
err.multipart_suggestion(
"there is a variant with a similar name",
suggestion,
Applicability::HasPlaceholders,
Expand Down Expand Up @@ -1546,7 +1546,7 @@ pub fn prohibit_assoc_item_constraint(
(constraint.span.with_lo(constraint.ident.span.hi()), String::new()),
];

err.multipart_suggestion_verbose(
err.multipart_suggestion(
"declare the type parameter right after the `impl` keyword",
suggestions,
Applicability::MaybeIncorrect,
Expand Down Expand Up @@ -1721,7 +1721,7 @@ fn generics_args_err_extend<'a>(
},
(args_span, String::new()),
];
err.multipart_suggestion_verbose(msg, suggestion, Applicability::MaybeIncorrect);
err.multipart_suggestion(msg, suggestion, Applicability::MaybeIncorrect);
}
GenericsArgsErrExtend::DefVariant(segments) => {
let args: Vec<Span> = segments
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_hir_typeck/src/cast.rs
Original file line number Diff line number Diff line change
Expand Up @@ -485,7 +485,7 @@ impl<'a, 'tcx> CastCheck<'tcx> {
));
}

err.multipart_suggestion_verbose(
err.multipart_suggestion(
"consider borrowing the value",
suggestion,
Applicability::MachineApplicable,
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_hir_typeck/src/demand.rs
Original file line number Diff line number Diff line change
Expand Up @@ -888,7 +888,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
]);
// We suggest changing the argument from `mut ident: &Ty` to `ident: &'_ mut Ty` and the
// assignment from `ident = val;` to `*ident = val;`.
err.multipart_suggestion_verbose(
err.multipart_suggestion(
"you might have meant to mutate the pointed at value being passed in, instead of \
changing the reference in the local binding",
sugg,
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_hir_typeck/src/errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -304,7 +304,7 @@ impl Subdiagnostic for SuggestAnnotations {
}
}

diag.multipart_suggestion_verbose(
diag.multipart_suggestion(
"use `()` annotations to avoid fallback changes",
suggestions,
Applicability::MachineApplicable,
Expand Down
4 changes: 2 additions & 2 deletions compiler/rustc_hir_typeck/src/fn_ctxt/checks.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1994,7 +1994,7 @@ impl<'a, 'b, 'tcx> FnCallDiagCtxt<'a, 'b, 'tcx> {
),
);
err.code(self.err_code.to_owned());
err.multipart_suggestion_verbose(
err.multipart_suggestion(
"wrap these arguments in parentheses to construct a tuple",
vec![
(lo.shrink_to_lo(), "(".to_string()),
Expand Down Expand Up @@ -2649,7 +2649,7 @@ impl<'a, 'b, 'tcx> FnCallDiagCtxt<'a, 'b, 'tcx> {
Some(format!("provide the argument{}", if plural { "s" } else { "" }))
}
SuggestionText::Remove(plural) => {
err.multipart_suggestion_verbose(
err.multipart_suggestion(
format!("remove the extra argument{}", if plural { "s" } else { "" }),
suggestions,
Applicability::HasPlaceholders,
Expand Down
Loading
Loading