Create const block DefIds in typeck instead of ast lowering
This commit is contained in:
parent
e5cba17b84
commit
ddc5f9b6c1
39 changed files with 162 additions and 189 deletions
|
@ -321,7 +321,7 @@ impl<'hir> Map<'hir> {
|
|||
|
||||
/// Returns an iterator of the `DefId`s for all body-owners in this
|
||||
/// crate. If you would prefer to iterate over the bodies
|
||||
/// themselves, you can do `self.hir().krate().body_ids.iter()`.
|
||||
/// themselves, you can do `self.hir().krate().owners.iter()`.
|
||||
#[inline]
|
||||
pub fn body_owners(self) -> impl Iterator<Item = LocalDefId> + 'hir {
|
||||
self.tcx.hir_crate_items(()).body_owners.iter().copied()
|
||||
|
@ -508,7 +508,17 @@ impl<'hir> Map<'hir> {
|
|||
/// Whether the expression pointed at by `hir_id` belongs to a `const` evaluation context.
|
||||
/// Used exclusively for diagnostics, to avoid suggestion function calls.
|
||||
pub fn is_inside_const_context(self, hir_id: HirId) -> bool {
|
||||
self.body_const_context(self.enclosing_body_owner(hir_id)).is_some()
|
||||
for (_, node) in self.parent_iter(hir_id) {
|
||||
if let Some((def_id, _)) = node.associated_body() {
|
||||
return self.body_const_context(def_id).is_some();
|
||||
}
|
||||
if let Node::Expr(e) = node {
|
||||
if let ExprKind::ConstBlock(_) = e.kind {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
false
|
||||
}
|
||||
|
||||
/// Retrieves the `HirId` for `id`'s enclosing function *if* the `id` block or return is
|
||||
|
@ -891,7 +901,6 @@ impl<'hir> Map<'hir> {
|
|||
Node::Variant(variant) => variant.span,
|
||||
Node::Field(field) => field.span,
|
||||
Node::AnonConst(constant) => constant.span,
|
||||
Node::ConstBlock(constant) => self.body(constant.body).value.span,
|
||||
Node::Expr(expr) => expr.span,
|
||||
Node::ExprField(field) => field.span,
|
||||
Node::Stmt(stmt) => stmt.span,
|
||||
|
@ -1161,7 +1170,6 @@ fn hir_id_to_string(map: Map<'_>, id: HirId) -> String {
|
|||
format!("{id} (field `{}` in {})", field.ident, path_str(field.def_id))
|
||||
}
|
||||
Node::AnonConst(_) => node_str("const"),
|
||||
Node::ConstBlock(_) => node_str("const"),
|
||||
Node::Expr(_) => node_str("expr"),
|
||||
Node::ExprField(_) => node_str("expr field"),
|
||||
Node::Stmt(_) => node_str("stmt"),
|
||||
|
@ -1311,11 +1319,6 @@ impl<'hir> Visitor<'hir> for ItemCollector<'hir> {
|
|||
intravisit::walk_anon_const(self, c)
|
||||
}
|
||||
|
||||
fn visit_inline_const(&mut self, c: &'hir ConstBlock) {
|
||||
self.body_owners.push(c.def_id);
|
||||
intravisit::walk_inline_const(self, c)
|
||||
}
|
||||
|
||||
fn visit_expr(&mut self, ex: &'hir Expr<'hir>) {
|
||||
if let ExprKind::Closure(closure) = ex.kind {
|
||||
self.body_owners.push(closure.def_id);
|
||||
|
|
|
@ -217,6 +217,10 @@ pub struct TypeckResults<'tcx> {
|
|||
|
||||
/// Container types and field indices of `offset_of!` expressions
|
||||
offset_of_data: ItemLocalMap<(Ty<'tcx>, Vec<(VariantIdx, FieldIdx)>)>,
|
||||
|
||||
/// Maps from `HirId`s of const blocks (the `ExprKind::ConstBlock`, not the inner expression's)
|
||||
/// to the `DefId` of the corresponding inline const.
|
||||
pub inline_consts: FxIndexMap<ItemLocalId, LocalDefId>,
|
||||
}
|
||||
|
||||
impl<'tcx> TypeckResults<'tcx> {
|
||||
|
@ -249,6 +253,7 @@ impl<'tcx> TypeckResults<'tcx> {
|
|||
treat_byte_string_as_slice: Default::default(),
|
||||
closure_size_eval: Default::default(),
|
||||
offset_of_data: Default::default(),
|
||||
inline_consts: Default::default(),
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue