Auto merge of #83684 - cjgillot:csp, r=petrochenkov

Remove hir::CrateItem.

The crate span is exactly the crate module's inner span. There is no need to store it twice.
This commit is contained in:
bors 2021-03-31 08:34:40 +00:00
commit a5029ac0ab
17 changed files with 28 additions and 42 deletions

View file

@ -569,7 +569,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
}
hir::Crate {
item: hir::CrateItem { module, span: c.span },
item: module,
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,

View file

@ -625,13 +625,6 @@ pub struct ModuleItems {
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 crate currently being compiled.
///
@ -640,7 +633,7 @@ pub struct CrateItem<'hir> {
/// [rustc dev guide]: https://rustc-dev-guide.rust-lang.org/hir.html
#[derive(Debug)]
pub struct Crate<'hir> {
pub item: CrateItem<'hir>,
pub item: Mod<'hir>,
pub exported_macros: &'hir [MacroDef<'hir>],
// Attributes from non-exported macros, kept only for collecting the library feature list.
pub non_exported_macro_attrs: &'hir [Attribute],
@ -2983,7 +2976,7 @@ pub enum Node<'hir> {
GenericParam(&'hir GenericParam<'hir>),
Visibility(&'hir Visibility<'hir>),
Crate(&'hir CrateItem<'hir>),
Crate(&'hir Mod<'hir>),
}
impl<'hir> Node<'hir> {

View file

@ -478,7 +478,7 @@ pub trait Visitor<'v>: Sized {
/// 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>) {
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);
for (&id, attrs) in krate.attrs.iter() {
for a in *attrs {

View file

@ -170,7 +170,7 @@ pub fn print_crate<'a>(
// When printing the AST, we sometimes need to inject `#[no_std]` here.
// 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.s.eof()
}

View file

@ -565,7 +565,7 @@ impl<'tcx> LateLintPass<'tcx> for MissingDoc {
}
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 {
let attrs = cx.tcx.hir().attrs(macro_def.hir_id());

View file

@ -427,7 +427,7 @@ impl<'a, 'tcx> EncodeContext<'a, 'tcx> {
fn encode_info_for_items(&mut self) {
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
// up using `proc_macro_data`

View file

@ -459,7 +459,7 @@ impl<'hir> Map<'hir> {
let hir_id = self.local_def_id_to_hir_id(module);
match self.get_entry(hir_id).node {
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),
}
}
@ -868,7 +868,7 @@ impl<'hir> Map<'hir> {
Node::Visibility(v) => bug!("unexpected Visibility {:?}", v),
Node::Local(local) => local.span,
Node::MacroDef(macro_def) => macro_def.span,
Node::Crate(item) => item.span,
Node::Crate(item) => item.inner,
};
Some(span)
}

View file

@ -171,7 +171,7 @@ fn configure_main(
}
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() {
// 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.

View file

@ -686,7 +686,7 @@ fn new_index(tcx: TyCtxt<'tcx>) -> Index<'tcx> {
annotator.annotate(
hir::CRATE_HIR_ID,
krate.item.span,
krate.item.inner,
AnnotationKind::Required,
InheritDeprecation::Yes,
InheritConstStability::No,
@ -885,7 +885,7 @@ pub fn check_unused_or_stable_features(tcx: TyCtxt<'_>) {
if tcx.stability().staged_api[&LOCAL_CRATE] {
let krate = tcx.hir().krate();
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);
krate.visit_all_item_likes(&mut missing.as_deep_visitor());
}

View file

@ -151,7 +151,7 @@ impl<'tcx> DumpVisitor<'tcx> {
},
crate_root: crate_root.unwrap_or_else(|| "<no source>".to_owned()),
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);
@ -1097,16 +1097,11 @@ impl<'tcx> DumpVisitor<'tcx> {
format!("::{}", self.tcx.def_path_str(self.tcx.hir().local_def_id(id).to_def_id()));
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 children = krate
.item
.module
.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 children =
krate.item.item_ids.iter().map(|i| id_from_def_id(i.def_id.to_def_id())).collect();
let span = self.span_from_span(krate.item.inner);
let attrs = self.tcx.hir().attrs(id);
self.dumper.dump_def(