diff options
| author | Camille GILLOT <gillot.camille@gmail.com> | 2022-06-22 22:19:02 +0200 |
|---|---|---|
| committer | Camille GILLOT <gillot.camille@gmail.com> | 2022-07-13 14:17:09 +0200 |
| commit | 5a20834884f653e84485fb905785fdbca98b7e02 (patch) | |
| tree | 8c4896f7859f481058b7b3708bae43a4a69d71fa /src/test/ui/suggestions | |
| parent | 3b1b38d17f223378386f768204e4c5ad106b7c50 (diff) | |
| download | rust-5a20834884f653e84485fb905785fdbca98b7e02.tar.gz rust-5a20834884f653e84485fb905785fdbca98b7e02.zip | |
Add feature gate.
Diffstat (limited to 'src/test/ui/suggestions')
4 files changed, 90 insertions, 2 deletions
diff --git a/src/test/ui/suggestions/impl-trait-missing-lifetime-gated.rs b/src/test/ui/suggestions/impl-trait-missing-lifetime-gated.rs new file mode 100644 index 00000000000..fe291e021bc --- /dev/null +++ b/src/test/ui/suggestions/impl-trait-missing-lifetime-gated.rs @@ -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() {} diff --git a/src/test/ui/suggestions/impl-trait-missing-lifetime-gated.stderr b/src/test/ui/suggestions/impl-trait-missing-lifetime-gated.stderr new file mode 100644 index 00000000000..9adc9679eee --- /dev/null +++ b/src/test/ui/suggestions/impl-trait-missing-lifetime-gated.stderr @@ -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`. diff --git a/src/test/ui/suggestions/impl-trait-missing-lifetime.rs b/src/test/ui/suggestions/impl-trait-missing-lifetime.rs index 2ef0f5a4853..dcc716f56b7 100644 --- a/src/test/ui/suggestions/impl-trait-missing-lifetime.rs +++ b/src/test/ui/suggestions/impl-trait-missing-lifetime.rs @@ -1,3 +1,7 @@ +// edition:2021 + +#![feature(anonymous_lifetime_in_impl_trait)] + // This is understood as `fn foo<'_1>(_: impl Iterator<Item = &'_1 ()>) {}`. fn f(_: impl Iterator<Item = &'_ ()>) {} @@ -5,4 +9,11 @@ fn f(_: impl Iterator<Item = &'_ ()>) {} fn g(x: impl Iterator<Item = &'_ ()>) -> Option<&'_ ()> { x.next() } //~^ 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() {} diff --git a/src/test/ui/suggestions/impl-trait-missing-lifetime.stderr b/src/test/ui/suggestions/impl-trait-missing-lifetime.stderr index a09ef8121d7..d3c64cb466d 100644 --- a/src/test/ui/suggestions/impl-trait-missing-lifetime.stderr +++ b/src/test/ui/suggestions/impl-trait-missing-lifetime.stderr @@ -1,5 +1,5 @@ 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() } | ^^ 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() } | ~~~~~~~ -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`. |
