Skip to content

Commit

Permalink
Unrolled build for rust-lang#132938
Browse files Browse the repository at this point in the history
Rollup merge of rust-lang#132938 - compiler-errors:ed2024-apit-sugg, r=chenyukang

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

cc rust-lang#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.
  • Loading branch information
rust-timer authored Nov 12, 2024
2 parents 6503543 + 0dc6c1e commit 3324c7e
Show file tree
Hide file tree
Showing 4 changed files with 61 additions and 1 deletion.
10 changes: 9 additions & 1 deletion compiler/rustc_trait_selection/src/errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
//@ run-rustfix
//@ rustfix-only-machine-applicable

// Make sure that simple overcapture suggestions remain machine applicable.

#![allow(unused)]
#![deny(impl_trait_overcaptures)]

fn named<'a>(x: &'a i32) -> impl Sized + use<> { *x }
//~^ ERROR `impl Sized` will capture more lifetimes than possibly intended in edition 2024
//~| WARN this changes meaning in Rust 2024

fn main() {}
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
//@ run-rustfix
//@ rustfix-only-machine-applicable

// Make sure that simple overcapture suggestions remain machine applicable.

#![allow(unused)]
#![deny(impl_trait_overcaptures)]

fn named<'a>(x: &'a i32) -> impl Sized { *x }
//~^ ERROR `impl Sized` will capture more lifetimes than possibly intended in edition 2024
//~| WARN this changes meaning in Rust 2024

fn main() {}
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
error: `impl Sized` will capture more lifetimes than possibly intended in edition 2024
--> $DIR/overcaptures-2024-machine-applicable.rs:9:29
|
LL | fn named<'a>(x: &'a i32) -> impl Sized { *x }
| ^^^^^^^^^^
|
= warning: this changes meaning in Rust 2024
= note: for more information, see <https://doc.rust-lang.org/nightly/edition-guide/rust-2024/rpit-lifetime-capture.html>
note: specifically, this lifetime is in scope but not mentioned in the type's bounds
--> $DIR/overcaptures-2024-machine-applicable.rs:9:10
|
LL | fn named<'a>(x: &'a i32) -> impl Sized { *x }
| ^^
= note: all lifetimes in scope will be captured by `impl Trait`s in edition 2024
note: the lint level is defined here
--> $DIR/overcaptures-2024-machine-applicable.rs:7:9
|
LL | #![deny(impl_trait_overcaptures)]
| ^^^^^^^^^^^^^^^^^^^^^^^
help: use the precise capturing `use<...>` syntax to make the captures explicit
|
LL | fn named<'a>(x: &'a i32) -> impl Sized + use<> { *x }
| +++++++

error: aborting due to 1 previous error

0 comments on commit 3324c7e

Please sign in to comment.