Rollup merge of #132938 - compiler-errors:ed2024-apit-sugg, r=chenyukang

Make precise capturing suggestion machine-applicable only if it has no APITs

cc https://github.com/rust-lang/rust/issues/132932

The only case where this suggestion is not machine-applicable is when we suggest turning arg-position impl trait into type parameters, which may expose type parameters that were not turbofishable before.
This commit is contained in:
Matthias Krüger 2024-11-12 18:11:06 +01:00 committed by GitHub
commit 11c7b01aa7
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
4 changed files with 61 additions and 1 deletions

View file

@ -1907,10 +1907,18 @@ impl Subdiagnostic for AddPreciseCapturingForOvercapture {
diag: &mut Diag<'_, G>,
_f: &F,
) {
let applicability = if self.apit_spans.is_empty() {
Applicability::MachineApplicable
} else {
// If there are APIT that are converted to regular parameters,
// then this may make the API turbofishable in ways that were
// not intended.
Applicability::MaybeIncorrect
};
diag.multipart_suggestion_verbose(
fluent::trait_selection_precise_capturing_overcaptures,
self.suggs,
Applicability::MaybeIncorrect,
applicability,
);
if !self.apit_spans.is_empty() {
diag.span_note(