Skip to content
/ rust Public
forked from rust-lang/rust

Commit 078b942

Browse files
committed
fix: not insert missing lifetime for ConstParamTy
1 parent 8e7fd55 commit 078b942

File tree

4 files changed

+31
-7
lines changed

4 files changed

+31
-7
lines changed

compiler/rustc_resolve/src/late/diagnostics.rs

+4-2
Original file line numberDiff line numberDiff line change
@@ -2404,7 +2404,7 @@ impl<'a: 'ast, 'ast, 'tcx> LateResolutionVisitor<'a, '_, 'ast, 'tcx> {
24042404
should_continue = suggest(err, false, span, message, sugg);
24052405
}
24062406
}
2407-
LifetimeRibKind::Item => break,
2407+
LifetimeRibKind::Item | LifetimeRibKind::ConstParamTy => break,
24082408
_ => {}
24092409
}
24102410
if !should_continue {
@@ -2510,7 +2510,9 @@ impl<'a: 'ast, 'ast, 'tcx> LateResolutionVisitor<'a, '_, 'ast, 'tcx> {
25102510
.lifetime_ribs
25112511
.iter()
25122512
.rev()
2513-
.take_while(|rib| !matches!(rib.kind, LifetimeRibKind::Item))
2513+
.take_while(|rib| {
2514+
!matches!(rib.kind, LifetimeRibKind::Item | LifetimeRibKind::ConstParamTy)
2515+
})
25142516
.flat_map(|rib| rib.bindings.iter())
25152517
.map(|(&ident, &res)| (ident, res))
25162518
.filter(|(ident, _)| ident.name != kw::UnderscoreLifetime)
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
// https://github.com/rust-lang/rust/issues/113462
2+
3+
struct S2<'b>(&'b ());
4+
5+
struct S<'a, const N: S2>(&'a ());
6+
//~^ ERROR missing lifetime specifier [E0106]
7+
//~| ERROR `S2<'_>` is forbidden as the type of a const generic parameter
8+
9+
fn main() {}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
error[E0106]: missing lifetime specifier
2+
--> $DIR/lifetime-in-const-param.rs:5:23
3+
|
4+
LL | struct S<'a, const N: S2>(&'a ());
5+
| ^^ expected named lifetime parameter
6+
7+
error: `S2<'_>` is forbidden as the type of a const generic parameter
8+
--> $DIR/lifetime-in-const-param.rs:5:23
9+
|
10+
LL | struct S<'a, const N: S2>(&'a ());
11+
| ^^
12+
|
13+
= note: the only supported types are integers, `bool` and `char`
14+
= help: more complex types are supported with `#![feature(adt_const_params)]`
15+
16+
error: aborting due to 2 previous errors
17+
18+
For more information about this error, try `rustc --explain E0106`.

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

-5
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,6 @@ error[E0106]: missing lifetime specifier
33
|
44
LL | fn d<const C: S>() {}
55
| ^ expected named lifetime parameter
6-
|
7-
help: consider introducing a named lifetime parameter
8-
|
9-
LL | fn d<'a, const C: S<'a>>() {}
10-
| +++ ++++
116

127
error[E0770]: the type of const parameters must not depend on other generic parameters
138
--> $DIR/unusual-rib-combinations.rs:29:22

0 commit comments

Comments
 (0)