diff options
| author | Michael Goulet <michael@errs.io> | 2024-04-21 11:27:27 -0400 |
|---|---|---|
| committer | Michael Goulet <michael@errs.io> | 2024-05-13 23:57:56 -0400 |
| commit | 052de1da4f579f63d2403f8045f2d6e342a90200 (patch) | |
| tree | 4a3a7ebb49fe0fe9d64566d44db2bd17d3be369c /tests/ui/impl-trait | |
| parent | 1529c661e4f1f5294877a471e388d9097e742414 (diff) | |
| download | rust-052de1da4f579f63d2403f8045f2d6e342a90200.tar.gz rust-052de1da4f579f63d2403f8045f2d6e342a90200.zip | |
And finally add tests
Diffstat (limited to 'tests/ui/impl-trait')
3 files changed, 133 insertions, 0 deletions
diff --git a/tests/ui/impl-trait/precise-capturing/overcaptures-2024.fixed b/tests/ui/impl-trait/precise-capturing/overcaptures-2024.fixed new file mode 100644 index 00000000000..014ab23e4eb --- /dev/null +++ b/tests/ui/impl-trait/precise-capturing/overcaptures-2024.fixed @@ -0,0 +1,29 @@ +//@ run-rustfix + +#![feature(precise_capturing)] +#![allow(unused, incomplete_features)] +#![deny(impl_trait_overcaptures)] + +fn named<'a>(x: &'a i32) -> impl use<> Sized { *x } +//~^ ERROR `impl Sized` will capture more lifetimes than possibly intended in edition 2024 + +fn implicit(x: &i32) -> impl use<> Sized { *x } +//~^ ERROR `impl Sized` will capture more lifetimes than possibly intended in edition 2024 + +struct W; +impl W { + fn hello(&self, x: &i32) -> impl use<'_> Sized + '_ { self } + //~^ ERROR `impl Sized + '_` will capture more lifetimes than possibly intended in edition 2024 +} + +trait Higher<'a> { + type Output; +} +impl Higher<'_> for () { + type Output = (); +} + +fn hrtb() -> impl for<'a> Higher<'a, Output = impl use<> Sized> {} +//~^ ERROR `impl Sized` will capture more lifetimes than possibly intended in edition 2024 + +fn main() {} diff --git a/tests/ui/impl-trait/precise-capturing/overcaptures-2024.rs b/tests/ui/impl-trait/precise-capturing/overcaptures-2024.rs new file mode 100644 index 00000000000..e4b7828d60f --- /dev/null +++ b/tests/ui/impl-trait/precise-capturing/overcaptures-2024.rs @@ -0,0 +1,29 @@ +//@ run-rustfix + +#![feature(precise_capturing)] +#![allow(unused, incomplete_features)] +#![deny(impl_trait_overcaptures)] + +fn named<'a>(x: &'a i32) -> impl Sized { *x } +//~^ ERROR `impl Sized` will capture more lifetimes than possibly intended in edition 2024 + +fn implicit(x: &i32) -> impl Sized { *x } +//~^ ERROR `impl Sized` will capture more lifetimes than possibly intended in edition 2024 + +struct W; +impl W { + fn hello(&self, x: &i32) -> impl Sized + '_ { self } + //~^ ERROR `impl Sized + '_` will capture more lifetimes than possibly intended in edition 2024 +} + +trait Higher<'a> { + type Output; +} +impl Higher<'_> for () { + type Output = (); +} + +fn hrtb() -> impl for<'a> Higher<'a, Output = impl Sized> {} +//~^ ERROR `impl Sized` will capture more lifetimes than possibly intended in edition 2024 + +fn main() {} diff --git a/tests/ui/impl-trait/precise-capturing/overcaptures-2024.stderr b/tests/ui/impl-trait/precise-capturing/overcaptures-2024.stderr new file mode 100644 index 00000000000..16cb8b7e94b --- /dev/null +++ b/tests/ui/impl-trait/precise-capturing/overcaptures-2024.stderr @@ -0,0 +1,75 @@ +error: `impl Sized` will capture more lifetimes than possibly intended in edition 2024 + --> $DIR/overcaptures-2024.rs:7:29 + | +LL | fn named<'a>(x: &'a i32) -> impl Sized { *x } + | ^^^^^^^^^^ + | +note: specifically, this lifetime is in scope but not mentioned in the type's bounds + --> $DIR/overcaptures-2024.rs:7:10 + | +LL | fn named<'a>(x: &'a i32) -> impl Sized { *x } + | ^^ + = note: all lifetimes in scope will be captured by `impl Trait`s in edition 2024 +note: the lint level is defined here + --> $DIR/overcaptures-2024.rs:5:9 + | +LL | #![deny(impl_trait_overcaptures)] + | ^^^^^^^^^^^^^^^^^^^^^^^ +help: use the precise capturing `use<...>` syntax to make the captures explicit + | +LL | fn named<'a>(x: &'a i32) -> impl use<> Sized { *x } + | +++++ + +error: `impl Sized` will capture more lifetimes than possibly intended in edition 2024 + --> $DIR/overcaptures-2024.rs:10:25 + | +LL | fn implicit(x: &i32) -> impl Sized { *x } + | ^^^^^^^^^^ + | +note: specifically, this lifetime is in scope but not mentioned in the type's bounds + --> $DIR/overcaptures-2024.rs:10:16 + | +LL | fn implicit(x: &i32) -> impl Sized { *x } + | ^ + = note: all lifetimes in scope will be captured by `impl Trait`s in edition 2024 +help: use the precise capturing `use<...>` syntax to make the captures explicit + | +LL | fn implicit(x: &i32) -> impl use<> Sized { *x } + | +++++ + +error: `impl Sized + '_` will capture more lifetimes than possibly intended in edition 2024 + --> $DIR/overcaptures-2024.rs:15:33 + | +LL | fn hello(&self, x: &i32) -> impl Sized + '_ { self } + | ^^^^^^^^^^^^^^^ + | +note: specifically, this lifetime is in scope but not mentioned in the type's bounds + --> $DIR/overcaptures-2024.rs:15:24 + | +LL | fn hello(&self, x: &i32) -> impl Sized + '_ { self } + | ^ + = note: all lifetimes in scope will be captured by `impl Trait`s in edition 2024 +help: use the precise capturing `use<...>` syntax to make the captures explicit + | +LL | fn hello(&self, x: &i32) -> impl use<'_> Sized + '_ { self } + | +++++++ + +error: `impl Sized` will capture more lifetimes than possibly intended in edition 2024 + --> $DIR/overcaptures-2024.rs:26:47 + | +LL | fn hrtb() -> impl for<'a> Higher<'a, Output = impl Sized> {} + | ^^^^^^^^^^ + | +note: specifically, this lifetime is in scope but not mentioned in the type's bounds + --> $DIR/overcaptures-2024.rs:26:23 + | +LL | fn hrtb() -> impl for<'a> Higher<'a, Output = impl Sized> {} + | ^^ + = note: all lifetimes in scope will be captured by `impl Trait`s in edition 2024 +help: use the precise capturing `use<...>` syntax to make the captures explicit + | +LL | fn hrtb() -> impl for<'a> Higher<'a, Output = impl use<> Sized> {} + | +++++ + +error: aborting due to 4 previous errors + |
