Remove hir::Crate::attrs.
This commit is contained in:
parent
c05c90275c
commit
a987bbb97c
@ -568,7 +568,7 @@ fn visit_ty(&mut self, t: &'tcx Ty) {
|
||||
visit::walk_crate(&mut item::ItemLowerer { lctx: &mut self }, c);
|
||||
|
||||
let module = self.lower_mod(&c.items, c.span);
|
||||
let attrs = self.lower_attrs(hir::CRATE_HIR_ID, &c.attrs);
|
||||
self.lower_attrs(hir::CRATE_HIR_ID, &c.attrs);
|
||||
let body_ids = body_ids(&self.bodies);
|
||||
let proc_macros =
|
||||
c.proc_macros.iter().map(|id| self.node_id_to_hir_id[*id].unwrap()).collect();
|
||||
@ -599,7 +599,7 @@ fn visit_ty(&mut self, t: &'tcx Ty) {
|
||||
self.attrs.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, span: c.span },
|
||||
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,
|
||||
|
@ -433,12 +433,10 @@ pub fn start_async_codegen<B: ExtraBackendMethods>(
|
||||
let sess = tcx.sess;
|
||||
|
||||
let crate_name = tcx.crate_name(LOCAL_CRATE);
|
||||
let no_builtins = tcx.sess.contains_name(&tcx.hir().krate().item.attrs, sym::no_builtins);
|
||||
let is_compiler_builtins =
|
||||
tcx.sess.contains_name(&tcx.hir().krate().item.attrs, sym::compiler_builtins);
|
||||
let subsystem = tcx
|
||||
.sess
|
||||
.first_attr_value_str_by_name(&tcx.hir().krate().item.attrs, sym::windows_subsystem);
|
||||
let crate_attrs = tcx.hir().attrs(rustc_hir::CRATE_HIR_ID);
|
||||
let no_builtins = tcx.sess.contains_name(crate_attrs, sym::no_builtins);
|
||||
let is_compiler_builtins = tcx.sess.contains_name(crate_attrs, sym::compiler_builtins);
|
||||
let subsystem = tcx.sess.first_attr_value_str_by_name(crate_attrs, sym::windows_subsystem);
|
||||
let windows_subsystem = subsystem.map(|subsystem| {
|
||||
if subsystem != sym::windows && subsystem != sym::console {
|
||||
tcx.sess.fatal(&format!(
|
||||
|
@ -629,7 +629,6 @@ pub struct ModuleItems {
|
||||
#[derive(Encodable, Debug, HashStable_Generic)]
|
||||
pub struct CrateItem<'hir> {
|
||||
pub module: Mod<'hir>,
|
||||
pub attrs: &'hir [Attribute],
|
||||
pub span: Span,
|
||||
}
|
||||
|
||||
|
@ -168,7 +168,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, &krate.item.attrs);
|
||||
s.print_mod(&krate.item.module, krate.attrs[hir::CRATE_HIR_ID]);
|
||||
s.print_remaining_comments();
|
||||
s.s.eof()
|
||||
}
|
||||
|
@ -44,7 +44,7 @@ pub fn assert_module_sources(tcx: TyCtxt<'_>) {
|
||||
|
||||
let ams = AssertModuleSource { tcx, available_cgus };
|
||||
|
||||
for attr in tcx.hir().krate().item.attrs {
|
||||
for attr in tcx.hir().attrs(rustc_hir::CRATE_HIR_ID) {
|
||||
ams.check_attr(attr);
|
||||
}
|
||||
})
|
||||
|
@ -38,7 +38,7 @@ fn lint_levels(tcx: TyCtxt<'_>, cnum: CrateNum) -> LintLevelMap {
|
||||
|
||||
builder.levels.id_to_set.reserve(krate.exported_macros.len() + 1);
|
||||
|
||||
let push = builder.levels.push(&krate.item.attrs, &store, true);
|
||||
let push = builder.levels.push(tcx.hir().attrs(hir::CRATE_HIR_ID), &store, true);
|
||||
builder.levels.register_id(hir::CRATE_HIR_ID);
|
||||
for macro_def in krate.exported_macros {
|
||||
builder.levels.register_id(macro_def.hir_id());
|
||||
|
@ -8,7 +8,7 @@
|
||||
let mut collector = Collector { tcx, args: Vec::new() };
|
||||
tcx.hir().krate().visit_all_item_likes(&mut collector);
|
||||
|
||||
for attr in tcx.hir().krate().item.attrs.iter() {
|
||||
for attr in tcx.hir().attrs(hir::CRATE_HIR_ID).iter() {
|
||||
if attr.has_name(sym::link_args) {
|
||||
if let Some(linkarg) = attr.value_str() {
|
||||
collector.add_link_args(linkarg);
|
||||
|
@ -2,7 +2,7 @@
|
||||
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;
|
||||
@ -60,7 +60,7 @@ fn entry_fn(tcx: TyCtxt<'_>, cnum: CrateNum) -> Option<(LocalDefId, EntryFnType)
|
||||
}
|
||||
|
||||
// If the user wants no main function at all, then stop here.
|
||||
if tcx.sess.contains_name(&tcx.hir().krate().item.attrs, sym::no_main) {
|
||||
if tcx.sess.contains_name(&tcx.hir().attrs(CRATE_HIR_ID), sym::no_main) {
|
||||
return None;
|
||||
}
|
||||
|
||||
|
@ -1118,6 +1118,7 @@ pub(crate) fn process_crate(&mut self, krate: &'tcx hir::Crate<'tcx>) {
|
||||
.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);
|
||||
|
||||
self.dumper.dump_def(
|
||||
&Access { public: true, reachable: true },
|
||||
@ -1131,9 +1132,9 @@ pub(crate) fn process_crate(&mut self, krate: &'tcx hir::Crate<'tcx>) {
|
||||
children,
|
||||
parent: None,
|
||||
decl_id: None,
|
||||
docs: self.save_ctxt.docs_for_attrs(krate.item.attrs),
|
||||
docs: self.save_ctxt.docs_for_attrs(attrs),
|
||||
sig: None,
|
||||
attributes: lower_attributes(krate.item.attrs.to_owned(), &self.save_ctxt),
|
||||
attributes: lower_attributes(attrs.to_owned(), &self.save_ctxt),
|
||||
},
|
||||
);
|
||||
intravisit::walk_crate(self, krate);
|
||||
|
@ -106,25 +106,27 @@
|
||||
|
||||
let tests = interface::run_compiler(config, |compiler| {
|
||||
compiler.enter(|queries| {
|
||||
let lower_to_hir = queries.lower_to_hir()?;
|
||||
|
||||
let mut opts = scrape_test_config(lower_to_hir.peek().0);
|
||||
opts.display_warnings |= options.display_warnings;
|
||||
let enable_per_target_ignores = options.enable_per_target_ignores;
|
||||
let mut collector = Collector::new(
|
||||
queries.crate_name()?.peek().to_string(),
|
||||
options,
|
||||
false,
|
||||
opts,
|
||||
Some(compiler.session().parse_sess.clone_source_map()),
|
||||
None,
|
||||
enable_per_target_ignores,
|
||||
);
|
||||
let _lower_to_hir = queries.lower_to_hir()?;
|
||||
|
||||
let crate_name = queries.crate_name()?.peek().to_string();
|
||||
let mut global_ctxt = queries.global_ctxt()?.take();
|
||||
|
||||
global_ctxt.enter(|tcx| {
|
||||
let collector = global_ctxt.enter(|tcx| {
|
||||
let krate = tcx.hir().krate();
|
||||
let crate_attrs = tcx.hir().attrs(CRATE_HIR_ID);
|
||||
|
||||
let mut opts = scrape_test_config(crate_attrs);
|
||||
opts.display_warnings |= options.display_warnings;
|
||||
let enable_per_target_ignores = options.enable_per_target_ignores;
|
||||
let mut collector = Collector::new(
|
||||
crate_name,
|
||||
options,
|
||||
false,
|
||||
opts,
|
||||
Some(compiler.session().parse_sess.clone_source_map()),
|
||||
None,
|
||||
enable_per_target_ignores,
|
||||
);
|
||||
|
||||
let mut hir_collector = HirCollector {
|
||||
sess: compiler.session(),
|
||||
@ -143,6 +145,8 @@
|
||||
intravisit::walk_crate(this, krate);
|
||||
},
|
||||
);
|
||||
|
||||
collector
|
||||
});
|
||||
compiler.session().abort_if_errors();
|
||||
|
||||
@ -167,15 +171,13 @@
|
||||
}
|
||||
|
||||
// Look for `#![doc(test(no_crate_inject))]`, used by crates in the std facade.
|
||||
fn scrape_test_config(krate: &::rustc_hir::Crate<'_>) -> TestOptions {
|
||||
fn scrape_test_config(attrs: &[ast::Attribute]) -> TestOptions {
|
||||
use rustc_ast_pretty::pprust;
|
||||
|
||||
let mut opts =
|
||||
TestOptions { no_crate_inject: false, display_warnings: false, attrs: Vec::new() };
|
||||
|
||||
let test_attrs: Vec<_> = krate
|
||||
.item
|
||||
.attrs
|
||||
let test_attrs: Vec<_> = attrs
|
||||
.iter()
|
||||
.filter(|a| a.has_name(sym::doc))
|
||||
.flat_map(|a| a.meta_item_list().unwrap_or_else(Vec::new))
|
||||
|
@ -208,8 +208,9 @@ pub fn new(valid_idents: FxHashSet<String>) -> Self {
|
||||
);
|
||||
|
||||
impl<'tcx> LateLintPass<'tcx> for DocMarkdown {
|
||||
fn check_crate(&mut self, cx: &LateContext<'tcx>, krate: &'tcx hir::Crate<'_>) {
|
||||
check_attrs(cx, &self.valid_idents, &krate.item.attrs);
|
||||
fn check_crate(&mut self, cx: &LateContext<'tcx>, _: &'tcx hir::Crate<'_>) {
|
||||
let attrs = cx.tcx.hir().attrs(hir::CRATE_HIR_ID);
|
||||
check_attrs(cx, &self.valid_idents, attrs);
|
||||
}
|
||||
|
||||
fn check_item(&mut self, cx: &LateContext<'tcx>, item: &'tcx hir::Item<'_>) {
|
||||
|
@ -578,7 +578,7 @@ fn check_expr(&mut self, cx: &LateContext<'tcx>, expr: &'tcx Expr<'_>) {
|
||||
// also check for empty `loop {}` statements, skipping those in #[panic_handler]
|
||||
if block.stmts.is_empty() && block.expr.is_none() && !is_in_panic_handler(cx, expr) {
|
||||
let msg = "empty `loop {}` wastes CPU cycles";
|
||||
let help = if is_no_std_crate(cx.tcx.hir().krate()) {
|
||||
let help = if is_no_std_crate(cx) {
|
||||
"you should either use `panic!()` or add a call pausing or sleeping the thread to the loop body"
|
||||
} else {
|
||||
"you should either use `panic!()` or add `std::thread::sleep(..);` to the loop body"
|
||||
|
@ -32,8 +32,8 @@ pub struct MainRecursion {
|
||||
impl_lint_pass!(MainRecursion => [MAIN_RECURSION]);
|
||||
|
||||
impl LateLintPass<'_> for MainRecursion {
|
||||
fn check_crate(&mut self, _: &LateContext<'_>, krate: &Crate<'_>) {
|
||||
self.has_no_std_attr = is_no_std_crate(krate);
|
||||
fn check_crate(&mut self, cx: &LateContext<'_>, _: &Crate<'_>) {
|
||||
self.has_no_std_attr = is_no_std_crate(cx);
|
||||
}
|
||||
|
||||
fn check_expr_post(&mut self, cx: &LateContext<'_>, expr: &Expr<'_>) {
|
||||
|
@ -127,7 +127,8 @@ fn exit_lint_attrs(&mut self, _: &LateContext<'tcx>, _: &'tcx [ast::Attribute])
|
||||
}
|
||||
|
||||
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");
|
||||
let attrs = cx.tcx.hir().attrs(hir::CRATE_HIR_ID);
|
||||
self.check_missing_docs_attrs(cx, attrs, krate.item.span, "the", "crate");
|
||||
}
|
||||
|
||||
fn check_item(&mut self, cx: &LateContext<'tcx>, it: &'tcx hir::Item<'_>) {
|
||||
|
@ -61,7 +61,7 @@
|
||||
use rustc_hir::intravisit::{self, NestedVisitorMap, Visitor};
|
||||
use rustc_hir::Node;
|
||||
use rustc_hir::{
|
||||
def, Arm, Block, Body, Constness, Crate, Expr, ExprKind, FnDecl, HirId, ImplItem, ImplItemKind, Item, ItemKind,
|
||||
def, Arm, Block, Body, Constness, Expr, ExprKind, FnDecl, HirId, ImplItem, ImplItemKind, Item, ItemKind,
|
||||
MatchSource, Param, Pat, PatKind, Path, PathSegment, QPath, TraitItem, TraitItemKind, TraitRef, TyKind, Unsafety,
|
||||
};
|
||||
use rustc_infer::infer::TyCtxtInferExt;
|
||||
@ -1510,8 +1510,8 @@ pub fn is_must_use_func_call(cx: &LateContext<'_>, expr: &Expr<'_>) -> bool {
|
||||
did.map_or(false, |did| must_use_attr(&cx.tcx.get_attrs(did)).is_some())
|
||||
}
|
||||
|
||||
pub fn is_no_std_crate(krate: &Crate<'_>) -> bool {
|
||||
krate.item.attrs.iter().any(|attr| {
|
||||
pub fn is_no_std_crate(cx: &LateContext<'_>) -> bool {
|
||||
cx.tcx.hir().attrs(hir::CRATE_HIR_ID).iter().any(|attr| {
|
||||
if let ast::AttrKind::Normal(ref attr, _) = attr.kind {
|
||||
attr.path == sym::no_std
|
||||
} else {
|
||||
|
Loading…
Reference in New Issue
Block a user