Skip to content

Commit 9d8f833

Browse files
committed
Remove hir::CrateItem.
1 parent 16156fb commit 9d8f833

File tree

15 files changed

+26
-40
lines changed

15 files changed

+26
-40
lines changed

compiler/rustc_ast_lowering/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -569,7 +569,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
569569
}
570570

571571
hir::Crate {
572-
item: hir::CrateItem { module, span: c.span },
572+
item: module,
573573
exported_macros: self.arena.alloc_from_iter(self.exported_macros),
574574
non_exported_macro_attrs: self.arena.alloc_from_iter(self.non_exported_macro_attrs),
575575
items: self.items,

compiler/rustc_hir/src/hir.rs

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -625,13 +625,6 @@ pub struct ModuleItems {
625625
pub foreign_items: BTreeSet<ForeignItemId>,
626626
}
627627

628-
/// A type representing only the top-level module.
629-
#[derive(Encodable, Debug, HashStable_Generic)]
630-
pub struct CrateItem<'hir> {
631-
pub module: Mod<'hir>,
632-
pub span: Span,
633-
}
634-
635628
/// The top-level data structure that stores the entire contents of
636629
/// the crate currently being compiled.
637630
///
@@ -640,7 +633,7 @@ pub struct CrateItem<'hir> {
640633
/// [rustc dev guide]: https://rustc-dev-guide.rust-lang.org/hir.html
641634
#[derive(Debug)]
642635
pub struct Crate<'hir> {
643-
pub item: CrateItem<'hir>,
636+
pub item: Mod<'hir>,
644637
pub exported_macros: &'hir [MacroDef<'hir>],
645638
// Attributes from non-exported macros, kept only for collecting the library feature list.
646639
pub non_exported_macro_attrs: &'hir [Attribute],
@@ -2983,7 +2976,7 @@ pub enum Node<'hir> {
29832976
GenericParam(&'hir GenericParam<'hir>),
29842977
Visibility(&'hir Visibility<'hir>),
29852978

2986-
Crate(&'hir CrateItem<'hir>),
2979+
Crate(&'hir Mod<'hir>),
29872980
}
29882981

