From 803772e81d1245a4d1eebcea5484b1f78ba5aca6 Mon Sep 17 00:00:00 2001
From: Michael Goulet <michael@errs.io>
Date: Tue, 7 Nov 2023 00:07:57 +0000
Subject: [PATCH] Enable new capture rules by default on edition 2024

---
 compiler/rustc_ast_lowering/src/lib.rs    |  1 +
 tests/ui/impl-trait/variance.e2024.stderr | 26 +++++++++++++++++++++++
 tests/ui/impl-trait/variance.new.stderr   |  8 +++----
 tests/ui/impl-trait/variance.old.stderr   |  8 +++----
 tests/ui/impl-trait/variance.rs           |  6 +++++-
 5 files changed, 40 insertions(+), 9 deletions(-)
 create mode 100644 tests/ui/impl-trait/variance.e2024.stderr

diff --git a/compiler/rustc_ast_lowering/src/lib.rs b/compiler/rustc_ast_lowering/src/lib.rs
index 241b47046fe..72adcac679b 100644
--- a/compiler/rustc_ast_lowering/src/lib.rs
+++ b/compiler/rustc_ast_lowering/src/lib.rs
@@ -1575,6 +1575,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
                     fn_kind.expect("expected RPITs to be lowered with a FnKind"),
                     FnDeclKind::Impl | FnDeclKind::Trait
                 ) || self.tcx.features().lifetime_capture_rules_2024
+                    || span.at_least_rust_2024()
                 {
                     // return-position impl trait in trait was decided to capture all
                     // in-scope lifetimes, which we collect for all opaques during resolution.
diff --git a/tests/ui/impl-trait/variance.e2024.stderr b/tests/ui/impl-trait/variance.e2024.stderr
new file mode 100644
index 00000000000..17245055744
--- /dev/null
+++ b/tests/ui/impl-trait/variance.e2024.stderr
@@ -0,0 +1,26 @@
+error: [*, o]
+  --> $DIR/variance.rs:14:36
+   |
+LL | fn not_captured_early<'a: 'a>() -> impl Sized {}
+   |                                    ^^^^^^^^^^
+
+error: [*, o]
+  --> $DIR/variance.rs:19:32
+   |
+LL | fn captured_early<'a: 'a>() -> impl Sized + Captures<'a> {}
+   |                                ^^^^^^^^^^^^^^^^^^^^^^^^^
+
+error: [o]
+  --> $DIR/variance.rs:21:40
+   |
+LL | fn not_captured_late<'a>(_: &'a ()) -> impl Sized {}
+   |                                        ^^^^^^^^^^
+
+error: [o]
+  --> $DIR/variance.rs:26:36
+   |
+LL | fn captured_late<'a>(_: &'a ()) -> impl Sized + Captures<'a> {}
+   |                                    ^^^^^^^^^^^^^^^^^^^^^^^^^
+
+error: aborting due to 4 previous errors
+
diff --git a/tests/ui/impl-trait/variance.new.stderr b/tests/ui/impl-trait/variance.new.stderr
index abf4b1ac210..17245055744 100644
--- a/tests/ui/impl-trait/variance.new.stderr
+++ b/tests/ui/impl-trait/variance.new.stderr
@@ -1,23 +1,23 @@
 error: [*, o]
-  --> $DIR/variance.rs:12:36
+  --> $DIR/variance.rs:14:36
    |
 LL | fn not_captured_early<'a: 'a>() -> impl Sized {}
    |                                    ^^^^^^^^^^
 
 error: [*, o]
-  --> $DIR/variance.rs:16:32
+  --> $DIR/variance.rs:19:32
    |
 LL | fn captured_early<'a: 'a>() -> impl Sized + Captures<'a> {}
    |                                ^^^^^^^^^^^^^^^^^^^^^^^^^
 
 error: [o]
-  --> $DIR/variance.rs:18:40
+  --> $DIR/variance.rs:21:40
    |
 LL | fn not_captured_late<'a>(_: &'a ()) -> impl Sized {}
    |                                        ^^^^^^^^^^
 
 error: [o]
-  --> $DIR/variance.rs:22:36
+  --> $DIR/variance.rs:26:36
    |
 LL | fn captured_late<'a>(_: &'a ()) -> impl Sized + Captures<'a> {}
    |                                    ^^^^^^^^^^^^^^^^^^^^^^^^^
diff --git a/tests/ui/impl-trait/variance.old.stderr b/tests/ui/impl-trait/variance.old.stderr
index 8b4d6314359..9410b54b491 100644
--- a/tests/ui/impl-trait/variance.old.stderr
+++ b/tests/ui/impl-trait/variance.old.stderr
@@ -1,23 +1,23 @@
 error: [*]
-  --> $DIR/variance.rs:12:36
+  --> $DIR/variance.rs:14:36
    |
 LL | fn not_captured_early<'a: 'a>() -> impl Sized {}
    |                                    ^^^^^^^^^^
 
 error: [*, o]
-  --> $DIR/variance.rs:16:32
+  --> $DIR/variance.rs:19:32
    |
 LL | fn captured_early<'a: 'a>() -> impl Sized + Captures<'a> {}
    |                                ^^^^^^^^^^^^^^^^^^^^^^^^^
 
 error: []
-  --> $DIR/variance.rs:18:40
+  --> $DIR/variance.rs:21:40
    |
 LL | fn not_captured_late<'a>(_: &'a ()) -> impl Sized {}
    |                                        ^^^^^^^^^^
 
 error: [o]
-  --> $DIR/variance.rs:22:36
+  --> $DIR/variance.rs:26:36
    |
 LL | fn captured_late<'a>(_: &'a ()) -> impl Sized + Captures<'a> {}
    |                                    ^^^^^^^^^^^^^^^^^^^^^^^^^
diff --git a/tests/ui/impl-trait/variance.rs b/tests/ui/impl-trait/variance.rs
index e111d37761f..86da1908509 100644
--- a/tests/ui/impl-trait/variance.rs
+++ b/tests/ui/impl-trait/variance.rs
@@ -1,4 +1,6 @@
-// revisions: old new
+// revisions: old new e2024
+//[e2024] edition: 2024
+//[e2024] compile-flags: -Z unstable-options
 
 #![cfg_attr(new, feature(lifetime_capture_rules_2024))]
 
@@ -12,12 +14,14 @@ impl<T> Captures<'_> for T {}
 fn not_captured_early<'a: 'a>() -> impl Sized {}
 //[old]~^ [*]
 //[new]~^^ [*, o]
+//[e2024]~^^^ [*, o]
 
 fn captured_early<'a: 'a>() -> impl Sized + Captures<'a> {} //~ [*, o]
 
 fn not_captured_late<'a>(_: &'a ()) -> impl Sized {}
 //[old]~^ []
 //[new]~^^ [o]
+//[e2024]~^^^ [o]
 
 fn captured_late<'a>(_: &'a ()) -> impl Sized + Captures<'a> {} //~ [o]