Skip to content

Commit

Permalink
Remove Span from hir::CrateItem.
Browse files Browse the repository at this point in the history
  • Loading branch information
cjgillot committed Jan 6, 2021
1 parent 7ec01a6 commit 304bdec
Show file tree
Hide file tree
Showing 8 changed files with 16 additions and 10 deletions.
2 changes: 1 addition & 1 deletion compiler/rustc_ast_lowering/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -599,7 +599,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
1 change: 0 additions & 1 deletion compiler/rustc_hir/src/hir.rs
Original file line number Diff line number Diff line change
Expand Up @@ -580,7 +580,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
9 changes: 8 additions & 1 deletion compiler/rustc_lint/src/builtin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -517,7 +517,14 @@ impl<'tcx> LateLintPass<'tcx> for MissingDoc {
}

fn check_crate(&mut self, cx: &LateContext<'_>, krate: &hir::Crate<'_>) {
self.check_missing_docs_attrs(cx, None, &krate.item.attrs, krate.item.span, "the", "crate");
self.check_missing_docs_attrs(
cx,
None,
&krate.item.attrs,
cx.tcx.hir().span(hir::CRATE_HIR_ID),
"the",
"crate",
);

for macro_def in krate.exported_macros {
let has_doc = macro_def.attrs.iter().any(|a| has_doc(cx.sess(), a));
Expand Down
4 changes: 2 additions & 2 deletions compiler/rustc_passes/src/entry.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use rustc_ast::entry::EntryPointType;
use rustc_errors::struct_span_err;
use rustc_hir::def_id::{CrateNum, LocalDefId, CRATE_DEF_INDEX, LOCAL_CRATE};
use rustc_hir::itemlikevisit::ItemLikeVisitor;
use rustc_hir::{ForeignItem, HirId, ImplItem, Item, ItemKind, TraitItem};
use rustc_hir::{ForeignItem, HirId, ImplItem, Item, ItemKind, TraitItem, CRATE_HIR_ID};
use rustc_middle::hir::map::Map;
use rustc_middle::ty::query::Providers;
use rustc_middle::ty::TyCtxt;
Expand Down Expand Up @@ -170,7 +170,7 @@ fn configure_main(
}

fn no_main_err(tcx: TyCtxt<'_>, visitor: &EntryContext<'_, '_>) {
let sp = tcx.hir().krate().item.span;
let sp = tcx.hir().span(CRATE_HIR_ID);
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.
Expand Down
4 changes: 2 additions & 2 deletions compiler/rustc_passes/src/stability.rs
Original file line number Diff line number Diff line change
Expand Up @@ -621,7 +621,7 @@ fn new_index(tcx: TyCtxt<'tcx>) -> Index<'tcx> {
annotator.annotate(
hir::CRATE_HIR_ID,
&krate.item.attrs,
krate.item.span,
tcx.hir().span(hir::CRATE_HIR_ID),
AnnotationKind::Required,
InheritDeprecation::Yes,
|v| intravisit::walk_crate(v, krate),
Expand Down Expand Up @@ -824,7 +824,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, tcx.hir().span(hir::CRATE_HIR_ID));
intravisit::walk_crate(&mut missing, krate);
krate.visit_all_item_likes(&mut missing.as_deep_visitor());
}
Expand Down
2 changes: 1 addition & 1 deletion src/librustdoc/doctest.rs
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ crate fn run(options: Options) -> Result<(), ErrorReported> {
"".to_string(),
&krate.item.attrs,
CRATE_HIR_ID,
krate.item.span,
tcx.hir().span(CRATE_HIR_ID),
|this| {
intravisit::walk_crate(this, krate);
},
Expand Down
2 changes: 1 addition & 1 deletion src/librustdoc/visit_ast.rs
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ impl<'a, 'tcx> RustdocVisitor<'a, 'tcx> {

crate fn visit(mut self, krate: &'tcx hir::Crate<'_>) -> Module<'tcx> {
let mut module = self.visit_mod_contents(
krate.item.span,
self.cx.tcx.hir().span(hir::CRATE_HIR_ID),
&Spanned { span: rustc_span::DUMMY_SP, node: hir::VisibilityKind::Public },
hir::CRATE_HIR_ID,
&krate.item.module,
Expand Down
2 changes: 1 addition & 1 deletion src/tools/clippy/clippy_lints/src/missing_doc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ impl<'tcx> LateLintPass<'tcx> for MissingDoc {
}

fn check_crate(&mut self, cx: &LateContext<'tcx>, krate: &'tcx hir::Crate<'_>) {
self.check_missing_docs_attrs(cx, &krate.item.attrs, krate.item.span, "the", "crate");
self.check_missing_docs_attrs(cx, &krate.item.attrs, cx.tcx.hir().span(hir::CRATE_HIR_ID), "the", "crate");
}

fn check_item(&mut self, cx: &LateContext<'tcx>, it: &'tcx hir::Item<'_>) {
Expand Down

0 comments on commit 304bdec

Please sign in to comment.