Do not pass hir::Crate to lints.
This commit is contained in:
parent
abc57f63ad
commit
faa7d4221b
17 changed files with 32 additions and 33 deletions
|
@ -584,7 +584,7 @@ impl<'tcx> LateLintPass<'tcx> for MissingDoc {
|
|||
self.doc_hidden_stack.pop().expect("empty doc_hidden_stack");
|
||||
}
|
||||
|
||||
fn check_crate(&mut self, cx: &LateContext<'_>, _: &hir::Crate<'_>) {
|
||||
fn check_crate(&mut self, cx: &LateContext<'_>) {
|
||||
self.check_missing_docs_attrs(
|
||||
cx,
|
||||
CRATE_DEF_ID,
|
||||
|
|
|
@ -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>);
|
||||
|
|
|
@ -164,7 +164,7 @@ impl<'hir> Map<'hir> {
|
|||
}
|
||||
}
|
||||
|
||||
crate fn items(&self) -> impl Iterator<Item = &'hir Item<'hir>> + 'hir {
|
||||
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),
|
||||
|
|
|
@ -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;
|
||||
|
||||
|
@ -102,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>, _: &'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, cx.tcx.hir().root_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…
Add table
Reference in a new issue