Remove hir::CrateItem.
This commit is contained in:
parent
16156fb278
commit
9d8f833e05
15 changed files with 26 additions and 40 deletions
|
@ -569,7 +569,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
|
||||||
}
|
}
|
||||||
|
|
||||||
hir::Crate {
|
hir::Crate {
|
||||||
item: hir::CrateItem { module, span: c.span },
|
item: module,
|
||||||
exported_macros: self.arena.alloc_from_iter(self.exported_macros),
|
exported_macros: self.arena.alloc_from_iter(self.exported_macros),
|
||||||
non_exported_macro_attrs: self.arena.alloc_from_iter(self.non_exported_macro_attrs),
|
non_exported_macro_attrs: self.arena.alloc_from_iter(self.non_exported_macro_attrs),
|
||||||
items: self.items,
|
items: self.items,
|
||||||
|
|
|
@ -625,13 +625,6 @@ pub struct ModuleItems {
|
||||||
pub foreign_items: BTreeSet<ForeignItemId>,
|
pub foreign_items: BTreeSet<ForeignItemId>,
|
||||||
}
|
}
|
||||||
|
|
||||||
/// A type representing only the top-level module.
|
|
||||||
#[derive(Encodable, Debug, HashStable_Generic)]
|
|
||||||
pub struct CrateItem<'hir> {
|
|
||||||
pub module: Mod<'hir>,
|
|
||||||
pub span: Span,
|
|
||||||
}
|
|
||||||
|
|
||||||
/// The top-level data structure that stores the entire contents of
|
/// The top-level data structure that stores the entire contents of
|
||||||
/// the crate currently being compiled.
|
/// the crate currently being compiled.
|
||||||
///
|
///
|
||||||
|
@ -640,7 +633,7 @@ pub struct CrateItem<'hir> {
|
||||||
/// [rustc dev guide]: https://rustc-dev-guide.rust-lang.org/hir.html
|
/// [rustc dev guide]: https://rustc-dev-guide.rust-lang.org/hir.html
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
pub struct Crate<'hir> {
|
pub struct Crate<'hir> {
|
||||||
pub item: CrateItem<'hir>,
|
pub item: Mod<'hir>,
|
||||||
pub exported_macros: &'hir [MacroDef<'hir>],
|
pub exported_macros: &'hir [MacroDef<'hir>],
|
||||||
// Attributes from non-exported macros, kept only for collecting the library feature list.
|
// Attributes from non-exported macros, kept only for collecting the library feature list.
|
||||||
pub non_exported_macro_attrs: &'hir [Attribute],
|
pub non_exported_macro_attrs: &'hir [Attribute],
|
||||||
|
@ -2983,7 +2976,7 @@ pub enum Node<'hir> {
|
||||||
GenericParam(&'hir GenericParam<'hir>),
|
GenericParam(&'hir GenericParam<'hir>),
|
||||||
Visibility(&'hir Visibility<'hir>),
|
Visibility(&'hir Visibility<'hir>),
|
||||||
|
|
||||||
Crate(&'hir CrateItem<'hir>),
|
Crate(&'hir Mod<'hir>),
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'hir> Node<'hir> {
|
impl<'hir> Node<'hir> {
|
||||||
|
|
|
@ -478,7 +478,7 @@ pub trait Visitor<'v>: Sized {
|
||||||
|
|
||||||
/// Walks the contents of a crate. See also `Crate::visit_all_items`.
|
/// Walks the contents of a crate. See also `Crate::visit_all_items`.
|
||||||
pub fn walk_crate<'v, V: Visitor<'v>>(visitor: &mut V, krate: &'v Crate<'v>) {
|
pub fn walk_crate<'v, V: Visitor<'v>>(visitor: &mut V, krate: &'v Crate<'v>) {
|
||||||
visitor.visit_mod(&krate.item.module, krate.item.span, CRATE_HIR_ID);
|
visitor.visit_mod(&krate.item, krate.item.inner, CRATE_HIR_ID);
|
||||||
walk_list!(visitor, visit_macro_def, krate.exported_macros);
|
walk_list!(visitor, visit_macro_def, krate.exported_macros);
|
||||||
for (&id, attrs) in krate.attrs.iter() {
|
for (&id, attrs) in krate.attrs.iter() {
|
||||||
for a in *attrs {
|
for a in *attrs {
|
||||||
|
|
|
@ -170,7 +170,7 @@ pub fn print_crate<'a>(
|
||||||
// When printing the AST, we sometimes need to inject `#[no_std]` here.
|
// When printing the AST, we sometimes need to inject `#[no_std]` here.
|
||||||
// Since you can't compile the HIR, it's not necessary.
|
// Since you can't compile the HIR, it's not necessary.
|
||||||
|
|
||||||
s.print_mod(&krate.item.module, s.attrs(hir::CRATE_HIR_ID));
|
s.print_mod(&krate.item, s.attrs(hir::CRATE_HIR_ID));
|
||||||
s.print_remaining_comments();
|
s.print_remaining_comments();
|
||||||
s.s.eof()
|
s.s.eof()
|
||||||
}
|
}
|
||||||
|
|
|
@ -565,7 +565,7 @@ impl<'tcx> LateLintPass<'tcx> for MissingDoc {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn check_crate(&mut self, cx: &LateContext<'_>, krate: &hir::Crate<'_>) {
|
fn check_crate(&mut self, cx: &LateContext<'_>, krate: &hir::Crate<'_>) {
|
||||||
self.check_missing_docs_attrs(cx, hir::CRATE_HIR_ID, krate.item.span, "the", "crate");
|
self.check_missing_docs_attrs(cx, hir::CRATE_HIR_ID, krate.item.inner, "the", "crate");
|
||||||
|
|
||||||
for macro_def in krate.exported_macros {
|
for macro_def in krate.exported_macros {
|
||||||
let attrs = cx.tcx.hir().attrs(macro_def.hir_id());
|
let attrs = cx.tcx.hir().attrs(macro_def.hir_id());
|
||||||
|
|
|
@ -427,7 +427,7 @@ impl<'a, 'tcx> EncodeContext<'a, 'tcx> {
|
||||||
|
|
||||||
fn encode_info_for_items(&mut self) {
|
fn encode_info_for_items(&mut self) {
|
||||||
let krate = self.tcx.hir().krate();
|
let krate = self.tcx.hir().krate();
|
||||||
self.encode_info_for_mod(CRATE_DEF_ID, &krate.item.module);
|
self.encode_info_for_mod(CRATE_DEF_ID, &krate.item);
|
||||||
|
|
||||||
// Proc-macro crates only export proc-macro items, which are looked
|
// Proc-macro crates only export proc-macro items, which are looked
|
||||||
// up using `proc_macro_data`
|
// up using `proc_macro_data`
|
||||||
|
|
|
@ -459,7 +459,7 @@ impl<'hir> Map<'hir> {
|
||||||
let hir_id = self.local_def_id_to_hir_id(module);
|
let hir_id = self.local_def_id_to_hir_id(module);
|
||||||
match self.get_entry(hir_id).node {
|
match self.get_entry(hir_id).node {
|
||||||
Node::Item(&Item { span, kind: ItemKind::Mod(ref m), .. }) => (m, span, hir_id),
|
Node::Item(&Item { span, kind: ItemKind::Mod(ref m), .. }) => (m, span, hir_id),
|
||||||
Node::Crate(item) => (&item.module, item.span, hir_id),
|
Node::Crate(item) => (&item, item.inner, hir_id),
|
||||||
node => panic!("not a module: {:?}", node),
|
node => panic!("not a module: {:?}", node),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -868,7 +868,7 @@ impl<'hir> Map<'hir> {
|
||||||
Node::Visibility(v) => bug!("unexpected Visibility {:?}", v),
|
Node::Visibility(v) => bug!("unexpected Visibility {:?}", v),
|
||||||
Node::Local(local) => local.span,
|
Node::Local(local) => local.span,
|
||||||
Node::MacroDef(macro_def) => macro_def.span,
|
Node::MacroDef(macro_def) => macro_def.span,
|
||||||
Node::Crate(item) => item.span,
|
Node::Crate(item) => item.inner,
|
||||||
};
|
};
|
||||||
Some(span)
|
Some(span)
|
||||||
}
|
}
|
||||||
|
|
|
@ -171,7 +171,7 @@ fn configure_main(
|
||||||
}
|
}
|
||||||
|
|
||||||
fn no_main_err(tcx: TyCtxt<'_>, visitor: &EntryContext<'_, '_>) {
|
fn no_main_err(tcx: TyCtxt<'_>, visitor: &EntryContext<'_, '_>) {
|
||||||
let sp = tcx.hir().krate().item.span;
|
let sp = tcx.hir().krate().item.inner;
|
||||||
if *tcx.sess.parse_sess.reached_eof.borrow() {
|
if *tcx.sess.parse_sess.reached_eof.borrow() {
|
||||||
// There's an unclosed brace that made the parser reach `Eof`, we shouldn't complain about
|
// There's an unclosed brace that made the parser reach `Eof`, we shouldn't complain about
|
||||||
// the missing `fn main()` then as it might have been hidden inside an unclosed block.
|
// the missing `fn main()` then as it might have been hidden inside an unclosed block.
|
||||||
|
|
|
@ -686,7 +686,7 @@ fn new_index(tcx: TyCtxt<'tcx>) -> Index<'tcx> {
|
||||||
|
|
||||||
annotator.annotate(
|
annotator.annotate(
|
||||||
hir::CRATE_HIR_ID,
|
hir::CRATE_HIR_ID,
|
||||||
krate.item.span,
|
krate.item.inner,
|
||||||
AnnotationKind::Required,
|
AnnotationKind::Required,
|
||||||
InheritDeprecation::Yes,
|
InheritDeprecation::Yes,
|
||||||
InheritConstStability::No,
|
InheritConstStability::No,
|
||||||
|
@ -885,7 +885,7 @@ pub fn check_unused_or_stable_features(tcx: TyCtxt<'_>) {
|
||||||
if tcx.stability().staged_api[&LOCAL_CRATE] {
|
if tcx.stability().staged_api[&LOCAL_CRATE] {
|
||||||
let krate = tcx.hir().krate();
|
let krate = tcx.hir().krate();
|
||||||
let mut missing = MissingStabilityAnnotations { tcx, access_levels };
|
let mut missing = MissingStabilityAnnotations { tcx, access_levels };
|
||||||
missing.check_missing_stability(hir::CRATE_HIR_ID, krate.item.span);
|
missing.check_missing_stability(hir::CRATE_HIR_ID, krate.item.inner);
|
||||||
intravisit::walk_crate(&mut missing, krate);
|
intravisit::walk_crate(&mut missing, krate);
|
||||||
krate.visit_all_item_likes(&mut missing.as_deep_visitor());
|
krate.visit_all_item_likes(&mut missing.as_deep_visitor());
|
||||||
}
|
}
|
||||||
|
|
|
@ -151,7 +151,7 @@ impl<'tcx> DumpVisitor<'tcx> {
|
||||||
},
|
},
|
||||||
crate_root: crate_root.unwrap_or_else(|| "<no source>".to_owned()),
|
crate_root: crate_root.unwrap_or_else(|| "<no source>".to_owned()),
|
||||||
external_crates: self.save_ctxt.get_external_crates(),
|
external_crates: self.save_ctxt.get_external_crates(),
|
||||||
span: self.span_from_span(krate.item.span),
|
span: self.span_from_span(krate.item.inner),
|
||||||
};
|
};
|
||||||
|
|
||||||
self.dumper.crate_prelude(data);
|
self.dumper.crate_prelude(data);
|
||||||
|
@ -1097,16 +1097,11 @@ impl<'tcx> DumpVisitor<'tcx> {
|
||||||
format!("::{}", self.tcx.def_path_str(self.tcx.hir().local_def_id(id).to_def_id()));
|
format!("::{}", self.tcx.def_path_str(self.tcx.hir().local_def_id(id).to_def_id()));
|
||||||
|
|
||||||
let sm = self.tcx.sess.source_map();
|
let sm = self.tcx.sess.source_map();
|
||||||
let filename = sm.span_to_filename(krate.item.span);
|
let filename = sm.span_to_filename(krate.item.inner);
|
||||||
let data_id = id_from_hir_id(id, &self.save_ctxt);
|
let data_id = id_from_hir_id(id, &self.save_ctxt);
|
||||||
let children = krate
|
let children =
|
||||||
.item
|
krate.item.item_ids.iter().map(|i| id_from_def_id(i.def_id.to_def_id())).collect();
|
||||||
.module
|
let span = self.span_from_span(krate.item.inner);
|
||||||
.item_ids
|
|
||||||
.iter()
|
|
||||||
.map(|i| id_from_def_id(i.def_id.to_def_id()))
|
|
||||||
.collect();
|
|
||||||
let span = self.span_from_span(krate.item.span);
|
|
||||||
let attrs = self.tcx.hir().attrs(id);
|
let attrs = self.tcx.hir().attrs(id);
|
||||||
|
|
||||||
self.dumper.dump_def(
|
self.dumper.dump_def(
|
||||||
|
|
|
@ -129,7 +129,6 @@ impl Clean<ExternalCrate> for CrateNum {
|
||||||
tcx.hir()
|
tcx.hir()
|
||||||
.krate()
|
.krate()
|
||||||
.item
|
.item
|
||||||
.module
|
|
||||||
.item_ids
|
.item_ids
|
||||||
.iter()
|
.iter()
|
||||||
.filter_map(|&id| {
|
.filter_map(|&id| {
|
||||||
|
@ -174,7 +173,6 @@ impl Clean<ExternalCrate> for CrateNum {
|
||||||
tcx.hir()
|
tcx.hir()
|
||||||
.krate()
|
.krate()
|
||||||
.item
|
.item
|
||||||
.module
|
|
||||||
.item_ids
|
.item_ids
|
||||||
.iter()
|
.iter()
|
||||||
.filter_map(|&id| {
|
.filter_map(|&id| {
|
||||||
|
|
|
@ -141,7 +141,7 @@ crate fn run(options: Options) -> Result<(), ErrorReported> {
|
||||||
hir_collector.visit_testable(
|
hir_collector.visit_testable(
|
||||||
"".to_string(),
|
"".to_string(),
|
||||||
CRATE_HIR_ID,
|
CRATE_HIR_ID,
|
||||||
krate.item.span,
|
krate.item.inner,
|
||||||
|this| {
|
|this| {
|
||||||
intravisit::walk_crate(this, krate);
|
intravisit::walk_crate(this, krate);
|
||||||
},
|
},
|
||||||
|
|
|
@ -72,10 +72,10 @@ impl<'a, 'tcx> RustdocVisitor<'a, 'tcx> {
|
||||||
|
|
||||||
crate fn visit(mut self, krate: &'tcx hir::Crate<'_>) -> Module<'tcx> {
|
crate fn visit(mut self, krate: &'tcx hir::Crate<'_>) -> Module<'tcx> {
|
||||||
let mut top_level_module = self.visit_mod_contents(
|
let mut top_level_module = self.visit_mod_contents(
|
||||||
krate.item.span,
|
krate.item.inner,
|
||||||
&Spanned { span: rustc_span::DUMMY_SP, node: hir::VisibilityKind::Public },
|
&Spanned { span: rustc_span::DUMMY_SP, node: hir::VisibilityKind::Public },
|
||||||
hir::CRATE_HIR_ID,
|
hir::CRATE_HIR_ID,
|
||||||
&krate.item.module,
|
&krate.item,
|
||||||
self.cx.tcx.crate_name,
|
self.cx.tcx.crate_name,
|
||||||
);
|
);
|
||||||
top_level_module.is_crate = true;
|
top_level_module.is_crate = true;
|
||||||
|
|
|
@ -128,7 +128,7 @@ impl<'tcx> LateLintPass<'tcx> for MissingDoc {
|
||||||
|
|
||||||
fn check_crate(&mut self, cx: &LateContext<'tcx>, krate: &'tcx hir::Crate<'_>) {
|
fn check_crate(&mut self, cx: &LateContext<'tcx>, krate: &'tcx hir::Crate<'_>) {
|
||||||
let attrs = cx.tcx.hir().attrs(hir::CRATE_HIR_ID);
|
let attrs = cx.tcx.hir().attrs(hir::CRATE_HIR_ID);
|
||||||
self.check_missing_docs_attrs(cx, attrs, krate.item.span, "the", "crate");
|
self.check_missing_docs_attrs(cx, attrs, krate.item.inner, "the", "crate");
|
||||||
}
|
}
|
||||||
|
|
||||||
fn check_item(&mut self, cx: &LateContext<'tcx>, it: &'tcx hir::Item<'_>) {
|
fn check_item(&mut self, cx: &LateContext<'tcx>, it: &'tcx hir::Item<'_>) {
|
||||||
|
|
|
@ -61,10 +61,10 @@ use rustc_hir::def::{CtorKind, CtorOf, DefKind, Res};
|
||||||
use rustc_hir::def_id::{DefId, LOCAL_CRATE};
|
use rustc_hir::def_id::{DefId, LOCAL_CRATE};
|
||||||
use rustc_hir::intravisit::{self, NestedVisitorMap, Visitor};
|
use rustc_hir::intravisit::{self, NestedVisitorMap, Visitor};
|
||||||
use rustc_hir::{
|
use rustc_hir::{
|
||||||
def, Arm, BindingAnnotation, Block, Body, Constness, CrateItem, Expr, ExprKind, FieldDef, FnDecl, ForeignItem,
|
def, Arm, BindingAnnotation, Block, Body, Constness, Expr, ExprKind, FieldDef, FnDecl, ForeignItem, GenericArgs,
|
||||||
GenericArgs, GenericParam, HirId, Impl, ImplItem, ImplItemKind, Item, ItemKind, LangItem, Lifetime, Local,
|
GenericParam, HirId, Impl, ImplItem, ImplItemKind, Item, ItemKind, LangItem, Lifetime, Local, MacroDef,
|
||||||
MacroDef, MatchSource, Node, Param, Pat, PatKind, Path, PathSegment, QPath, Stmt, TraitItem, TraitItemKind,
|
MatchSource, Mod, Node, Param, Pat, PatKind, Path, PathSegment, QPath, Stmt, TraitItem, TraitItemKind, TraitRef,
|
||||||
TraitRef, TyKind, Variant, Visibility,
|
TyKind, Variant, Visibility,
|
||||||
};
|
};
|
||||||
use rustc_lint::{LateContext, Level, Lint, LintContext};
|
use rustc_lint::{LateContext, Level, Lint, LintContext};
|
||||||
use rustc_middle::hir::exports::Export;
|
use rustc_middle::hir::exports::Export;
|
||||||
|
@ -743,7 +743,7 @@ pub fn get_node_span(node: Node<'_>) -> Option<Span> {
|
||||||
| Node::Lifetime(Lifetime { span, .. })
|
| Node::Lifetime(Lifetime { span, .. })
|
||||||
| Node::GenericParam(GenericParam { span, .. })
|
| Node::GenericParam(GenericParam { span, .. })
|
||||||
| Node::Visibility(Visibility { span, .. })
|
| Node::Visibility(Visibility { span, .. })
|
||||||
| Node::Crate(CrateItem { span, .. }) => Some(*span),
|
| Node::Crate(Mod { inner: span, .. }) => Some(*span),
|
||||||
Node::Ctor(_) | Node::AnonConst(_) => None,
|
Node::Ctor(_) | Node::AnonConst(_) => None,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue