Skip to content

Commit

Permalink
Remove span from hir::Item.
Browse files Browse the repository at this point in the history
  • Loading branch information
cjgillot committed Jun 23, 2020
1 parent 066195c commit edbbd56
Show file tree
Hide file tree
Showing 64 changed files with 414 additions and 380 deletions.
30 changes: 3 additions & 27 deletions src/librustc_ast_lowering/item.rs
Original file line number Diff line number Diff line change
Expand Up @@ -223,14 +223,7 @@ impl<'hir> LoweringContext<'_, 'hir> {

let kind = self.lower_item_kind(i.span, i.id, &mut ident, attrs, &mut vis, &i.kind);

Some(hir::Item {
hir_id: self.lower_node_id(i.id, i.span),
ident,
attrs,
kind,
vis,
span: i.span,
})
Some(hir::Item { hir_id: self.lower_node_id(i.id, i.span), ident, attrs, kind, vis })
}

fn lower_item_kind(
Expand Down Expand Up @@ -511,14 +504,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
let kind = hir::ItemKind::Use(path, hir::UseKind::Single);
let vis = this.rebuild_vis(&vis);

this.insert_item(hir::Item {
hir_id: new_id,
ident,
attrs,
kind,
vis,
span,
});
this.insert_item(hir::Item { hir_id: new_id, ident, attrs, kind, vis });
});
}

Expand Down Expand Up @@ -580,14 +566,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
let kind =
this.lower_use_tree(use_tree, &prefix, id, &mut vis, &mut ident, attrs);

this.insert_item(hir::Item {
hir_id: new_hir_id,
ident,
attrs,
kind,
vis,
span: use_tree.span,
});
this.insert_item(hir::Item { hir_id: new_hir_id, ident, attrs, kind, vis });
});
}

Expand Down Expand Up @@ -683,7 +662,6 @@ impl<'hir> LoweringContext<'_, 'hir> {
ForeignItemKind::MacCall(_) => panic!("macro shouldn't exist here"),
},
vis: self.lower_visibility(&i.vis, None),
span: i.span,
}
}

Expand Down Expand Up @@ -790,7 +768,6 @@ impl<'hir> LoweringContext<'_, 'hir> {
attrs: self.lower_attrs(&i.attrs),
generics,
kind,
span: i.span,
}
}

Expand Down Expand Up @@ -876,7 +853,6 @@ impl<'hir> LoweringContext<'_, 'hir> {
vis: self.lower_visibility(&i.vis, None),
defaultness,
kind,
span: i.span,
}
}

Expand Down
3 changes: 1 addition & 2 deletions src/librustc_ast_lowering/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -575,7 +575,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
self.spans.push_owner(Idx::new(self.resolver.definitions().def_index_count() - 1));

hir::Crate {
item: hir::CrateItem { module, attrs, span: c.span },
item: hir::CrateItem { module, attrs },
exported_macros: self.arena.alloc_from_iter(self.exported_macros),
non_exported_macro_attrs: self.arena.alloc_from_iter(self.non_exported_macro_attrs),
items: self.items,
Expand Down Expand Up @@ -1507,7 +1507,6 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
attrs: Default::default(),
kind: opaque_ty_item_kind,
vis: respan(span.shrink_to_lo(), hir::VisibilityKind::Inherited),
span: opaque_ty_span,
};

