1
Fork 0

Use ConstArg for const param defaults

Now everything that actually affects the type system (i.e., excluding
const blocks, enum variant discriminants, etc.) *should* be using
`ConstArg`.
This commit is contained in:
Noah Lev 2024-06-07 20:26:50 -07:00
parent 67fccb7045
commit 1c49d406b6
12 changed files with 34 additions and 26 deletions

View file

@ -181,7 +181,7 @@ impl<'a, 'hir> Visitor<'hir> for NodeCollector<'a, 'hir> {
intravisit::walk_generic_param(self, param);
}
fn visit_const_param_default(&mut self, param: HirId, ct: &'hir AnonConst) {
fn visit_const_param_default(&mut self, param: HirId, ct: &'hir ConstArg<'hir>) {
self.with_parent(param, |this| {
intravisit::walk_const_param_default(this, ct);
})

View file

@ -1601,7 +1601,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
if let Some((span, hir_id, def_id)) = host_param_parts {
let const_node_id = self.next_node_id();
let anon_const =
let anon_const_did =
self.create_def(def_id, const_node_id, kw::Empty, DefKind::AnonConst, span);
let const_id = self.next_id();
@ -1609,7 +1609,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
let bool_id = self.next_id();
self.children.push((def_id, hir::MaybeOwner::NonOwner(hir_id)));
self.children.push((anon_const, hir::MaybeOwner::NonOwner(const_id)));
self.children.push((anon_const_did, hir::MaybeOwner::NonOwner(const_id)));
let const_body = self.lower_body(|this| {
(
@ -1624,6 +1624,16 @@ impl<'hir> LoweringContext<'_, 'hir> {
)
});
let default_ac = self.arena.alloc(hir::AnonConst {
def_id: anon_const_did,
hir_id: const_id,
body: const_body,
span,
});
let default_ct = self.arena.alloc(hir::ConstArg {
kind: hir::ConstArgKind::Anon(default_ac),
is_desugared_from_effects: true,
});
let param = hir::GenericParam {
def_id,
hir_id,
@ -1647,13 +1657,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
}),
)),
)),
// FIXME(effects) we might not need a default.
default: Some(self.arena.alloc(hir::AnonConst {
def_id: anon_const,
hir_id: const_id,
body: const_body,
span,
})),
default: Some(default_ct),
is_host_effect: true,
synthetic: true,
},

View file

@ -2204,7 +2204,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
false
}
})
.map(|def| self.lower_anon_const_to_anon_const(def));
.map(|def| self.lower_anon_const_to_const_arg(def));
(
hir::ParamName::Plain(self.lower_ident(param.ident)),