mirror of
https://github.com/rust-lang/rust.git
synced 2024-11-26 00:34:06 +00:00
Auto merge of #88880 - cjgillot:no-krate, r=oli-obk
Rework HIR API to make invocations of the hir_crate query harder. `hir_crate` forces the recomputation of queries that depend on it. This PR aims at avoiding useless invocations of `hir_crate` by making dependent code go through `tcx.hir()`.
This commit is contained in:
commit
c02371c442
@ -489,7 +489,7 @@ fn print_with_analysis(
|
||||
let mut out = String::new();
|
||||
abort_on_err(rustc_typeck::check_crate(tcx), tcx.sess);
|
||||
debug!("pretty printing THIR tree");
|
||||
for did in tcx.body_owners() {
|
||||
for did in tcx.hir().body_owners() {
|
||||
let _ = writeln!(
|
||||
out,
|
||||
"{:?}:\n{}\n",
|
||||
|
@ -1,7 +1,7 @@
|
||||
use crate::def::{CtorKind, DefKind, Res};
|
||||
use crate::def_id::{DefId, CRATE_DEF_ID};
|
||||
crate use crate::hir_id::{HirId, ItemLocalId};
|
||||
use crate::{itemlikevisit, LangItem};
|
||||
use crate::LangItem;
|
||||
|
||||
use rustc_ast::util::parser::ExprPrecedence;
|
||||
use rustc_ast::{self as ast, CrateSugar, LlvmAsmDialect};
|
||||
@ -10,7 +10,6 @@ pub use rustc_ast::{BorrowKind, ImplPolarity, IsAuto};
|
||||
pub use rustc_ast::{CaptureBy, Movability, Mutability};
|
||||
use rustc_ast::{InlineAsmOptions, InlineAsmTemplatePiece};
|
||||
use rustc_data_structures::fx::FxHashMap;
|
||||
use rustc_data_structures::sync::{par_for_each_in, Send, Sync};
|
||||
use rustc_index::vec::IndexVec;
|
||||
use rustc_macros::HashStable_Generic;
|
||||
use rustc_span::source_map::Spanned;
|
||||
@ -708,52 +707,6 @@ impl Crate<'hir> {
|
||||
}
|
||||
}
|
||||
|
||||
impl Crate<'_> {
|
||||
/// Visits all items in the crate in some deterministic (but
|
||||
/// unspecified) order. If you just need to process every item,
|
||||
/// but don't care about nesting, this method is the best choice.
|
||||
///
|
||||
/// If you do care about nesting -- usually because your algorithm
|
||||
/// follows lexical scoping rules -- then you want a different
|
||||
/// approach. You should override `visit_nested_item` in your
|
||||
/// visitor and then call `intravisit::walk_crate` instead.
|
||||
pub fn visit_all_item_likes<'hir, V>(&'hir self, visitor: &mut V)
|
||||
where
|
||||
V: itemlikevisit::ItemLikeVisitor<'hir>,
|
||||
{
|
||||
for owner in self.owners.iter().filter_map(Option::as_ref) {
|
||||
match owner {
|
||||
OwnerNode::Item(item) => visitor.visit_item(item),
|
||||
OwnerNode::ForeignItem(item) => visitor.visit_foreign_item(item),
|
||||
OwnerNode::ImplItem(item) => visitor.visit_impl_item(item),
|
||||
OwnerNode::TraitItem(item) => visitor.visit_trait_item(item),
|
||||
OwnerNode::Crate(_) => {}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// A parallel version of `visit_all_item_likes`.
|
||||
pub fn par_visit_all_item_likes<'hir, V>(&'hir self, visitor: &V)
|
||||
where
|
||||
V: itemlikevisit::ParItemLikeVisitor<'hir> + Sync + Send,
|
||||
{
|
||||
par_for_each_in(&self.owners.raw, |owner| match owner {
|
||||
Some(OwnerNode::Item(item)) => visitor.visit_item(item),
|
||||
Some(OwnerNode::ForeignItem(item)) => visitor.visit_foreign_item(item),
|
||||
Some(OwnerNode::ImplItem(item)) => visitor.visit_impl_item(item),
|
||||
Some(OwnerNode::TraitItem(item)) => visitor.visit_trait_item(item),
|
||||
Some(OwnerNode::Crate(_)) | None => {}
|
||||
})
|
||||
}
|
||||
|
||||
pub fn items<'hir>(&'hir self) -> impl Iterator<Item = &'hir Item<'hir>> + 'hir {
|
||||
self.owners.iter().filter_map(|owner| match owner {
|
||||
Some(OwnerNode::Item(item)) => Some(*item),
|
||||
_ => None,
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
/// A block of statements `{ .. }`, which may have a label (in this case the
|
||||
/// `targeted_by_break` field will be `true`) and may be `unsafe` by means of
|
||||
/// the `rules` being anything but `DefaultBlock`.
|
||||
|
@ -51,19 +51,6 @@ pub struct NoAnn;
|
||||
impl PpAnn for NoAnn {}
|
||||
pub const NO_ANN: &dyn PpAnn = &NoAnn;
|
||||
|
||||
impl PpAnn for hir::Crate<'_> {
|
||||
fn nested(&self, state: &mut State<'_>, nested: Nested) {
|
||||
match nested {
|
||||
Nested::Item(id) => state.print_item(self.item(id)),
|
||||
Nested::TraitItem(id) => state.print_trait_item(self.trait_item(id)),
|
||||
Nested::ImplItem(id) => state.print_impl_item(self.impl_item(id)),
|
||||
Nested::ForeignItem(id) => state.print_foreign_item(self.foreign_item(id)),
|
||||
Nested::Body(id) => state.print_expr(&self.body(id).value),
|
||||
Nested::BodyParamPat(id, i) => state.print_pat(&self.body(id).params[i].pat),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// Identical to the `PpAnn` implementation for `hir::Crate`,
|
||||
/// except it avoids creating a dependency on the whole crate.
|
||||
impl PpAnn for &dyn rustc_hir::intravisit::Map<'_> {
|
||||
|
@ -74,7 +74,7 @@ pub fn assert_dep_graph(tcx: TyCtxt<'_>) {
|
||||
let mut visitor =
|
||||
IfThisChanged { tcx, if_this_changed: vec![], then_this_would_need: vec![] };
|
||||
visitor.process_attrs(hir::CRATE_HIR_ID);
|
||||
tcx.hir().krate().visit_all_item_likes(&mut visitor.as_deep_visitor());
|
||||
tcx.hir().visit_all_item_likes(&mut visitor.as_deep_visitor());
|
||||
(visitor.if_this_changed, visitor.then_this_would_need)
|
||||
};
|
||||
|
||||
|
@ -137,9 +137,8 @@ pub fn check_dirty_clean_annotations(tcx: TyCtxt<'_>) {
|
||||
}
|
||||
|
||||
tcx.dep_graph.with_ignore(|| {
|
||||
let krate = tcx.hir().krate();
|
||||
let mut dirty_clean_visitor = DirtyCleanVisitor { tcx, checked_attrs: Default::default() };
|
||||
krate.visit_all_item_likes(&mut dirty_clean_visitor);
|
||||
tcx.hir().visit_all_item_likes(&mut dirty_clean_visitor);
|
||||
|
||||
let mut all_attrs = FindAllAttrs { tcx, found_attrs: vec![] };
|
||||
tcx.hir().walk_attributes(&mut all_attrs);
|
||||
|
@ -886,9 +886,7 @@ fn analysis(tcx: TyCtxt<'_>, (): ()) -> Result<()> {
|
||||
parallel!(
|
||||
{
|
||||
sess.time("match_checking", || {
|
||||
tcx.par_body_owners(|def_id| {
|
||||
tcx.ensure().check_match(def_id.to_def_id());
|
||||
});
|
||||
tcx.hir().par_body_owners(|def_id| tcx.ensure().check_match(def_id.to_def_id()))
|
||||
});
|
||||
},
|
||||
{
|
||||
@ -907,11 +905,11 @@ fn analysis(tcx: TyCtxt<'_>, (): ()) -> Result<()> {
|
||||
});
|
||||
|
||||
sess.time("MIR_borrow_checking", || {
|
||||
tcx.par_body_owners(|def_id| tcx.ensure().mir_borrowck(def_id));
|
||||
tcx.hir().par_body_owners(|def_id| tcx.ensure().mir_borrowck(def_id));
|
||||
});
|
||||
|
||||
sess.time("MIR_effect_checking", || {
|
||||
for def_id in tcx.body_owners() {
|
||||
for def_id in tcx.hir().body_owners() {
|
||||
tcx.ensure().thir_check_unsafety(def_id);
|
||||
if !tcx.sess.opts.debugging_opts.thir_unsafeck {
|
||||
rustc_mir_transform::check_unsafety::check_unsafety(tcx, def_id);
|
||||
|
@ -7,7 +7,7 @@ use rustc_span::symbol::sym;
|
||||
|
||||
fn proc_macro_decls_static(tcx: TyCtxt<'_>, (): ()) -> Option<LocalDefId> {
|
||||
let mut finder = Finder { tcx, decls: None };
|
||||
tcx.hir().krate().visit_all_item_likes(&mut finder);
|
||||
tcx.hir().visit_all_item_likes(&mut finder);
|
||||
|
||||
finder.decls.map(|id| tcx.hir().local_def_id(id))
|
||||
}
|
||||
|
@ -584,8 +584,14 @@ impl<'tcx> LateLintPass<'tcx> for MissingDoc {
|
||||
self.doc_hidden_stack.pop().expect("empty doc_hidden_stack");
|
||||
}
|
||||
|
||||
fn check_crate(&mut self, cx: &LateContext<'_>, krate: &hir::Crate<'_>) {
|
||||
self.check_missing_docs_attrs(cx, CRATE_DEF_ID, krate.module().inner, "the", "crate");
|
||||
fn check_crate(&mut self, cx: &LateContext<'_>) {
|
||||
self.check_missing_docs_attrs(
|
||||
cx,
|
||||
CRATE_DEF_ID,
|
||||
cx.tcx.def_span(CRATE_DEF_ID),
|
||||
"the",
|
||||
"crate",
|
||||
);
|
||||
}
|
||||
|
||||
fn check_item(&mut self, cx: &LateContext<'_>, it: &hir::Item<'_>) {
|
||||
|
@ -430,8 +430,6 @@ pub fn late_lint_mod<'tcx, T: LateLintPass<'tcx>>(
|
||||
fn late_lint_pass_crate<'tcx, T: LateLintPass<'tcx>>(tcx: TyCtxt<'tcx>, pass: T) {
|
||||
let access_levels = &tcx.privacy_access_levels(());
|
||||
|
||||
let krate = tcx.hir().krate();
|
||||
|
||||
let context = LateContext {
|
||||
tcx,
|
||||
enclosing_body: None,
|
||||
@ -450,10 +448,10 @@ fn late_lint_pass_crate<'tcx, T: LateLintPass<'tcx>>(tcx: TyCtxt<'tcx>, pass: T)
|
||||
cx.with_lint_attrs(hir::CRATE_HIR_ID, |cx| {
|
||||
// since the root module isn't visited as an item (because it isn't an
|
||||
// item), warn for it here.
|
||||
lint_callback!(cx, check_crate, krate);
|
||||
lint_callback!(cx, check_crate,);
|
||||
tcx.hir().walk_toplevel_module(cx);
|
||||
tcx.hir().walk_attributes(cx);
|
||||
lint_callback!(cx, check_crate_post, krate);
|
||||
lint_callback!(cx, check_crate_post,);
|
||||
})
|
||||
}
|
||||
|
||||
|
@ -16,8 +16,8 @@ macro_rules! late_lint_methods {
|
||||
fn check_body(a: &$hir hir::Body<$hir>);
|
||||
fn check_body_post(a: &$hir hir::Body<$hir>);
|
||||
fn check_name(a: Span, b: Symbol);
|
||||
fn check_crate(a: &$hir hir::Crate<$hir>);
|
||||
fn check_crate_post(a: &$hir hir::Crate<$hir>);
|
||||
fn check_crate();
|
||||
fn check_crate_post();
|
||||
fn check_mod(a: &$hir hir::Mod<$hir>, b: Span, c: hir::HirId);
|
||||
fn check_mod_post(a: &$hir hir::Mod<$hir>, b: Span, c: hir::HirId);
|
||||
fn check_foreign_item(a: &$hir hir::ForeignItem<$hir>);
|
||||
|
@ -5,7 +5,7 @@ use rustc_middle::ty::TyCtxt;
|
||||
|
||||
crate fn collect(tcx: TyCtxt<'_>) -> Vec<ForeignModule> {
|
||||
let mut collector = Collector { modules: Vec::new() };
|
||||
tcx.hir().krate().visit_all_item_likes(&mut collector);
|
||||
tcx.hir().visit_all_item_likes(&mut collector);
|
||||
collector.modules
|
||||
}
|
||||
|
||||
|
@ -14,7 +14,7 @@ use rustc_target::spec::abi::Abi;
|
||||
|
||||
crate fn collect(tcx: TyCtxt<'_>) -> Vec<NativeLib> {
|
||||
let mut collector = Collector { tcx, libs: Vec::new() };
|
||||
tcx.hir().krate().visit_all_item_likes(&mut collector);
|
||||
tcx.hir().visit_all_item_likes(&mut collector);
|
||||
collector.process_command_line();
|
||||
collector.libs
|
||||
}
|
||||
|
@ -440,8 +440,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.module());
|
||||
self.encode_info_for_mod(CRATE_DEF_ID, self.tcx.hir().root_module());
|
||||
|
||||
// Proc-macro crates only export proc-macro items, which are looked
|
||||
// up using `proc_macro_data`
|
||||
@ -449,7 +448,7 @@ impl<'a, 'tcx> EncodeContext<'a, 'tcx> {
|
||||
return;
|
||||
}
|
||||
|
||||
krate.visit_all_item_likes(&mut self.as_deep_visitor());
|
||||
self.tcx.hir().visit_all_item_likes(&mut self.as_deep_visitor());
|
||||
}
|
||||
|
||||
fn encode_def_path_table(&mut self) {
|
||||
@ -1782,7 +1781,7 @@ impl EncodeContext<'a, 'tcx> {
|
||||
debug!("EncodeContext::encode_impls()");
|
||||
let tcx = self.tcx;
|
||||
let mut visitor = ImplVisitor { tcx, impls: FxHashMap::default() };
|
||||
tcx.hir().krate().visit_all_item_likes(&mut visitor);
|
||||
tcx.hir().visit_all_item_likes(&mut visitor);
|
||||
|
||||
let mut all_impls: Vec<_> = visitor.impls.into_iter().collect();
|
||||
|
||||
|
@ -6,6 +6,7 @@ use rustc_ast as ast;
|
||||
use rustc_data_structures::fingerprint::Fingerprint;
|
||||
use rustc_data_structures::stable_hasher::{HashStable, StableHasher};
|
||||
use rustc_data_structures::svh::Svh;
|
||||
use rustc_data_structures::sync::{par_for_each_in, Send, Sync};
|
||||
use rustc_hir::def::{DefKind, Res};
|
||||
use rustc_hir::def_id::{CrateNum, DefId, LocalDefId, CRATE_DEF_ID, LOCAL_CRATE};
|
||||
use rustc_hir::definitions::{DefKey, DefPath, DefPathHash};
|
||||
@ -156,6 +157,21 @@ impl<'hir> Map<'hir> {
|
||||
self.tcx.hir_crate(())
|
||||
}
|
||||
|
||||
pub fn root_module(&self) -> &'hir Mod<'hir> {
|
||||
match self.tcx.hir_owner(CRATE_DEF_ID).map(|o| o.node) {
|
||||
Some(OwnerNode::Crate(item)) => item,
|
||||
_ => bug!(),
|
||||
}
|
||||
}
|
||||
|
||||
pub fn items(&self) -> impl Iterator<Item = &'hir Item<'hir>> + 'hir {
|
||||
let krate = self.krate();
|
||||
krate.owners.iter().filter_map(|owner| match owner.as_ref()? {
|
||||
OwnerNode::Item(item) => Some(*item),
|
||||
_ => None,
|
||||
})
|
||||
}
|
||||
|
||||
pub fn def_key(&self, def_id: LocalDefId) -> DefKey {
|
||||
// Accessing the DefKey is ok, since it is part of DefPathHash.
|
||||
self.tcx.untracked_resolutions.definitions.def_key(def_id)
|
||||
@ -475,6 +491,17 @@ impl<'hir> Map<'hir> {
|
||||
Some(ccx)
|
||||
}
|
||||
|
||||
/// Returns an iterator of the `DefId`s for all body-owners in this
|
||||
/// crate. If you would prefer to iterate over the bodies
|
||||
/// themselves, you can do `self.hir().krate().body_ids.iter()`.
|
||||
pub fn body_owners(self) -> impl Iterator<Item = LocalDefId> + 'hir {
|
||||
self.krate().bodies.keys().map(move |&body_id| self.body_owner_def_id(body_id))
|
||||
}
|
||||
|
||||
pub fn par_body_owners<F: Fn(LocalDefId) + Sync + Send>(self, f: F) {
|
||||
par_for_each_in(&self.krate().bodies, |(&body_id, _)| f(self.body_owner_def_id(body_id)));
|
||||
}
|
||||
|
||||
pub fn ty_param_owner(&self, id: HirId) -> HirId {
|
||||
match self.get(id) {
|
||||
Node::Item(&Item { kind: ItemKind::Trait(..) | ItemKind::TraitAlias(..), .. }) => id,
|
||||
@ -531,6 +558,45 @@ impl<'hir> Map<'hir> {
|
||||
}
|
||||
}
|
||||
|
||||
/// Visits all items in the crate in some deterministic (but
|
||||
/// unspecified) order. If you just need to process every item,
|
||||
/// but don't care about nesting, this method is the best choice.
|
||||
///
|
||||
/// If you do care about nesting -- usually because your algorithm
|
||||
/// follows lexical scoping rules -- then you want a different
|
||||
/// approach. You should override `visit_nested_item` in your
|
||||
/// visitor and then call `intravisit::walk_crate` instead.
|
||||
pub fn visit_all_item_likes<V>(&self, visitor: &mut V)
|
||||
where
|
||||
V: itemlikevisit::ItemLikeVisitor<'hir>,
|
||||
{
|
||||
let krate = self.krate();
|
||||
for owner in krate.owners.iter().filter_map(Option::as_ref) {
|
||||
match owner {
|
||||
OwnerNode::Item(item) => visitor.visit_item(item),
|
||||
OwnerNode::ForeignItem(item) => visitor.visit_foreign_item(item),
|
||||
OwnerNode::ImplItem(item) => visitor.visit_impl_item(item),
|
||||
OwnerNode::TraitItem(item) => visitor.visit_trait_item(item),
|
||||
OwnerNode::Crate(_) => {}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// A parallel version of `visit_all_item_likes`.
|
||||
pub fn par_visit_all_item_likes<V>(&self, visitor: &V)
|
||||
where
|
||||
V: itemlikevisit::ParItemLikeVisitor<'hir> + Sync + Send,
|
||||
{
|
||||
let krate = self.krate();
|
||||
par_for_each_in(&krate.owners.raw, |owner| match owner.as_ref() {
|
||||
Some(OwnerNode::Item(item)) => visitor.visit_item(item),
|
||||
Some(OwnerNode::ForeignItem(item)) => visitor.visit_foreign_item(item),
|
||||
Some(OwnerNode::ImplItem(item)) => visitor.visit_impl_item(item),
|
||||
Some(OwnerNode::TraitItem(item)) => visitor.visit_trait_item(item),
|
||||
Some(OwnerNode::Crate(_)) | None => {}
|
||||
})
|
||||
}
|
||||
|
||||
pub fn visit_item_likes_in_module<V>(&self, module: LocalDefId, visitor: &mut V)
|
||||
where
|
||||
V: ItemLikeVisitor<'hir>,
|
||||
|
@ -29,10 +29,8 @@ use crate::ty::subst::{GenericArg, InternalSubsts, Subst, SubstsRef};
|
||||
use crate::ty::util::Discr;
|
||||
use rustc_ast as ast;
|
||||
use rustc_attr as attr;
|
||||
use rustc_data_structures::captures::Captures;
|
||||
use rustc_data_structures::fx::{FxHashMap, FxHashSet};
|
||||
use rustc_data_structures::stable_hasher::{HashStable, StableHasher};
|
||||
use rustc_data_structures::sync::{self, par_iter, ParallelIterator};
|
||||
use rustc_data_structures::tagged_ptr::CopyTaggedPtr;
|
||||
use rustc_hir as hir;
|
||||
use rustc_hir::def::{CtorKind, CtorOf, DefKind, Res};
|
||||
@ -1696,18 +1694,6 @@ impl<'tcx> TyCtxt<'tcx> {
|
||||
self.typeck(self.hir().body_owner_def_id(body))
|
||||
}
|
||||
|
||||
/// Returns an iterator of the `DefId`s for all body-owners in this
|
||||
/// crate. If you would prefer to iterate over the bodies
|
||||
/// themselves, you can do `self.hir().krate().body_ids.iter()`.
|
||||
pub fn body_owners(self) -> impl Iterator<Item = LocalDefId> + Captures<'tcx> + 'tcx {
|
||||
self.hir().krate().bodies.keys().map(move |&body_id| self.hir().body_owner_def_id(body_id))
|
||||
}
|
||||
|
||||
pub fn par_body_owners<F: Fn(LocalDefId) + sync::Sync + sync::Send>(self, f: F) {
|
||||
par_iter(&self.hir().krate().bodies)
|
||||
.for_each(|(&body_id, _)| f(self.hir().body_owner_def_id(body_id)));
|
||||
}
|
||||
|
||||
pub fn provided_trait_methods(self, id: DefId) -> impl 'tcx + Iterator<Item = &'tcx AssocItem> {
|
||||
self.associated_items(id)
|
||||
.in_definition_order()
|
||||
|
@ -2340,7 +2340,7 @@ define_print_and_forward_display! {
|
||||
fn for_each_def(tcx: TyCtxt<'_>, mut collect_fn: impl for<'b> FnMut(&'b Ident, Namespace, DefId)) {
|
||||
// Iterate all local crate items no matter where they are defined.
|
||||
let hir = tcx.hir();
|
||||
for item in hir.krate().items() {
|
||||
for item in hir.items() {
|
||||
if item.ident.name.as_str().is_empty() || matches!(item.kind, ItemKind::Use(_, _)) {
|
||||
continue;
|
||||
}
|
||||
|
@ -133,7 +133,7 @@ fn mir_keys(tcx: TyCtxt<'_>, (): ()) -> FxHashSet<LocalDefId> {
|
||||
let mut set = FxHashSet::default();
|
||||
|
||||
// All body-owners have MIR associated with them.
|
||||
set.extend(tcx.body_owners());
|
||||
set.extend(tcx.hir().body_owners());
|
||||
|
||||
// Additionally, tuple struct/variant constructors have MIR, but
|
||||
// they don't have a BodyId, so we need to build them separately.
|
||||
@ -160,9 +160,7 @@ fn mir_keys(tcx: TyCtxt<'_>, (): ()) -> FxHashSet<LocalDefId> {
|
||||
NestedVisitorMap::None
|
||||
}
|
||||
}
|
||||
tcx.hir()
|
||||
.krate()
|
||||
.visit_all_item_likes(&mut GatherCtors { tcx, set: &mut set }.as_deep_visitor());
|
||||
tcx.hir().visit_all_item_likes(&mut GatherCtors { tcx, set: &mut set }.as_deep_visitor());
|
||||
|
||||
set
|
||||
}
|
||||
|
@ -330,7 +330,7 @@ fn collect_roots(tcx: TyCtxt<'_>, mode: MonoItemCollectionMode) -> Vec<MonoItem<
|
||||
|
||||
let mut visitor = RootCollector { tcx, mode, entry_fn, output: &mut roots };
|
||||
|
||||
tcx.hir().krate().visit_all_item_likes(&mut visitor);
|
||||
tcx.hir().visit_all_item_likes(&mut visitor);
|
||||
|
||||
visitor.push_extra_entry_roots();
|
||||
}
|
||||
|
@ -510,15 +510,14 @@ fn has_allow_dead_code_or_lang_attr(tcx: TyCtxt<'_>, id: hir::HirId) -> bool {
|
||||
// or
|
||||
// 2) We are not sure to be live or not
|
||||
// * Implementations of traits and trait methods
|
||||
struct LifeSeeder<'k, 'tcx> {
|
||||
struct LifeSeeder<'tcx> {
|
||||
worklist: Vec<LocalDefId>,
|
||||
krate: &'k hir::Crate<'k>,
|
||||
tcx: TyCtxt<'tcx>,
|
||||
// see `MarkSymbolVisitor::struct_constructors`
|
||||
struct_constructors: FxHashMap<LocalDefId, LocalDefId>,
|
||||
}
|
||||
|
||||
impl<'v, 'k, 'tcx> ItemLikeVisitor<'v> for LifeSeeder<'k, 'tcx> {
|
||||
impl<'v, 'tcx> ItemLikeVisitor<'v> for LifeSeeder<'tcx> {
|
||||
fn visit_item(&mut self, item: &hir::Item<'_>) {
|
||||
let allow_dead_code = has_allow_dead_code_or_lang_attr(self.tcx, item.hir_id());
|
||||
if allow_dead_code {
|
||||
@ -545,7 +544,7 @@ impl<'v, 'k, 'tcx> ItemLikeVisitor<'v> for LifeSeeder<'k, 'tcx> {
|
||||
self.worklist.push(item.def_id);
|
||||
}
|
||||
for impl_item_ref in items {
|
||||
let impl_item = self.krate.impl_item(impl_item_ref.id);
|
||||
let impl_item = self.tcx.hir().impl_item(impl_item_ref.id);
|
||||
if of_trait.is_some()
|
||||
|| has_allow_dead_code_or_lang_attr(self.tcx, impl_item.hir_id())
|
||||
{
|
||||
@ -589,7 +588,6 @@ impl<'v, 'k, 'tcx> ItemLikeVisitor<'v> for LifeSeeder<'k, 'tcx> {
|
||||
fn create_and_seed_worklist<'tcx>(
|
||||
tcx: TyCtxt<'tcx>,
|
||||
access_levels: &privacy::AccessLevels,
|
||||
krate: &hir::Crate<'_>,
|
||||
) -> (Vec<LocalDefId>, FxHashMap<LocalDefId, LocalDefId>) {
|
||||
let worklist = access_levels
|
||||
.map
|
||||
@ -604,9 +602,8 @@ fn create_and_seed_worklist<'tcx>(
|
||||
.collect::<Vec<_>>();
|
||||
|
||||
// Seed implemented trait items
|
||||
let mut life_seeder =
|
||||
LifeSeeder { worklist, krate, tcx, struct_constructors: Default::default() };
|
||||
krate.visit_all_item_likes(&mut life_seeder);
|
||||
let mut life_seeder = LifeSeeder { worklist, tcx, struct_constructors: Default::default() };
|
||||
tcx.hir().visit_all_item_likes(&mut life_seeder);
|
||||
|
||||
(life_seeder.worklist, life_seeder.struct_constructors)
|
||||
}
|
||||
@ -614,9 +611,8 @@ fn create_and_seed_worklist<'tcx>(
|
||||
fn find_live<'tcx>(
|
||||
tcx: TyCtxt<'tcx>,
|
||||
access_levels: &privacy::AccessLevels,
|
||||
krate: &hir::Crate<'_>,
|
||||
) -> FxHashSet<LocalDefId> {
|
||||
let (worklist, struct_constructors) = create_and_seed_worklist(tcx, access_levels, krate);
|
||||
let (worklist, struct_constructors) = create_and_seed_worklist(tcx, access_levels);
|
||||
let mut symbol_visitor = MarkSymbolVisitor {
|
||||
worklist,
|
||||
tcx,
|
||||
@ -834,8 +830,7 @@ impl Visitor<'tcx> for DeadVisitor<'tcx> {
|
||||
|
||||
pub fn check_crate(tcx: TyCtxt<'_>) {
|
||||
let access_levels = &tcx.privacy_access_levels(());
|
||||
let krate = tcx.hir().krate();
|
||||
let live_symbols = find_live(tcx, access_levels, krate);
|
||||
let live_symbols = find_live(tcx, access_levels);
|
||||
let mut visitor = DeadVisitor { tcx, live_symbols };
|
||||
tcx.hir().walk_toplevel_module(&mut visitor);
|
||||
}
|
||||
|
@ -105,7 +105,7 @@ fn diagnostic_items<'tcx>(tcx: TyCtxt<'tcx>, cnum: CrateNum) -> FxHashMap<Symbol
|
||||
let mut collector = DiagnosticItemCollector::new(tcx);
|
||||
|
||||
// Collect diagnostic items in this crate.
|
||||
tcx.hir().krate().visit_all_item_likes(&mut collector);
|
||||
tcx.hir().visit_all_item_likes(&mut collector);
|
||||
|
||||
collector.items
|
||||
}
|
||||
|
@ -1,6 +1,6 @@
|
||||
use rustc_ast::entry::EntryPointType;
|
||||
use rustc_errors::struct_span_err;
|
||||
use rustc_hir::def_id::{DefId, CRATE_DEF_INDEX, LOCAL_CRATE};
|
||||
use rustc_hir::def_id::{DefId, CRATE_DEF_ID, CRATE_DEF_INDEX, LOCAL_CRATE};
|
||||
use rustc_hir::itemlikevisit::ItemLikeVisitor;
|
||||
use rustc_hir::{ForeignItem, HirId, ImplItem, Item, ItemKind, Node, TraitItem, CRATE_HIR_ID};
|
||||
use rustc_middle::hir::map::Map;
|
||||
@ -68,7 +68,7 @@ fn entry_fn(tcx: TyCtxt<'_>, (): ()) -> Option<(DefId, EntryFnType)> {
|
||||
non_main_fns: Vec::new(),
|
||||
};
|
||||
|
||||
tcx.hir().krate().visit_all_item_likes(&mut ctxt);
|
||||
tcx.hir().visit_all_item_likes(&mut ctxt);
|
||||
|
||||
configure_main(tcx, &ctxt)
|
||||
}
|
||||
@ -183,7 +183,7 @@ fn configure_main(tcx: TyCtxt<'_>, visitor: &EntryContext<'_, '_>) -> Option<(De
|
||||
}
|
||||
|
||||
fn no_main_err(tcx: TyCtxt<'_>, visitor: &EntryContext<'_, '_>) {
|
||||
let sp = tcx.hir().krate().module().inner;
|
||||
let sp = tcx.def_span(CRATE_DEF_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.
|
||||
|
@ -262,7 +262,7 @@ fn get_lang_items(tcx: TyCtxt<'_>, (): ()) -> LanguageItems {
|
||||
}
|
||||
|
||||
// Collect lang items in this crate.
|
||||
tcx.hir().krate().visit_all_item_likes(&mut collector);
|
||||
tcx.hir().visit_all_item_likes(&mut collector);
|
||||
|
||||
// Extract out the found lang items.
|
||||
let LanguageItemCollector { mut items, .. } = collector;
|
||||
|
@ -12,7 +12,7 @@ use rustc_target::abi::{HasDataLayout, TargetDataLayout};
|
||||
pub fn test_layout(tcx: TyCtxt<'_>) {
|
||||
if tcx.features().rustc_attrs {
|
||||
// if the `rustc_attrs` feature is not enabled, don't bother testing layout
|
||||
tcx.hir().krate().visit_all_item_likes(&mut LayoutTest { tcx });
|
||||
tcx.hir().visit_all_item_likes(&mut LayoutTest { tcx });
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -427,7 +427,7 @@ fn reachable_set<'tcx>(tcx: TyCtxt<'tcx>, (): ()) -> FxHashSet<LocalDefId> {
|
||||
access_levels,
|
||||
worklist: &mut reachable_context.worklist,
|
||||
};
|
||||
tcx.hir().krate().visit_all_item_likes(&mut collect_private_impl_items);
|
||||
tcx.hir().visit_all_item_likes(&mut collect_private_impl_items);
|
||||
}
|
||||
|
||||
// Step 2: Mark all symbols that the symbols on the worklist touch.
|
||||
|
@ -906,11 +906,10 @@ pub fn check_unused_or_stable_features(tcx: TyCtxt<'_>) {
|
||||
let access_levels = &tcx.privacy_access_levels(());
|
||||
|
||||
if tcx.stability().staged_api[&LOCAL_CRATE] {
|
||||
let krate = tcx.hir().krate();
|
||||
let mut missing = MissingStabilityAnnotations { tcx, access_levels };
|
||||
missing.check_missing_stability(CRATE_DEF_ID, tcx.hir().span(CRATE_HIR_ID));
|
||||
tcx.hir().walk_toplevel_module(&mut missing);
|
||||
krate.visit_all_item_likes(&mut missing.as_deep_visitor());
|
||||
tcx.hir().visit_all_item_likes(&mut missing.as_deep_visitor());
|
||||
}
|
||||
|
||||
let declared_lang_features = &tcx.features().declared_lang_features;
|
||||
|
@ -33,7 +33,7 @@ pub fn check_crate<'tcx>(tcx: TyCtxt<'tcx>, items: &mut lang_items::LanguageItem
|
||||
|
||||
{
|
||||
let mut cx = Context { tcx, items };
|
||||
tcx.hir().krate().visit_all_item_likes(&mut cx.as_deep_visitor());
|
||||
tcx.hir().visit_all_item_likes(&mut cx.as_deep_visitor());
|
||||
}
|
||||
verify(tcx, items);
|
||||
}
|
||||
|
@ -2189,8 +2189,6 @@ fn privacy_access_levels(tcx: TyCtxt<'_>, (): ()) -> &AccessLevels {
|
||||
fn check_private_in_public(tcx: TyCtxt<'_>, (): ()) {
|
||||
let access_levels = tcx.privacy_access_levels(());
|
||||
|
||||
let krate = tcx.hir().krate();
|
||||
|
||||
let mut visitor = ObsoleteVisiblePrivateTypesVisitor {
|
||||
tcx,
|
||||
access_levels: &access_levels,
|
||||
@ -2230,5 +2228,5 @@ fn check_private_in_public(tcx: TyCtxt<'_>, (): ()) {
|
||||
.filter_map(|hir_id| tcx.hir().opt_local_def_id(hir_id))
|
||||
.collect(),
|
||||
};
|
||||
krate.visit_all_item_likes(&mut DeepVisitor::new(&mut visitor));
|
||||
tcx.hir().visit_all_item_likes(&mut DeepVisitor::new(&mut visitor));
|
||||
}
|
||||
|
@ -18,7 +18,7 @@ use rustc_ast::walk_list;
|
||||
use rustc_data_structures::fx::FxHashSet;
|
||||
use rustc_hir as hir;
|
||||
use rustc_hir::def::{DefKind as HirDefKind, Res};
|
||||
use rustc_hir::def_id::{DefId, LocalDefId};
|
||||
use rustc_hir::def_id::{DefId, LocalDefId, CRATE_DEF_ID};
|
||||
use rustc_hir::intravisit::{self, Visitor};
|
||||
use rustc_hir_pretty::{bounds_to_string, fn_to_string, generic_params_to_string, ty_to_string};
|
||||
use rustc_middle::hir::map::Map;
|
||||
@ -128,7 +128,7 @@ impl<'tcx> DumpVisitor<'tcx> {
|
||||
self.save_ctxt.lookup_def_id(ref_id)
|
||||
}
|
||||
|
||||
pub fn dump_crate_info(&mut self, name: &str, krate: &hir::Crate<'_>) {
|
||||
pub fn dump_crate_info(&mut self, name: &str) {
|
||||
let source_file = self.tcx.sess.local_crate_source_file.as_ref();
|
||||
let crate_root = source_file.map(|source_file| {
|
||||
let source_file = Path::new(source_file);
|
||||
@ -146,7 +146,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.module().inner),
|
||||
span: self.span_from_span(self.tcx.def_span(CRATE_DEF_ID)),
|
||||
};
|
||||
|
||||
self.dumper.crate_prelude(data);
|
||||
@ -1090,13 +1090,13 @@ impl<'tcx> DumpVisitor<'tcx> {
|
||||
}
|
||||
}
|
||||
|
||||
pub(crate) fn process_crate(&mut self, krate: &'tcx hir::Crate<'tcx>) {
|
||||
pub(crate) fn process_crate(&mut self) {
|
||||
let id = hir::CRATE_HIR_ID;
|
||||
let qualname =
|
||||
format!("::{}", self.tcx.def_path_str(self.tcx.hir().local_def_id(id).to_def_id()));
|
||||
|
||||
let sm = self.tcx.sess.source_map();
|
||||
let krate_mod = krate.module();
|
||||
let krate_mod = self.tcx.hir().root_module();
|
||||
let filename = sm.span_to_filename(krate_mod.inner);
|
||||
let data_id = id_from_hir_id(id, &self.save_ctxt);
|
||||
let children =
|
||||
|
@ -1003,9 +1003,9 @@ pub fn process_crate<'l, 'tcx, H: SaveHandler>(
|
||||
|
||||
let mut visitor = DumpVisitor::new(save_ctxt);
|
||||
|
||||
visitor.dump_crate_info(cratename, tcx.hir().krate());
|
||||
visitor.dump_crate_info(cratename);
|
||||
visitor.dump_compilation_options(input, cratename);
|
||||
visitor.process_crate(tcx.hir().krate());
|
||||
visitor.process_crate();
|
||||
|
||||
handler.save(&visitor.save_ctxt, &visitor.analysis())
|
||||
})
|
||||
|
@ -23,7 +23,7 @@ pub fn report_symbol_names(tcx: TyCtxt<'_>) {
|
||||
|
||||
tcx.dep_graph.with_ignore(|| {
|
||||
let mut visitor = SymbolNamesTest { tcx };
|
||||
tcx.hir().krate().visit_all_item_likes(&mut visitor);
|
||||
tcx.hir().visit_all_item_likes(&mut visitor);
|
||||
})
|
||||
}
|
||||
|
||||
|
@ -31,7 +31,7 @@ use std::ops::ControlFlow;
|
||||
|
||||
pub fn check_wf_new(tcx: TyCtxt<'_>) {
|
||||
let visit = wfcheck::CheckTypeWellFormedVisitor::new(tcx);
|
||||
tcx.hir().krate().par_visit_all_item_likes(&visit);
|
||||
tcx.hir().par_visit_all_item_likes(&visit);
|
||||
}
|
||||
|
||||
pub(super) fn check_abi(tcx: TyCtxt<'_>, hir_id: hir::HirId, span: Span, abi: Abi) {
|
||||
|
@ -1646,7 +1646,7 @@ fn compute_all_traits(tcx: TyCtxt<'_>, (): ()) -> &[DefId] {
|
||||
fn visit_foreign_item(&mut self, _foreign_item: &hir::ForeignItem<'_>) {}
|
||||
}
|
||||
|
||||
tcx.hir().krate().visit_all_item_likes(&mut Visitor { traits: &mut traits });
|
||||
tcx.hir().visit_all_item_likes(&mut Visitor { traits: &mut traits });
|
||||
|
||||
// Cross-crate:
|
||||
|
||||
|
@ -921,9 +921,7 @@ impl ItemLikeVisitor<'tcx> for CheckItemTypesVisitor<'tcx> {
|
||||
}
|
||||
|
||||
fn typeck_item_bodies(tcx: TyCtxt<'_>, (): ()) {
|
||||
tcx.par_body_owners(|body_owner_def_id| {
|
||||
tcx.ensure().typeck(body_owner_def_id);
|
||||
});
|
||||
tcx.hir().par_body_owners(|body_owner_def_id| tcx.ensure().typeck(body_owner_def_id));
|
||||
}
|
||||
|
||||
fn fatally_break_rust(sess: &Session) {
|
||||
|
@ -9,14 +9,14 @@ use rustc_span::{Span, Symbol};
|
||||
|
||||
pub fn check_crate(tcx: TyCtxt<'_>) {
|
||||
let mut used_trait_imports = FxHashSet::default();
|
||||
for item_def_id in tcx.body_owners() {
|
||||
for item_def_id in tcx.hir().body_owners() {
|
||||
let imports = tcx.used_trait_imports(item_def_id);
|
||||
debug!("GatherVisitor: item_def_id={:?} with imports {:#?}", item_def_id, imports);
|
||||
used_trait_imports.extend(imports.iter());
|
||||
}
|
||||
|
||||
let mut visitor = CheckVisitor { tcx, used_trait_imports };
|
||||
tcx.hir().krate().visit_all_item_likes(&mut visitor);
|
||||
tcx.hir().visit_all_item_likes(&mut visitor);
|
||||
|
||||
unused_crates_lint(tcx);
|
||||
}
|
||||
@ -111,7 +111,7 @@ fn unused_crates_lint(tcx: TyCtxt<'_>) {
|
||||
|
||||
// Collect all the extern crates (in a reliable order).
|
||||
let mut crates_to_lint = vec![];
|
||||
tcx.hir().krate().visit_all_item_likes(&mut CollectExternCrateVisitor {
|
||||
tcx.hir().visit_all_item_likes(&mut CollectExternCrateVisitor {
|
||||
crates_to_lint: &mut crates_to_lint,
|
||||
});
|
||||
|
||||
|
@ -17,9 +17,8 @@ use rustc_span::Span;
|
||||
|
||||
/// On-demand query: yields a map containing all types mapped to their inherent impls.
|
||||
pub fn crate_inherent_impls(tcx: TyCtxt<'_>, (): ()) -> CrateInherentImpls {
|
||||
let krate = tcx.hir().krate();
|
||||
let mut collect = InherentCollect { tcx, impls_map: Default::default() };
|
||||
krate.visit_all_item_likes(&mut collect);
|
||||
tcx.hir().visit_all_item_likes(&mut collect);
|
||||
collect.impls_map
|
||||
}
|
||||
|
||||
|
@ -10,8 +10,7 @@ use smallvec::SmallVec;
|
||||
use std::collections::hash_map::Entry;
|
||||
|
||||
pub fn crate_inherent_impls_overlap_check(tcx: TyCtxt<'_>, (): ()) {
|
||||
let krate = tcx.hir().krate();
|
||||
krate.visit_all_item_likes(&mut InherentOverlapChecker { tcx });
|
||||
tcx.hir().visit_all_item_likes(&mut InherentOverlapChecker { tcx });
|
||||
}
|
||||
|
||||
struct InherentOverlapChecker<'tcx> {
|
||||
|
@ -10,7 +10,7 @@ use rustc_trait_selection::traits;
|
||||
|
||||
pub fn check(tcx: TyCtxt<'_>) {
|
||||
let mut orphan = OrphanChecker { tcx };
|
||||
tcx.hir().krate().visit_all_item_likes(&mut orphan);
|
||||
tcx.hir().visit_all_item_likes(&mut orphan);
|
||||
}
|
||||
|
||||
struct OrphanChecker<'tcx> {
|
||||
|
@ -9,7 +9,7 @@ use rustc_middle::ty::TyCtxt;
|
||||
|
||||
pub fn check(tcx: TyCtxt<'_>) {
|
||||
let mut unsafety = UnsafetyChecker { tcx };
|
||||
tcx.hir().krate().visit_all_item_likes(&mut unsafety);
|
||||
tcx.hir().visit_all_item_likes(&mut unsafety);
|
||||
}
|
||||
|
||||
struct UnsafetyChecker<'tcx> {
|
||||
|
@ -37,7 +37,7 @@ pub fn infer_predicates<'tcx>(
|
||||
};
|
||||
|
||||
// Visit all the crates and infer predicates
|
||||
tcx.hir().krate().visit_all_item_likes(&mut visitor);
|
||||
tcx.hir().visit_all_item_likes(&mut visitor);
|
||||
}
|
||||
|
||||
global_inferred_outlives
|
||||
|
@ -5,7 +5,7 @@ use rustc_middle::ty::TyCtxt;
|
||||
use rustc_span::symbol::sym;
|
||||
|
||||
pub fn test_inferred_outlives(tcx: TyCtxt<'_>) {
|
||||
tcx.hir().krate().visit_all_item_likes(&mut OutlivesTest { tcx });
|
||||
tcx.hir().visit_all_item_likes(&mut OutlivesTest { tcx });
|
||||
}
|
||||
|
||||
struct OutlivesTest<'tcx> {
|
||||
|
@ -62,7 +62,7 @@ pub fn add_constraints_from_crate<'a, 'tcx>(
|
||||
constraints: Vec::new(),
|
||||
};
|
||||
|
||||
tcx.hir().krate().visit_all_item_likes(&mut constraint_cx);
|
||||
tcx.hir().visit_all_item_likes(&mut constraint_cx);
|
||||
|
||||
constraint_cx
|
||||
}
|
||||
|
@ -79,7 +79,7 @@ pub fn determine_parameters_to_be_inferred<'a, 'tcx>(
|
||||
//
|
||||
// - https://rustc-dev-guide.rust-lang.org/query.html
|
||||
// - https://rustc-dev-guide.rust-lang.org/variance.html
|
||||
tcx.hir().krate().visit_all_item_likes(&mut terms_cx);
|
||||
tcx.hir().visit_all_item_likes(&mut terms_cx);
|
||||
|
||||
terms_cx
|
||||
}
|
||||
|
@ -5,7 +5,7 @@ use rustc_middle::ty::TyCtxt;
|
||||
use rustc_span::symbol::sym;
|
||||
|
||||
pub fn test_variance(tcx: TyCtxt<'_>) {
|
||||
tcx.hir().krate().visit_all_item_likes(&mut VarianceTest { tcx });
|
||||
tcx.hir().visit_all_item_likes(&mut VarianceTest { tcx });
|
||||
}
|
||||
|
||||
struct VarianceTest<'tcx> {
|
||||
|
@ -230,8 +230,7 @@ impl ExternalCrate {
|
||||
};
|
||||
if root.is_local() {
|
||||
tcx.hir()
|
||||
.krate()
|
||||
.module()
|
||||
.root_module()
|
||||
.item_ids
|
||||
.iter()
|
||||
.filter_map(|&id| {
|
||||
@ -297,8 +296,7 @@ impl ExternalCrate {
|
||||
|
||||
if root.is_local() {
|
||||
tcx.hir()
|
||||
.krate()
|
||||
.module()
|
||||
.root_module()
|
||||
.item_ids
|
||||
.iter()
|
||||
.filter_map(|&id| {
|
||||
|
@ -26,8 +26,7 @@ mod tests;
|
||||
crate fn krate(cx: &mut DocContext<'_>) -> Crate {
|
||||
use crate::visit_lib::LibEmbargoVisitor;
|
||||
|
||||
let krate = cx.tcx.hir().krate();
|
||||
let module = crate::visit_ast::RustdocVisitor::new(cx).visit(krate);
|
||||
let module = crate::visit_ast::RustdocVisitor::new(cx).visit();
|
||||
|
||||
let mut externs = Vec::new();
|
||||
for &cnum in cx.tcx.crates(()).iter() {
|
||||
|
@ -71,12 +71,12 @@ impl<'a, 'tcx> RustdocVisitor<'a, 'tcx> {
|
||||
self.exact_paths.entry(did).or_insert_with(|| def_id_to_path(tcx, did));
|
||||
}
|
||||
|
||||
crate fn visit(mut self, krate: &'tcx hir::Crate<'_>) -> Module<'tcx> {
|
||||
let span = krate.module().inner;
|
||||
crate fn visit(mut self) -> Module<'tcx> {
|
||||
let span = self.cx.tcx.def_span(CRATE_DEF_ID);
|
||||
let mut top_level_module = self.visit_mod_contents(
|
||||
&Spanned { span, node: hir::VisibilityKind::Public },
|
||||
hir::CRATE_HIR_ID,
|
||||
&krate.module(),
|
||||
self.cx.tcx.hir().root_module(),
|
||||
self.cx.tcx.crate_name(LOCAL_CRATE),
|
||||
);
|
||||
|
||||
|
@ -48,7 +48,6 @@ fn main() {
|
||||
pub struct CompilerCalls;
|
||||
|
||||
impl rustc_driver::Callbacks for CompilerCalls {
|
||||
|
||||
// In this callback we override the mir_borrowck query.
|
||||
fn config(&mut self, config: &mut Config) {
|
||||
assert!(config.override_queries.is_none());
|
||||
@ -64,12 +63,10 @@ impl rustc_driver::Callbacks for CompilerCalls {
|
||||
) -> Compilation {
|
||||
compiler.session().abort_if_errors();
|
||||
queries.global_ctxt().unwrap().peek_mut().enter(|tcx| {
|
||||
|
||||
// Collect definition ids of MIR bodies.
|
||||
let hir = tcx.hir();
|
||||
let krate = hir.krate();
|
||||
let mut visitor = HirVisitor { bodies: Vec::new() };
|
||||
krate.visit_all_item_likes(&mut visitor);
|
||||
hir.visit_all_item_likes(&mut visitor);
|
||||
|
||||
// Trigger borrow checking of all bodies.
|
||||
for def_id in visitor.bodies {
|
||||
|
@ -13,6 +13,7 @@ extern crate rustc_ast;
|
||||
use rustc_ast::attr;
|
||||
use rustc_driver::plugin::Registry;
|
||||
use rustc_lint::{LateContext, LateLintPass, LintContext, LintPass};
|
||||
use rustc_span::def_id::CRATE_DEF_ID;
|
||||
use rustc_span::symbol::Symbol;
|
||||
|
||||
macro_rules! fake_lint_pass {
|
||||
@ -26,13 +27,14 @@ macro_rules! fake_lint_pass {
|
||||
}
|
||||
|
||||
impl LateLintPass<'_> for $struct {
|
||||
fn check_crate(&mut self, cx: &LateContext, krate: &rustc_hir::Crate) {
|
||||
fn check_crate(&mut self, cx: &LateContext) {
|
||||
let attrs = cx.tcx.hir().attrs(rustc_hir::CRATE_HIR_ID);
|
||||
let span = cx.tcx.def_span(CRATE_DEF_ID);
|
||||
$(
|
||||
if !cx.sess().contains_name(attrs, $attr) {
|
||||
cx.lint(CRATE_NOT_OKAY, |lint| {
|
||||
let msg = format!("crate is not marked with #![{}]", $attr);
|
||||
lint.build(&msg).set_span(krate.module().inner).emit()
|
||||
lint.build(&msg).set_span(span).emit()
|
||||
});
|
||||
}
|
||||
)*
|
||||
|
@ -8,13 +8,13 @@ extern crate rustc_hir;
|
||||
extern crate rustc_lint;
|
||||
#[macro_use]
|
||||
extern crate rustc_session;
|
||||
extern crate rustc_span;
|
||||
extern crate rustc_ast;
|
||||
extern crate rustc_span;
|
||||
|
||||
use rustc_driver::plugin::Registry;
|
||||
use rustc_lint::{LateContext, LateLintPass, LintArray, LintContext, LintPass};
|
||||
use rustc_lint::{LateContext, LateLintPass, LintContext};
|
||||
use rustc_span::def_id::CRATE_DEF_ID;
|
||||
use rustc_span::symbol::Symbol;
|
||||
use rustc_ast::attr;
|
||||
|
||||
declare_lint! {
|
||||
CRATE_NOT_OKAY,
|
||||
@ -25,13 +25,12 @@ declare_lint! {
|
||||
declare_lint_pass!(Pass => [CRATE_NOT_OKAY]);
|
||||
|
||||
impl<'tcx> LateLintPass<'tcx> for Pass {
|
||||
fn check_crate(&mut self, cx: &LateContext, krate: &rustc_hir::Crate) {
|
||||
fn check_crate(&mut self, cx: &LateContext) {
|
||||
let attrs = cx.tcx.hir().attrs(rustc_hir::CRATE_HIR_ID);
|
||||
let span = cx.tcx.def_span(CRATE_DEF_ID);
|
||||
if !cx.sess().contains_name(attrs, Symbol::intern("crate_okay")) {
|
||||
cx.lint(CRATE_NOT_OKAY, |lint| {
|
||||
lint.build("crate is not marked with #![crate_okay]")
|
||||
.set_span(krate.module().inner)
|
||||
.emit()
|
||||
lint.build("crate is not marked with #![crate_okay]").set_span(span).emit()
|
||||
});
|
||||
}
|
||||
}
|
||||
|
@ -23,7 +23,13 @@ LL | pub fn foo() {}
|
||||
|
||||
error: requires `sized` lang_item
|
||||
|
||||
error: aborting due to 3 previous errors
|
||||
error: requires `sized` lang_item
|
||||
|
||||
error: requires `sized` lang_item
|
||||
|
||||
error: requires `sized` lang_item
|
||||
|
||||
error: aborting due to 6 previous errors
|
||||
|
||||
Some errors have detailed explanations: E0432, E0603.
|
||||
For more information about an error, try `rustc --explain E0432`.
|
||||
|
@ -6,6 +6,12 @@ LL | use bar::gpriv;
|
||||
|
||||
error: requires `sized` lang_item
|
||||
|
||||
error: aborting due to 2 previous errors
|
||||
error: requires `sized` lang_item
|
||||
|
||||
error: requires `sized` lang_item
|
||||
|
||||
error: requires `sized` lang_item
|
||||
|
||||
error: aborting due to 5 previous errors
|
||||
|
||||
For more information about this error, try `rustc --explain E0432`.
|
||||
|
@ -1,7 +1,7 @@
|
||||
//! lint on missing cargo common metadata
|
||||
|
||||
use clippy_utils::{diagnostics::span_lint, is_lint_allowed};
|
||||
use rustc_hir::{hir_id::CRATE_HIR_ID, Crate};
|
||||
use rustc_hir::hir_id::CRATE_HIR_ID;
|
||||
use rustc_lint::{LateContext, LateLintPass};
|
||||
use rustc_session::{declare_tool_lint, impl_lint_pass};
|
||||
use rustc_span::source_map::DUMMY_SP;
|
||||
@ -77,7 +77,7 @@ fn is_empty_vec(value: &[String]) -> bool {
|
||||
}
|
||||
|
||||
impl LateLintPass<'_> for CargoCommonMetadata {
|
||||
fn check_crate(&mut self, cx: &LateContext<'_>, _: &Crate<'_>) {
|
||||
fn check_crate(&mut self, cx: &LateContext<'_>) {
|
||||
if is_lint_allowed(cx, CARGO_COMMON_METADATA, CRATE_HIR_ID) {
|
||||
return;
|
||||
}
|
||||
|
@ -1,7 +1,7 @@
|
||||
use clippy_utils::diagnostics::span_lint_and_then;
|
||||
use clippy_utils::fn_def_id;
|
||||
|
||||
use rustc_hir::{def::Res, def_id::DefIdMap, Crate, Expr};
|
||||
use rustc_hir::{def::Res, def_id::DefIdMap, Expr};
|
||||
use rustc_lint::{LateContext, LateLintPass};
|
||||
use rustc_session::{declare_tool_lint, impl_lint_pass};
|
||||
|
||||
@ -70,7 +70,7 @@ impl DisallowedMethod {
|
||||
impl_lint_pass!(DisallowedMethod => [DISALLOWED_METHOD]);
|
||||
|
||||
impl<'tcx> LateLintPass<'tcx> for DisallowedMethod {
|
||||
fn check_crate(&mut self, cx: &LateContext<'_>, _: &Crate<'_>) {
|
||||
fn check_crate(&mut self, cx: &LateContext<'_>) {
|
||||
for conf in &self.conf_disallowed {
|
||||
let (path, reason) = match conf {
|
||||
conf::DisallowedMethod::Simple(path) => (path, None),
|
||||
|
@ -2,7 +2,7 @@ use clippy_utils::diagnostics::span_lint;
|
||||
|
||||
use rustc_data_structures::fx::FxHashSet;
|
||||
use rustc_hir::{
|
||||
def::Res, def_id::DefId, Crate, Item, ItemKind, PolyTraitRef, PrimTy, TraitBoundModifier, Ty, TyKind, UseKind,
|
||||
def::Res, def_id::DefId, Item, ItemKind, PolyTraitRef, PrimTy, TraitBoundModifier, Ty, TyKind, UseKind,
|
||||
};
|
||||
use rustc_lint::{LateContext, LateLintPass};
|
||||
use rustc_session::{declare_tool_lint, impl_lint_pass};
|
||||
@ -75,7 +75,7 @@ impl DisallowedType {
|
||||
impl_lint_pass!(DisallowedType => [DISALLOWED_TYPE]);
|
||||
|
||||
impl<'tcx> LateLintPass<'tcx> for DisallowedType {
|
||||
fn check_crate(&mut self, cx: &LateContext<'_>, _: &Crate<'_>) {
|
||||
fn check_crate(&mut self, cx: &LateContext<'_>) {
|
||||
for path in &self.disallowed {
|
||||
let segs = path.iter().map(ToString::to_string).collect::<Vec<_>>();
|
||||
match clippy_utils::path_to_res(cx, &segs.iter().map(String::as_str).collect::<Vec<_>>()) {
|
||||
|
@ -212,7 +212,7 @@ impl_lint_pass!(DocMarkdown =>
|
||||
);
|
||||
|
||||
impl<'tcx> LateLintPass<'tcx> for DocMarkdown {
|
||||
fn check_crate(&mut self, cx: &LateContext<'tcx>, _: &'tcx hir::Crate<'_>) {
|
||||
fn check_crate(&mut self, cx: &LateContext<'tcx>) {
|
||||
let attrs = cx.tcx.hir().attrs(hir::CRATE_HIR_ID);
|
||||
check_attrs(cx, &self.valid_idents, attrs);
|
||||
}
|
||||
|
@ -1,6 +1,6 @@
|
||||
use clippy_utils::diagnostics::span_lint_and_help;
|
||||
use clippy_utils::{diagnostics::span_lint, is_lint_allowed};
|
||||
use rustc_hir::{Crate, CRATE_HIR_ID};
|
||||
use rustc_hir::CRATE_HIR_ID;
|
||||
use rustc_lint::{LateContext, LateLintPass};
|
||||
use rustc_session::{declare_lint_pass, declare_tool_lint};
|
||||
use rustc_span::source_map::DUMMY_SP;
|
||||
@ -110,7 +110,7 @@ fn lint(cx: &LateContext<'_>, feature: &str, substring: &str, is_prefix: bool) {
|
||||
}
|
||||
|
||||
impl LateLintPass<'_> for FeatureName {
|
||||
fn check_crate(&mut self, cx: &LateContext<'_>, _: &Crate<'_>) {
|
||||
fn check_crate(&mut self, cx: &LateContext<'_>) {
|
||||
if is_lint_allowed(cx, REDUNDANT_FEATURE_NAMES, CRATE_HIR_ID)
|
||||
&& is_lint_allowed(cx, NEGATIVE_FEATURE_NAMES, CRATE_HIR_ID)
|
||||
{
|
||||
|
@ -3,7 +3,7 @@
|
||||
use clippy_utils::diagnostics::span_lint_and_note;
|
||||
use clippy_utils::{in_macro, is_lint_allowed};
|
||||
use rustc_data_structures::fx::FxHashMap;
|
||||
use rustc_hir::{def_id::LocalDefId, Crate, Item, ItemKind, Node};
|
||||
use rustc_hir::{def_id::LocalDefId, Item, ItemKind, Node};
|
||||
use rustc_lint::{LateContext, LateLintPass};
|
||||
use rustc_session::{declare_lint_pass, declare_tool_lint};
|
||||
use rustc_span::Span;
|
||||
@ -44,7 +44,7 @@ declare_clippy_lint! {
|
||||
declare_lint_pass!(MultipleInherentImpl => [MULTIPLE_INHERENT_IMPL]);
|
||||
|
||||
impl<'tcx> LateLintPass<'tcx> for MultipleInherentImpl {
|
||||
fn check_crate_post(&mut self, cx: &LateContext<'tcx>, _: &'tcx Crate<'_>) {
|
||||
fn check_crate_post(&mut self, cx: &LateContext<'tcx>) {
|
||||
// Map from a type to it's first impl block. Needed to distinguish generic arguments.
|
||||
// e.g. `Foo<Bar>` and `Foo<Baz>`
|
||||
let mut type_map = FxHashMap::default();
|
||||
|
@ -135,7 +135,7 @@ impl<'tcx> LateLintPass<'tcx> for MacroUseImports {
|
||||
}
|
||||
}
|
||||
#[allow(clippy::too_many_lines)]
|
||||
fn check_crate_post(&mut self, cx: &LateContext<'_>, _krate: &hir::Crate<'_>) {
|
||||
fn check_crate_post(&mut self, cx: &LateContext<'_>) {
|
||||
let mut used = FxHashMap::default();
|
||||
let mut check_dup = vec![];
|
||||
for (import, span) in &self.imports {
|
||||
|
@ -2,7 +2,7 @@ use clippy_utils::diagnostics::span_lint_and_help;
|
||||
use clippy_utils::source::snippet;
|
||||
use clippy_utils::{is_entrypoint_fn, is_no_std_crate};
|
||||
use if_chain::if_chain;
|
||||
use rustc_hir::{Crate, Expr, ExprKind, QPath};
|
||||
use rustc_hir::{Expr, ExprKind, QPath};
|
||||
use rustc_lint::{LateContext, LateLintPass};
|
||||
use rustc_session::{declare_tool_lint, impl_lint_pass};
|
||||
|
||||
@ -33,7 +33,7 @@ pub struct MainRecursion {
|
||||
impl_lint_pass!(MainRecursion => [MAIN_RECURSION]);
|
||||
|
||||
impl LateLintPass<'_> for MainRecursion {
|
||||
fn check_crate(&mut self, cx: &LateContext<'_>, _: &Crate<'_>) {
|
||||
fn check_crate(&mut self, cx: &LateContext<'_>) {
|
||||
self.has_no_std_attr = is_no_std_crate(cx);
|
||||
}
|
||||
|
||||
|
@ -12,6 +12,7 @@ use rustc_hir as hir;
|
||||
use rustc_lint::{LateContext, LateLintPass, LintContext};
|
||||
use rustc_middle::ty;
|
||||
use rustc_session::{declare_tool_lint, impl_lint_pass};
|
||||
use rustc_span::def_id::CRATE_DEF_ID;
|
||||
use rustc_span::source_map::Span;
|
||||
use rustc_span::sym;
|
||||
|
||||
@ -78,9 +79,7 @@ impl MissingDoc {
|
||||
return;
|
||||
}
|
||||
|
||||
let has_doc = attrs
|
||||
.iter()
|
||||
.any(|a| a.doc_str().is_some());
|
||||
let has_doc = attrs.iter().any(|a| a.doc_str().is_some());
|
||||
if !has_doc {
|
||||
span_lint(
|
||||
cx,
|
||||
@ -104,9 +103,9 @@ impl<'tcx> LateLintPass<'tcx> for MissingDoc {
|
||||
self.doc_hidden_stack.pop().expect("empty doc_hidden_stack");
|
||||
}
|
||||
|
||||
fn check_crate(&mut self, cx: &LateContext<'tcx>, krate: &'tcx hir::Crate<'_>) {
|
||||
fn check_crate(&mut self, cx: &LateContext<'tcx>) {
|
||||
let attrs = cx.tcx.hir().attrs(hir::CRATE_HIR_ID);
|
||||
self.check_missing_docs_attrs(cx, attrs, krate.module().inner, "the", "crate");
|
||||
self.check_missing_docs_attrs(cx, attrs, cx.tcx.def_span(CRATE_DEF_ID), "the", "crate");
|
||||
}
|
||||
|
||||
fn check_item(&mut self, cx: &LateContext<'tcx>, it: &'tcx hir::Item<'_>) {
|
||||
|
@ -2,7 +2,7 @@ use clippy_utils::{diagnostics::span_lint_and_sugg, source::snippet_opt};
|
||||
|
||||
use rustc_data_structures::fx::FxHashMap;
|
||||
use rustc_errors::Applicability;
|
||||
use rustc_hir::{def::Res, def_id::DefId, Crate, Item, ItemKind, UseKind};
|
||||
use rustc_hir::{def::Res, def_id::DefId, Item, ItemKind, UseKind};
|
||||
use rustc_lint::{LateContext, LateLintPass, LintContext};
|
||||
use rustc_session::{declare_tool_lint, impl_lint_pass};
|
||||
use rustc_span::Symbol;
|
||||
@ -55,7 +55,7 @@ impl ImportRename {
|
||||
impl_lint_pass!(ImportRename => [MISSING_ENFORCED_IMPORT_RENAMES]);
|
||||
|
||||
impl LateLintPass<'_> for ImportRename {
|
||||
fn check_crate(&mut self, cx: &LateContext<'_>, _: &Crate<'_>) {
|
||||
fn check_crate(&mut self, cx: &LateContext<'_>) {
|
||||
for Rename { path, rename } in &self.conf_renames {
|
||||
if let Res::Def(_, id) = clippy_utils::path_to_res(cx, &path.split("::").collect::<Vec<_>>()) {
|
||||
self.renames.insert(id, Symbol::intern(rename));
|
||||
|
@ -3,7 +3,7 @@
|
||||
use clippy_utils::diagnostics::span_lint;
|
||||
use clippy_utils::is_lint_allowed;
|
||||
use rustc_hir::def_id::LOCAL_CRATE;
|
||||
use rustc_hir::{Crate, CRATE_HIR_ID};
|
||||
use rustc_hir::CRATE_HIR_ID;
|
||||
use rustc_lint::{LateContext, LateLintPass};
|
||||
use rustc_session::{declare_lint_pass, declare_tool_lint};
|
||||
use rustc_span::source_map::DUMMY_SP;
|
||||
@ -41,7 +41,7 @@ declare_clippy_lint! {
|
||||
declare_lint_pass!(MultipleCrateVersions => [MULTIPLE_CRATE_VERSIONS]);
|
||||
|
||||
impl LateLintPass<'_> for MultipleCrateVersions {
|
||||
fn check_crate(&mut self, cx: &LateContext<'_>, _: &Crate<'_>) {
|
||||
fn check_crate(&mut self, cx: &LateContext<'_>) {
|
||||
if is_lint_allowed(cx, MULTIPLE_CRATE_VERSIONS, CRATE_HIR_ID) {
|
||||
return;
|
||||
}
|
||||
|
@ -1,7 +1,7 @@
|
||||
use clippy_utils::diagnostics::span_lint_and_then;
|
||||
use rustc_data_structures::fx::FxHashMap;
|
||||
use rustc_hir::def::{DefKind, Res};
|
||||
use rustc_hir::{Crate, Impl, ItemKind, Node, Path, QPath, TraitRef, TyKind};
|
||||
use rustc_hir::{Impl, ItemKind, Node, Path, QPath, TraitRef, TyKind};
|
||||
use rustc_lint::{LateContext, LateLintPass};
|
||||
use rustc_middle::ty::AssocKind;
|
||||
use rustc_session::{declare_lint_pass, declare_tool_lint};
|
||||
@ -46,10 +46,10 @@ struct ExistingName {
|
||||
}
|
||||
|
||||
impl<'tcx> LateLintPass<'tcx> for SameNameMethod {
|
||||
fn check_crate_post(&mut self, cx: &LateContext<'tcx>, krate: &'tcx Crate<'tcx>) {
|
||||
fn check_crate_post(&mut self, cx: &LateContext<'tcx>) {
|
||||
let mut map = FxHashMap::<Res, ExistingName>::default();
|
||||
|
||||
for item in krate.items() {
|
||||
for item in cx.tcx.hir().items() {
|
||||
if let ItemKind::Impl(Impl {
|
||||
items,
|
||||
of_trait,
|
||||
|
@ -1,5 +1,5 @@
|
||||
use clippy_utils::{diagnostics::span_lint, is_lint_allowed};
|
||||
use rustc_hir::{hir_id::CRATE_HIR_ID, Crate};
|
||||
use rustc_hir::hir_id::CRATE_HIR_ID;
|
||||
use rustc_lint::{LateContext, LateLintPass};
|
||||
use rustc_session::{declare_lint_pass, declare_tool_lint};
|
||||
use rustc_span::source_map::DUMMY_SP;
|
||||
@ -28,7 +28,7 @@ declare_clippy_lint! {
|
||||
declare_lint_pass!(WildcardDependencies => [WILDCARD_DEPENDENCIES]);
|
||||
|
||||
impl LateLintPass<'_> for WildcardDependencies {
|
||||
fn check_crate(&mut self, cx: &LateContext<'_>, _: &Crate<'_>) {
|
||||
fn check_crate(&mut self, cx: &LateContext<'_>) {
|
||||
if is_lint_allowed(cx, WILDCARD_DEPENDENCIES, CRATE_HIR_ID) {
|
||||
return;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user