Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: not insert missing lifetime for ConstParamTy #114606

Merged
merged 1 commit into from
Aug 9, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions compiler/rustc_resolve/src/late/diagnostics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2404,7 +2404,7 @@ impl<'a: 'ast, 'ast, 'tcx> LateResolutionVisitor<'a, '_, 'ast, 'tcx> {
should_continue = suggest(err, false, span, message, sugg);
}
}
LifetimeRibKind::Item => break,
LifetimeRibKind::Item | LifetimeRibKind::ConstParamTy => break,
_ => {}
}
if !should_continue {
Expand Down Expand Up @@ -2510,7 +2510,9 @@ impl<'a: 'ast, 'ast, 'tcx> LateResolutionVisitor<'a, '_, 'ast, 'tcx> {
.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)
Expand Down
9 changes: 9 additions & 0 deletions tests/ui/const-generics/lifetime-in-const-param.rs
Original file line number Diff line number Diff line change
@@ -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() {}
18 changes: 18 additions & 0 deletions tests/ui/const-generics/lifetime-in-const-param.stderr
Original file line number Diff line number Diff line change
@@ -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`.
5 changes: 0 additions & 5 deletions tests/ui/lifetimes/unusual-rib-combinations.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Loading