Skip to content

Commit 50831b4

Browse files
authored
Unrolled build for rust-lang#129600
Rollup merge of rust-lang#129600 - traviscross:TC/tie-impl_trait_overcaptures-to-rust-2024, r=compiler-errors Tie `impl_trait_overcaptures` lint to Rust 2024 The `impl_trait_overcaptures` lint is part of the migration to Rust 2024 and the Lifetime Capture Rules 2024. Now that we've stabilized precise capturing (RFC 3617), let's tie this lint to the `rust_2024_compatibility` lint group. Tracking: - rust-lang#117587 r? `@compiler-errors`
2 parents 22572d0 + 6982785 commit 50831b4

File tree

4 files changed

+28
-10
lines changed

4 files changed

+28
-10
lines changed

compiler/rustc_lint/src/impl_trait_overcaptures.rs

+6-4
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,9 @@ use rustc_middle::middle::resolve_bound_vars::ResolvedArg;
1010
use rustc_middle::ty::{
1111
self, Ty, TyCtxt, TypeSuperVisitable, TypeVisitable, TypeVisitableExt, TypeVisitor,
1212
};
13+
use rustc_session::lint::FutureIncompatibilityReason;
1314
use rustc_session::{declare_lint, declare_lint_pass};
15+
use rustc_span::edition::Edition;
1416
use rustc_span::Span;
1517

1618
use crate::{fluent_generated as fluent, LateContext, LateLintPass};
@@ -54,10 +56,10 @@ declare_lint! {
5456
pub IMPL_TRAIT_OVERCAPTURES,
5557
Allow,
5658
"`impl Trait` will capture more lifetimes than possibly intended in edition 2024",
57-
//@future_incompatible = FutureIncompatibleInfo {
58-
// reason: FutureIncompatibilityReason::EditionSemanticsChange(Edition::Edition2024),
59-
// reference: "<FIXME>",
60-
//};
59+
@future_incompatible = FutureIncompatibleInfo {
60+
reason: FutureIncompatibilityReason::EditionSemanticsChange(Edition::Edition2024),
61+
reference: "<https://doc.rust-lang.org/nightly/edition-guide/rust-2024/rpit-lifetime-capture.html>",
62+
};
6163
}
6264

6365
declare_lint! {

tests/ui/impl-trait/precise-capturing/overcaptures-2024.fixed

+4
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,17 @@
55

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

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

1214
struct W;
1315
impl W {
1416
fn hello(&self, x: &i32) -> impl Sized + '_ + use<'_> { self }
1517
//~^ ERROR `impl Sized + '_` will capture more lifetimes than possibly intended in edition 2024
18+
//~| WARN this changes meaning in Rust 2024
1619
}
1720

1821
trait Higher<'a> {
@@ -24,5 +27,6 @@ impl Higher<'_> for () {
2427

2528
fn hrtb() -> impl for<'a> Higher<'a, Output = impl Sized + use<>> {}
2629
//~^ ERROR `impl Sized` will capture more lifetimes than possibly intended in edition 2024
30+
//~| WARN this changes meaning in Rust 2024
2731

2832
fn main() {}

tests/ui/impl-trait/precise-capturing/overcaptures-2024.rs

+4
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,17 @@
55

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

910
fn implicit(x: &i32) -> impl Sized { *x }
1011
//~^ ERROR `impl Sized` will capture more lifetimes than possibly intended in edition 2024
12+
//~| WARN this changes meaning in Rust 2024
1113

1214
struct W;
1315
impl W {
1416
fn hello(&self, x: &i32) -> impl Sized + '_ { self }
1517
//~^ ERROR `impl Sized + '_` will capture more lifetimes than possibly intended in edition 2024
18+
//~| WARN this changes meaning in Rust 2024
1619
}
1720

1821
trait Higher<'a> {
@@ -24,5 +27,6 @@ impl Higher<'_> for () {
2427

2528
fn hrtb() -> impl for<'a> Higher<'a, Output = impl Sized> {}
2629
//~^ ERROR `impl Sized` will capture more lifetimes than possibly intended in edition 2024
30+
//~| WARN this changes meaning in Rust 2024
2731

2832
fn main() {}

tests/ui/impl-trait/precise-capturing/overcaptures-2024.stderr

+14-6
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ error: `impl Sized` will capture more lifetimes than possibly intended in editio
44
LL | fn named<'a>(x: &'a i32) -> impl Sized { *x }
55
| ^^^^^^^^^^
66
|
7+
= warning: this changes meaning in Rust 2024
8+
= note: for more information, see <https://doc.rust-lang.org/nightly/edition-guide/rust-2024/rpit-lifetime-capture.html>
79
note: specifically, this lifetime is in scope but not mentioned in the type's bounds
810
--> $DIR/overcaptures-2024.rs:6:10
911
|
@@ -21,13 +23,15 @@ LL | fn named<'a>(x: &'a i32) -> impl Sized + use<> { *x }
2123
| +++++++
2224

