Skip to content

Commit c938594

Browse files
authored
Rollup merge of rust-lang#136787 - compiler-errors:lt2024feat, r=oli-obk
Remove `lifetime_capture_rules_2024` feature Just use edition 2024 instead
2 parents fb63887 + 6fe8b8d commit c938594

File tree

12 files changed

+35
-78
lines changed

12 files changed

+35
-78
lines changed

compiler/rustc_feature/src/removed.rs

+2
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,8 @@ declare_features! (
135135
Some("removed as it caused some confusion and discussion was inactive for years")),
136136
/// Lazily evaluate constants. This allows constants to depend on type parameters.
137137
(removed, lazy_normalization_consts, "1.46.0", Some(72219), Some("superseded by `generic_const_exprs`")),
138+
/// Changes `impl Trait` to capture all lifetimes in scope.
139+
(removed, lifetime_capture_rules_2024, "1.76.0", None, Some("unnecessary -- use edition 2024 instead")),
138140
/// Allows using the `#[link_args]` attribute.
139141
(removed, link_args, "1.53.0", Some(29596),
140142
Some("removed in favor of using `-C link-arg=ARG` on command line, \

compiler/rustc_feature/src/unstable.rs

-2
Original file line numberDiff line numberDiff line change
@@ -214,8 +214,6 @@ declare_features! (
214214
(internal, intrinsics, "1.0.0", None),
215215
/// Allows using `#[lang = ".."]` attribute for linking items to special compiler logic.
216216
(internal, lang_items, "1.0.0", None),
217-
/// Changes `impl Trait` to capture all lifetimes in scope.
218-
(unstable, lifetime_capture_rules_2024, "1.76.0", None),
219217
/// Allows `#[link(..., cfg(..))]`; perma-unstable per #37406
220218
(internal, link_cfg, "1.14.0", None),
221219
/// Allows using `?Trait` trait bounds in more contexts.

compiler/rustc_hir_analysis/src/collect/resolve_bound_vars.rs

+12-21
Original file line numberDiff line numberDiff line change
@@ -305,21 +305,15 @@ fn generic_param_def_as_bound_arg(param: &ty::GenericParamDef) -> ty::BoundVaria
305305
}
306306

307307
/// Whether this opaque always captures lifetimes in scope.
308-
/// Right now, this is all RPITIT and TAITs, and when `lifetime_capture_rules_2024`
309-
/// is enabled. We don't check the span of the edition, since this is done
310-
/// on a per-opaque basis to account for nested opaques.
311-
fn opaque_captures_all_in_scope_lifetimes<'tcx>(
312-
tcx: TyCtxt<'tcx>,
313-
opaque: &'tcx hir::OpaqueTy<'tcx>,
314-
) -> bool {
308+
/// Right now, this is all RPITIT and TAITs, and when the opaque
309+
/// is coming from a span corresponding to edition 2024.
310+
fn opaque_captures_all_in_scope_lifetimes<'tcx>(opaque: &'tcx hir::OpaqueTy<'tcx>) -> bool {
315311
match opaque.origin {
316312
// if the opaque has the `use<...>` syntax, the user is telling us that they only want
317313
// to account for those lifetimes, so do not try to be clever.
318314
_ if opaque.bounds.iter().any(|bound| matches!(bound, hir::GenericBound::Use(..))) => false,
319315
hir::OpaqueTyOrigin::AsyncFn { .. } | hir::OpaqueTyOrigin::TyAlias { .. } => true,
320-
_ if tcx.features().lifetime_capture_rules_2024() || opaque.span.at_least_rust_2024() => {
321-
true
322-
}
316+
_ if opaque.span.at_least_rust_2024() => true,
323317
hir::OpaqueTyOrigin::FnReturn { in_trait_or_impl, .. } => in_trait_or_impl.is_some(),
324318
}
325319
}
@@ -519,8 +513,7 @@ impl<'a, 'tcx> Visitor<'tcx> for BoundVarContext<'a, 'tcx> {
519513
fn visit_opaque_ty(&mut self, opaque: &'tcx rustc_hir::OpaqueTy<'tcx>) {
520514
let captures = RefCell::new(FxIndexMap::default());
521515

522-
let capture_all_in_scope_lifetimes =
523-
opaque_captures_all_in_scope_lifetimes(self.tcx, opaque);
516+
let capture_all_in_scope_lifetimes = opaque_captures_all_in_scope_lifetimes(opaque);
524517
if capture_all_in_scope_lifetimes {
525518
let lifetime_ident = |def_id: LocalDefId| {
526519
let name = self.tcx.item_name(def_id.to_def_id());
@@ -2276,7 +2269,7 @@ fn is_late_bound_map(
22762269
}
22772270

22782271
let mut appears_in_output =
2279-
AllCollector { tcx, has_fully_capturing_opaque: false, regions: Default::default() };
2272+
AllCollector { has_fully_capturing_opaque: false, regions: Default::default() };
22802273
intravisit::walk_fn_ret_ty(&mut appears_in_output, &sig.decl.output);
22812274
if appears_in_output.has_fully_capturing_opaque {
22822275
appears_in_output.regions.extend(generics.params.iter().map(|param| param.def_id));
@@ -2289,7 +2282,7 @@ fn is_late_bound_map(
22892282
// Subtle point: because we disallow nested bindings, we can just
22902283
// ignore binders here and scrape up all names we see.
22912284
let mut appears_in_where_clause =
2292-
AllCollector { tcx, has_fully_capturing_opaque: true, regions: Default::default() };
2285+
AllCollector { has_fully_capturing_opaque: true, regions: Default::default() };
22932286
appears_in_where_clause.visit_generics(generics);
22942287
debug!(?appears_in_where_clause.regions);
22952288

@@ -2455,23 +2448,21 @@ fn is_late_bound_map(
24552448
}
24562449
}
24572450

2458-
struct AllCollector<'tcx> {
2459-
tcx: TyCtxt<'tcx>,
2451+
struct AllCollector {
24602452
has_fully_capturing_opaque: bool,
24612453
regions: FxHashSet<LocalDefId>,
24622454
}
24632455

2464-
impl<'v> Visitor<'v> for AllCollector<'v> {
2465-
fn visit_lifetime(&mut self, lifetime_ref: &'v hir::Lifetime) {
2456+
impl<'tcx> Visitor<'tcx> for AllCollector {
2457+
fn visit_lifetime(&mut self, lifetime_ref: &'tcx hir::Lifetime) {
24662458
if let hir::LifetimeName::Param(def_id) = lifetime_ref.res {
24672459
self.regions.insert(def_id);
24682460
}
24692461
}
24702462

2471-
fn visit_opaque_ty(&mut self, opaque: &'v hir::OpaqueTy<'v>) {
2463+
fn visit_opaque_ty(&mut self, opaque: &'tcx hir::OpaqueTy<'tcx>) {
24722464
if !self.has_fully_capturing_opaque {
2473-
self.has_fully_capturing_opaque =
2474-
opaque_captures_all_in_scope_lifetimes(self.tcx, opaque);
2465+
self.has_fully_capturing_opaque = opaque_captures_all_in_scope_lifetimes(opaque);
24752466
}
24762467
intravisit::walk_opaque_ty(self, opaque);
24772468
}

compiler/rustc_lint/src/impl_trait_overcaptures.rs

+2-4
Original file line numberDiff line numberDiff line change
@@ -86,8 +86,7 @@ declare_lint! {
8686
///
8787
/// ### Example
8888
///
89-
/// ```rust,compile_fail
90-
/// # #![feature(lifetime_capture_rules_2024)]
89+
/// ```rust,edition2024,compile_fail
9190
/// # #![deny(impl_trait_redundant_captures)]
9291
/// fn test<'a>(x: &'a i32) -> impl Sized + use<'a> { x }
9392
/// ```
@@ -268,8 +267,7 @@ where
268267
&& parent == self.parent_def_id
269268
{
270269
let opaque_span = self.tcx.def_span(opaque_def_id);
271-
let new_capture_rules = opaque_span.at_least_rust_2024()
272-
|| self.tcx.features().lifetime_capture_rules_2024();
270+
let new_capture_rules = opaque_span.at_least_rust_2024();
273271
if !new_capture_rules
274272
&& !opaque.bounds.iter().any(|bound| matches!(bound, hir::GenericBound::Use(..)))
275273
{

tests/ui/impl-trait/implicit-capture-late.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
1-
//@ known-bug: #117647
1+
//@ edition: 2024
22

3-
#![feature(lifetime_capture_rules_2024)]
43
#![feature(rustc_attrs)]
54
#![allow(internal_features)]
65
#![rustc_variance_of_opaques]
76

87
use std::ops::Deref;
98

10-
fn foo(x: Vec<i32>) -> Box<dyn for<'a> Deref<Target = impl ?Sized>> {
9+
fn foo(x: Vec<i32>) -> Box<dyn for<'a> Deref<Target = impl ?Sized>> { //~ ['a: o]
10+
//~^ ERROR cannot capture higher-ranked lifetime
1111
Box::new(x)
1212
}
1313

tests/ui/impl-trait/implicit-capture-late.stderr

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,17 @@
11
error[E0657]: `impl Trait` cannot capture higher-ranked lifetime from `dyn` type
2-
--> $DIR/implicit-capture-late.rs:10:55
2+
--> $DIR/implicit-capture-late.rs:9:55
33
|
44
LL | fn foo(x: Vec<i32>) -> Box<dyn for<'a> Deref<Target = impl ?Sized>> {
55
| ^^^^^^^^^^^ `impl Trait` implicitly captures all lifetimes in scope
66
|
77
note: lifetime declared here
8-
--> $DIR/implicit-capture-late.rs:10:36
8+
--> $DIR/implicit-capture-late.rs:9:36
99
|
1010
LL | fn foo(x: Vec<i32>) -> Box<dyn for<'a> Deref<Target = impl ?Sized>> {
1111
| ^^
1212

1313
error: ['a: o]
14-
--> $DIR/implicit-capture-late.rs:10:55
14+
--> $DIR/implicit-capture-late.rs:9:55
1515
|
1616
LL | fn foo(x: Vec<i32>) -> Box<dyn for<'a> Deref<Target = impl ?Sized>> {
1717
| ^^^^^^^^^^^

tests/ui/impl-trait/precise-capturing/higher-ranked.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
11
//@ check-pass
2+
//@ edition: 2024
23

34
// Show how precise captures allow us to skip capturing a higher-ranked lifetime
45

5-
#![feature(lifetime_capture_rules_2024)]
6-
76
trait Trait<'a> {
87
type Item;
98
}

tests/ui/impl-trait/precise-capturing/outlives.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
11
//@ check-pass
2+
//@ edition: 2024
23

34
// Show that precise captures allow us to skip a lifetime param for outlives
45

5-
#![feature(lifetime_capture_rules_2024)]
6-
76
fn hello<'a: 'a, 'b: 'b>() -> impl Sized + use<'a> { }
87

98
fn outlives<'a, T: 'a>(_: T) {}

tests/ui/impl-trait/variance.e2024.stderr

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,23 @@
11
error: ['a: *, 'a: o]
2-
--> $DIR/variance.rs:13:36
2+
--> $DIR/variance.rs:11:36
33
|
44
LL | fn not_captured_early<'a: 'a>() -> impl Sized {}
55
| ^^^^^^^^^^
66

77
error: ['a: *, 'a: o]
8-
--> $DIR/variance.rs:18:32
8+
--> $DIR/variance.rs:15:32
99
|
1010
LL | fn captured_early<'a: 'a>() -> impl Sized + Captures<'a> {}
1111
| ^^^^^^^^^^^^^^^^^^^^^^^^^
1212

1313
error: ['a: o]
14-
--> $DIR/variance.rs:20:40
14+
--> $DIR/variance.rs:17:40
1515
|
1616
LL | fn not_captured_late<'a>(_: &'a ()) -> impl Sized {}
1717
| ^^^^^^^^^^
1818

1919
error: ['a: o]
20-
--> $DIR/variance.rs:25:36
20+
--> $DIR/variance.rs:21:36
2121
|
2222
LL | fn captured_late<'a>(_: &'a ()) -> impl Sized + Captures<'a> {}
2323
| ^^^^^^^^^^^^^^^^^^^^^^^^^

tests/ui/impl-trait/variance.new.stderr

-26
This file was deleted.

tests/ui/impl-trait/variance.old.stderr

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,23 @@
11
error: ['a: *]
2-
--> $DIR/variance.rs:13:36
2+
--> $DIR/variance.rs:11:36
33
|
44
LL | fn not_captured_early<'a: 'a>() -> impl Sized {}
55
| ^^^^^^^^^^
66

77
error: ['a: *, 'a: o]
8-
--> $DIR/variance.rs:18:32
8+
--> $DIR/variance.rs:15:32
99
|
1010
LL | fn captured_early<'a: 'a>() -> impl Sized + Captures<'a> {}
1111
| ^^^^^^^^^^^^^^^^^^^^^^^^^
1212

1313
error: []
14-
--> $DIR/variance.rs:20:40
14+
--> $DIR/variance.rs:17:40
1515
|
1616
LL | fn not_captured_late<'a>(_: &'a ()) -> impl Sized {}
1717
| ^^^^^^^^^^
1818

1919
error: ['a: o]
20-
--> $DIR/variance.rs:25:36
20+
--> $DIR/variance.rs:21:36
2121
|
2222
LL | fn captured_late<'a>(_: &'a ()) -> impl Sized + Captures<'a> {}
2323
| ^^^^^^^^^^^^^^^^^^^^^^^^^

tests/ui/impl-trait/variance.rs

+3-7
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
1-
//@ revisions: old new e2024
1+
//@ revisions: old e2024
22
//@[e2024] edition: 2024
33

4-
#![cfg_attr(new, feature(lifetime_capture_rules_2024))]
5-
64
#![feature(rustc_attrs)]
75
#![allow(internal_features)]
86
#![rustc_variance_of_opaques]
@@ -12,15 +10,13 @@ impl<T> Captures<'_> for T {}
1210

1311
fn not_captured_early<'a: 'a>() -> impl Sized {}
1412
//[old]~^ ['a: *]
15-
//[new]~^^ ['a: *, 'a: o]
16-
//[e2024]~^^^ ['a: *, 'a: o]
13+
//[e2024]~^^ ['a: *, 'a: o]
1714

1815
fn captured_early<'a: 'a>() -> impl Sized + Captures<'a> {} //~ ['a: *, 'a: o]
1916

2017
fn not_captured_late<'a>(_: &'a ()) -> impl Sized {}
2118
//[old]~^ []
22-
//[new]~^^ ['a: o]
23-
//[e2024]~^^^ ['a: o]
19+
//[e2024]~^^ ['a: o]
2420

2521
fn captured_late<'a>(_: &'a ()) -> impl Sized + Captures<'a> {} //~ ['a: o]
2622

0 commit comments

Comments
 (0)