Make it translatable too

This commit is contained in:
Michael Goulet 2024-07-11 14:14:17 -04:00
parent 03bee1e1e5
commit 42653c0045
3 changed files with 43 additions and 13 deletions

View file

@ -221,6 +221,10 @@ infer_opaque_hidden_type =
infer_outlives_bound = lifetime of the source pointer does not outlive lifetime bound of the object type
infer_outlives_content = lifetime of reference outlives lifetime of borrowed content...
infer_precise_capturing_existing = add `{$new_lifetime}` to the `use<...>` bound to explicitly capture it
infer_precise_capturing_new = add a `use<...>` bound to explicitly capture `{$new_lifetime}`
infer_prlf_defined_with_sub = the lifetime `{$sub_symbol}` defined here...
infer_prlf_defined_without_sub = the lifetime defined here...
infer_prlf_known_limitation = this is a known limitation that will be removed in the future (see issue #100013 <https://github.com/rust-lang/rust/issues/100013> for more information)

View file

@ -1581,3 +1581,32 @@ pub enum ObligationCauseFailureCode {
subdiags: Vec<TypeErrorAdditionalDiags>,
},
}
#[derive(Subdiagnostic)]
pub enum AddPreciseCapturing {
#[suggestion(
infer_precise_capturing_new,
style = "verbose",
code = " + use<{concatenated_bounds}>",
applicability = "machine-applicable"
)]
New {
#[primary_span]
span: Span,
new_lifetime: Symbol,
concatenated_bounds: String,
},
#[suggestion(
infer_precise_capturing_existing,
style = "verbose",
code = "{pre}{new_lifetime}{post}",
applicability = "machine-applicable"
)]
Existing {
#[primary_span]
span: Span,
new_lifetime: Symbol,
pre: &'static str,
post: &'static str,
},
}

View file

@ -1288,20 +1288,18 @@ fn suggest_precise_capturing<'tcx>(
_ => None,
});
let (insertion_span, pre, post) = if let Some(last_lifetime_span) = last_lifetime_span {
let (span, pre, post) = if let Some(last_lifetime_span) = last_lifetime_span {
(last_lifetime_span.shrink_to_hi(), ", ", "")
} else if let Some(first_param_span) = first_param_span {
(first_param_span.shrink_to_lo(), "", ", ")
} else {
// If we have no args, then have `use<>` and need to fall back to using
// span math. This sucks, but should be reliable due to the construction
// of the `use<>` span.
(span.with_hi(span.hi() - BytePos(1)).shrink_to_hi(), "", "")
};
diag.span_suggestion_verbose(
insertion_span,
format!("add `{new_lifetime}` to the `use<...>` bound to explicitly capture it",),
format!("{pre}{new_lifetime}{post}"),
Applicability::MachineApplicable,
);
diag.subdiagnostic(errors::AddPreciseCapturing::Existing { span, new_lifetime, pre, post });
} else {
let mut captured_lifetimes = FxIndexSet::default();
let mut captured_non_lifetimes = FxIndexSet::default();
@ -1349,11 +1347,10 @@ fn suggest_precise_capturing<'tcx>(
.collect::<Vec<_>>()
.join(", ");
diag.span_suggestion_verbose(
tcx.def_span(opaque_def_id).shrink_to_hi(),
format!("add a `use<...>` bound to explicitly capture `{new_lifetime}`",),
format!(" + use<{concatenated_bounds}>"),
Applicability::MachineApplicable,
);
diag.subdiagnostic(errors::AddPreciseCapturing::New {
span: tcx.def_span(opaque_def_id).shrink_to_hi(),
new_lifetime,
concatenated_bounds,
});
}
}