No,
}
+#[derive(Copy, Clone, Debug, Eq, PartialEq)]
+crate enum ConstantItemKind {
+ Const,
+ Static,
+}
+
/// The rib kind restricts certain accesses,
/// e.g. to a `Res::Local` of an outer item.
#[derive(Copy, Clone, Debug)]
///
/// The `bool` indicates if this constant may reference generic parameters
/// and is used to only allow generic parameters to be used in trivial constant expressions.
- ConstantItemRibKind(bool),
+ ConstantItemRibKind(bool, Option<(Ident, ConstantItemKind)>),
/// We passed through a module.
ModuleRibKind(Module<'a>),
NormalRibKind
| ClosureOrAsyncRibKind
| FnItemRibKind
- | ConstantItemRibKind(_)
+ | ConstantItemRibKind(..)
| ModuleRibKind(_)
| MacroDefinition(_)
| ConstParamTyRibKind => false,
// Note that we might not be inside of an repeat expression here,
// but considering that `IsRepeatExpr` is only relevant for
// non-trivial constants this is doesn't matter.
- self.with_constant_rib(IsRepeatExpr::No, true, |this| {
+ self.with_constant_rib(IsRepeatExpr::No, true, None, |this| {
this.smart_resolve_path(
ty.id,
qself.as_ref(),
| ClosureOrAsyncRibKind
| FnItemRibKind
| ItemRibKind(..)
- | ConstantItemRibKind(_)
+ | ConstantItemRibKind(..)
| ModuleRibKind(..)
| ForwardTyParamBanRibKind
| ConstParamTyRibKind => {
this.with_constant_rib(
IsRepeatExpr::No,
true,
+ None,
|this| this.visit_expr(expr),
);
}
self.with_item_rib(HasGenericParams::No, |this| {
this.visit_ty(ty);
if let Some(expr) = expr {
+ let constant_item_kind = match item.kind {
+ ItemKind::Const(..) => ConstantItemKind::Const,
+ ItemKind::Static(..) => ConstantItemKind::Static,
+ _ => unreachable!(),
+ };
// We already forbid generic params because of the above item rib,
// so it doesn't matter whether this is a trivial constant.
- this.with_constant_rib(IsRepeatExpr::No, true, |this| {
- this.visit_expr(expr)
- });
+ this.with_constant_rib(
+ IsRepeatExpr::No,
+ true,
+ Some((item.ident, constant_item_kind)),
+ |this| this.visit_expr(expr),
+ );
}
});
}
&mut self,
is_repeat: IsRepeatExpr,
is_trivial: bool,
+ item: Option<(Ident, ConstantItemKind)>,
f: impl FnOnce(&mut Self),
) {
debug!("with_constant_rib: is_repeat={:?} is_trivial={}", is_repeat, is_trivial);
- self.with_rib(ValueNS, ConstantItemRibKind(is_trivial), |this| {
+ self.with_rib(ValueNS, ConstantItemRibKind(is_trivial, item), |this| {
this.with_rib(
TypeNS,
- ConstantItemRibKind(is_repeat == IsRepeatExpr::Yes || is_trivial),
+ ConstantItemRibKind(is_repeat == IsRepeatExpr::Yes || is_trivial, item),
|this| {
- this.with_label_rib(ConstantItemRibKind(is_trivial), f);
+ this.with_label_rib(ConstantItemRibKind(is_trivial, item), f);
},
)
});
this.with_constant_rib(
IsRepeatExpr::No,
true,
+ None,
|this| {
visit::walk_assoc_item(
this,
self.with_constant_rib(
is_repeat,
constant.value.is_potential_trivial_const_param(),
+ None,
|this| {
visit::walk_anon_const(this, constant);
},