Rollup merge of #114606 - bvanjoi:fix-113462, r=compiler-errors

fix: not insert missing lifetime for `ConstParamTy`

Fixes #113462

We should ignore the missing lifetime, as it's illegal to include a lifetime in a const param.

r? ``@compiler-errors``
This commit is contained in:
Matthias Krüger 2023-08-09 06:32:25 +02:00 committed by GitHub
commit 41d26941d6
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 31 additions and 7 deletions

View File

@ -2404,7 +2404,7 @@ fn suggest_introducing_lifetime(
should_continue = suggest(err, false, span, message, sugg);
}
}
LifetimeRibKind::Item => break,
LifetimeRibKind::Item | LifetimeRibKind::ConstParamTy => break,
_ => {}
}
if !should_continue {
@ -2510,7 +2510,9 @@ fn add_missing_lifetime_specifiers_label(
.lifetime_ribs
.iter()
.rev()
.take_while(|rib| !matches!(rib.kind, LifetimeRibKind::Item))
.take_while(|rib| {
!matches!(rib.kind, LifetimeRibKind::Item | LifetimeRibKind::ConstParamTy)
})
.flat_map(|rib| rib.bindings.iter())
.map(|(&ident, &res)| (ident, res))
.filter(|(ident, _)| ident.name != kw::UnderscoreLifetime)

View File

@ -0,0 +1,9 @@
// https://github.com/rust-lang/rust/issues/113462
struct S2<'b>(&'b ());
struct S<'a, const N: S2>(&'a ());
//~^ ERROR missing lifetime specifier [E0106]
//~| ERROR `S2<'_>` is forbidden as the type of a const generic parameter
fn main() {}

View File

@ -0,0 +1,18 @@
error[E0106]: missing lifetime specifier
--> $DIR/lifetime-in-const-param.rs:5:23
|
LL | struct S<'a, const N: S2>(&'a ());
| ^^ expected named lifetime parameter
error: `S2<'_>` is forbidden as the type of a const generic parameter
--> $DIR/lifetime-in-const-param.rs:5:23
|
LL | struct S<'a, const N: S2>(&'a ());
| ^^
|
= note: the only supported types are integers, `bool` and `char`
= help: more complex types are supported with `#![feature(adt_const_params)]`
error: aborting due to 2 previous errors
For more information about this error, try `rustc --explain E0106`.

View File

@ -3,11 +3,6 @@ error[E0106]: missing lifetime specifier
|
LL | fn d<const C: S>() {}
| ^ expected named lifetime parameter
|
help: consider introducing a named lifetime parameter
|
LL | fn d<'a, const C: S<'a>>() {}
| +++ ++++
error[E0770]: the type of const parameters must not depend on other generic parameters
--> $DIR/unusual-rib-combinations.rs:29:22