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.
This commit is contained in:
Travis Cross 2024-08-26 06:46:56 +00:00
parent 6b678c57b6
commit 6982785f18
4 changed files with 28 additions and 10 deletions

View File

@ -10,7 +10,9 @@ use rustc_middle::middle::resolve_bound_vars::ResolvedArg;
use rustc_middle::ty::{ use rustc_middle::ty::{
self, Ty, TyCtxt, TypeSuperVisitable, TypeVisitable, TypeVisitableExt, TypeVisitor, self, Ty, TyCtxt, TypeSuperVisitable, TypeVisitable, TypeVisitableExt, TypeVisitor,
}; };
use rustc_session::lint::FutureIncompatibilityReason;
use rustc_session::{declare_lint, declare_lint_pass}; use rustc_session::{declare_lint, declare_lint_pass};
use rustc_span::edition::Edition;
use rustc_span::Span; use rustc_span::Span;
use crate::{fluent_generated as fluent, LateContext, LateLintPass}; use crate::{fluent_generated as fluent, LateContext, LateLintPass};
@ -54,10 +56,10 @@ declare_lint! {
pub IMPL_TRAIT_OVERCAPTURES, pub IMPL_TRAIT_OVERCAPTURES,
Allow, Allow,
"`impl Trait` will capture more lifetimes than possibly intended in edition 2024", "`impl Trait` will capture more lifetimes than possibly intended in edition 2024",
//@future_incompatible = FutureIncompatibleInfo { @future_incompatible = FutureIncompatibleInfo {
// reason: FutureIncompatibilityReason::EditionSemanticsChange(Edition::Edition2024), reason: FutureIncompatibilityReason::EditionSemanticsChange(Edition::Edition2024),
// reference: "<FIXME>", reference: "<https://doc.rust-lang.org/nightly/edition-guide/rust-2024/rpit-lifetime-capture.html>",
//}; };
} }
declare_lint! { declare_lint! {

View File

@ -5,14 +5,17 @@
fn named<'a>(x: &'a i32) -> impl Sized + use<> { *x } fn named<'a>(x: &'a i32) -> impl Sized + use<> { *x }
//~^ ERROR `impl Sized` will capture more lifetimes than possibly intended in edition 2024 //~^ ERROR `impl Sized` will capture more lifetimes than possibly intended in edition 2024
//~| WARN this changes meaning in Rust 2024
fn implicit(x: &i32) -> impl Sized + use<> { *x } fn implicit(x: &i32) -> impl Sized + use<> { *x }
//~^ ERROR `impl Sized` will capture more lifetimes than possibly intended in edition 2024 //~^ ERROR `impl Sized` will capture more lifetimes than possibly intended in edition 2024
//~| WARN this changes meaning in Rust 2024
struct W; struct W;
impl W { impl W {
fn hello(&self, x: &i32) -> impl Sized + '_ + use<'_> { self } fn hello(&self, x: &i32) -> impl Sized + '_ + use<'_> { self }
//~^ ERROR `impl Sized + '_` will capture more lifetimes than possibly intended in edition 2024 //~^ ERROR `impl Sized + '_` will capture more lifetimes than possibly intended in edition 2024
//~| WARN this changes meaning in Rust 2024
} }
trait Higher<'a> { trait Higher<'a> {
@ -24,5 +27,6 @@ impl Higher<'_> for () {
fn hrtb() -> impl for<'a> Higher<'a, Output = impl Sized + use<>> {} fn hrtb() -> impl for<'a> Higher<'a, Output = impl Sized + use<>> {}
//~^ ERROR `impl Sized` will capture more lifetimes than possibly intended in edition 2024 //~^ ERROR `impl Sized` will capture more lifetimes than possibly intended in edition 2024
//~| WARN this changes meaning in Rust 2024
fn main() {} fn main() {}

View File

@ -5,14 +5,17 @@
fn named<'a>(x: &'a i32) -> impl Sized { *x } fn named<'a>(x: &'a i32) -> impl Sized { *x }
//~^ ERROR `impl Sized` will capture more lifetimes than possibly intended in edition 2024 //~^ ERROR `impl Sized` will capture more lifetimes than possibly intended in edition 2024
//~| WARN this changes meaning in Rust 2024
fn implicit(x: &i32) -> impl Sized { *x } fn implicit(x: &i32) -> impl Sized { *x }
//~^ ERROR `impl Sized` will capture more lifetimes than possibly intended in edition 2024 //~^ ERROR `impl Sized` will capture more lifetimes than possibly intended in edition 2024
//~| WARN this changes meaning in Rust 2024
struct W; struct W;
impl W { impl W {
fn hello(&self, x: &i32) -> impl Sized + '_ { self } fn hello(&self, x: &i32) -> impl Sized + '_ { self }
//~^ ERROR `impl Sized + '_` will capture more lifetimes than possibly intended in edition 2024 //~^ ERROR `impl Sized + '_` will capture more lifetimes than possibly intended in edition 2024
//~| WARN this changes meaning in Rust 2024
} }
trait Higher<'a> { trait Higher<'a> {
@ -24,5 +27,6 @@ impl Higher<'_> for () {
fn hrtb() -> impl for<'a> Higher<'a, Output = impl Sized> {} fn hrtb() -> impl for<'a> Higher<'a, Output = impl Sized> {}
//~^ ERROR `impl Sized` will capture more lifetimes than possibly intended in edition 2024 //~^ ERROR `impl Sized` will capture more lifetimes than possibly intended in edition 2024
//~| WARN this changes meaning in Rust 2024
fn main() {} fn main() {}

View File

@ -4,6 +4,8 @@ error: `impl Sized` will capture more lifetimes than possibly intended in editio
LL | fn named<'a>(x: &'a i32) -> impl Sized { *x } 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 note: specifically, this lifetime is in scope but not mentioned in the type's bounds
--> $DIR/overcaptures-2024.rs:6:10 --> $DIR/overcaptures-2024.rs:6:10
| |
@ -21,13 +23,15 @@ LL | fn named<'a>(x: &'a i32) -> impl Sized + use<> { *x }
| +++++++ | +++++++
error: `impl Sized` will capture more lifetimes than possibly intended in edition 2024 error: `impl Sized` will capture more lifetimes than possibly intended in edition 2024
--> $DIR/overcaptures-2024.rs:9:25 --> $DIR/overcaptures-2024.rs:10:25
| |
LL | fn implicit(x: &i32) -> impl Sized { *x } LL | fn implicit(x: &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 note: specifically, this lifetime is in scope but not mentioned in the type's bounds
--> $DIR/overcaptures-2024.rs:9:16 --> $DIR/overcaptures-2024.rs:10:16
| |
LL | fn implicit(x: &i32) -> impl Sized { *x } LL | fn implicit(x: &i32) -> impl Sized { *x }
| ^ | ^
@ -38,13 +42,15 @@ LL | fn implicit(x: &i32) -> impl Sized + use<> { *x }
| +++++++ | +++++++
error: `impl Sized + '_` will capture more lifetimes than possibly intended in edition 2024 error: `impl Sized + '_` will capture more lifetimes than possibly intended in edition 2024
--> $DIR/overcaptures-2024.rs:14:33 --> $DIR/overcaptures-2024.rs:16:33
| |
LL | fn hello(&self, x: &i32) -> impl Sized + '_ { self } LL | fn hello(&self, x: &i32) -> impl Sized + '_ { self }
| ^^^^^^^^^^^^^^^ | ^^^^^^^^^^^^^^^
| |
= 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 note: specifically, this lifetime is in scope but not mentioned in the type's bounds
--> $DIR/overcaptures-2024.rs:14:24 --> $DIR/overcaptures-2024.rs:16:24
| |
LL | fn hello(&self, x: &i32) -> impl Sized + '_ { self } LL | fn hello(&self, x: &i32) -> impl Sized + '_ { self }
| ^ | ^
@ -55,13 +61,15 @@ LL | fn hello(&self, x: &i32) -> impl Sized + '_ + use<'_> { self }
| +++++++++ | +++++++++
error: `impl Sized` will capture more lifetimes than possibly intended in edition 2024 error: `impl Sized` will capture more lifetimes than possibly intended in edition 2024
--> $DIR/overcaptures-2024.rs:25:47 --> $DIR/overcaptures-2024.rs:28:47
| |
LL | fn hrtb() -> impl for<'a> Higher<'a, Output = impl Sized> {} LL | fn hrtb() -> impl for<'a> Higher<'a, Output = impl Sized> {}
| ^^^^^^^^^^ | ^^^^^^^^^^
| |
= 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 note: specifically, this lifetime is in scope but not mentioned in the type's bounds
--> $DIR/overcaptures-2024.rs:25:23 --> $DIR/overcaptures-2024.rs:28:23
| |
LL | fn hrtb() -> impl for<'a> Higher<'a, Output = impl Sized> {} LL | fn hrtb() -> impl for<'a> Higher<'a, Output = impl Sized> {}
| ^^ | ^^