Show errors instead of hiding them due to an earlier error

This commit is contained in:
Oli Scherer 2022-09-23 07:12:59 +00:00
parent 5ace12c409
commit 90ec6f847f
4 changed files with 62 additions and 16 deletions

View File

@ -6,6 +6,7 @@ fn defining(a: &str) -> Ty<'_> { a }
fn assert_static<'a: 'static>() {} fn assert_static<'a: 'static>() {}
//~^ WARN: unnecessary lifetime parameter `'a` //~^ WARN: unnecessary lifetime parameter `'a`
fn test<'a>() where Ty<'a>: 'static { assert_static::<'a>() } fn test<'a>() where Ty<'a>: 'static { assert_static::<'a>() }
//~^ ERROR: lifetime may not live long enough
} }
mod test_higher_kinded_lifetime_param { mod test_higher_kinded_lifetime_param {
@ -14,14 +15,14 @@ fn defining(a: &str) -> Ty<'_> { a }
fn assert_static<'a: 'static>() {} fn assert_static<'a: 'static>() {}
//~^ WARN: unnecessary lifetime parameter `'a` //~^ WARN: unnecessary lifetime parameter `'a`
fn test<'a>() where for<'b> Ty<'b>: 'a { assert_static::<'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 { mod test_higher_kinded_lifetime_param2 {
fn assert_static<'a: 'static>() {} fn assert_static<'a: 'static>() {}
//~^ WARN: unnecessary lifetime parameter `'a` //~^ WARN: unnecessary lifetime parameter `'a`
fn test<'a>() { assert_static::<'a>() } fn test<'a>() { assert_static::<'a>() }
// no error because all the other errors happen first and then we abort before //~^ ERROR: lifetime may not live long enough
// emitting an error here.
} }
mod test_type_param { mod test_type_param {
@ -29,14 +30,14 @@ mod test_type_param {
fn defining<A>(s: A) -> Ty<A> { s } fn defining<A>(s: A) -> Ty<A> { s }
fn assert_static<A: 'static>() {} fn assert_static<A: 'static>() {}
fn test<A>() where Ty<A>: 'static { assert_static::<A>() } fn test<A>() where Ty<A>: 'static { assert_static::<A>() }
//~^ ERROR: parameter type `A` may not live long enough
} }
mod test_type_param_static { mod test_implied_from_fn_sig {
type Ty<A> = impl Sized + 'static; type Opaque<T: 'static> = impl Sized;
//~^ ERROR: the parameter type `A` may not live long enough fn defining<T: 'static>() -> Opaque<T> {}
fn defining<A: 'static>(s: A) -> Ty<A> { s } fn assert_static<T: 'static>() {}
fn assert_static<A: 'static>() {} fn test<T>(_: Opaque<T>) { assert_static::<T>(); }
fn test<A>() where Ty<A>: 'static { assert_static::<A>() }
} }
fn main() {} fn main() {}

View File

@ -7,7 +7,7 @@ LL | fn assert_static<'a: 'static>() {}
= help: you can use the `'static` lifetime directly, in place of `'a` = help: you can use the `'static` lifetime directly, in place of `'a`
warning: unnecessary lifetime parameter `'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>() {} 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` = help: you can use the `'static` lifetime directly, in place of `'a`
warning: unnecessary lifetime parameter `'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>() {} LL | fn assert_static<'a: 'static>() {}
| ^^ | ^^
| |
= help: you can use the `'static` lifetime directly, in place of `'a` = help: you can use the `'static` lifetime directly, in place of `'a`
error[E0310]: the parameter type `A` may not live long enough error: lifetime may not live long enough
--> $DIR/implied_lifetime_wf_check3.rs:35:18 --> $DIR/implied_lifetime_wf_check3.rs:8:43
| |
LL | type Ty<A> = impl Sized + 'static; LL | fn test<'a>() where Ty<'a>: 'static { assert_static::<'a>() }
| ^^^^^^^^^^^^^^^^^^^^ ...so that the type `A` will meet its required lifetime bounds | -- 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<A>() where Ty<A>: 'static { assert_static::<A>() }
| ^^^^^^^^^^^^^^^^^^ ...so that the type `A` will meet its required lifetime bounds
| |
help: consider adding an explicit lifetime bound... help: consider adding an explicit lifetime bound...
| |
LL | type Ty<A: 'static> = impl Sized + 'static; LL | fn test<A: 'static>() where Ty<A>: 'static { assert_static::<A>() }
| +++++++++ | +++++++++
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`. For more information about this error, try `rustc --explain E0310`.

View File

@ -0,0 +1,11 @@
#![feature(type_alias_impl_trait)]
mod test_type_param_static {
type Ty<A> = impl Sized + 'static;
//~^ ERROR: the parameter type `A` may not live long enough
fn defining<A: 'static>(s: A) -> Ty<A> { s }
fn assert_static<A: 'static>() {}
fn test<A>() where Ty<A>: 'static { assert_static::<A>() }
}
fn main() {}

View File

@ -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<A> = impl Sized + 'static;
| ^^^^^^^^^^^^^^^^^^^^ ...so that the type `A` will meet its required lifetime bounds
|
help: consider adding an explicit lifetime bound...
|
LL | type Ty<A: 'static> = impl Sized + 'static;
| +++++++++
error: aborting due to previous error
For more information about this error, try `rustc --explain E0310`.