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,
// Allow all following defaults to refer to this type parameter.
default_ban_rib.bindings.remove(&Ident::with_dummy_span(param.ident.name));
}
- GenericParamKind::Const { ref ty, kw_span: _ } => {
+ GenericParamKind::Const { ref ty, kw_span: _, default: _ } => {
+ // FIXME(const_generics_defaults): handle `default` value here
for bound in ¶m.bounds {
self.visit_param_bound(bound);
}
// 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,
if this.should_report_errs() {
let (err, candidates) = this.smart_resolve_report_errors(path, span, source, res);
- let def_id = this.parent_scope.module.normal_ancestor_id;
+ let def_id = this.parent_scope.module.nearest_parent_mod;
let instead = res.is_some();
let suggestion =
if res.is_none() { this.report_missing_type_error(path) } else { None };
drop(parent_err);
- let def_id = this.parent_scope.module.normal_ancestor_id;
+ let def_id = this.parent_scope.module.nearest_parent_mod;
if this.should_report_errs() {
this.r.use_injections.push(UseError {
self.with_constant_rib(
is_repeat,
constant.value.is_potential_trivial_const_param(),
+ None,
|this| {
visit::walk_anon_const(this, constant);
},