Skip to content

Commit dfd2b64

Browse files
authored
Rollup merge of #109222 - chenyukang:yukang/fix-109143, r=petrochenkov
Do not ICE for unexpected lifetime with ConstGeneric rib Fixes #109143 r? ````@petrochenkov```` Combining this test with the previous test will affect the previous diagnostics, so I added a separate test case.
2 parents e7d6369 + 827a990 commit dfd2b64

File tree

3 files changed

+27
-4
lines changed

3 files changed

+27
-4
lines changed

compiler/rustc_resolve/src/late.rs

+3-2
Original file line numberDiff line numberDiff line change
@@ -1478,8 +1478,9 @@ impl<'a: 'ast, 'b, 'ast, 'tcx> LateResolutionVisitor<'a, 'b, 'ast, 'tcx> {
14781478
} else {
14791479
LifetimeUseSet::Many
14801480
}),
1481-
LifetimeRibKind::Generics { .. } => None,
1482-
LifetimeRibKind::ConstGeneric | LifetimeRibKind::AnonConst => {
1481+
LifetimeRibKind::Generics { .. }
1482+
| LifetimeRibKind::ConstGeneric => None,
1483+
LifetimeRibKind::AnonConst => {
14831484
span_bug!(ident.span, "unexpected rib kind: {:?}", rib.kind)
14841485
}
14851486
})

tests/ui/lifetimes/unusual-rib-combinations.rs

+5
Original file line numberDiff line numberDiff line change
@@ -25,4 +25,9 @@ fn d<const C: S>() {}
2525
//~^ ERROR missing lifetime specifier
2626
//~| ERROR `S<'_>` is forbidden as the type of a const generic parameter
2727

28+
trait Foo<'a> {}
29+
struct Bar<const N: &'a (dyn for<'a> Foo<'a>)>;
30+
//~^ ERROR use of non-static lifetime `'a` in const generic
31+
//~| ERROR `&dyn for<'a> Foo<'a>` is forbidden as the type of a const generic parameter
32+
2833
fn main() {}

tests/ui/lifetimes/unusual-rib-combinations.stderr

+19-2
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,14 @@ help: consider introducing a named lifetime parameter
99
LL | fn d<'a, const C: S<'a>>() {}
1010
| +++ ++++
1111

12+
error[E0771]: use of non-static lifetime `'a` in const generic
13+
--> $DIR/unusual-rib-combinations.rs:29:22
14+
|
15+
LL | struct Bar<const N: &'a (dyn for<'a> Foo<'a>)>;
16+
| ^^
17+
|
18+
= note: for more information, see issue #74052 <https://github.com/rust-lang/rust/issues/74052>
19+
1220
error[E0214]: parenthesized type parameters may only be used with a `Fn` trait
1321
--> $DIR/unusual-rib-combinations.rs:7:16
1422
|
@@ -55,7 +63,16 @@ LL | fn d<const C: S>() {}
5563
= note: the only supported types are integers, `bool` and `char`
5664
= help: more complex types are supported with `#![feature(adt_const_params)]`
5765

58-
error: aborting due to 7 previous errors
66+
error: `&dyn for<'a> Foo<'a>` is forbidden as the type of a const generic parameter
67+
--> $DIR/unusual-rib-combinations.rs:29:21
68+
|
69+
LL | struct Bar<const N: &'a (dyn for<'a> Foo<'a>)>;
70+
| ^^^^^^^^^^^^^^^^^^^^^^^^^
71+
|
72+
= note: the only supported types are integers, `bool` and `char`
73+
= help: more complex types are supported with `#![feature(adt_const_params)]`
74+
75+
error: aborting due to 9 previous errors
5976

60-
Some errors have detailed explanations: E0106, E0214, E0308.
77+
Some errors have detailed explanations: E0106, E0214, E0308, E0771.
6178
For more information about an error, try `rustc --explain E0106`.

0 commit comments

Comments
 (0)