// Insert the item into the global item list. This usually happens
Expand Down
8 changes: 6 additions & 2 deletions src/librustc_codegen_llvm/consts.rs
Original file line number Diff line number Diff line change
Expand Up @@ -214,10 +214,13 @@ impl CodegenCx<'ll, 'tcx> {
let llty = self.layout_of(ty).llvm_type(self);
// FIXME: refactor this to work without accessing the HIR
let (g, attrs) = match self.tcx.hir().get(id) {
Node::Item(&hir::Item { attrs, span, kind: hir::ItemKind::Static(..), .. }) => {
Node::Item(&hir::Item {
attrs, hir_id, kind: hir::ItemKind::Static(..), ..
}) => {
let sym_str = sym.as_str();
if let Some(g) = self.get_declared_value(&sym_str) {
if self.val_ty(g) != self.type_ptr_to(llty) {
let span = self.tcx.hir().span(hir_id);
span_bug!(span, "Conflicting types for static");
}
}
Expand All @@ -235,11 +238,12 @@ impl CodegenCx<'ll, 'tcx> {

Node::ForeignItem(&hir::ForeignItem {
ref attrs,
span,
hir_id,
kind: hir::ForeignItemKind::Static(..),
..
}) => {
let fn_attrs = self.tcx.codegen_fn_attrs(def_id);
let span = self.tcx.hir().span(hir_id);
(check_and_apply_linkage(&self, &fn_attrs, ty, sym, span), &**attrs)
}

Expand Down
3 changes: 2 additions & 1 deletion src/librustc_codegen_ssa/mono_item.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,8 @@ impl<'a, 'tcx: 'a> MonoItemExt<'a, 'tcx> for MonoItem<'tcx> {
if let hir::ItemKind::GlobalAsm(ref ga) = item.kind {
cx.codegen_global_asm(ga);
} else {
span_bug!(item.span, "Mismatch between hir::Item type and MonoItem type")
let span = cx.tcx().hir().span(hir_id);
span_bug!(span, "Mismatch between hir::Item type and MonoItem type")
}
}
MonoItem::Fn(instance) => {
Expand Down
5 changes: 0 additions & 5 deletions src/librustc_hir/hir.rs
Original file line number Diff line number Diff line change
Expand Up @@ -581,7 +581,6 @@ pub struct ModuleItems {
pub struct CrateItem<'hir> {
pub module: Mod<'hir>,
pub attrs: &'hir [Attribute],
pub span: Span,
}

/// The top-level data structure that stores the entire contents of
Expand Down Expand Up @@ -1846,7 +1845,6 @@ pub struct TraitItem<'hir> {
pub attrs: &'hir [Attribute],
pub generics: Generics<'hir>,
pub kind: TraitItemKind<'hir>,
pub span: Span,
}

/// Represents a trait method's body (or just argument names).
Expand Down Expand Up @@ -1889,7 +1887,6 @@ pub struct ImplItem<'hir> {
pub attrs: &'hir [Attribute],
pub generics: Generics<'hir>,
pub kind: ImplItemKind<'hir>,
pub span: Span,
}

/// Represents various kinds of content within an `impl`.
Expand Down Expand Up @@ -2424,7 +2421,6 @@ pub struct Item<'hir> {
pub attrs: &'hir [Attribute],
pub kind: ItemKind<'hir>,
pub vis: Visibility<'hir>,
pub span: Span,
}

#[derive(Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Hash, Debug)]
Expand Down Expand Up @@ -2597,7 +2593,6 @@ pub struct ForeignItem<'hir> {
pub attrs: &'hir [Attribute],
pub kind: ForeignItemKind<'hir>,
pub hir_id: HirId,
pub span: Span,
pub vis: Visibility<'hir>,
}

Expand Down
12 changes: 2 additions & 10 deletions src/librustc_hir/intravisit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -941,16 +941,8 @@ pub fn walk_trait_item_ref<'v, V: Visitor<'v>>(visitor: &mut V, trait_item_ref:

pub fn walk_impl_item<'v, V: Visitor<'v>>(visitor: &mut V, impl_item: &'v ImplItem<'v>) {
// N.B., deliberately force a compilation error if/when new fields are added.
let ImplItem {
hir_id: _,
ident,
ref vis,
ref defaultness,
attrs,
ref generics,
ref kind,
span: _,
} = *impl_item;
let ImplItem { hir_id: _, ident, ref vis, ref defaultness, attrs, ref generics, ref kind } =
*impl_item;

visitor.visit_ident(ident);
visitor.visit_vis(vis);
Expand Down
19 changes: 4 additions & 15 deletions src/librustc_hir/stable_hash_impls.rs
Original file line number Diff line number Diff line change
Expand Up @@ -115,30 +115,21 @@ impl<HirCtx: crate::HashStableContext> HashStable<HirCtx> for VisibilityKind<'_>

impl<HirCtx: crate::HashStableContext> HashStable<HirCtx> for TraitItem<'_> {
fn hash_stable(&self, hcx: &mut HirCtx, hasher: &mut StableHasher) {
let TraitItem { hir_id: _, ident, ref attrs, ref generics, ref kind, span } = *self;
let TraitItem { hir_id: _, ident, ref attrs, ref generics, ref kind } = *self;

hcx.hash_hir_item_like(|hcx| {
ident.name.hash_stable(hcx, hasher);
attrs.hash_stable(hcx, hasher);
generics.hash_stable(hcx, hasher);
kind.hash_stable(hcx, hasher);
span.hash_stable(hcx, hasher);
});
}
}

impl<HirCtx: crate::HashStableContext> HashStable<HirCtx> for ImplItem<'_> {
fn hash_stable(&self, hcx: &mut HirCtx, hasher: &mut StableHasher) {
let ImplItem {
hir_id: _,
ident,
ref vis,
defaultness,
ref attrs,
ref generics,
ref kind,
span,
} = *self;
let ImplItem { hir_id: _, ident, ref vis, defaultness, ref attrs, ref generics, ref kind } =
*self;

hcx.hash_hir_item_like(|hcx| {
ident.name.hash_stable(hcx, hasher);
Expand All @@ -147,21 +138,19 @@ impl<HirCtx: crate::HashStableContext> HashStable<HirCtx> for ImplItem<'_> {
attrs.hash_stable(hcx, hasher);
generics.hash_stable(hcx, hasher);
kind.hash_stable(hcx, hasher);
span.hash_stable(hcx, hasher);
});
}
}

impl<HirCtx: crate::HashStableContext> HashStable<HirCtx> for Item<'_> {
fn hash_stable(&self, hcx: &mut HirCtx, hasher: &mut StableHasher) {
let Item { ident, ref attrs, hir_id: _, ref kind, ref vis, span } = *self;
let Item { ident, ref attrs, hir_id: _, ref kind, ref vis } = *self;

hcx.hash_hir_item_like(|hcx| {
ident.name.hash_stable(hcx, hasher);
attrs.hash_stable(hcx, hasher);
kind.hash_stable(hcx, hasher);
vis.hash_stable(hcx, hasher);
span.hash_stable(hcx, hasher);
});
}
}
26 changes: 15 additions & 11 deletions src/librustc_hir_pretty/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -466,8 +466,9 @@ impl<'a> State<'a> {
}

pub fn print_foreign_item(&mut self, item: &hir::ForeignItem<'_>) {
let item_span = self.span(item.hir_id);
self.hardbreak_if_not_bol();
self.maybe_print_comment(item.span.lo());
self.maybe_print_comment(item_span.lo());
self.print_outer_attributes(&item.attrs);
match item.kind {
hir::ForeignItemKind::Fn(ref decl, ref arg_names, ref generics) => {
Expand Down Expand Up @@ -574,8 +575,9 @@ impl<'a> State<'a> {

/// Pretty-print an item
pub fn print_item(&mut self, item: &hir::Item<'_>) {
let span = self.span(item.hir_id);
self.hardbreak_if_not_bol();
self.maybe_print_comment(item.span.lo());
self.maybe_print_comment(span.lo());
self.print_outer_attributes(&item.attrs);
self.ann.pre(self, AnnNode::Item(item));
match item.kind {
Expand Down Expand Up @@ -662,14 +664,14 @@ impl<'a> State<'a> {
self.nbsp();
self.bopen();
self.print_mod(_mod, &item.attrs);
self.bclose(item.span);
self.bclose(span);
}
hir::ItemKind::ForeignMod(ref nmod) => {
self.head("extern");
self.word_nbsp(nmod.abi.to_string());
self.bopen();
self.print_foreign_mod(nmod, &item.attrs);
self.bclose(item.span);
self.bclose(span);
}
hir::ItemKind::GlobalAsm(ref ga) => {
self.head(visibility_qualified(&item.vis, "global asm"));
Expand Down Expand Up @@ -698,15 +700,15 @@ impl<'a> State<'a> {
});
}
hir::ItemKind::Enum(ref enum_definition, ref params) => {
self.print_enum_def(enum_definition, params, item.ident.name, item.span, &item.vis);
self.print_enum_def(enum_definition, params, item.ident.name, span, &item.vis);
}
hir::ItemKind::Struct(ref struct_def, ref generics) => {
self.head(visibility_qualified(&item.vis, "struct"));
self.print_struct(struct_def, generics, item.ident.name, item.span, true);
self.print_struct(struct_def, generics, item.ident.name, span, true);
}
hir::ItemKind::Union(ref struct_def, ref generics) => {
self.head(visibility_qualified(&item.vis, "union"));
self.print_struct(struct_def, generics, item.ident.name, item.span, true);
self.print_struct(struct_def, generics, item.ident.name, span, true);
}
hir::ItemKind::Impl {
unsafety,
Expand Down Expand Up @@ -753,7 +755,7 @@ impl<'a> State<'a> {
for impl_item in items {
self.ann.nested(self, Nested::ImplItem(impl_item.id));
}
self.bclose(item.span);
self.bclose(span);
}
hir::ItemKind::Trait(is_auto, unsafety, ref generics, ref bounds, trait_items) => {
self.head("");
Expand All @@ -780,7 +782,7 @@ impl<'a> State<'a> {
for trait_item in trait_items {
self.ann.nested(self, Nested::TraitItem(trait_item.id));
}
self.bclose(item.span);
self.bclose(span);
}
hir::ItemKind::TraitAlias(ref generics, ref bounds) => {
self.head("");
Expand Down Expand Up @@ -961,9 +963,10 @@ impl<'a> State<'a> {
}

pub fn print_trait_item(&mut self, ti: &hir::TraitItem<'_>) {
let span = self.span(ti.hir_id);
self.ann.pre(self, AnnNode::SubItem(ti.hir_id));
self.hardbreak_if_not_bol();
self.maybe_print_comment(ti.span.lo());
self.maybe_print_comment(span.lo());
self.print_outer_attributes(&ti.attrs);
match ti.kind {
hir::TraitItemKind::Const(ref ty, default) => {
Expand Down Expand Up @@ -1000,9 +1003,10 @@ impl<'a> State<'a> {
}

pub fn print_impl_item(&mut self, ii: &hir::ImplItem<'_>) {
let span = self.span(ii.hir_id);
self.ann.pre(self, AnnNode::SubItem(ii.hir_id));
self.hardbreak_if_not_bol();
self.maybe_print_comment(ii.span.lo());
self.maybe_print_comment(span.lo());
self.print_outer_attributes(&ii.attrs);
self.print_defaultness(ii.defaultness);

Expand Down
9 changes: 5 additions & 4 deletions src/librustc_incremental/persist/dirty_clean.rs
Original file line number Diff line number Diff line change
Expand Up @@ -431,8 +431,9 @@ impl DirtyCleanVisitor<'tcx> {
}
}

fn check_item(&mut self, item_id: hir::HirId, item_span: Span) {
fn check_item(&mut self, item_id: hir::HirId) {
let def_id = self.tcx.hir().local_def_id(item_id);
let item_span = self.tcx.hir().span(item_id);
for attr in self.tcx.get_attrs(def_id.to_def_id()).iter() {
let assertion = match self.assertion_maybe(item_id, attr) {
Some(a) => a,
Expand All @@ -451,15 +452,15 @@ impl DirtyCleanVisitor<'tcx> {

impl ItemLikeVisitor<'tcx> for DirtyCleanVisitor<'tcx> {
fn visit_item(&mut self, item: &'tcx hir::Item<'tcx>) {
self.check_item(item.hir_id, item.span);
self.check_item(item.hir_id);
}

fn visit_trait_item(&mut self, item: &hir::TraitItem<'_>) {
self.check_item(item.hir_id, item.span);
self.check_item(item.hir_id);
}

fn visit_impl_item(&mut self, item: &hir::ImplItem<'_>) {
self.check_item(item.hir_id, item.span);
self.check_item(item.hir_id);
}
}

Expand Down
Loading

0 comments on commit edbbd56

Please sign in to comment.