Skip to content

Commit a99bb12

Browse files
committed
WF check lifetime bounds for locals with type params
1 parent cf8a955 commit a99bb12

File tree

10 files changed

+37
-14
lines changed

10 files changed

+37
-14
lines changed

compiler/rustc_hir_typeck/src/fn_ctxt/_impl.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -547,7 +547,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
547547
where
548548
T: TypeVisitable<TyCtxt<'tcx>>,
549549
{
550-
t.has_free_regions() || t.has_aliases() || t.has_infer_types()
550+
t.has_free_regions() || t.has_aliases() || t.has_infer_types() || t.has_param()
551551
}
552552

553553
pub(crate) fn node_ty(&self, id: HirId) -> Ty<'tcx> {

tests/ui/consts/issue-102117.stderr

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ error[E0310]: the parameter type `T` may not live long enough
22
--> $DIR/issue-102117.rs:17:26
33
|
44
LL | type_id: TypeId::of::<T>(),
5-
| ^^^^^^^^^^^^^^^^^
5+
| ^^^^^^^^^^^^^^^
66
| |
77
| the parameter type `T` must be valid for the static lifetime...
88
| ...so that the type `T` will meet its required lifetime bounds
@@ -16,7 +16,7 @@ error[E0310]: the parameter type `T` may not live long enough
1616
--> $DIR/issue-102117.rs:17:26
1717
|
1818
LL | type_id: TypeId::of::<T>(),
19-
| ^^^^^^^^^^^^^^^^^
19+
| ^^^^^^^^^^^^^^^
2020
| |
2121
| the parameter type `T` must be valid for the static lifetime...
2222
| ...so that the type `T` will meet its required lifetime bounds

tests/ui/higher-ranked/leak-check/candidate-from-env-universe-err-project.current.stderr

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,10 @@ error[E0308]: mismatched types
22
--> $DIR/candidate-from-env-universe-err-project.rs:38:5
33
|
44
LL | projection_bound::<T>();
5-
| ^^^^^^^^^^^^^^^^^^^^^^^ one type is more general than the other
5+
| ^^^^^^^^^^^^^^^^^^^^^ one type is more general than the other
66
|
77
= note: expected associated type `<T as Trait<'static>>::Assoc`
88
found associated type `<T as Trait<'a>>::Assoc`
9-
note: the lifetime requirement is introduced here
10-
--> $DIR/candidate-from-env-universe-err-project.rs:19:42
11-
|
12-
LL | fn projection_bound<T: for<'a> Trait<'a, Assoc = usize>>() {}
13-
| ^^^^^^^^^^^^^
149

1510
error[E0308]: mismatched types
1611
--> $DIR/candidate-from-env-universe-err-project.rs:52:30

tests/ui/nll/issue-98693.stderr

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ error[E0310]: the parameter type `T` may not live long enough
22
--> $DIR/issue-98693.rs:16:9
33
|
44
LL | assert_static::<T>();
5-
| ^^^^^^^^^^^^^^^^^^^^
5+
| ^^^^^^^^^^^^^^^^^^
66
| |
77
| the parameter type `T` must be valid for the static lifetime...
88
| ...so that the type `T` will meet its required lifetime bounds

tests/ui/nll/type-test-universe.stderr

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ error: `S` does not live long enough
22
--> $DIR/type-test-universe.rs:11:5
33
|
44
LL | outlives_forall::<S>();
5-
| ^^^^^^^^^^^^^^^^^^^^^^
5+
| ^^^^^^^^^^^^^^^^^^^^
66

77
error: lifetime may not live long enough
88
--> $DIR/type-test-universe.rs:17:5

tests/ui/regions/forall-wf-ref-reflexive.stderr

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ error: `T` does not live long enough
22
--> $DIR/forall-wf-ref-reflexive.rs:12:5
33
|
44
LL | self_wf2::<T>();
5-
| ^^^^^^^^^^^^^^^
5+
| ^^^^^^^^^^^^^
66

77
error: aborting due to 1 previous error
88

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
// A regression test for https://github.com/rust-lang/rust/issues/115175.
2+
// This used to compile without error despite of unsatisfied outlives bound `T: 'static` on local.
3+
4+
struct Static<T: 'static>(T);
5+
6+
fn test<T>() {
7+
let _ = None::<Static<T>>;
8+
//~^ ERROR the parameter type `T` may not live long enough
9+
}
10+
11+
fn main() {}
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
error[E0310]: the parameter type `T` may not live long enough
2+
--> $DIR/wf-bound-region-in-local-issue-115175.rs:7:13
3+
|
4+
LL | let _ = None::<Static<T>>;
5+
| ^^^^^^^^^^^^^^^^^
6+
| |
7+
| the parameter type `T` must be valid for the static lifetime...
8+
| ...so that the type `T` will meet its required lifetime bounds
9+
|
10+
help: consider adding an explicit lifetime bound
11+
|
12+
LL | fn test<T: 'static>() {
13+
| +++++++++
14+
15+
error: aborting due to 1 previous error
16+
17+
For more information about this error, try `rustc --explain E0310`.

tests/ui/type-alias-impl-trait/implied_lifetime_wf_check3.stderr

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ error[E0310]: the parameter type `A` may not live long enough
2828
--> $DIR/implied_lifetime_wf_check3.rs:55:5
2929
|
3030
LL | test_type_param::assert_static::<A>()
31-
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
31+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
3232
| |
3333
| the parameter type `A` must be valid for the static lifetime...
3434
| ...so that the type `A` will meet its required lifetime bounds

tests/ui/type-alias-impl-trait/implied_lifetime_wf_check4_static.stderr

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ error[E0310]: the parameter type `A` may not live long enough
2121
--> $DIR/implied_lifetime_wf_check4_static.rs:15:5
2222
|
2323
LL | assert_static::<A>()
24-
| ^^^^^^^^^^^^^^^^^^^^
24+
| ^^^^^^^^^^^^^^^^^^
2525
| |
2626
| the parameter type `A` must be valid for the static lifetime...
2727
| ...so that the type `A` will meet its required lifetime bounds

0 commit comments

Comments
 (0)