2325
error: `impl Sized` will capture more lifetimes than possibly intended in edition 2024
24-
--> $DIR/overcaptures-2024.rs:9:25
26+
--> $DIR/overcaptures-2024.rs:10:25
2527
|
2628
LL | fn implicit(x: &i32) -> impl Sized { *x }
2729
| ^^^^^^^^^^
2830
|
31+
= warning: this changes meaning in Rust 2024
32+
= note: for more information, see <https://doc.rust-lang.org/nightly/edition-guide/rust-2024/rpit-lifetime-capture.html>
2933
note: specifically, this lifetime is in scope but not mentioned in the type's bounds
30-
--> $DIR/overcaptures-2024.rs:9:16
34+
--> $DIR/overcaptures-2024.rs:10:16
3135
|
3236
LL | fn implicit(x: &i32) -> impl Sized { *x }
3337
| ^
@@ -38,13 +42,15 @@ LL | fn implicit(x: &i32) -> impl Sized + use<> { *x }
3842
| +++++++
3943

4044
error: `impl Sized + '_` will capture more lifetimes than possibly intended in edition 2024
41-
--> $DIR/overcaptures-2024.rs:14:33
45+
--> $DIR/overcaptures-2024.rs:16:33
4246
|
4347
LL | fn hello(&self, x: &i32) -> impl Sized + '_ { self }
4448
| ^^^^^^^^^^^^^^^
4549
|
50+
= warning: this changes meaning in Rust 2024
51+
= note: for more information, see <https://doc.rust-lang.org/nightly/edition-guide/rust-2024/rpit-lifetime-capture.html>
4652
note: specifically, this lifetime is in scope but not mentioned in the type's bounds
47-
--> $DIR/overcaptures-2024.rs:14:24
53+
--> $DIR/overcaptures-2024.rs:16:24
4854
|
4955
LL | fn hello(&self, x: &i32) -> impl Sized + '_ { self }
5056
| ^
@@ -55,13 +61,15 @@ LL | fn hello(&self, x: &i32) -> impl Sized + '_ + use<'_> { self }
5561
| +++++++++
5662

5763
error: `impl Sized` will capture more lifetimes than possibly intended in edition 2024
58-
--> $DIR/overcaptures-2024.rs:25:47
64+
--> $DIR/overcaptures-2024.rs:28:47
5965
|
6066
LL | fn hrtb() -> impl for<'a> Higher<'a, Output = impl Sized> {}
6167
| ^^^^^^^^^^
6268
|
69+
= warning: this changes meaning in Rust 2024
70+
= note: for more information, see <https://doc.rust-lang.org/nightly/edition-guide/rust-2024/rpit-lifetime-capture.html>
6371
note: specifically, this lifetime is in scope but not mentioned in the type's bounds
64-
--> $DIR/overcaptures-2024.rs:25:23
72+
--> $DIR/overcaptures-2024.rs:28:23
6573
|
6674
LL | fn hrtb() -> impl for<'a> Higher<'a, Output = impl Sized> {}
6775
| ^^

0 commit comments

Comments
 (0)