29892982
impl<'hir> Node<'hir> {

compiler/rustc_hir/src/intravisit.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -478,7 +478,7 @@ pub trait Visitor<'v>: Sized {
478478

479479
/// Walks the contents of a crate. See also `Crate::visit_all_items`.
480480
pub fn walk_crate<'v, V: Visitor<'v>>(visitor: &mut V, krate: &'v Crate<'v>) {
481-
visitor.visit_mod(&krate.item.module, krate.item.span, CRATE_HIR_ID);
481+
visitor.visit_mod(&krate.item, krate.item.inner, CRATE_HIR_ID);
482482
walk_list!(visitor, visit_macro_def, krate.exported_macros);
483483
for (&id, attrs) in krate.attrs.iter() {
484484
for a in *attrs {

compiler/rustc_hir_pretty/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -170,7 +170,7 @@ pub fn print_crate<'a>(
170170
// When printing the AST, we sometimes need to inject `#[no_std]` here.
171171
// Since you can't compile the HIR, it's not necessary.
172172

173-
s.print_mod(&krate.item.module, s.attrs(hir::CRATE_HIR_ID));
173+
s.print_mod(&krate.item, s.attrs(hir::CRATE_HIR_ID));
174174
s.print_remaining_comments();
175175
s.s.eof()
176176
}

compiler/rustc_lint/src/builtin.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -565,7 +565,7 @@ impl<'tcx> LateLintPass<'tcx> for MissingDoc {
565565
}
566566

567567
fn check_crate(&mut self, cx: &LateContext<'_>, krate: &hir::Crate<'_>) {
568-
self.check_missing_docs_attrs(cx, hir::CRATE_HIR_ID, krate.item.span, "the", "crate");
568+
self.check_missing_docs_attrs(cx, hir::CRATE_HIR_ID, krate.item.inner, "the", "crate");
569569

570570
for macro_def in krate.exported_macros {
571571
let attrs = cx.tcx.hir().attrs(macro_def.hir_id());

compiler/rustc_metadata/src/rmeta/encoder.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -427,7 +427,7 @@ impl<'a, 'tcx> EncodeContext<'a, 'tcx> {
427427

428428
fn encode_info_for_items(&mut self) {
429429
let krate = self.tcx.hir().krate();
430-
self.encode_info_for_mod(CRATE_DEF_ID, &krate.item.module);
430+
self.encode_info_for_mod(CRATE_DEF_ID, &krate.item);
431431

432432
// Proc-macro crates only export proc-macro items, which are looked
433433
// up using `proc_macro_data`

compiler/rustc_middle/src/hir/map/mod.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -459,7 +459,7 @@ impl<'hir> Map<'hir> {
459459
let hir_id = self.local_def_id_to_hir_id(module);
460460
match self.get_entry(hir_id).node {
461461
Node::Item(&Item { span, kind: ItemKind::Mod(ref m), .. }) => (m, span, hir_id),
462-
Node::Crate(item) => (&item.module, item.span, hir_id),
462+
Node::Crate(item) => (&item, item.inner, hir_id),
463463
node => panic!("not a module: {:?}", node),
464464
}
465465
}
@@ -868,7 +868,7 @@ impl<'hir> Map<'hir> {
868868
Node::Visibility(v) => bug!("unexpected Visibility {:?}", v),
869869
Node::Local(local) => local.span,
870870
Node::MacroDef(macro_def) => macro_def.span,
871-
Node::Crate(item) => item.span,
871+
Node::Crate(item) => item.inner,
872872
};
873873
Some(span)
874874
}

compiler/rustc_passes/src/entry.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -171,7 +171,7 @@ fn configure_main(
171171
}
172172

173173
fn no_main_err(tcx: TyCtxt<'_>, visitor: &EntryContext<'_, '_>) {
174-
let sp = tcx.hir().krate().item.span;
174+
let sp = tcx.hir().krate().item.inner;
175175
if *tcx.sess.parse_sess.reached_eof.borrow() {
176176
// There's an unclosed brace that made the parser reach `Eof`, we shouldn't complain about
177177
// the missing `fn main()` then as it might have been hidden inside an unclosed block.

compiler/rustc_passes/src/stability.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -686,7 +686,7 @@ fn new_index(tcx: TyCtxt<'tcx>) -> Index<'tcx> {
686686

687687
annotator.annotate(
688688
hir::CRATE_HIR_ID,
689-
krate.item.span,
689+
krate.item.inner,
690690
AnnotationKind::Required,
691691
InheritDeprecation::Yes,
692692
InheritConstStability::No,
@@ -885,7 +885,7 @@ pub fn check_unused_or_stable_features(tcx: TyCtxt<'_>) {
885885
if tcx.stability().staged_api[&LOCAL_CRATE] {
886886
let krate = tcx.hir().krate();
887887
let mut missing = MissingStabilityAnnotations { tcx, access_levels };
888-
missing.check_missing_stability(hir::CRATE_HIR_ID, krate.item.span);
888+
missing.check_missing_stability(hir::CRATE_HIR_ID, krate.item.inner);
889889
intravisit::walk_crate(&mut missing, krate);
890890
krate.visit_all_item_likes(&mut missing.as_deep_visitor());
891891
}

compiler/rustc_save_analysis/src/dump_visitor.rs

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,7 @@ impl<'tcx> DumpVisitor<'tcx> {
151151
},
152152
crate_root: crate_root.unwrap_or_else(|| "<no source>".to_owned()),
153153
external_crates: self.save_ctxt.get_external_crates(),
154-
span: self.span_from_span(krate.item.span),
154+
span: self.span_from_span(krate.item.inner),
155155
};
156156

157157
self.dumper.crate_prelude(data);
@@ -1097,16 +1097,11 @@ impl<'tcx> DumpVisitor<'tcx> {
10971097
format!("::{}", self.tcx.def_path_str(self.tcx.hir().local_def_id(id).to_def_id()));
10981098

10991099
let sm = self.tcx.sess.source_map();
1100-
let filename = sm.span_to_filename(krate.item.span);
1100+
let filename = sm.span_to_filename(krate.item.inner);
11011101
let data_id = id_from_hir_id(id, &self.save_ctxt);
1102-
let children = krate
1103-
.item
1104-
.module
1105-
.item_ids
1106-
.iter()
1107-
.map(|i| id_from_def_id(i.def_id.to_def_id()))
1108-
.collect();
1109-
let span = self.span_from_span(krate.item.span);
1102+
let children =
1103+
krate.item.item_ids.iter().map(|i| id_from_def_id(i.def_id.to_def_id())).collect();
1104+
let span = self.span_from_span(krate.item.inner);
11101105
let attrs = self.tcx.hir().attrs(id);
11111106

11121107
self.dumper.dump_def(

0 commit comments

Comments
 (0)