Skip to content

Commit

Permalink
Enable new capture rules by default on edition 2024
Browse files Browse the repository at this point in the history
  • Loading branch information
compiler-errors committed Dec 5, 2023
1 parent acba7ef commit 803772e
Show file tree
Hide file tree
Showing 5 changed files with 40 additions and 9 deletions.
1 change: 1 addition & 0 deletions compiler/rustc_ast_lowering/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
26 changes: 26 additions & 0 deletions tests/ui/impl-trait/variance.e2024.stderr
Original file line number Diff line number Diff line change
@@ -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

8 changes: 4 additions & 4 deletions tests/ui/impl-trait/variance.new.stderr
Original file line number Diff line number Diff line change
@@ -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> {}
| ^^^^^^^^^^^^^^^^^^^^^^^^^
Expand Down
8 changes: 4 additions & 4 deletions tests/ui/impl-trait/variance.old.stderr
Original file line number Diff line number Diff line change
@@ -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> {}
| ^^^^^^^^^^^^^^^^^^^^^^^^^
Expand Down
6 changes: 5 additions & 1 deletion tests/ui/impl-trait/variance.rs
Original file line number Diff line number Diff line change
@@ -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))]

Expand All @@ -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]

Expand Down

0 comments on commit 803772e

Please sign in to comment.