diff --git a/src/test/ui/type-alias-impl-trait/implied_lifetime_wf_check3.rs b/src/test/ui/type-alias-impl-trait/implied_lifetime_wf_check3.rs index 4cbb6b63670..6e5b8f491ea 100644 --- a/src/test/ui/type-alias-impl-trait/implied_lifetime_wf_check3.rs +++ b/src/test/ui/type-alias-impl-trait/implied_lifetime_wf_check3.rs @@ -6,6 +6,7 @@ fn defining(a: &str) -> Ty<'_> { a } fn assert_static<'a: 'static>() {} //~^ WARN: unnecessary lifetime parameter `'a` fn test<'a>() where Ty<'a>: 'static { assert_static::<'a>() } + //~^ ERROR: lifetime may not live long enough } mod test_higher_kinded_lifetime_param { @@ -14,14 +15,14 @@ fn defining(a: &str) -> Ty<'_> { a } fn assert_static<'a: 'static>() {} //~^ WARN: unnecessary lifetime parameter `'a` fn test<'a>() where for<'b> Ty<'b>: 'a { assert_static::<'a>() } + //~^ ERROR: lifetime may not live long enough } mod test_higher_kinded_lifetime_param2 { fn assert_static<'a: 'static>() {} //~^ WARN: unnecessary lifetime parameter `'a` fn test<'a>() { assert_static::<'a>() } - // no error because all the other errors happen first and then we abort before - // emitting an error here. + //~^ ERROR: lifetime may not live long enough } mod test_type_param { @@ -29,14 +30,14 @@ mod test_type_param { fn defining(s: A) -> Ty { s } fn assert_static() {} fn test() where Ty: 'static { assert_static::() } + //~^ ERROR: parameter type `A` may not live long enough } -mod test_type_param_static { - type Ty = impl Sized + 'static; - //~^ ERROR: the parameter type `A` may not live long enough - fn defining(s: A) -> Ty { s } - fn assert_static() {} - fn test() where Ty: 'static { assert_static::() } +mod test_implied_from_fn_sig { + type Opaque = impl Sized; + fn defining() -> Opaque {} + fn assert_static() {} + fn test(_: Opaque) { assert_static::(); } } fn main() {} diff --git a/src/test/ui/type-alias-impl-trait/implied_lifetime_wf_check3.stderr b/src/test/ui/type-alias-impl-trait/implied_lifetime_wf_check3.stderr index 16d529698f4..887620a4d50 100644 --- a/src/test/ui/type-alias-impl-trait/implied_lifetime_wf_check3.stderr +++ b/src/test/ui/type-alias-impl-trait/implied_lifetime_wf_check3.stderr @@ -7,7 +7,7 @@ LL | fn assert_static<'a: 'static>() {} = help: you can use the `'static` lifetime directly, in place of `'a` warning: unnecessary lifetime parameter `'a` - --> $DIR/implied_lifetime_wf_check3.rs:14:22 + --> $DIR/implied_lifetime_wf_check3.rs:15:22 | LL | fn assert_static<'a: 'static>() {} | ^^ @@ -15,24 +15,44 @@ LL | fn assert_static<'a: 'static>() {} = help: you can use the `'static` lifetime directly, in place of `'a` warning: unnecessary lifetime parameter `'a` - --> $DIR/implied_lifetime_wf_check3.rs:20:22 + --> $DIR/implied_lifetime_wf_check3.rs:22:22 | LL | fn assert_static<'a: 'static>() {} | ^^ | = help: you can use the `'static` lifetime directly, in place of `'a` -error[E0310]: the parameter type `A` may not live long enough - --> $DIR/implied_lifetime_wf_check3.rs:35:18 +error: lifetime may not live long enough + --> $DIR/implied_lifetime_wf_check3.rs:8:43 | -LL | type Ty = impl Sized + 'static; - | ^^^^^^^^^^^^^^^^^^^^ ...so that the type `A` will meet its required lifetime bounds +LL | fn test<'a>() where Ty<'a>: 'static { assert_static::<'a>() } + | -- lifetime `'a` defined here ^^^^^^^^^^^^^^^^^^^ requires that `'a` must outlive `'static` + +error: lifetime may not live long enough + --> $DIR/implied_lifetime_wf_check3.rs:17:46 + | +LL | fn test<'a>() where for<'b> Ty<'b>: 'a { assert_static::<'a>() } + | -- lifetime `'a` defined here ^^^^^^^^^^^^^^^^^^^ requires that `'a` must outlive `'static` + +error: lifetime may not live long enough + --> $DIR/implied_lifetime_wf_check3.rs:24:21 + | +LL | fn test<'a>() { assert_static::<'a>() } + | -- ^^^^^^^^^^^^^^^^^^^ requires that `'a` must outlive `'static` + | | + | lifetime `'a` defined here + +error[E0310]: the parameter type `A` may not live long enough + --> $DIR/implied_lifetime_wf_check3.rs:32:41 + | +LL | fn test() where Ty: 'static { assert_static::() } + | ^^^^^^^^^^^^^^^^^^ ...so that the type `A` will meet its required lifetime bounds | help: consider adding an explicit lifetime bound... | -LL | type Ty = impl Sized + 'static; +LL | fn test() where Ty: 'static { assert_static::() } | +++++++++ -error: aborting due to previous error; 3 warnings emitted +error: aborting due to 4 previous errors; 3 warnings emitted For more information about this error, try `rustc --explain E0310`. diff --git a/src/test/ui/type-alias-impl-trait/implied_lifetime_wf_check4_static.rs b/src/test/ui/type-alias-impl-trait/implied_lifetime_wf_check4_static.rs new file mode 100644 index 00000000000..ac32dbde04b --- /dev/null +++ b/src/test/ui/type-alias-impl-trait/implied_lifetime_wf_check4_static.rs @@ -0,0 +1,11 @@ +#![feature(type_alias_impl_trait)] + +mod test_type_param_static { + type Ty = impl Sized + 'static; + //~^ ERROR: the parameter type `A` may not live long enough + fn defining(s: A) -> Ty { s } + fn assert_static() {} + fn test() where Ty: 'static { assert_static::() } +} + +fn main() {} diff --git a/src/test/ui/type-alias-impl-trait/implied_lifetime_wf_check4_static.stderr b/src/test/ui/type-alias-impl-trait/implied_lifetime_wf_check4_static.stderr new file mode 100644 index 00000000000..47bc31e78c3 --- /dev/null +++ b/src/test/ui/type-alias-impl-trait/implied_lifetime_wf_check4_static.stderr @@ -0,0 +1,14 @@ +error[E0310]: the parameter type `A` may not live long enough + --> $DIR/implied_lifetime_wf_check4_static.rs:4:18 + | +LL | type Ty = impl Sized + 'static; + | ^^^^^^^^^^^^^^^^^^^^ ...so that the type `A` will meet its required lifetime bounds + | +help: consider adding an explicit lifetime bound... + | +LL | type Ty = impl Sized + 'static; + | +++++++++ + +error: aborting due to previous error + +For more information about this error, try `rustc --explain E0310`.