Skip to content

Commit 90ec6f8

Browse files
committed
Show errors instead of hiding them due to an earlier error
1 parent 5ace12c commit 90ec6f8

4 files changed

+61
-15
lines changed

src/test/ui/type-alias-impl-trait/implied_lifetime_wf_check3.rs

+9-8
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ mod test_lifetime_param {
66
fn assert_static<'a: 'static>() {}
77
//~^ WARN: unnecessary lifetime parameter `'a`
88
fn test<'a>() where Ty<'a>: 'static { assert_static::<'a>() }
9+
//~^ ERROR: lifetime may not live long enough
910
}
1011

1112
mod test_higher_kinded_lifetime_param {
@@ -14,29 +15,29 @@ mod test_higher_kinded_lifetime_param {
1415
fn assert_static<'a: 'static>() {}
1516
//~^ WARN: unnecessary lifetime parameter `'a`
1617
fn test<'a>() where for<'b> Ty<'b>: 'a { assert_static::<'a>() }
18+
//~^ ERROR: lifetime may not live long enough
1719
}
1820

1921
mod test_higher_kinded_lifetime_param2 {
2022
fn assert_static<'a: 'static>() {}
2123
//~^ WARN: unnecessary lifetime parameter `'a`
2224
fn test<'a>() { assert_static::<'a>() }
23-
// no error because all the other errors happen first and then we abort before
24-
// emitting an error here.
25+
//~^ ERROR: lifetime may not live long enough
2526
}
2627

2728
mod test_type_param {
2829
type Ty<A> = impl Sized;
2930
fn defining<A>(s: A) -> Ty<A> { s }
3031
fn assert_static<A: 'static>() {}
3132
fn test<A>() where Ty<A>: 'static { assert_static::<A>() }
33+
//~^ ERROR: parameter type `A` may not live long enough
3234
}
3335

34-
mod test_type_param_static {
35-
type Ty<A> = impl Sized + 'static;
36-
//~^ ERROR: the parameter type `A` may not live long enough
37-
fn defining<A: 'static>(s: A) -> Ty<A> { s }
38-
fn assert_static<A: 'static>() {}
39-
fn test<A>() where Ty<A>: 'static { assert_static::<A>() }
36+
mod test_implied_from_fn_sig {
37+
type Opaque<T: 'static> = impl Sized;
38+
fn defining<T: 'static>() -> Opaque<T> {}
39+
fn assert_static<T: 'static>() {}
40+
fn test<T>(_: Opaque<T>) { assert_static::<T>(); }
4041
}
4142

4243
fn main() {}

src/test/ui/type-alias-impl-trait/implied_lifetime_wf_check3.stderr

+27-7
Original file line numberDiff line numberDiff line change
@@ -7,32 +7,52 @@ LL | fn assert_static<'a: 'static>() {}
77
= help: you can use the `'static` lifetime directly, in place of `'a`
88

99
warning: unnecessary lifetime parameter `'a`
10-
--> $DIR/implied_lifetime_wf_check3.rs:14:22
10+
--> $DIR/implied_lifetime_wf_check3.rs:15:22
1111
|
1212
LL | fn assert_static<'a: 'static>() {}
1313
| ^^
1414
|
1515
= help: you can use the `'static` lifetime directly, in place of `'a`
1616

1717
warning: unnecessary lifetime parameter `'a`
18-
--> $DIR/implied_lifetime_wf_check3.rs:20:22
18+
--> $DIR/implied_lifetime_wf_check3.rs:22:22
1919
|
2020
LL | fn assert_static<'a: 'static>() {}
2121
| ^^
2222
|
2323
= help: you can use the `'static` lifetime directly, in place of `'a`
2424

25+
error: lifetime may not live long enough
26+
--> $DIR/implied_lifetime_wf_check3.rs:8:43
27+
|
28+
LL | fn test<'a>() where Ty<'a>: 'static { assert_static::<'a>() }
29+
| -- lifetime `'a` defined here ^^^^^^^^^^^^^^^^^^^ requires that `'a` must outlive `'static`
30+
31+
error: lifetime may not live long enough
32+
--> $DIR/implied_lifetime_wf_check3.rs:17:46
33+
|
34+
LL | fn test<'a>() where for<'b> Ty<'b>: 'a { assert_static::<'a>() }
35+
| -- lifetime `'a` defined here ^^^^^^^^^^^^^^^^^^^ requires that `'a` must outlive `'static`
36+
37+
error: lifetime may not live long enough
38+
--> $DIR/implied_lifetime_wf_check3.rs:24:21
39+
|
40+
LL | fn test<'a>() { assert_static::<'a>() }
41+
| -- ^^^^^^^^^^^^^^^^^^^ requires that `'a` must outlive `'static`
42+
| |
43+
| lifetime `'a` defined here
44+
2545
error[E0310]: the parameter type `A` may not live long enough
26-
--> $DIR/implied_lifetime_wf_check3.rs:35:18
46+
--> $DIR/implied_lifetime_wf_check3.rs:32:41
2747
|
28-
LL | type Ty<A> = impl Sized + 'static;
29-
| ^^^^^^^^^^^^^^^^^^^^ ...so that the type `A` will meet its required lifetime bounds
48+
LL | fn test<A>() where Ty<A>: 'static { assert_static::<A>() }
49+
| ^^^^^^^^^^^^^^^^^^ ...so that the type `A` will meet its required lifetime bounds
3050
|
3151
help: consider adding an explicit lifetime bound...
3252
|
33-
LL | type Ty<A: 'static> = impl Sized + 'static;
53+
LL | fn test<A: 'static>() where Ty<A>: 'static { assert_static::<A>() }
3454
| +++++++++
3555

36-
error: aborting due to previous error; 3 warnings emitted
56+
error: aborting due to 4 previous errors; 3 warnings emitted
3757

3858
For more information about this error, try `rustc --explain E0310`.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
#![feature(type_alias_impl_trait)]
2+
3+
mod test_type_param_static {
4+
type Ty<A> = impl Sized + 'static;
5+
//~^ ERROR: the parameter type `A` may not live long enough
6+
fn defining<A: 'static>(s: A) -> Ty<A> { s }
7+
fn assert_static<A: 'static>() {}
8+
fn test<A>() where Ty<A>: 'static { assert_static::<A>() }
9+
}
10+
11+
fn main() {}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
error[E0310]: the parameter type `A` may not live long enough
2+
--> $DIR/implied_lifetime_wf_check4_static.rs:4:18
3+
|
4+
LL | type Ty<A> = impl Sized + 'static;
5+
| ^^^^^^^^^^^^^^^^^^^^ ...so that the type `A` will meet its required lifetime bounds
6+
|
7+
help: consider adding an explicit lifetime bound...
8+
|
9+
LL | type Ty<A: 'static> = impl Sized + 'static;
10+
| +++++++++
11+
12+
error: aborting due to previous error
13+
14+
For more information about this error, try `rustc --explain E0310`.

0 commit comments

Comments
 (0)