Add feature gate.
This commit is contained in:
parent
3b1b38d17f
commit
5a20834884
8 changed files with 110 additions and 4 deletions
|
@ -148,6 +148,8 @@ declare_features! (
|
||||||
/// below (it has to be checked before expansion possibly makes
|
/// below (it has to be checked before expansion possibly makes
|
||||||
/// macros disappear).
|
/// macros disappear).
|
||||||
(active, allow_internal_unstable, "1.0.0", None, None),
|
(active, allow_internal_unstable, "1.0.0", None, None),
|
||||||
|
/// Allows using anonymous lifetimes in argument-position impl-trait.
|
||||||
|
(active, anonymous_lifetime_in_impl_trait, "1.63.0", None, None),
|
||||||
/// Allows identifying the `compiler_builtins` crate.
|
/// Allows identifying the `compiler_builtins` crate.
|
||||||
(active, compiler_builtins, "1.13.0", None, None),
|
(active, compiler_builtins, "1.13.0", None, None),
|
||||||
/// Outputs useful `assert!` messages
|
/// Outputs useful `assert!` messages
|
||||||
|
|
|
@ -1677,7 +1677,7 @@ impl<'a, 'tcx> LifetimeContext<'a, 'tcx> {
|
||||||
break None;
|
break None;
|
||||||
}
|
}
|
||||||
|
|
||||||
Scope::Binder { ref lifetimes, scope_type, s, .. } => {
|
Scope::Binder { ref lifetimes, scope_type, s, where_bound_origin, .. } => {
|
||||||
if let Some(&def) = lifetimes.get(®ion_def_id) {
|
if let Some(&def) = lifetimes.get(®ion_def_id) {
|
||||||
break Some(def.shifted(late_depth));
|
break Some(def.shifted(late_depth));
|
||||||
}
|
}
|
||||||
|
@ -1685,6 +1685,21 @@ impl<'a, 'tcx> LifetimeContext<'a, 'tcx> {
|
||||||
BinderScopeType::Normal => late_depth += 1,
|
BinderScopeType::Normal => late_depth += 1,
|
||||||
BinderScopeType::Concatenating => {}
|
BinderScopeType::Concatenating => {}
|
||||||
}
|
}
|
||||||
|
// Fresh lifetimes in APIT used to be allowed in async fns and forbidden in
|
||||||
|
// regular fns.
|
||||||
|
if let Some(hir::PredicateOrigin::ImplTrait) = where_bound_origin
|
||||||
|
&& let hir::LifetimeName::Param(_, hir::ParamName::Fresh) = lifetime_ref.name
|
||||||
|
&& let hir::IsAsync::NotAsync = self.tcx.asyncness(lifetime_ref.hir_id.owner)
|
||||||
|
&& !self.tcx.features().anonymous_lifetime_in_impl_trait
|
||||||
|
{
|
||||||
|
rustc_session::parse::feature_err(
|
||||||
|
&self.tcx.sess.parse_sess,
|
||||||
|
sym::anonymous_lifetime_in_impl_trait,
|
||||||
|
lifetime_ref.span,
|
||||||
|
"anonymous lifetimes in `impl Trait` are unstable",
|
||||||
|
).emit();
|
||||||
|
return;
|
||||||
|
}
|
||||||
scope = s;
|
scope = s;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -341,6 +341,7 @@ symbols! {
|
||||||
always,
|
always,
|
||||||
and,
|
and,
|
||||||
and_then,
|
and_then,
|
||||||
|
anonymous_lifetime_in_impl_trait,
|
||||||
any,
|
any,
|
||||||
append_const_msg,
|
append_const_msg,
|
||||||
arbitrary_enum_discriminant,
|
arbitrary_enum_discriminant,
|
||||||
|
|
|
@ -3,7 +3,7 @@
|
||||||
// at some point in the future.
|
// at some point in the future.
|
||||||
|
|
||||||
#![feature(generic_associated_types)]
|
#![feature(generic_associated_types)]
|
||||||
|
#![feature(anonymous_lifetime_in_impl_trait)]
|
||||||
trait Foo {
|
trait Foo {
|
||||||
type Item<'a>;
|
type Item<'a>;
|
||||||
}
|
}
|
||||||
|
|
21
src/test/ui/suggestions/impl-trait-missing-lifetime-gated.rs
Normal file
21
src/test/ui/suggestions/impl-trait-missing-lifetime-gated.rs
Normal file
|
@ -0,0 +1,21 @@
|
||||||
|
// edition:2021
|
||||||
|
// gate-test-anonymous_lifetime_in_impl_trait
|
||||||
|
// Verify the behaviour of `feature(anonymous_lifetime_in_impl_trait)`.
|
||||||
|
|
||||||
|
fn f(_: impl Iterator<Item = &'_ ()>) {}
|
||||||
|
//~^ ERROR anonymous lifetimes in `impl Trait` are unstable
|
||||||
|
|
||||||
|
fn g(x: impl Iterator<Item = &'_ ()>) -> Option<&'_ ()> { x.next() }
|
||||||
|
//~^ ERROR anonymous lifetimes in `impl Trait` are unstable
|
||||||
|
//~| ERROR missing lifetime specifier
|
||||||
|
|
||||||
|
// Anonymous lifetimes in async fn are already allowed.
|
||||||
|
// This is understood as `fn foo<'_1>(_: impl Iterator<Item = &'_1 ()>) {}`.
|
||||||
|
async fn h(_: impl Iterator<Item = &'_ ()>) {}
|
||||||
|
|
||||||
|
// Anonymous lifetimes in async fn are already allowed.
|
||||||
|
// But that lifetime does not participate in resolution.
|
||||||
|
async fn i(x: impl Iterator<Item = &'_ ()>) -> Option<&'_ ()> { x.next() }
|
||||||
|
//~^ ERROR missing lifetime specifier
|
||||||
|
|
||||||
|
fn main() {}
|
|
@ -0,0 +1,44 @@
|
||||||
|
error[E0658]: anonymous lifetimes in `impl Trait` are unstable
|
||||||
|
--> $DIR/impl-trait-missing-lifetime-gated.rs:5:31
|
||||||
|
|
|
||||||
|
LL | fn f(_: impl Iterator<Item = &'_ ()>) {}
|
||||||
|
| ^^
|
||||||
|
|
|
||||||
|
= help: add `#![feature(anonymous_lifetime_in_impl_trait)]` to the crate attributes to enable
|
||||||
|
|
||||||
|
error[E0106]: missing lifetime specifier
|
||||||
|
--> $DIR/impl-trait-missing-lifetime-gated.rs:8:50
|
||||||
|
|
|
||||||
|
LL | fn g(x: impl Iterator<Item = &'_ ()>) -> Option<&'_ ()> { x.next() }
|
||||||
|
| ^^ expected named lifetime parameter
|
||||||
|
|
|
||||||
|
= help: this function's return type contains a borrowed value with an elided lifetime, but the lifetime cannot be derived from the arguments
|
||||||
|
help: consider using the `'static` lifetime
|
||||||
|
|
|
||||||
|
LL | fn g(x: impl Iterator<Item = &'_ ()>) -> Option<&'static ()> { x.next() }
|
||||||
|
| ~~~~~~~
|
||||||
|
|
||||||
|
error[E0658]: anonymous lifetimes in `impl Trait` are unstable
|
||||||
|
--> $DIR/impl-trait-missing-lifetime-gated.rs:8:31
|
||||||
|
|
|
||||||
|
LL | fn g(x: impl Iterator<Item = &'_ ()>) -> Option<&'_ ()> { x.next() }
|
||||||
|
| ^^
|
||||||
|
|
|
||||||
|
= help: add `#![feature(anonymous_lifetime_in_impl_trait)]` to the crate attributes to enable
|
||||||
|
|
||||||
|
error[E0106]: missing lifetime specifier
|
||||||
|
--> $DIR/impl-trait-missing-lifetime-gated.rs:18:56
|
||||||
|
|
|
||||||
|
LL | async fn i(x: impl Iterator<Item = &'_ ()>) -> Option<&'_ ()> { x.next() }
|
||||||
|
| ^^ expected named lifetime parameter
|
||||||
|
|
|
||||||
|
= help: this function's return type contains a borrowed value with an elided lifetime, but the lifetime cannot be derived from the arguments
|
||||||
|
help: consider using the `'static` lifetime
|
||||||
|
|
|
||||||
|
LL | async fn i(x: impl Iterator<Item = &'_ ()>) -> Option<&'static ()> { x.next() }
|
||||||
|
| ~~~~~~~
|
||||||
|
|
||||||
|
error: aborting due to 4 previous errors
|
||||||
|
|
||||||
|
Some errors have detailed explanations: E0106, E0658.
|
||||||
|
For more information about an error, try `rustc --explain E0106`.
|
|
@ -1,3 +1,7 @@
|
||||||
|
// edition:2021
|
||||||
|
|
||||||
|
#![feature(anonymous_lifetime_in_impl_trait)]
|
||||||
|
|
||||||
// This is understood as `fn foo<'_1>(_: impl Iterator<Item = &'_1 ()>) {}`.
|
// This is understood as `fn foo<'_1>(_: impl Iterator<Item = &'_1 ()>) {}`.
|
||||||
fn f(_: impl Iterator<Item = &'_ ()>) {}
|
fn f(_: impl Iterator<Item = &'_ ()>) {}
|
||||||
|
|
||||||
|
@ -5,4 +9,11 @@ fn f(_: impl Iterator<Item = &'_ ()>) {}
|
||||||
fn g(x: impl Iterator<Item = &'_ ()>) -> Option<&'_ ()> { x.next() }
|
fn g(x: impl Iterator<Item = &'_ ()>) -> Option<&'_ ()> { x.next() }
|
||||||
//~^ ERROR missing lifetime specifier
|
//~^ ERROR missing lifetime specifier
|
||||||
|
|
||||||
|
// This is understood as `fn foo<'_1>(_: impl Iterator<Item = &'_1 ()>) {}`.
|
||||||
|
async fn h(_: impl Iterator<Item = &'_ ()>) {}
|
||||||
|
|
||||||
|
// But that lifetime does not participate in resolution.
|
||||||
|
async fn i(x: impl Iterator<Item = &'_ ()>) -> Option<&'_ ()> { x.next() }
|
||||||
|
//~^ ERROR missing lifetime specifier
|
||||||
|
|
||||||
fn main() {}
|
fn main() {}
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
error[E0106]: missing lifetime specifier
|
error[E0106]: missing lifetime specifier
|
||||||
--> $DIR/impl-trait-missing-lifetime.rs:5:50
|
--> $DIR/impl-trait-missing-lifetime.rs:9:50
|
||||||
|
|
|
|
||||||
LL | fn g(x: impl Iterator<Item = &'_ ()>) -> Option<&'_ ()> { x.next() }
|
LL | fn g(x: impl Iterator<Item = &'_ ()>) -> Option<&'_ ()> { x.next() }
|
||||||
| ^^ expected named lifetime parameter
|
| ^^ expected named lifetime parameter
|
||||||
|
@ -10,6 +10,18 @@ help: consider using the `'static` lifetime
|
||||||
LL | fn g(x: impl Iterator<Item = &'_ ()>) -> Option<&'static ()> { x.next() }
|
LL | fn g(x: impl Iterator<Item = &'_ ()>) -> Option<&'static ()> { x.next() }
|
||||||
| ~~~~~~~
|
| ~~~~~~~
|
||||||
|
|
||||||
error: aborting due to previous error
|
error[E0106]: missing lifetime specifier
|
||||||
|
--> $DIR/impl-trait-missing-lifetime.rs:16:56
|
||||||
|
|
|
||||||
|
LL | async fn i(x: impl Iterator<Item = &'_ ()>) -> Option<&'_ ()> { x.next() }
|
||||||
|
| ^^ expected named lifetime parameter
|
||||||
|
|
|
||||||
|
= help: this function's return type contains a borrowed value with an elided lifetime, but the lifetime cannot be derived from the arguments
|
||||||
|
help: consider using the `'static` lifetime
|
||||||
|
|
|
||||||
|
LL | async fn i(x: impl Iterator<Item = &'_ ()>) -> Option<&'static ()> { x.next() }
|
||||||
|
| ~~~~~~~
|
||||||
|
|
||||||
|
error: aborting due to 2 previous errors
|
||||||
|
|
||||||
For more information about this error, try `rustc --explain E0106`.
|
For more information about this error, try `rustc --explain E0106`.
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue