From b9f241d4077c8d0a633aa6589ef18065db7a4372 Mon Sep 17 00:00:00 2001 From: Jack Huey <31162821+jackh726@users.noreply.github.com> Date: Sat, 21 May 2022 13:15:53 -0400 Subject: Use revisions for NLL in impl-trait --- .../multiple-lifetimes/inverse-bounds.rs | 2 - .../must_outlive_least_region_or_bound.base.stderr | 227 +++++++++++++++++++++ .../must_outlive_least_region_or_bound.nll.stderr | 20 +- .../must_outlive_least_region_or_bound.rs | 35 +++- .../must_outlive_least_region_or_bound.stderr | 227 --------------------- .../type_parameters_captured.base.stderr | 14 ++ .../impl-trait/type_parameters_captured.nll.stderr | 2 +- src/test/ui/impl-trait/type_parameters_captured.rs | 7 +- .../ui/impl-trait/type_parameters_captured.stderr | 14 -- 9 files changed, 284 insertions(+), 264 deletions(-) create mode 100644 src/test/ui/impl-trait/must_outlive_least_region_or_bound.base.stderr delete mode 100644 src/test/ui/impl-trait/must_outlive_least_region_or_bound.stderr create mode 100644 src/test/ui/impl-trait/type_parameters_captured.base.stderr delete mode 100644 src/test/ui/impl-trait/type_parameters_captured.stderr (limited to 'src/test/ui/impl-trait') diff --git a/src/test/ui/impl-trait/multiple-lifetimes/inverse-bounds.rs b/src/test/ui/impl-trait/multiple-lifetimes/inverse-bounds.rs index 41b6a9eb055..5251eeee8bb 100644 --- a/src/test/ui/impl-trait/multiple-lifetimes/inverse-bounds.rs +++ b/src/test/ui/impl-trait/multiple-lifetimes/inverse-bounds.rs @@ -1,7 +1,5 @@ // edition:2018 // check-pass -// revisions: migrate mir -//[mir]compile-flags: -Z borrowck=mir trait Trait<'a, 'b> {} impl Trait<'_, '_> for T {} diff --git a/src/test/ui/impl-trait/must_outlive_least_region_or_bound.base.stderr b/src/test/ui/impl-trait/must_outlive_least_region_or_bound.base.stderr new file mode 100644 index 00000000000..45cc935b7cc --- /dev/null +++ b/src/test/ui/impl-trait/must_outlive_least_region_or_bound.base.stderr @@ -0,0 +1,227 @@ +error[E0700]: hidden type for `impl Trait` captures lifetime that does not appear in bounds + --> $DIR/must_outlive_least_region_or_bound.rs:7:35 + | +LL | fn elided(x: &i32) -> impl Copy { x } + | ---- ^ + | | + | hidden type `&i32` captures the anonymous lifetime defined here + | +help: to declare that the `impl Trait` captures `'_`, you can add an explicit `'_` lifetime bound + | +LL | fn elided(x: &i32) -> impl Copy + '_ { x } + | ++++ + +error[E0700]: hidden type for `impl Trait` captures lifetime that does not appear in bounds + --> $DIR/must_outlive_least_region_or_bound.rs:10:44 + | +LL | fn explicit<'a>(x: &'a i32) -> impl Copy { x } + | -- ^ + | | + | hidden type `&'a i32` captures the lifetime `'a` as defined here + | +help: to declare that the `impl Trait` captures `'a`, you can add an explicit `'a` lifetime bound + | +LL | fn explicit<'a>(x: &'a i32) -> impl Copy + 'a { x } + | ++++ + +error[E0759]: `x` has an anonymous lifetime `'_` but it needs to satisfy a `'static` lifetime requirement + --> $DIR/must_outlive_least_region_or_bound.rs:13:46 + | +LL | fn elided2(x: &i32) -> impl Copy + 'static { x } + | ---- ^ ...is used here... + | | + | this data with an anonymous lifetime `'_`... + | +note: ...and is required to live as long as `'static` here + --> $DIR/must_outlive_least_region_or_bound.rs:13:24 + | +LL | fn elided2(x: &i32) -> impl Copy + 'static { x } + | ^^^^^^^^^^^^^^^^^^^ +help: consider changing the `impl Trait`'s explicit `'static` bound to the lifetime of argument `x` + | +LL | fn elided2(x: &i32) -> impl Copy + '_ { x } + | ~~ +help: alternatively, add an explicit `'static` bound to this reference + | +LL | fn elided2(x: &'static i32) -> impl Copy + 'static { x } + | ~~~~~~~~~~~~ + +error[E0759]: `x` has lifetime `'a` but it needs to satisfy a `'static` lifetime requirement + --> $DIR/must_outlive_least_region_or_bound.rs:17:55 + | +LL | fn explicit2<'a>(x: &'a i32) -> impl Copy + 'static { x } + | ------- ^ ...is used here... + | | + | this data with lifetime `'a`... + | +note: ...and is required to live as long as `'static` here + --> $DIR/must_outlive_least_region_or_bound.rs:17:33 + | +LL | fn explicit2<'a>(x: &'a i32) -> impl Copy + 'static { x } + | ^^^^^^^^^^^^^^^^^^^ +help: consider changing the `impl Trait`'s explicit `'static` bound to the lifetime of argument `x` + | +LL | fn explicit2<'a>(x: &'a i32) -> impl Copy + 'a { x } + | ~~ +help: alternatively, add an explicit `'static` bound to this reference + | +LL | fn explicit2<'a>(x: &'static i32) -> impl Copy + 'static { x } + | ~~~~~~~~~~~~ + +error[E0621]: explicit lifetime required in the type of `x` + --> $DIR/must_outlive_least_region_or_bound.rs:21:24 + | +LL | fn foo<'a>(x: &i32) -> impl Copy + 'a { x } + | ---- ^^^^^^^^^^^^^^ lifetime `'a` required + | | + | help: add explicit lifetime `'a` to the type of `x`: `&'a i32` + +error[E0759]: `x` has an anonymous lifetime `'_` but it needs to satisfy a `'static` lifetime requirement + --> $DIR/must_outlive_least_region_or_bound.rs:36:65 + | +LL | fn elided5(x: &i32) -> (Box, impl Debug) { (Box::new(x), x) } + | ---- this data with an anonymous lifetime `'_`... ^ ...is used and required to live as long as `'static` here + | +help: to declare that the trait object captures data from argument `x`, you can add an explicit `'_` lifetime bound + | +LL | fn elided5(x: &i32) -> (Box, impl Debug) { (Box::new(x), x) } + | ++++ +help: to declare that the `impl Trait` captures data from argument `x`, you can add an explicit `'_` lifetime bound + | +LL | fn elided5(x: &i32) -> (Box, impl Debug + '_) { (Box::new(x), x) } + | ++++ + +error[E0759]: `x` has lifetime `'a` but it needs to satisfy a `'static` lifetime requirement + --> $DIR/must_outlive_least_region_or_bound.rs:43:69 + | +LL | fn with_bound<'a>(x: &'a i32) -> impl LifetimeTrait<'a> + 'static { x } + | ------- this data with lifetime `'a`... ^ ...is used here... + | +note: ...and is required to live as long as `'static` here + --> $DIR/must_outlive_least_region_or_bound.rs:43:34 + | +LL | fn with_bound<'a>(x: &'a i32) -> impl LifetimeTrait<'a> + 'static { x } + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ +help: consider changing the `impl Trait`'s explicit `'static` bound to the lifetime of argument `x` + | +LL | fn with_bound<'a>(x: &'a i32) -> impl LifetimeTrait<'a> + 'a { x } + | ~~ +help: alternatively, add an explicit `'static` bound to this reference + | +LL | fn with_bound<'a>(x: &'static i32) -> impl LifetimeTrait<'a> + 'static { x } + | ~~~~~~~~~~~~ + +error[E0700]: hidden type for `impl Trait` captures lifetime that does not appear in bounds + --> $DIR/must_outlive_least_region_or_bound.rs:50:5 + | +LL | fn move_lifetime_into_fn<'a, 'b>(x: &'a u32, y: &'b u32) -> impl Fn(&'a u32) { + | -- hidden type `[closure@$DIR/must_outlive_least_region_or_bound.rs:50:5: 50:31]` captures the lifetime `'b` as defined here +LL | move |_| println!("{}", y) + | ^^^^^^^^^^^^^^^^^^^^^^^^^^ + | +help: to declare that the `impl Trait` captures `'b`, you can add an explicit `'b` lifetime bound + | +LL | fn move_lifetime_into_fn<'a, 'b>(x: &'a u32, y: &'b u32) -> impl Fn(&'a u32) + 'b { + | ++++ + +error[E0310]: the parameter type `T` may not live long enough + --> $DIR/must_outlive_least_region_or_bound.rs:54:51 + | +LL | fn ty_param_wont_outlive_static(x: T) -> impl Debug + 'static { + | ^^^^^^^^^^^^^^^^^^^^ ...so that the type `T` will meet its required lifetime bounds + | +help: consider adding an explicit lifetime bound... + | +LL | fn ty_param_wont_outlive_static(x: T) -> impl Debug + 'static { + | +++++++++ + +error[E0759]: `x` has an anonymous lifetime `'_` but it needs to satisfy a `'static` lifetime requirement + --> $DIR/must_outlive_least_region_or_bound.rs:24:50 + | +LL | fn elided3(x: &i32) -> Box { Box::new(x) } + | ---- ^ ...is used and required to live as long as `'static` here + | | + | this data with an anonymous lifetime `'_`... + | +note: `'static` lifetime requirement introduced by the return type + --> $DIR/must_outlive_least_region_or_bound.rs:24:28 + | +LL | fn elided3(x: &i32) -> Box { Box::new(x) } + | ^^^^^^^^^ ----------- because of this returned expression + | | + | `'static` requirement introduced here +help: to declare that the trait object captures data from argument `x`, you can add an explicit `'_` lifetime bound + | +LL | fn elided3(x: &i32) -> Box { Box::new(x) } + | ++++ + +error[E0759]: `x` has lifetime `'a` but it needs to satisfy a `'static` lifetime requirement + --> $DIR/must_outlive_least_region_or_bound.rs:27:59 + | +LL | fn explicit3<'a>(x: &'a i32) -> Box { Box::new(x) } + | ------- ^ ...is used and required to live as long as `'static` here + | | + | this data with lifetime `'a`... + | +note: `'static` lifetime requirement introduced by the return type + --> $DIR/must_outlive_least_region_or_bound.rs:27:37 + | +LL | fn explicit3<'a>(x: &'a i32) -> Box { Box::new(x) } + | ^^^^^^^^^ ----------- because of this returned expression + | | + | `'static` requirement introduced here +help: to declare that the trait object captures data from argument `x`, you can add an explicit `'a` lifetime bound + | +LL | fn explicit3<'a>(x: &'a i32) -> Box { Box::new(x) } + | ++++ + +error[E0759]: `x` has an anonymous lifetime `'_` but it needs to satisfy a `'static` lifetime requirement + --> $DIR/must_outlive_least_region_or_bound.rs:30:60 + | +LL | fn elided4(x: &i32) -> Box { Box::new(x) } + | ---- ^ ...is used and required to live as long as `'static` here + | | + | this data with an anonymous lifetime `'_`... + | +note: `'static` lifetime requirement introduced by the return type + --> $DIR/must_outlive_least_region_or_bound.rs:30:40 + | +LL | fn elided4(x: &i32) -> Box { Box::new(x) } + | ^^^^^^^ ----------- because of this returned expression + | | + | `'static` requirement introduced here +help: consider changing the trait object's explicit `'static` bound to the lifetime of argument `x` + | +LL | fn elided4(x: &i32) -> Box { Box::new(x) } + | ~~ +help: alternatively, add an explicit `'static` bound to this reference + | +LL | fn elided4(x: &'static i32) -> Box { Box::new(x) } + | ~~~~~~~~~~~~ + +error[E0759]: `x` has lifetime `'a` but it needs to satisfy a `'static` lifetime requirement + --> $DIR/must_outlive_least_region_or_bound.rs:33:69 + | +LL | fn explicit4<'a>(x: &'a i32) -> Box { Box::new(x) } + | ------- this data with lifetime `'a`... ^ ...is used and required to live as long as `'static` here + | +note: `'static` lifetime requirement introduced by the return type + --> $DIR/must_outlive_least_region_or_bound.rs:33:49 + | +LL | fn explicit4<'a>(x: &'a i32) -> Box { Box::new(x) } + | ^^^^^^^ ----------- because of this returned expression + | | + | `'static` requirement introduced here +help: consider changing the trait object's explicit `'static` bound to the lifetime of argument `x` + | +LL | fn explicit4<'a>(x: &'a i32) -> Box { Box::new(x) } + | ~~ +help: alternatively, add an explicit `'static` bound to this reference + | +LL | fn explicit4<'a>(x: &'static i32) -> Box { Box::new(x) } + | ~~~~~~~~~~~~ + +error: aborting due to 13 previous errors + +Some errors have detailed explanations: E0310, E0621, E0700, E0759. +For more information about an error, try `rustc --explain E0310`. diff --git a/src/test/ui/impl-trait/must_outlive_least_region_or_bound.nll.stderr b/src/test/ui/impl-trait/must_outlive_least_region_or_bound.nll.stderr index db737a9c544..0252e546fb0 100644 --- a/src/test/ui/impl-trait/must_outlive_least_region_or_bound.nll.stderr +++ b/src/test/ui/impl-trait/must_outlive_least_region_or_bound.nll.stderr @@ -1,5 +1,5 @@ error[E0700]: hidden type for `impl Trait` captures lifetime that does not appear in bounds - --> $DIR/must_outlive_least_region_or_bound.rs:3:35 + --> $DIR/must_outlive_least_region_or_bound.rs:7:35 | LL | fn elided(x: &i32) -> impl Copy { x } | ---- ^ @@ -12,7 +12,7 @@ LL | fn elided(x: &i32) -> impl Copy + '_ { x } | ++++ error[E0700]: hidden type for `impl Trait` captures lifetime that does not appear in bounds - --> $DIR/must_outlive_least_region_or_bound.rs:6:44 + --> $DIR/must_outlive_least_region_or_bound.rs:10:44 | LL | fn explicit<'a>(x: &'a i32) -> impl Copy { x } | -- ^ @@ -25,7 +25,7 @@ LL | fn explicit<'a>(x: &'a i32) -> impl Copy + 'a { x } | ++++ error: lifetime may not live long enough - --> $DIR/must_outlive_least_region_or_bound.rs:9:46 + --> $DIR/must_outlive_least_region_or_bound.rs:13:46 | LL | fn elided2(x: &i32) -> impl Copy + 'static { x } | - ^ returning this value requires that `'1` must outlive `'static` @@ -42,7 +42,7 @@ LL | fn elided2(x: &'static i32) -> impl Copy + 'static { x } | ~~~~~~~~~~~~ error: lifetime may not live long enough - --> $DIR/must_outlive_least_region_or_bound.rs:11:55 + --> $DIR/must_outlive_least_region_or_bound.rs:17:55 | LL | fn explicit2<'a>(x: &'a i32) -> impl Copy + 'static { x } | -- lifetime `'a` defined here ^ returning this value requires that `'a` must outlive `'static` @@ -57,7 +57,7 @@ LL | fn explicit2<'a>(x: &'static i32) -> impl Copy + 'static { x } | ~~~~~~~~~~~~ error[E0621]: explicit lifetime required in the type of `x` - --> $DIR/must_outlive_least_region_or_bound.rs:13:41 + --> $DIR/must_outlive_least_region_or_bound.rs:21:41 | LL | fn foo<'a>(x: &i32) -> impl Copy + 'a { x } | ---- ^ lifetime `'a` required @@ -65,7 +65,7 @@ LL | fn foo<'a>(x: &i32) -> impl Copy + 'a { x } | help: add explicit lifetime `'a` to the type of `x`: `&'a i32` error: lifetime may not live long enough - --> $DIR/must_outlive_least_region_or_bound.rs:24:55 + --> $DIR/must_outlive_least_region_or_bound.rs:36:55 | LL | fn elided5(x: &i32) -> (Box, impl Debug) { (Box::new(x), x) } | - ^^^^^^^^^^^^^^^^ returning this value requires that `'1` must outlive `'static` @@ -82,7 +82,7 @@ LL | fn elided5(x: &i32) -> (Box, impl Debug + '_) { (Box::new(x), x) | ++++ error: lifetime may not live long enough - --> $DIR/must_outlive_least_region_or_bound.rs:29:69 + --> $DIR/must_outlive_least_region_or_bound.rs:43:69 | LL | fn with_bound<'a>(x: &'a i32) -> impl LifetimeTrait<'a> + 'static { x } | -- lifetime `'a` defined here ^ returning this value requires that `'a` must outlive `'static` @@ -97,10 +97,10 @@ LL | fn with_bound<'a>(x: &'static i32) -> impl LifetimeTrait<'a> + 'static { x | ~~~~~~~~~~~~ error[E0700]: hidden type for `impl Trait` captures lifetime that does not appear in bounds - --> $DIR/must_outlive_least_region_or_bound.rs:34:5 + --> $DIR/must_outlive_least_region_or_bound.rs:50:5 | LL | fn move_lifetime_into_fn<'a, 'b>(x: &'a u32, y: &'b u32) -> impl Fn(&'a u32) { - | -- hidden type `[closure@$DIR/must_outlive_least_region_or_bound.rs:34:5: 34:31]` captures the lifetime `'b` as defined here + | -- hidden type `[closure@$DIR/must_outlive_least_region_or_bound.rs:50:5: 50:31]` captures the lifetime `'b` as defined here LL | move |_| println!("{}", y) | ^^^^^^^^^^^^^^^^^^^^^^^^^^ | @@ -110,7 +110,7 @@ LL | fn move_lifetime_into_fn<'a, 'b>(x: &'a u32, y: &'b u32) -> impl Fn(&'a u32 | ++++ error[E0310]: the parameter type `T` may not live long enough - --> $DIR/must_outlive_least_region_or_bound.rs:40:5 + --> $DIR/must_outlive_least_region_or_bound.rs:56:5 | LL | x | ^ ...so that the type `T` will meet its required lifetime bounds diff --git a/src/test/ui/impl-trait/must_outlive_least_region_or_bound.rs b/src/test/ui/impl-trait/must_outlive_least_region_or_bound.rs index 60e4672f1b7..6bb3141b012 100644 --- a/src/test/ui/impl-trait/must_outlive_least_region_or_bound.rs +++ b/src/test/ui/impl-trait/must_outlive_least_region_or_bound.rs @@ -1,3 +1,7 @@ +// ignore-compare-mode-nll +// revisions: base nll +// [nll]compile-flags: -Zborrowck=mir + use std::fmt::Debug; fn elided(x: &i32) -> impl Copy { x } @@ -6,27 +10,39 @@ fn elided(x: &i32) -> impl Copy { x } fn explicit<'a>(x: &'a i32) -> impl Copy { x } //~^ ERROR: captures lifetime that does not appear in bounds -fn elided2(x: &i32) -> impl Copy + 'static { x } //~ ERROR E0759 +fn elided2(x: &i32) -> impl Copy + 'static { x } +//[base]~^ ERROR E0759 +//[nll]~^^ ERROR lifetime may not live long enough -fn explicit2<'a>(x: &'a i32) -> impl Copy + 'static { x } //~ ERROR E0759 +fn explicit2<'a>(x: &'a i32) -> impl Copy + 'static { x } +//[base]~^ ERROR E0759 +//[nll]~^^ ERROR lifetime may not live long enough fn foo<'a>(x: &i32) -> impl Copy + 'a { x } //~^ ERROR explicit lifetime required in the type of `x` -fn elided3(x: &i32) -> Box { Box::new(x) } //~ ERROR E0759 +fn elided3(x: &i32) -> Box { Box::new(x) } +//[base]~^ ERROR E0759 -fn explicit3<'a>(x: &'a i32) -> Box { Box::new(x) } //~ ERROR E0759 +fn explicit3<'a>(x: &'a i32) -> Box { Box::new(x) } +//[base]~^ ERROR E0759 -fn elided4(x: &i32) -> Box { Box::new(x) } //~ ERROR E0759 +fn elided4(x: &i32) -> Box { Box::new(x) } +//[base]~^ ERROR E0759 -fn explicit4<'a>(x: &'a i32) -> Box { Box::new(x) } //~ ERROR E0759 +fn explicit4<'a>(x: &'a i32) -> Box { Box::new(x) } +//[base]~^ ERROR E0759 -fn elided5(x: &i32) -> (Box, impl Debug) { (Box::new(x), x) } //~ ERROR E0759 +fn elided5(x: &i32) -> (Box, impl Debug) { (Box::new(x), x) } +//[base]~^ ERROR E0759 +//[nll]~^^ ERROR lifetime may not live long enough trait LifetimeTrait<'a> {} impl<'a> LifetimeTrait<'a> for &'a i32 {} -fn with_bound<'a>(x: &'a i32) -> impl LifetimeTrait<'a> + 'static { x } //~ ERROR E0759 +fn with_bound<'a>(x: &'a i32) -> impl LifetimeTrait<'a> + 'static { x } +//[base]~^ ERROR E0759 +//[nll]~^^ ERROR lifetime may not live long enough // Tests that a closure type containing 'b cannot be returned from a type where // only 'a was expected. @@ -36,8 +52,9 @@ fn move_lifetime_into_fn<'a, 'b>(x: &'a u32, y: &'b u32) -> impl Fn(&'a u32) { } fn ty_param_wont_outlive_static(x: T) -> impl Debug + 'static { - //~^ ERROR the parameter type `T` may not live long enough + //[base]~^ ERROR the parameter type `T` may not live long enough x + //[nll]~^ ERROR the parameter type `T` may not live long enough } fn main() {} diff --git a/src/test/ui/impl-trait/must_outlive_least_region_or_bound.stderr b/src/test/ui/impl-trait/must_outlive_least_region_or_bound.stderr deleted file mode 100644 index dade2b91fe0..00000000000 --- a/src/test/ui/impl-trait/must_outlive_least_region_or_bound.stderr +++ /dev/null @@ -1,227 +0,0 @@ -error[E0700]: hidden type for `impl Trait` captures lifetime that does not appear in bounds - --> $DIR/must_outlive_least_region_or_bound.rs:3:35 - | -LL | fn elided(x: &i32) -> impl Copy { x } - | ---- ^ - | | - | hidden type `&i32` captures the anonymous lifetime defined here - | -help: to declare that the `impl Trait` captures `'_`, you can add an explicit `'_` lifetime bound - | -LL | fn elided(x: &i32) -> impl Copy + '_ { x } - | ++++ - -error[E0700]: hidden type for `impl Trait` captures lifetime that does not appear in bounds - --> $DIR/must_outlive_least_region_or_bound.rs:6:44 - | -LL | fn explicit<'a>(x: &'a i32) -> impl Copy { x } - | -- ^ - | | - | hidden type `&'a i32` captures the lifetime `'a` as defined here - | -help: to declare that the `impl Trait` captures `'a`, you can add an explicit `'a` lifetime bound - | -LL | fn explicit<'a>(x: &'a i32) -> impl Copy + 'a { x } - | ++++ - -error[E0759]: `x` has an anonymous lifetime `'_` but it needs to satisfy a `'static` lifetime requirement - --> $DIR/must_outlive_least_region_or_bound.rs:9:46 - | -LL | fn elided2(x: &i32) -> impl Copy + 'static { x } - | ---- ^ ...is used here... - | | - | this data with an anonymous lifetime `'_`... - | -note: ...and is required to live as long as `'static` here - --> $DIR/must_outlive_least_region_or_bound.rs:9:24 - | -LL | fn elided2(x: &i32) -> impl Copy + 'static { x } - | ^^^^^^^^^^^^^^^^^^^ -help: consider changing the `impl Trait`'s explicit `'static` bound to the lifetime of argument `x` - | -LL | fn elided2(x: &i32) -> impl Copy + '_ { x } - | ~~ -help: alternatively, add an explicit `'static` bound to this reference - | -LL | fn elided2(x: &'static i32) -> impl Copy + 'static { x } - | ~~~~~~~~~~~~ - -error[E0759]: `x` has lifetime `'a` but it needs to satisfy a `'static` lifetime requirement - --> $DIR/must_outlive_least_region_or_bound.rs:11:55 - | -LL | fn explicit2<'a>(x: &'a i32) -> impl Copy + 'static { x } - | ------- ^ ...is used here... - | | - | this data with lifetime `'a`... - | -note: ...and is required to live as long as `'static` here - --> $DIR/must_outlive_least_region_or_bound.rs:11:33 - | -LL | fn explicit2<'a>(x: &'a i32) -> impl Copy + 'static { x } - | ^^^^^^^^^^^^^^^^^^^ -help: consider changing the `impl Trait`'s explicit `'static` bound to the lifetime of argument `x` - | -LL | fn explicit2<'a>(x: &'a i32) -> impl Copy + 'a { x } - | ~~ -help: alternatively, add an explicit `'static` bound to this reference - | -LL | fn explicit2<'a>(x: &'static i32) -> impl Copy + 'static { x } - | ~~~~~~~~~~~~ - -error[E0621]: explicit lifetime required in the type of `x` - --> $DIR/must_outlive_least_region_or_bound.rs:13:24 - | -LL | fn foo<'a>(x: &i32) -> impl Copy + 'a { x } - | ---- ^^^^^^^^^^^^^^ lifetime `'a` required - | | - | help: add explicit lifetime `'a` to the type of `x`: `&'a i32` - -error[E0759]: `x` has an anonymous lifetime `'_` but it needs to satisfy a `'static` lifetime requirement - --> $DIR/must_outlive_least_region_or_bound.rs:24:65 - | -LL | fn elided5(x: &i32) -> (Box, impl Debug) { (Box::new(x), x) } - | ---- this data with an anonymous lifetime `'_`... ^ ...is used and required to live as long as `'static` here - | -help: to declare that the trait object captures data from argument `x`, you can add an explicit `'_` lifetime bound - | -LL | fn elided5(x: &i32) -> (Box, impl Debug) { (Box::new(x), x) } - | ++++ -help: to declare that the `impl Trait` captures data from argument `x`, you can add an explicit `'_` lifetime bound - | -LL | fn elided5(x: &i32) -> (Box, impl Debug + '_) { (Box::new(x), x) } - | ++++ - -error[E0759]: `x` has lifetime `'a` but it needs to satisfy a `'static` lifetime requirement - --> $DIR/must_outlive_least_region_or_bound.rs:29:69 - | -LL | fn with_bound<'a>(x: &'a i32) -> impl LifetimeTrait<'a> + 'static { x } - | ------- this data with lifetime `'a`... ^ ...is used here... - | -note: ...and is required to live as long as `'static` here - --> $DIR/must_outlive_least_region_or_bound.rs:29:34 - | -LL | fn with_bound<'a>(x: &'a i32) -> impl LifetimeTrait<'a> + 'static { x } - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ -help: consider changing the `impl Trait`'s explicit `'static` bound to the lifetime of argument `x` - | -LL | fn with_bound<'a>(x: &'a i32) -> impl LifetimeTrait<'a> + 'a { x } - | ~~ -help: alternatively, add an explicit `'static` bound to this reference - | -LL | fn with_bound<'a>(x: &'static i32) -> impl LifetimeTrait<'a> + 'static { x } - | ~~~~~~~~~~~~ - -error[E0700]: hidden type for `impl Trait` captures lifetime that does not appear in bounds - --> $DIR/must_outlive_least_region_or_bound.rs:34:5 - | -LL | fn move_lifetime_into_fn<'a, 'b>(x: &'a u32, y: &'b u32) -> impl Fn(&'a u32) { - | -- hidden type `[closure@$DIR/must_outlive_least_region_or_bound.rs:34:5: 34:31]` captures the lifetime `'b` as defined here -LL | move |_| println!("{}", y) - | ^^^^^^^^^^^^^^^^^^^^^^^^^^ - | -help: to declare that the `impl Trait` captures `'b`, you can add an explicit `'b` lifetime bound - | -LL | fn move_lifetime_into_fn<'a, 'b>(x: &'a u32, y: &'b u32) -> impl Fn(&'a u32) + 'b { - | ++++ - -error[E0310]: the parameter type `T` may not live long enough - --> $DIR/must_outlive_least_region_or_bound.rs:38:51 - | -LL | fn ty_param_wont_outlive_static(x: T) -> impl Debug + 'static { - | ^^^^^^^^^^^^^^^^^^^^ ...so that the type `T` will meet its required lifetime bounds - | -help: consider adding an explicit lifetime bound... - | -LL | fn ty_param_wont_outlive_static(x: T) -> impl Debug + 'static { - | +++++++++ - -error[E0759]: `x` has an anonymous lifetime `'_` but it needs to satisfy a `'static` lifetime requirement - --> $DIR/must_outlive_least_region_or_bound.rs:16:50 - | -LL | fn elided3(x: &i32) -> Box { Box::new(x) } - | ---- ^ ...is used and required to live as long as `'static` here - | | - | this data with an anonymous lifetime `'_`... - | -note: `'static` lifetime requirement introduced by the return type - --> $DIR/must_outlive_least_region_or_bound.rs:16:28 - | -LL | fn elided3(x: &i32) -> Box { Box::new(x) } - | ^^^^^^^^^ ----------- because of this returned expression - | | - | `'static` requirement introduced here -help: to declare that the trait object captures data from argument `x`, you can add an explicit `'_` lifetime bound - | -LL | fn elided3(x: &i32) -> Box { Box::new(x) } - | ++++ - -error[E0759]: `x` has lifetime `'a` but it needs to satisfy a `'static` lifetime requirement - --> $DIR/must_outlive_least_region_or_bound.rs:18:59 - | -LL | fn explicit3<'a>(x: &'a i32) -> Box { Box::new(x) } - | ------- ^ ...is used and required to live as long as `'static` here - | | - | this data with lifetime `'a`... - | -note: `'static` lifetime requirement introduced by the return type - --> $DIR/must_outlive_least_region_or_bound.rs:18:37 - | -LL | fn explicit3<'a>(x: &'a i32) -> Box { Box::new(x) } - | ^^^^^^^^^ ----------- because of this returned expression - | | - | `'static` requirement introduced here -help: to declare that the trait object captures data from argument `x`, you can add an explicit `'a` lifetime bound - | -LL | fn explicit3<'a>(x: &'a i32) -> Box { Box::new(x) } - | ++++ - -error[E0759]: `x` has an anonymous lifetime `'_` but it needs to satisfy a `'static` lifetime requirement - --> $DIR/must_outlive_least_region_or_bound.rs:20:60 - | -LL | fn elided4(x: &i32) -> Box { Box::new(x) } - | ---- ^ ...is used and required to live as long as `'static` here - | | - | this data with an anonymous lifetime `'_`... - | -note: `'static` lifetime requirement introduced by the return type - --> $DIR/must_outlive_least_region_or_bound.rs:20:40 - | -LL | fn elided4(x: &i32) -> Box { Box::new(x) } - | ^^^^^^^ ----------- because of this returned expression - | | - | `'static` requirement introduced here -help: consider changing the trait object's explicit `'static` bound to the lifetime of argument `x` - | -LL | fn elided4(x: &i32) -> Box { Box::new(x) } - | ~~ -help: alternatively, add an explicit `'static` bound to this reference - | -LL | fn elided4(x: &'static i32) -> Box { Box::new(x) } - | ~~~~~~~~~~~~ - -error[E0759]: `x` has lifetime `'a` but it needs to satisfy a `'static` lifetime requirement - --> $DIR/must_outlive_least_region_or_bound.rs:22:69 - | -LL | fn explicit4<'a>(x: &'a i32) -> Box { Box::new(x) } - | ------- this data with lifetime `'a`... ^ ...is used and required to live as long as `'static` here - | -note: `'static` lifetime requirement introduced by the return type - --> $DIR/must_outlive_least_region_or_bound.rs:22:49 - | -LL | fn explicit4<'a>(x: &'a i32) -> Box { Box::new(x) } - | ^^^^^^^ ----------- because of this returned expression - | | - | `'static` requirement introduced here -help: consider changing the trait object's explicit `'static` bound to the lifetime of argument `x` - | -LL | fn explicit4<'a>(x: &'a i32) -> Box { Box::new(x) } - | ~~ -help: alternatively, add an explicit `'static` bound to this reference - | -LL | fn explicit4<'a>(x: &'static i32) -> Box { Box::new(x) } - | ~~~~~~~~~~~~ - -error: aborting due to 13 previous errors - -Some errors have detailed explanations: E0310, E0621, E0700, E0759. -For more information about an error, try `rustc --explain E0310`. diff --git a/src/test/ui/impl-trait/type_parameters_captured.base.stderr b/src/test/ui/impl-trait/type_parameters_captured.base.stderr new file mode 100644 index 00000000000..cfa1d93d571 --- /dev/null +++ b/src/test/ui/impl-trait/type_parameters_captured.base.stderr @@ -0,0 +1,14 @@ +error[E0310]: the parameter type `T` may not live long enough + --> $DIR/type_parameters_captured.rs:11:20 + | +LL | fn foo(x: T) -> impl Any + 'static { + | ^^^^^^^^^^^^^^^^^^ ...so that the type `T` will meet its required lifetime bounds + | +help: consider adding an explicit lifetime bound... + | +LL | fn foo(x: T) -> impl Any + 'static { + | +++++++++ + +error: aborting due to previous error + +For more information about this error, try `rustc --explain E0310`. diff --git a/src/test/ui/impl-trait/type_parameters_captured.nll.stderr b/src/test/ui/impl-trait/type_parameters_captured.nll.stderr index 3050f10b205..a07ba564490 100644 --- a/src/test/ui/impl-trait/type_parameters_captured.nll.stderr +++ b/src/test/ui/impl-trait/type_parameters_captured.nll.stderr @@ -1,5 +1,5 @@ error[E0310]: the parameter type `T` may not live long enough - --> $DIR/type_parameters_captured.rs:9:5 + --> $DIR/type_parameters_captured.rs:13:5 | LL | x | ^ ...so that the type `T` will meet its required lifetime bounds diff --git a/src/test/ui/impl-trait/type_parameters_captured.rs b/src/test/ui/impl-trait/type_parameters_captured.rs index 6c9c9d4a42a..0618beeef97 100644 --- a/src/test/ui/impl-trait/type_parameters_captured.rs +++ b/src/test/ui/impl-trait/type_parameters_captured.rs @@ -1,3 +1,7 @@ +// ignore-compare-mode-nll +// revisions: base nll +// [nll]compile-flags: -Zborrowck=mir + use std::fmt::Debug; trait Any {} @@ -5,8 +9,9 @@ impl Any for T {} // Check that type parameters are captured and not considered 'static fn foo(x: T) -> impl Any + 'static { - //~^ ERROR the parameter type `T` may not live long enough + //[base]~^ ERROR the parameter type `T` may not live long enough x + //[nll]~^ ERROR the parameter type `T` may not live long enough } fn main() {} diff --git a/src/test/ui/impl-trait/type_parameters_captured.stderr b/src/test/ui/impl-trait/type_parameters_captured.stderr deleted file mode 100644 index 9f28a8d44a7..00000000000 --- a/src/test/ui/impl-trait/type_parameters_captured.stderr +++ /dev/null @@ -1,14 +0,0 @@ -error[E0310]: the parameter type `T` may not live long enough - --> $DIR/type_parameters_captured.rs:7:20 - | -LL | fn foo(x: T) -> impl Any + 'static { - | ^^^^^^^^^^^^^^^^^^ ...so that the type `T` will meet its required lifetime bounds - | -help: consider adding an explicit lifetime bound... - | -LL | fn foo(x: T) -> impl Any + 'static { - | +++++++++ - -error: aborting due to previous error - -For more information about this error, try `rustc --explain E0310`. -- cgit 1.4.1-3-g733a5