Ban non-static in const generics in AST.

This commit is contained in:
Camille GILLOT
2021-12-05 00:07:21 +01:00
parent e85edd9a84
commit a87ab48099
3 changed files with 34 additions and 33 deletions

View File

@@ -199,6 +199,11 @@ enum LifetimeRibKind {
/// This rib declares generic parameters.
Generics { parent: NodeId, span: Span, kind: LifetimeBinderKind },
/// FIXME(const_generics): This patches over an ICE caused by non-'static lifetimes in const
/// generics. We are disallowing this until we can decide on how we want to handle non-'static
/// lifetimes in const generics. See issue #74052 for discussion.
ConstGeneric,
/// For **Modern** cases, create a new anonymous region parameter
/// and reference that.
///
@@ -1102,14 +1107,18 @@ impl<'a: 'ast, 'b, 'ast> LateResolutionVisitor<'a, 'b, 'ast> {
this.ribs[TypeNS].push(Rib::new(ConstParamTyRibKind));
this.ribs[ValueNS].push(Rib::new(ConstParamTyRibKind));
this.visit_ty(ty);
this.with_lifetime_rib(LifetimeRibKind::ConstGeneric, |this| {
this.visit_ty(ty)
});
this.ribs[TypeNS].pop().unwrap();
this.ribs[ValueNS].pop().unwrap();
if let Some(ref expr) = default {
this.ribs[TypeNS].push(forward_ty_ban_rib);
this.ribs[ValueNS].push(forward_const_ban_rib);
this.visit_anon_const(expr);
this.with_lifetime_rib(LifetimeRibKind::ConstGeneric, |this| {
this.visit_anon_const(expr)
});
forward_const_ban_rib = this.ribs[ValueNS].pop().unwrap();
forward_ty_ban_rib = this.ribs[TypeNS].pop().unwrap();
}
@@ -1158,8 +1167,14 @@ impl<'a: 'ast, 'b, 'ast> LateResolutionVisitor<'a, 'b, 'ast> {
return;
}
if let LifetimeRibKind::Item = rib.kind {
break;
match rib.kind {
LifetimeRibKind::Item => break,
LifetimeRibKind::ConstGeneric => {
self.emit_non_static_lt_in_const_generic_error(lifetime);
self.r.lifetimes_res_map.insert(lifetime.id, LifetimeRes::Error);
return;
}
_ => {}
}
}