Skip to content

Commit 23d76b8

Browse files
committed
Stabilize anonymous_lifetime_in_impl_trait
1 parent ffb7ed9 commit 23d76b8

18 files changed

+270
-266
lines changed

compiler/rustc_feature/src/accepted.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,8 @@ declare_features! (
5454
(accepted, abi_thiscall, "1.73.0", None, None),
5555
/// Allows using ADX intrinsics from `core::arch::{x86, x86_64}`.
5656
(accepted, adx_target_feature, "1.61.0", Some(44839), None),
57+
/// Allows using anonymous lifetimes in argument-position impl-trait.
58+
(accepted, anonymous_lifetime_in_impl_trait, "CURRENT_RUSTC_VERSION", None, None),
5759
/// Allows explicit discriminants on non-unit enum variants.
5860
(accepted, arbitrary_enum_discriminant, "1.66.0", Some(60553), None),
5961
/// Allows using `sym` operands in inline assembly.

compiler/rustc_feature/src/unstable.rs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -175,8 +175,6 @@ declare_features! (
175175
/// below (it has to be checked before expansion possibly makes
176176
/// macros disappear).
177177
(internal, allow_internal_unstable, "1.0.0", None, None),
178-
/// Allows using anonymous lifetimes in argument-position impl-trait.
179-
(unstable, anonymous_lifetime_in_impl_trait, "1.63.0", None, None),
180178
/// Allows identifying the `compiler_builtins` crate.
181179
(internal, compiler_builtins, "1.13.0", None, None),
182180
/// Allows writing custom MIR

compiler/rustc_hir_analysis/src/collect/resolve_bound_vars.rs

Lines changed: 2 additions & 63 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ use rustc_middle::query::Providers;
2121
use rustc_middle::ty::{self, TyCtxt, TypeSuperVisitable, TypeVisitor};
2222
use rustc_session::lint;
2323
use rustc_span::def_id::DefId;
24-
use rustc_span::symbol::{sym, Ident};
24+
use rustc_span::symbol::Ident;
2525
use rustc_span::{Span, DUMMY_SP};
2626
use std::fmt;
2727

@@ -1199,75 +1199,14 @@ impl<'a, 'tcx> BoundVarContext<'a, 'tcx> {
11991199
break None;
12001200
}
12011201

1202-
Scope::Binder { ref bound_vars, scope_type, s, where_bound_origin, .. } => {
1202+
Scope::Binder { ref bound_vars, scope_type, s, .. } => {
12031203
if let Some(&def) = bound_vars.get(&region_def_id) {
12041204
break Some(def.shifted(late_depth));
12051205
}
12061206
match scope_type {
12071207
BinderScopeType::Normal => late_depth += 1,
12081208
BinderScopeType::Concatenating => {}
12091209
}
1210-
// Fresh lifetimes in APIT used to be allowed in async fns and forbidden in
1211-
// regular fns.
1212-
if let Some(hir::PredicateOrigin::ImplTrait) = where_bound_origin
1213-
&& let hir::LifetimeName::Param(param_id) = lifetime_ref.res
1214-
&& let Some(generics) =
1215-
self.tcx.hir().get_generics(self.tcx.local_parent(param_id))
1216-
&& let Some(param) = generics.params.iter().find(|p| p.def_id == param_id)
1217-
&& param.is_elided_lifetime()
1218-
&& !self.tcx.asyncness(lifetime_ref.hir_id.owner.def_id).is_async()
1219-
&& !self.tcx.features().anonymous_lifetime_in_impl_trait
1220-
{
1221-
let mut diag = rustc_session::parse::feature_err(
1222-
&self.tcx.sess.parse_sess,
1223-
sym::anonymous_lifetime_in_impl_trait,
1224-
lifetime_ref.ident.span,
1225-
"anonymous lifetimes in `impl Trait` are unstable",
1226-
);
1227-
1228-
if let Some(generics) =
1229-
self.tcx.hir().get_generics(lifetime_ref.hir_id.owner.def_id)
1230-
{
1231-
let new_param_sugg =
1232-
if let Some(span) = generics.span_for_lifetime_suggestion() {
1233-
(span, "'a, ".to_owned())
1234-
} else {
1235-
(generics.span, "<'a>".to_owned())
1236-
};
1237-
1238-
let lifetime_sugg = match lifetime_ref.suggestion_position() {
1239-
(hir::LifetimeSuggestionPosition::Normal, span) => {
1240-
(span, "'a".to_owned())
1241-
}
1242-
(hir::LifetimeSuggestionPosition::Ampersand, span) => {
1243-
(span, "'a ".to_owned())
1244-
}
1245-
(hir::LifetimeSuggestionPosition::ElidedPath, span) => {
1246-
(span, "<'a>".to_owned())
1247-
}
1248-
(hir::LifetimeSuggestionPosition::ElidedPathArgument, span) => {
1249-
(span, "'a, ".to_owned())
1250-
}
1251-
(hir::LifetimeSuggestionPosition::ObjectDefault, span) => {
1252-
(span, "+ 'a".to_owned())
1253-
}
1254-
};
1255-
let suggestions = vec![lifetime_sugg, new_param_sugg];
1256-
1257-
diag.span_label(
1258-
lifetime_ref.ident.span,
1259-
"expected named lifetime parameter",
1260-
);
1261-
diag.multipart_suggestion(
1262-
"consider introducing a named lifetime parameter",
1263-
suggestions,
1264-
rustc_errors::Applicability::MaybeIncorrect,
1265-
);
1266-
}
1267-
1268-
diag.emit();
1269-
return;
1270-
}
12711210
scope = s;
12721211
}
12731212

tests/ui/associated-type-bounds/elision.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
#![feature(associated_type_bounds)]
2-
#![feature(anonymous_lifetime_in_impl_trait)]
32

43
// The same thing should happen for constraints in dyn trait.
54
fn f(x: &mut dyn Iterator<Item: Iterator<Item = &'_ ()>>) -> Option<&'_ ()> { x.next() }

tests/ui/associated-type-bounds/elision.stderr

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
error[E0106]: missing lifetime specifier
2-
--> $DIR/elision.rs:5:70
2+
--> $DIR/elision.rs:4:70
33
|
44
LL | fn f(x: &mut dyn Iterator<Item: Iterator<Item = &'_ ()>>) -> Option<&'_ ()> { x.next() }
55
| ------------------------------------------------ ^^ expected named lifetime parameter
@@ -11,7 +11,7 @@ LL | fn f<'a>(x: &'a mut dyn Iterator<Item: Iterator<Item = &'a ()>>) -> Option<
1111
| ++++ ++ ~~ ~~
1212

1313
error[E0308]: mismatched types
14-
--> $DIR/elision.rs:5:79
14+
--> $DIR/elision.rs:4:79
1515
|
1616
LL | fn f(x: &mut dyn Iterator<Item: Iterator<Item = &'_ ()>>) -> Option<&'_ ()> { x.next() }
1717
| ----------------------------- -------------- ^^^^^^^^ expected `Option<&()>`, found `Option<impl Iterator<Item = &'_ ()>>`

tests/ui/borrowck/anonymous-region-in-apit.rs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
#![feature(anonymous_lifetime_in_impl_trait)]
2-
31
trait Foo<T> {
42
fn bar(self, baz: T);
53
}

tests/ui/borrowck/anonymous-region-in-apit.stderr

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
error[E0521]: borrowed data escapes outside of closure
2-
--> $DIR/anonymous-region-in-apit.rs:8:17
2+
--> $DIR/anonymous-region-in-apit.rs:6:17
33
|
44
LL | fn qux(foo: impl Foo<&str>) {
55
| --- lifetime `'2` appears in the type of `foo`

tests/ui/generic-associated-types/issue-95305.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
// Forbid it for now but proper support might be added
33
// at some point in the future.
44

5-
#![feature(anonymous_lifetime_in_impl_trait)]
65
trait Foo {
76
type Item<'a>;
87
}

tests/ui/generic-associated-types/issue-95305.stderr

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
error[E0637]: `'_` cannot be used here
2-
--> $DIR/issue-95305.rs:10:26
2+
--> $DIR/issue-95305.rs:9:26
33
|
44
LL | fn foo(x: &impl Foo<Item<'_> = u32>) { }
55
| ^^ `'_` is a reserved lifetime name
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
trait FooBar<'a> {
2+
type Item;
3+
}
4+
5+
trait LendingIterator {
6+
type Item<'a>
7+
where
8+
Self: 'a;
9+
10+
fn iter(&mut self) -> Option<Self::Item<'_>>;
11+
}
12+
13+
fn main() {
14+
fn foo0(_: impl FooBar<_, Item = &u32>) {}
15+
//~^ the placeholder `_` is not allowed within types
16+
//~| trait takes 0 generic arguments but 1 generic
17+
fn foo1(_: impl LendingIterator<Item<'_> = &u32>) {}
18+
//~^ '_` cannot be used here [E0637]
19+
}

0 commit comments

Comments
 (0)