mirror of
https://github.com/rust-lang/rust.git
synced 2025-02-03 02:23:20 +00:00
Remove hir::Crate::attrs.
This commit is contained in:
parent
c05c90275c
commit
a987bbb97c
@ -568,7 +568,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
|
|||||||
visit::walk_crate(&mut item::ItemLowerer { lctx: &mut self }, c);
|
visit::walk_crate(&mut item::ItemLowerer { lctx: &mut self }, c);
|
||||||
|
|
||||||
let module = self.lower_mod(&c.items, c.span);
|
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 body_ids = body_ids(&self.bodies);
|
||||||
let proc_macros =
|
let proc_macros =
|
||||||
c.proc_macros.iter().map(|id| self.node_id_to_hir_id[*id].unwrap()).collect();
|
c.proc_macros.iter().map(|id| self.node_id_to_hir_id[*id].unwrap()).collect();
|
||||||
@ -599,7 +599,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
|
|||||||
self.attrs.push_owner(Idx::new(self.resolver.definitions().def_index_count() - 1));
|
self.attrs.push_owner(Idx::new(self.resolver.definitions().def_index_count() - 1));
|
||||||
|
|
||||||
hir::Crate {
|
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),
|
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,
|
||||||
|
@ -433,12 +433,10 @@ pub fn start_async_codegen<B: ExtraBackendMethods>(
|
|||||||
let sess = tcx.sess;
|
let sess = tcx.sess;
|
||||||
|
|
||||||
let crate_name = tcx.crate_name(LOCAL_CRATE);
|
let crate_name = tcx.crate_name(LOCAL_CRATE);
|
||||||
let no_builtins = tcx.sess.contains_name(&tcx.hir().krate().item.attrs, sym::no_builtins);
|
let crate_attrs = tcx.hir().attrs(rustc_hir::CRATE_HIR_ID);
|
||||||
let is_compiler_builtins =
|
let no_builtins = tcx.sess.contains_name(crate_attrs, sym::no_builtins);
|
||||||
tcx.sess.contains_name(&tcx.hir().krate().item.attrs, sym::compiler_builtins);
|
let is_compiler_builtins = tcx.sess.contains_name(crate_attrs, sym::compiler_builtins);
|
||||||
let subsystem = tcx
|
let subsystem = tcx.sess.first_attr_value_str_by_name(crate_attrs, sym::windows_subsystem);
|
||||||
.sess
|
|
||||||
.first_attr_value_str_by_name(&tcx.hir().krate().item.attrs, sym::windows_subsystem);
|
|
||||||
let windows_subsystem = subsystem.map(|subsystem| {
|
let windows_subsystem = subsystem.map(|subsystem| {
|
||||||
if subsystem != sym::windows && subsystem != sym::console {
|
if subsystem != sym::windows && subsystem != sym::console {
|
||||||
tcx.sess.fatal(&format!(
|
tcx.sess.fatal(&format!(
|
||||||
|
@ -629,7 +629,6 @@ pub struct ModuleItems {
|
|||||||
#[derive(Encodable, Debug, HashStable_Generic)]
|
#[derive(Encodable, Debug, HashStable_Generic)]
|
||||||
pub struct CrateItem<'hir> {
|
pub struct CrateItem<'hir> {
|
||||||
pub module: Mod<'hir>,
|
pub module: Mod<'hir>,
|
||||||
pub attrs: &'hir [Attribute],
|
|
||||||
pub span: Span,
|
pub span: Span,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -168,7 +168,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, &krate.item.attrs);
|
s.print_mod(&krate.item.module, krate.attrs[hir::CRATE_HIR_ID]);
|
||||||
s.print_remaining_comments();
|
s.print_remaining_comments();
|
||||||
s.s.eof()
|
s.s.eof()
|
||||||
}
|
}
|
||||||
|
@ -44,7 +44,7 @@ pub fn assert_module_sources(tcx: TyCtxt<'_>) {
|
|||||||
|
|
||||||
let ams = AssertModuleSource { tcx, available_cgus };
|
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);
|
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);
|
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);
|
builder.levels.register_id(hir::CRATE_HIR_ID);
|
||||||
for macro_def in krate.exported_macros {
|
for macro_def in krate.exported_macros {
|
||||||
builder.levels.register_id(macro_def.hir_id());
|
builder.levels.register_id(macro_def.hir_id());
|
||||||
|
@ -8,7 +8,7 @@ crate fn collect(tcx: TyCtxt<'_>) -> Vec<String> {
|
|||||||
let mut collector = Collector { tcx, args: Vec::new() };
|
let mut collector = Collector { tcx, args: Vec::new() };
|
||||||
tcx.hir().krate().visit_all_item_likes(&mut collector);
|
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 attr.has_name(sym::link_args) {
|
||||||
if let Some(linkarg) = attr.value_str() {
|
if let Some(linkarg) = attr.value_str() {
|
||||||
collector.add_link_args(linkarg);
|
collector.add_link_args(linkarg);
|
||||||
|
@ -2,7 +2,7 @@ use rustc_ast::entry::EntryPointType;
|
|||||||
use rustc_errors::struct_span_err;
|
use rustc_errors::struct_span_err;
|
||||||
use rustc_hir::def_id::{CrateNum, LocalDefId, CRATE_DEF_INDEX, LOCAL_CRATE};
|
use rustc_hir::def_id::{CrateNum, LocalDefId, CRATE_DEF_INDEX, LOCAL_CRATE};
|
||||||
use rustc_hir::itemlikevisit::ItemLikeVisitor;
|
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::hir::map::Map;
|
||||||
use rustc_middle::ty::query::Providers;
|
use rustc_middle::ty::query::Providers;
|
||||||
use rustc_middle::ty::TyCtxt;
|
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 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;
|
return None;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1118,6 +1118,7 @@ impl<'tcx> DumpVisitor<'tcx> {
|
|||||||
.map(|i| id_from_def_id(i.def_id.to_def_id()))
|
.map(|i| id_from_def_id(i.def_id.to_def_id()))
|
||||||
.collect();
|
.collect();
|
||||||
let span = self.span_from_span(krate.item.span);
|
let span = self.span_from_span(krate.item.span);
|
||||||
|
let attrs = self.tcx.hir().attrs(id);
|
||||||
|
|
||||||
self.dumper.dump_def(
|
self.dumper.dump_def(
|
||||||
&Access { public: true, reachable: true },
|
&Access { public: true, reachable: true },
|
||||||
@ -1131,9 +1132,9 @@ impl<'tcx> DumpVisitor<'tcx> {
|
|||||||
children,
|
children,
|
||||||
parent: None,
|
parent: None,
|
||||||
decl_id: None,
|
decl_id: None,
|
||||||
docs: self.save_ctxt.docs_for_attrs(krate.item.attrs),
|
docs: self.save_ctxt.docs_for_attrs(attrs),
|
||||||
sig: None,
|
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);
|
intravisit::walk_crate(self, krate);
|
||||||
|
@ -106,25 +106,27 @@ crate fn run(options: Options) -> Result<(), ErrorReported> {
|
|||||||
|
|
||||||
let tests = interface::run_compiler(config, |compiler| {
|
let tests = interface::run_compiler(config, |compiler| {
|
||||||
compiler.enter(|queries| {
|
compiler.enter(|queries| {
|
||||||
let lower_to_hir = queries.lower_to_hir()?;
|
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 crate_name = queries.crate_name()?.peek().to_string();
|
||||||
let mut global_ctxt = queries.global_ctxt()?.take();
|
let mut global_ctxt = queries.global_ctxt()?.take();
|
||||||
|
|
||||||
global_ctxt.enter(|tcx| {
|
let collector = global_ctxt.enter(|tcx| {
|
||||||
let krate = tcx.hir().krate();
|
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 {
|
let mut hir_collector = HirCollector {
|
||||||
sess: compiler.session(),
|
sess: compiler.session(),
|
||||||
@ -143,6 +145,8 @@ crate fn run(options: Options) -> Result<(), ErrorReported> {
|
|||||||
intravisit::walk_crate(this, krate);
|
intravisit::walk_crate(this, krate);
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
|
|
||||||
|
collector
|
||||||
});
|
});
|
||||||
compiler.session().abort_if_errors();
|
compiler.session().abort_if_errors();
|
||||||
|
|
||||||
@ -167,15 +171,13 @@ crate fn run(options: Options) -> Result<(), ErrorReported> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Look for `#![doc(test(no_crate_inject))]`, used by crates in the std facade.
|
// 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;
|
use rustc_ast_pretty::pprust;
|
||||||
|
|
||||||
let mut opts =
|
let mut opts =
|
||||||
TestOptions { no_crate_inject: false, display_warnings: false, attrs: Vec::new() };
|
TestOptions { no_crate_inject: false, display_warnings: false, attrs: Vec::new() };
|
||||||
|
|
||||||
let test_attrs: Vec<_> = krate
|
let test_attrs: Vec<_> = attrs
|
||||||
.item
|
|
||||||
.attrs
|
|
||||||
.iter()
|
.iter()
|
||||||
.filter(|a| a.has_name(sym::doc))
|
.filter(|a| a.has_name(sym::doc))
|
||||||
.flat_map(|a| a.meta_item_list().unwrap_or_else(Vec::new))
|
.flat_map(|a| a.meta_item_list().unwrap_or_else(Vec::new))
|
||||||
|
@ -208,8 +208,9 @@ impl_lint_pass!(DocMarkdown =>
|
|||||||
);
|
);
|
||||||
|
|
||||||
impl<'tcx> LateLintPass<'tcx> for DocMarkdown {
|
impl<'tcx> LateLintPass<'tcx> for DocMarkdown {
|
||||||
fn check_crate(&mut self, cx: &LateContext<'tcx>, krate: &'tcx hir::Crate<'_>) {
|
fn check_crate(&mut self, cx: &LateContext<'tcx>, _: &'tcx hir::Crate<'_>) {
|
||||||
check_attrs(cx, &self.valid_idents, &krate.item.attrs);
|
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<'_>) {
|
fn check_item(&mut self, cx: &LateContext<'tcx>, item: &'tcx hir::Item<'_>) {
|
||||||
|
@ -578,7 +578,7 @@ impl<'tcx> LateLintPass<'tcx> for Loops {
|
|||||||
// also check for empty `loop {}` statements, skipping those in #[panic_handler]
|
// 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) {
|
if block.stmts.is_empty() && block.expr.is_none() && !is_in_panic_handler(cx, expr) {
|
||||||
let msg = "empty `loop {}` wastes CPU cycles";
|
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"
|
"you should either use `panic!()` or add a call pausing or sleeping the thread to the loop body"
|
||||||
} else {
|
} else {
|
||||||
"you should either use `panic!()` or add `std::thread::sleep(..);` to the loop body"
|
"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_lint_pass!(MainRecursion => [MAIN_RECURSION]);
|
||||||
|
|
||||||
impl LateLintPass<'_> for MainRecursion {
|
impl LateLintPass<'_> for MainRecursion {
|
||||||
fn check_crate(&mut self, _: &LateContext<'_>, krate: &Crate<'_>) {
|
fn check_crate(&mut self, cx: &LateContext<'_>, _: &Crate<'_>) {
|
||||||
self.has_no_std_attr = is_no_std_crate(krate);
|
self.has_no_std_attr = is_no_std_crate(cx);
|
||||||
}
|
}
|
||||||
|
|
||||||
fn check_expr_post(&mut self, cx: &LateContext<'_>, expr: &Expr<'_>) {
|
fn check_expr_post(&mut self, cx: &LateContext<'_>, expr: &Expr<'_>) {
|
||||||
|
@ -127,7 +127,8 @@ 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<'_>) {
|
||||||
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<'_>) {
|
fn check_item(&mut self, cx: &LateContext<'tcx>, it: &'tcx hir::Item<'_>) {
|
||||||
|
@ -61,7 +61,7 @@ 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::Node;
|
use rustc_hir::Node;
|
||||||
use rustc_hir::{
|
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,
|
MatchSource, Param, Pat, PatKind, Path, PathSegment, QPath, TraitItem, TraitItemKind, TraitRef, TyKind, Unsafety,
|
||||||
};
|
};
|
||||||
use rustc_infer::infer::TyCtxtInferExt;
|
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())
|
did.map_or(false, |did| must_use_attr(&cx.tcx.get_attrs(did)).is_some())
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn is_no_std_crate(krate: &Crate<'_>) -> bool {
|
pub fn is_no_std_crate(cx: &LateContext<'_>) -> bool {
|
||||||
krate.item.attrs.iter().any(|attr| {
|
cx.tcx.hir().attrs(hir::CRATE_HIR_ID).iter().any(|attr| {
|
||||||
if let ast::AttrKind::Normal(ref attr, _) = attr.kind {
|
if let ast::AttrKind::Normal(ref attr, _) = attr.kind {
|
||||||
attr.path == sym::no_std
|
attr.path == sym::no_std
|
||||||
} else {
|
} else {
|
||||||
|
Loading…
Reference in New Issue
Block a user