Auto merge of #6789 - flip1995:rustup, r=flip1995
Rustup r? `@ghost` changelog: None
This commit is contained in:
commit
928e72dd10
@ -38,7 +38,7 @@ impl<'tcx> LateLintPass<'tcx> for CopyIterator {
|
||||
..
|
||||
}) = item.kind
|
||||
{
|
||||
let ty = cx.tcx.type_of(cx.tcx.hir().local_def_id(item.hir_id));
|
||||
let ty = cx.tcx.type_of(item.def_id);
|
||||
|
||||
if is_copy(cx, ty) && match_path(&trait_ref.path, &paths::ITERATOR) {
|
||||
span_lint_and_note(
|
||||
|
@ -169,7 +169,7 @@ impl<'tcx> LateLintPass<'tcx> for Derive {
|
||||
..
|
||||
}) = item.kind
|
||||
{
|
||||
let ty = cx.tcx.type_of(cx.tcx.hir().local_def_id(item.hir_id));
|
||||
let ty = cx.tcx.type_of(item.def_id);
|
||||
let is_automatically_derived = is_automatically_derived(&*item.attrs);
|
||||
|
||||
check_hash_peq(cx, item.span, trait_ref, ty, is_automatically_derived);
|
||||
|
@ -216,18 +216,23 @@ impl<'tcx> LateLintPass<'tcx> for DocMarkdown {
|
||||
let headers = check_attrs(cx, &self.valid_idents, &item.attrs);
|
||||
match item.kind {
|
||||
hir::ItemKind::Fn(ref sig, _, body_id) => {
|
||||
if !(is_entrypoint_fn(cx, cx.tcx.hir().local_def_id(item.hir_id).to_def_id())
|
||||
|| in_external_macro(cx.tcx.sess, item.span))
|
||||
{
|
||||
if !(is_entrypoint_fn(cx, item.def_id.to_def_id()) || in_external_macro(cx.tcx.sess, item.span)) {
|
||||
let body = cx.tcx.hir().body(body_id);
|
||||
let impl_item_def_id = cx.tcx.hir().local_def_id(item.hir_id);
|
||||
let mut fpu = FindPanicUnwrap {
|
||||
cx,
|
||||
typeck_results: cx.tcx.typeck(impl_item_def_id),
|
||||
typeck_results: cx.tcx.typeck(item.def_id),
|
||||
panic_span: None,
|
||||
};
|
||||
fpu.visit_expr(&body.value);
|
||||
lint_for_missing_headers(cx, item.hir_id, item.span, sig, headers, Some(body_id), fpu.panic_span);
|
||||
lint_for_missing_headers(
|
||||
cx,
|
||||
item.hir_id(),
|
||||
item.span,
|
||||
sig,
|
||||
headers,
|
||||
Some(body_id),
|
||||
fpu.panic_span,
|
||||
);
|
||||
}
|
||||
},
|
||||
hir::ItemKind::Impl(ref impl_) => {
|
||||
@ -247,7 +252,7 @@ impl<'tcx> LateLintPass<'tcx> for DocMarkdown {
|
||||
let headers = check_attrs(cx, &self.valid_idents, &item.attrs);
|
||||
if let hir::TraitItemKind::Fn(ref sig, ..) = item.kind {
|
||||
if !in_external_macro(cx.tcx.sess, item.span) {
|
||||
lint_for_missing_headers(cx, item.hir_id, item.span, sig, headers, None, None);
|
||||
lint_for_missing_headers(cx, item.hir_id(), item.span, sig, headers, None, None);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -259,14 +264,21 @@ impl<'tcx> LateLintPass<'tcx> for DocMarkdown {
|
||||
}
|
||||
if let hir::ImplItemKind::Fn(ref sig, body_id) = item.kind {
|
||||
let body = cx.tcx.hir().body(body_id);
|
||||
let impl_item_def_id = cx.tcx.hir().local_def_id(item.hir_id);
|
||||
let mut fpu = FindPanicUnwrap {
|
||||
cx,
|
||||
typeck_results: cx.tcx.typeck(impl_item_def_id),
|
||||
typeck_results: cx.tcx.typeck(item.def_id),
|
||||
panic_span: None,
|
||||
};
|
||||
fpu.visit_expr(&body.value);
|
||||
lint_for_missing_headers(cx, item.hir_id, item.span, sig, headers, Some(body_id), fpu.panic_span);
|
||||
lint_for_missing_headers(
|
||||
cx,
|
||||
item.hir_id(),
|
||||
item.span,
|
||||
sig,
|
||||
headers,
|
||||
Some(body_id),
|
||||
fpu.panic_span,
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -49,9 +49,8 @@ impl<'tcx> LateLintPass<'tcx> for EmptyEnum {
|
||||
return;
|
||||
}
|
||||
|
||||
let did = cx.tcx.hir().local_def_id(item.hir_id);
|
||||
if let ItemKind::Enum(..) = item.kind {
|
||||
let ty = cx.tcx.type_of(did);
|
||||
let ty = cx.tcx.type_of(item.def_id);
|
||||
let adt = ty.ty_adt_def().expect("already checked whether this is an enum");
|
||||
if adt.variants.is_empty() {
|
||||
span_lint_and_help(
|
||||
|
@ -87,11 +87,11 @@ impl<'tcx> LateLintPass<'tcx> for BoxedLocal {
|
||||
// find `self` ty for this trait if relevant
|
||||
if let ItemKind::Trait(_, _, _, _, items) = item.kind {
|
||||
for trait_item in items {
|
||||
if trait_item.id.hir_id == hir_id {
|
||||
if trait_item.id.hir_id() == hir_id {
|
||||
// be sure we have `self` parameter in this function
|
||||
if let AssocItemKind::Fn { has_self: true } = trait_item.kind {
|
||||
trait_self_ty =
|
||||
Some(TraitRef::identity(cx.tcx, trait_item.id.hir_id.owner.to_def_id()).self_ty());
|
||||
Some(TraitRef::identity(cx.tcx, trait_item.id.def_id.to_def_id()).self_ty());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -72,7 +72,7 @@ impl LateLintPass<'_> for ExhaustiveItems {
|
||||
fn check_item(&mut self, cx: &LateContext<'_>, item: &Item<'_>) {
|
||||
if_chain! {
|
||||
if let ItemKind::Enum(..) | ItemKind::Struct(..) = item.kind;
|
||||
if cx.access_levels.is_exported(item.hir_id);
|
||||
if cx.access_levels.is_exported(item.hir_id());
|
||||
if !item.attrs.iter().any(|a| a.has_name(sym::non_exhaustive));
|
||||
then {
|
||||
let (lint, msg) = if let ItemKind::Struct(ref v, ..) = item.kind {
|
||||
|
@ -52,10 +52,9 @@ declare_lint_pass!(FallibleImplFrom => [FALLIBLE_IMPL_FROM]);
|
||||
impl<'tcx> LateLintPass<'tcx> for FallibleImplFrom {
|
||||
fn check_item(&mut self, cx: &LateContext<'tcx>, item: &'tcx hir::Item<'_>) {
|
||||
// check for `impl From<???> for ..`
|
||||
let impl_def_id = cx.tcx.hir().local_def_id(item.hir_id);
|
||||
if_chain! {
|
||||
if let hir::ItemKind::Impl(impl_) = &item.kind;
|
||||
if let Some(impl_trait_ref) = cx.tcx.impl_trait_ref(impl_def_id);
|
||||
if let Some(impl_trait_ref) = cx.tcx.impl_trait_ref(item.def_id);
|
||||
if cx.tcx.is_diagnostic_item(sym::from_trait, impl_trait_ref.def_id);
|
||||
then {
|
||||
lint_impl_body(cx, item.span, impl_.items);
|
||||
@ -117,10 +116,9 @@ fn lint_impl_body<'tcx>(cx: &LateContext<'tcx>, impl_span: Span, impl_items: &[h
|
||||
then {
|
||||
// check the body for `begin_panic` or `unwrap`
|
||||
let body = cx.tcx.hir().body(body_id);
|
||||
let impl_item_def_id = cx.tcx.hir().local_def_id(impl_item.id.hir_id);
|
||||
let mut fpu = FindPanicUnwrap {
|
||||
lcx: cx,
|
||||
typeck_results: cx.tcx.typeck(impl_item_def_id),
|
||||
typeck_results: cx.tcx.typeck(impl_item.id.def_id),
|
||||
result: Vec::new(),
|
||||
};
|
||||
fpu.visit_expr(&body.value);
|
||||
|
@ -60,10 +60,9 @@ impl LateLintPass<'_> for FromOverInto {
|
||||
return;
|
||||
}
|
||||
|
||||
let impl_def_id = cx.tcx.hir().local_def_id(item.hir_id);
|
||||
if_chain! {
|
||||
if let hir::ItemKind::Impl{ .. } = &item.kind;
|
||||
if let Some(impl_trait_ref) = cx.tcx.impl_trait_ref(impl_def_id);
|
||||
if let Some(impl_trait_ref) = cx.tcx.impl_trait_ref(item.def_id);
|
||||
if match_def_path(cx, impl_trait_ref.def_id, &INTO);
|
||||
|
||||
then {
|
||||
|
@ -283,13 +283,13 @@ impl<'tcx> LateLintPass<'tcx> for Functions {
|
||||
fn check_item(&mut self, cx: &LateContext<'tcx>, item: &'tcx hir::Item<'_>) {
|
||||
let attr = must_use_attr(&item.attrs);
|
||||
if let hir::ItemKind::Fn(ref sig, ref _generics, ref body_id) = item.kind {
|
||||
let is_public = cx.access_levels.is_exported(item.hir_id);
|
||||
let is_public = cx.access_levels.is_exported(item.hir_id());
|
||||
let fn_header_span = item.span.with_hi(sig.decl.output.span().hi());
|
||||
if is_public {
|
||||
check_result_unit_err(cx, &sig.decl, item.span, fn_header_span);
|
||||
}
|
||||
if let Some(attr) = attr {
|
||||
check_needless_must_use(cx, &sig.decl, item.hir_id, item.span, fn_header_span, attr);
|
||||
check_needless_must_use(cx, &sig.decl, item.hir_id(), item.span, fn_header_span, attr);
|
||||
return;
|
||||
}
|
||||
if is_public && !is_proc_macro(cx.sess(), &item.attrs) && attr_by_name(&item.attrs, "no_mangle").is_none() {
|
||||
@ -298,7 +298,7 @@ impl<'tcx> LateLintPass<'tcx> for Functions {
|
||||
&sig.decl,
|
||||
cx.tcx.hir().body(*body_id),
|
||||
item.span,
|
||||
item.hir_id,
|
||||
item.hir_id(),
|
||||
item.span.with_hi(sig.decl.output.span().hi()),
|
||||
"this function could have a `#[must_use]` attribute",
|
||||
);
|
||||
@ -308,24 +308,24 @@ impl<'tcx> LateLintPass<'tcx> for Functions {
|
||||
|
||||
fn check_impl_item(&mut self, cx: &LateContext<'tcx>, item: &'tcx hir::ImplItem<'_>) {
|
||||
if let hir::ImplItemKind::Fn(ref sig, ref body_id) = item.kind {
|
||||
let is_public = cx.access_levels.is_exported(item.hir_id);
|
||||
let is_public = cx.access_levels.is_exported(item.hir_id());
|
||||
let fn_header_span = item.span.with_hi(sig.decl.output.span().hi());
|
||||
if is_public && trait_ref_of_method(cx, item.hir_id).is_none() {
|
||||
if is_public && trait_ref_of_method(cx, item.hir_id()).is_none() {
|
||||
check_result_unit_err(cx, &sig.decl, item.span, fn_header_span);
|
||||
}
|
||||
let attr = must_use_attr(&item.attrs);
|
||||
if let Some(attr) = attr {
|
||||
check_needless_must_use(cx, &sig.decl, item.hir_id, item.span, fn_header_span, attr);
|
||||
check_needless_must_use(cx, &sig.decl, item.hir_id(), item.span, fn_header_span, attr);
|
||||
} else if is_public
|
||||
&& !is_proc_macro(cx.sess(), &item.attrs)
|
||||
&& trait_ref_of_method(cx, item.hir_id).is_none()
|
||||
&& trait_ref_of_method(cx, item.hir_id()).is_none()
|
||||
{
|
||||
check_must_use_candidate(
|
||||
cx,
|
||||
&sig.decl,
|
||||
cx.tcx.hir().body(*body_id),
|
||||
item.span,
|
||||
item.hir_id,
|
||||
item.hir_id(),
|
||||
item.span.with_hi(sig.decl.output.span().hi()),
|
||||
"this method could have a `#[must_use]` attribute",
|
||||
);
|
||||
@ -339,7 +339,7 @@ impl<'tcx> LateLintPass<'tcx> for Functions {
|
||||
if sig.header.abi == Abi::Rust {
|
||||
self.check_arg_number(cx, &sig.decl, item.span.with_hi(sig.decl.output.span().hi()));
|
||||
}
|
||||
let is_public = cx.access_levels.is_exported(item.hir_id);
|
||||
let is_public = cx.access_levels.is_exported(item.hir_id());
|
||||
let fn_header_span = item.span.with_hi(sig.decl.output.span().hi());
|
||||
if is_public {
|
||||
check_result_unit_err(cx, &sig.decl, item.span, fn_header_span);
|
||||
@ -347,11 +347,11 @@ impl<'tcx> LateLintPass<'tcx> for Functions {
|
||||
|
||||
let attr = must_use_attr(&item.attrs);
|
||||
if let Some(attr) = attr {
|
||||
check_needless_must_use(cx, &sig.decl, item.hir_id, item.span, fn_header_span, attr);
|
||||
check_needless_must_use(cx, &sig.decl, item.hir_id(), item.span, fn_header_span, attr);
|
||||
}
|
||||
if let hir::TraitFn::Provided(eid) = *eid {
|
||||
let body = cx.tcx.hir().body(eid);
|
||||
Self::check_raw_ptr(cx, sig.header.unsafety, &sig.decl, body, item.hir_id);
|
||||
Self::check_raw_ptr(cx, sig.header.unsafety, &sig.decl, body, item.hir_id());
|
||||
|
||||
if attr.is_none() && is_public && !is_proc_macro(cx.sess(), &item.attrs) {
|
||||
check_must_use_candidate(
|
||||
@ -359,7 +359,7 @@ impl<'tcx> LateLintPass<'tcx> for Functions {
|
||||
&sig.decl,
|
||||
body,
|
||||
item.span,
|
||||
item.hir_id,
|
||||
item.hir_id(),
|
||||
item.span.with_hi(sig.decl.output.span().hi()),
|
||||
"this method could have a `#[must_use]` attribute",
|
||||
);
|
||||
|
@ -59,20 +59,15 @@ impl<'tcx> LateLintPass<'tcx> for MultipleInherentImpl {
|
||||
// but filter out implementations that have generic params (type or lifetime)
|
||||
// or are derived from a macro
|
||||
if !in_macro(item.span) && generics.params.is_empty() {
|
||||
self.impls.insert(item.hir_id.owner.to_def_id(), item.span);
|
||||
self.impls.insert(item.def_id.to_def_id(), item.span);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fn check_crate_post(&mut self, cx: &LateContext<'tcx>, krate: &'tcx Crate<'_>) {
|
||||
if let Some(item) = krate.items.values().next() {
|
||||
if !krate.items.is_empty() {
|
||||
// Retrieve all inherent implementations from the crate, grouped by type
|
||||
for impls in cx
|
||||
.tcx
|
||||
.crate_inherent_impls(item.hir_id.owner.to_def_id().krate)
|
||||
.inherent_impls
|
||||
.values()
|
||||
{
|
||||
for impls in cx.tcx.crate_inherent_impls(def_id::LOCAL_CRATE).inherent_impls.values() {
|
||||
// Filter out implementations that have generic params (type or lifetime)
|
||||
let mut impl_spans = impls.iter().filter_map(|impl_def| self.impls.get(impl_def));
|
||||
if let Some(initial_span) = impl_spans.next() {
|
||||
|
@ -109,10 +109,10 @@ impl<'tcx> LateLintPass<'tcx> for InherentToString {
|
||||
if impl_item.generics.params.is_empty();
|
||||
|
||||
// Check if return type is String
|
||||
if is_type_diagnostic_item(cx, return_ty(cx, impl_item.hir_id), sym::string_type);
|
||||
if is_type_diagnostic_item(cx, return_ty(cx, impl_item.hir_id()), sym::string_type);
|
||||
|
||||
// Filters instances of to_string which are required by a trait
|
||||
if trait_ref_of_method(cx, impl_item.hir_id).is_none();
|
||||
if trait_ref_of_method(cx, impl_item.hir_id()).is_none();
|
||||
|
||||
then {
|
||||
show_lint(cx, impl_item);
|
||||
@ -125,8 +125,7 @@ fn show_lint(cx: &LateContext<'_>, item: &ImplItem<'_>) {
|
||||
let display_trait_id = get_trait_def_id(cx, &paths::DISPLAY_TRAIT).expect("Failed to get trait ID of `Display`!");
|
||||
|
||||
// Get the real type of 'self'
|
||||
let fn_def_id = cx.tcx.hir().local_def_id(item.hir_id);
|
||||
let self_type = cx.tcx.fn_sig(fn_def_id).input(0);
|
||||
let self_type = cx.tcx.fn_sig(item.def_id).input(0);
|
||||
let self_type = self_type.skip_binder().peel_refs();
|
||||
|
||||
// Emit either a warning or an error
|
||||
|
@ -62,9 +62,8 @@ impl<'tcx> LateLintPass<'tcx> for LargeEnumVariant {
|
||||
if in_external_macro(cx.tcx.sess, item.span) {
|
||||
return;
|
||||
}
|
||||
let did = cx.tcx.hir().local_def_id(item.hir_id);
|
||||
if let ItemKind::Enum(ref def, _) = item.kind {
|
||||
let ty = cx.tcx.type_of(did);
|
||||
let ty = cx.tcx.type_of(item.def_id);
|
||||
let adt = ty.ty_adt_def().expect("already checked whether this is an enum");
|
||||
|
||||
let mut largest_variant: Option<(_, _)> = None;
|
||||
|
@ -159,10 +159,7 @@ fn check_trait_items(cx: &LateContext<'_>, visited_trait: &Item<'_>, trait_items
|
||||
fn is_named_self(cx: &LateContext<'_>, item: &TraitItemRef, name: &str) -> bool {
|
||||
item.ident.name.as_str() == name
|
||||
&& if let AssocItemKind::Fn { has_self } = item.kind {
|
||||
has_self && {
|
||||
let did = cx.tcx.hir().local_def_id(item.id.hir_id);
|
||||
cx.tcx.fn_sig(did).inputs().skip_binder().len() == 1
|
||||
}
|
||||
has_self && { cx.tcx.fn_sig(item.id.def_id).inputs().skip_binder().len() == 1 }
|
||||
} else {
|
||||
false
|
||||
}
|
||||
@ -177,10 +174,9 @@ fn check_trait_items(cx: &LateContext<'_>, visited_trait: &Item<'_>, trait_items
|
||||
}
|
||||
}
|
||||
|
||||
if cx.access_levels.is_exported(visited_trait.hir_id) && trait_items.iter().any(|i| is_named_self(cx, i, "len")) {
|
||||
if cx.access_levels.is_exported(visited_trait.hir_id()) && trait_items.iter().any(|i| is_named_self(cx, i, "len")) {
|
||||
let mut current_and_super_traits = FxHashSet::default();
|
||||
let visited_trait_def_id = cx.tcx.hir().local_def_id(visited_trait.hir_id);
|
||||
fill_trait_set(visited_trait_def_id.to_def_id(), &mut current_and_super_traits, cx);
|
||||
fill_trait_set(visited_trait.def_id.to_def_id(), &mut current_and_super_traits, cx);
|
||||
|
||||
let is_empty_method_found = current_and_super_traits
|
||||
.iter()
|
||||
@ -210,17 +206,14 @@ fn check_impl_items(cx: &LateContext<'_>, item: &Item<'_>, impl_items: &[ImplIte
|
||||
fn is_named_self(cx: &LateContext<'_>, item: &ImplItemRef<'_>, name: &str) -> bool {
|
||||
item.ident.name.as_str() == name
|
||||
&& if let AssocItemKind::Fn { has_self } = item.kind {
|
||||
has_self && {
|
||||
let did = cx.tcx.hir().local_def_id(item.id.hir_id);
|
||||
cx.tcx.fn_sig(did).inputs().skip_binder().len() == 1
|
||||
}
|
||||
has_self && cx.tcx.fn_sig(item.id.def_id).inputs().skip_binder().len() == 1
|
||||
} else {
|
||||
false
|
||||
}
|
||||
}
|
||||
|
||||
let is_empty = if let Some(is_empty) = impl_items.iter().find(|i| is_named_self(cx, i, "is_empty")) {
|
||||
if cx.access_levels.is_exported(is_empty.id.hir_id) {
|
||||
if cx.access_levels.is_exported(is_empty.id.hir_id()) {
|
||||
return;
|
||||
}
|
||||
"a private"
|
||||
@ -229,9 +222,8 @@ fn check_impl_items(cx: &LateContext<'_>, item: &Item<'_>, impl_items: &[ImplIte
|
||||
};
|
||||
|
||||
if let Some(i) = impl_items.iter().find(|i| is_named_self(cx, i, "len")) {
|
||||
if cx.access_levels.is_exported(i.id.hir_id) {
|
||||
let def_id = cx.tcx.hir().local_def_id(item.hir_id);
|
||||
let ty = cx.tcx.type_of(def_id);
|
||||
if cx.access_levels.is_exported(i.id.hir_id()) {
|
||||
let ty = cx.tcx.type_of(item.def_id);
|
||||
|
||||
span_lint(
|
||||
cx,
|
||||
|
@ -87,7 +87,7 @@ impl<'tcx> LateLintPass<'tcx> for Lifetimes {
|
||||
|
||||
fn check_impl_item(&mut self, cx: &LateContext<'tcx>, item: &'tcx ImplItem<'_>) {
|
||||
if let ImplItemKind::Fn(ref sig, id) = item.kind {
|
||||
let report_extra_lifetimes = trait_ref_of_method(cx, item.hir_id).is_none();
|
||||
let report_extra_lifetimes = trait_ref_of_method(cx, item.hir_id()).is_none();
|
||||
check_fn_inner(
|
||||
cx,
|
||||
&sig.decl,
|
||||
@ -375,7 +375,7 @@ impl<'a, 'tcx> Visitor<'tcx> for RefVisitor<'a, 'tcx> {
|
||||
match ty.kind {
|
||||
TyKind::OpaqueDef(item, _) => {
|
||||
let map = self.cx.tcx.hir();
|
||||
let item = map.expect_item(item.id);
|
||||
let item = map.item(item);
|
||||
walk_item(self, item);
|
||||
walk_ty(self, ty);
|
||||
},
|
||||
|
@ -340,7 +340,7 @@ declare_clippy_lint! {
|
||||
/// ```
|
||||
pub WHILE_LET_ON_ITERATOR,
|
||||
style,
|
||||
"using a while-let loop instead of a for loop on an iterator"
|
||||
"using a `while let` loop instead of a for loop on an iterator"
|
||||
}
|
||||
|
||||
declare_clippy_lint! {
|
||||
|
@ -102,7 +102,7 @@ fn future_trait_ref<'tcx>(
|
||||
) -> Option<(&'tcx TraitRef<'tcx>, Vec<LifetimeName>)> {
|
||||
if_chain! {
|
||||
if let TyKind::OpaqueDef(item_id, bounds) = ty.kind;
|
||||
let item = cx.tcx.hir().item(item_id.id);
|
||||
let item = cx.tcx.hir().item(item_id);
|
||||
if let ItemKind::OpaqueTy(opaque) = &item.kind;
|
||||
if let Some(trait_ref) = opaque.bounds.iter().find_map(|bound| {
|
||||
if let GenericBound::Trait(poly, _) = bound {
|
||||
|
@ -1737,10 +1737,9 @@ impl<'tcx> LateLintPass<'tcx> for Methods {
|
||||
return;
|
||||
}
|
||||
let name = impl_item.ident.name.as_str();
|
||||
let parent = cx.tcx.hir().get_parent_item(impl_item.hir_id);
|
||||
let parent = cx.tcx.hir().get_parent_item(impl_item.hir_id());
|
||||
let item = cx.tcx.hir().expect_item(parent);
|
||||
let def_id = cx.tcx.hir().local_def_id(item.hir_id);
|
||||
let self_ty = cx.tcx.type_of(def_id);
|
||||
let self_ty = cx.tcx.type_of(item.def_id);
|
||||
|
||||
// if this impl block implements a trait, lint in trait definition instead
|
||||
if let hir::ItemKind::Impl(hir::Impl { of_trait: Some(_), .. }) = item.kind {
|
||||
@ -1751,8 +1750,7 @@ impl<'tcx> LateLintPass<'tcx> for Methods {
|
||||
if let hir::ImplItemKind::Fn(ref sig, id) = impl_item.kind;
|
||||
if let Some(first_arg) = iter_input_pats(&sig.decl, cx.tcx.hir().body(id)).next();
|
||||
|
||||
let method_def_id = cx.tcx.hir().local_def_id(impl_item.hir_id);
|
||||
let method_sig = cx.tcx.fn_sig(method_def_id);
|
||||
let method_sig = cx.tcx.fn_sig(impl_item.def_id);
|
||||
let method_sig = cx.tcx.erase_late_bound_regions(method_sig);
|
||||
|
||||
let first_arg_ty = &method_sig.inputs().iter().next();
|
||||
@ -1761,7 +1759,7 @@ impl<'tcx> LateLintPass<'tcx> for Methods {
|
||||
if let Some(first_arg_ty) = first_arg_ty;
|
||||
|
||||
then {
|
||||
if cx.access_levels.is_exported(impl_item.hir_id) {
|
||||
if cx.access_levels.is_exported(impl_item.hir_id()) {
|
||||
// check missing trait implementations
|
||||
for method_config in &TRAIT_METHODS {
|
||||
if name == method_config.method_name &&
|
||||
@ -1803,7 +1801,7 @@ impl<'tcx> LateLintPass<'tcx> for Methods {
|
||||
}
|
||||
|
||||
if let hir::ImplItemKind::Fn(_, _) = impl_item.kind {
|
||||
let ret_ty = return_ty(cx, impl_item.hir_id);
|
||||
let ret_ty = return_ty(cx, impl_item.hir_id());
|
||||
|
||||
// walk the return type and check for Self (this does not check associated types)
|
||||
if contains_ty(ret_ty, self_ty) {
|
||||
@ -1844,7 +1842,7 @@ impl<'tcx> LateLintPass<'tcx> for Methods {
|
||||
if let Some(first_arg_ty) = sig.decl.inputs.iter().next();
|
||||
let first_arg_span = first_arg_ty.span;
|
||||
let first_arg_ty = hir_ty_to_ty(cx.tcx, first_arg_ty);
|
||||
let self_ty = TraitRef::identity(cx.tcx, item.hir_id.owner.to_def_id()).self_ty();
|
||||
let self_ty = TraitRef::identity(cx.tcx, item.def_id.to_def_id()).self_ty();
|
||||
|
||||
then {
|
||||
lint_wrong_self_convention(cx, &item.ident.name.as_str(), false, self_ty, first_arg_ty, first_arg_span);
|
||||
@ -1854,8 +1852,8 @@ impl<'tcx> LateLintPass<'tcx> for Methods {
|
||||
if_chain! {
|
||||
if item.ident.name == sym::new;
|
||||
if let TraitItemKind::Fn(_, _) = item.kind;
|
||||
let ret_ty = return_ty(cx, item.hir_id);
|
||||
let self_ty = TraitRef::identity(cx.tcx, item.hir_id.owner.to_def_id()).self_ty();
|
||||
let ret_ty = return_ty(cx, item.hir_id());
|
||||
let self_ty = TraitRef::identity(cx.tcx, item.def_id.to_def_id()).self_ty();
|
||||
if !contains_ty(ret_ty, self_ty);
|
||||
|
||||
then {
|
||||
|
@ -135,8 +135,7 @@ impl<'tcx> LateLintPass<'tcx> for MissingDoc {
|
||||
hir::ItemKind::Fn(..) => {
|
||||
// ignore main()
|
||||
if it.ident.name == sym::main {
|
||||
let def_id = it.hir_id.owner;
|
||||
let def_key = cx.tcx.hir().def_key(def_id);
|
||||
let def_key = cx.tcx.hir().def_key(it.def_id);
|
||||
if def_key.parent == Some(hir::def_id::CRATE_DEF_INDEX) {
|
||||
return;
|
||||
}
|
||||
@ -159,23 +158,20 @@ impl<'tcx> LateLintPass<'tcx> for MissingDoc {
|
||||
| hir::ItemKind::Use(..) => return,
|
||||
};
|
||||
|
||||
let def_id = cx.tcx.hir().local_def_id(it.hir_id);
|
||||
let (article, desc) = cx.tcx.article_and_description(def_id.to_def_id());
|
||||
let (article, desc) = cx.tcx.article_and_description(it.def_id.to_def_id());
|
||||
|
||||
self.check_missing_docs_attrs(cx, &it.attrs, it.span, article, desc);
|
||||
}
|
||||
|
||||
fn check_trait_item(&mut self, cx: &LateContext<'tcx>, trait_item: &'tcx hir::TraitItem<'_>) {
|
||||
let def_id = cx.tcx.hir().local_def_id(trait_item.hir_id);
|
||||
let (article, desc) = cx.tcx.article_and_description(def_id.to_def_id());
|
||||
let (article, desc) = cx.tcx.article_and_description(trait_item.def_id.to_def_id());
|
||||
|
||||
self.check_missing_docs_attrs(cx, &trait_item.attrs, trait_item.span, article, desc);
|
||||
}
|
||||
|
||||
fn check_impl_item(&mut self, cx: &LateContext<'tcx>, impl_item: &'tcx hir::ImplItem<'_>) {
|
||||
// If the method is an impl for a trait, don't doc.
|
||||
let def_id = cx.tcx.hir().local_def_id(impl_item.hir_id);
|
||||
match cx.tcx.associated_item(def_id).container {
|
||||
match cx.tcx.associated_item(impl_item.def_id).container {
|
||||
ty::TraitContainer(_) => return,
|
||||
ty::ImplContainer(cid) => {
|
||||
if cx.tcx.impl_trait_ref(cid).is_some() {
|
||||
@ -184,7 +180,7 @@ impl<'tcx> LateLintPass<'tcx> for MissingDoc {
|
||||
},
|
||||
}
|
||||
|
||||
let (article, desc) = cx.tcx.article_and_description(def_id.to_def_id());
|
||||
let (article, desc) = cx.tcx.article_and_description(impl_item.def_id.to_def_id());
|
||||
self.check_missing_docs_attrs(cx, &impl_item.attrs, impl_item.span, article, desc);
|
||||
}
|
||||
|
||||
|
@ -87,7 +87,7 @@ impl<'tcx> LateLintPass<'tcx> for MissingInline {
|
||||
return;
|
||||
}
|
||||
|
||||
if !cx.access_levels.is_exported(it.hir_id) {
|
||||
if !cx.access_levels.is_exported(it.hir_id()) {
|
||||
return;
|
||||
}
|
||||
match it.kind {
|
||||
@ -107,7 +107,7 @@ impl<'tcx> LateLintPass<'tcx> for MissingInline {
|
||||
// trait method with default body needs inline in case
|
||||
// an impl is not provided
|
||||
let desc = "a default trait method";
|
||||
let item = cx.tcx.hir().expect_trait_item(tit.id.hir_id);
|
||||
let item = cx.tcx.hir().trait_item(tit.id);
|
||||
check_missing_inline_attrs(cx, &item.attrs, item.span, desc);
|
||||
}
|
||||
},
|
||||
@ -138,7 +138,7 @@ impl<'tcx> LateLintPass<'tcx> for MissingInline {
|
||||
}
|
||||
|
||||
// If the item being implemented is not exported, then we don't need #[inline]
|
||||
if !cx.access_levels.is_exported(impl_item.hir_id) {
|
||||
if !cx.access_levels.is_exported(impl_item.hir_id()) {
|
||||
return;
|
||||
}
|
||||
|
||||
@ -147,14 +147,13 @@ impl<'tcx> LateLintPass<'tcx> for MissingInline {
|
||||
hir::ImplItemKind::Const(..) | hir::ImplItemKind::TyAlias(_) => return,
|
||||
};
|
||||
|
||||
let def_id = cx.tcx.hir().local_def_id(impl_item.hir_id);
|
||||
let trait_def_id = match cx.tcx.associated_item(def_id).container {
|
||||
let trait_def_id = match cx.tcx.associated_item(impl_item.def_id).container {
|
||||
TraitContainer(cid) => Some(cid),
|
||||
ImplContainer(cid) => cx.tcx.impl_trait_ref(cid).map(|t| t.def_id),
|
||||
};
|
||||
|
||||
if let Some(trait_def_id) = trait_def_id {
|
||||
if trait_def_id.is_local() && !cx.access_levels.is_exported(impl_item.hir_id) {
|
||||
if trait_def_id.is_local() && !cx.access_levels.is_exported(impl_item.hir_id()) {
|
||||
// If a trait is being implemented for an item, and the
|
||||
// trait is not exported, we don't need #[inline]
|
||||
return;
|
||||
|
@ -57,21 +57,21 @@ declare_lint_pass!(MutableKeyType => [ MUTABLE_KEY_TYPE ]);
|
||||
impl<'tcx> LateLintPass<'tcx> for MutableKeyType {
|
||||
fn check_item(&mut self, cx: &LateContext<'tcx>, item: &'tcx hir::Item<'tcx>) {
|
||||
if let hir::ItemKind::Fn(ref sig, ..) = item.kind {
|
||||
check_sig(cx, item.hir_id, &sig.decl);
|
||||
check_sig(cx, item.hir_id(), &sig.decl);
|
||||
}
|
||||
}
|
||||
|
||||
fn check_impl_item(&mut self, cx: &LateContext<'tcx>, item: &'tcx hir::ImplItem<'tcx>) {
|
||||
if let hir::ImplItemKind::Fn(ref sig, ..) = item.kind {
|
||||
if trait_ref_of_method(cx, item.hir_id).is_none() {
|
||||
check_sig(cx, item.hir_id, &sig.decl);
|
||||
if trait_ref_of_method(cx, item.hir_id()).is_none() {
|
||||
check_sig(cx, item.hir_id(), &sig.decl);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fn check_trait_item(&mut self, cx: &LateContext<'tcx>, item: &'tcx hir::TraitItem<'tcx>) {
|
||||
if let hir::TraitItemKind::Fn(ref sig, ..) = item.kind {
|
||||
check_sig(cx, item.hir_id, &sig.decl);
|
||||
check_sig(cx, item.hir_id(), &sig.decl);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -5,11 +5,12 @@
|
||||
use crate::utils::{is_automatically_derived, snippet_opt, span_lint_and_then};
|
||||
use if_chain::if_chain;
|
||||
use rustc_errors::Applicability;
|
||||
use rustc_hir::{BindingAnnotation, BorrowKind, Expr, ExprKind, HirId, Item, Mutability, Pat, PatKind};
|
||||
use rustc_hir::{BindingAnnotation, BorrowKind, Expr, ExprKind, Item, Mutability, Pat, PatKind};
|
||||
use rustc_lint::{LateContext, LateLintPass};
|
||||
use rustc_middle::ty;
|
||||
use rustc_middle::ty::adjustment::{Adjust, Adjustment};
|
||||
use rustc_session::{declare_tool_lint, impl_lint_pass};
|
||||
use rustc_span::def_id::LocalDefId;
|
||||
|
||||
declare_clippy_lint! {
|
||||
/// **What it does:** Checks for address of operations (`&`) that are going to
|
||||
@ -35,7 +36,7 @@ declare_clippy_lint! {
|
||||
|
||||
#[derive(Default)]
|
||||
pub struct NeedlessBorrow {
|
||||
derived_item: Option<HirId>,
|
||||
derived_item: Option<LocalDefId>,
|
||||
}
|
||||
|
||||
impl_lint_pass!(NeedlessBorrow => [NEEDLESS_BORROW]);
|
||||
@ -117,13 +118,13 @@ impl<'tcx> LateLintPass<'tcx> for NeedlessBorrow {
|
||||
fn check_item(&mut self, _: &LateContext<'tcx>, item: &'tcx Item<'_>) {
|
||||
if is_automatically_derived(item.attrs) {
|
||||
debug_assert!(self.derived_item.is_none());
|
||||
self.derived_item = Some(item.hir_id);
|
||||
self.derived_item = Some(item.def_id);
|
||||
}
|
||||
}
|
||||
|
||||
fn check_item_post(&mut self, _: &LateContext<'tcx>, item: &'tcx Item<'_>) {
|
||||
if let Some(id) = self.derived_item {
|
||||
if item.hir_id == id {
|
||||
if item.def_id == id {
|
||||
self.derived_item = None;
|
||||
}
|
||||
}
|
||||
|
@ -72,7 +72,7 @@ impl<'tcx> LateLintPass<'tcx> for NewWithoutDefault {
|
||||
}
|
||||
if let hir::ImplItemKind::Fn(ref sig, _) = impl_item.kind {
|
||||
let name = impl_item.ident.name;
|
||||
let id = impl_item.hir_id;
|
||||
let id = impl_item.hir_id();
|
||||
if sig.header.constness == hir::Constness::Const {
|
||||
// can't be implemented by default
|
||||
return;
|
||||
|
@ -271,7 +271,7 @@ impl<'tcx> LateLintPass<'tcx> for NonCopyConst {
|
||||
|
||||
fn check_impl_item(&mut self, cx: &LateContext<'tcx>, impl_item: &'tcx ImplItem<'_>) {
|
||||
if let ImplItemKind::Const(hir_ty, body_id) = &impl_item.kind {
|
||||
let item_hir_id = cx.tcx.hir().get_parent_node(impl_item.hir_id);
|
||||
let item_hir_id = cx.tcx.hir().get_parent_node(impl_item.hir_id());
|
||||
let item = cx.tcx.hir().expect_item(item_hir_id);
|
||||
|
||||
match &item.kind {
|
||||
|
@ -44,7 +44,7 @@ impl<'tcx> LateLintPass<'tcx> for PartialEqNeImpl {
|
||||
span_lint_hir(
|
||||
cx,
|
||||
PARTIALEQ_NE_IMPL,
|
||||
impl_item.id.hir_id,
|
||||
impl_item.id.hir_id(),
|
||||
impl_item.span,
|
||||
"re-implementing `PartialEq::ne` is unnecessary",
|
||||
);
|
||||
|
@ -206,7 +206,7 @@ impl<'tcx> LateLintPass<'tcx> for PassByRefOrValue {
|
||||
}
|
||||
|
||||
if let hir::TraitItemKind::Fn(method_sig, _) = &item.kind {
|
||||
self.check_poly_fn(cx, item.hir_id, &*method_sig.decl, None);
|
||||
self.check_poly_fn(cx, item.hir_id(), &*method_sig.decl, None);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -124,19 +124,19 @@ declare_lint_pass!(Ptr => [PTR_ARG, CMP_NULL, MUT_FROM_REF]);
|
||||
impl<'tcx> LateLintPass<'tcx> for Ptr {
|
||||
fn check_item(&mut self, cx: &LateContext<'tcx>, item: &'tcx Item<'_>) {
|
||||
if let ItemKind::Fn(ref sig, _, body_id) = item.kind {
|
||||
check_fn(cx, &sig.decl, item.hir_id, Some(body_id));
|
||||
check_fn(cx, &sig.decl, item.hir_id(), Some(body_id));
|
||||
}
|
||||
}
|
||||
|
||||
fn check_impl_item(&mut self, cx: &LateContext<'tcx>, item: &'tcx ImplItem<'_>) {
|
||||
if let ImplItemKind::Fn(ref sig, body_id) = item.kind {
|
||||
let parent_item = cx.tcx.hir().get_parent_item(item.hir_id);
|
||||
let parent_item = cx.tcx.hir().get_parent_item(item.hir_id());
|
||||
if let Some(Node::Item(it)) = cx.tcx.hir().find(parent_item) {
|
||||
if let ItemKind::Impl(Impl { of_trait: Some(_), .. }) = it.kind {
|
||||
return; // ignore trait impls
|
||||
}
|
||||
}
|
||||
check_fn(cx, &sig.decl, item.hir_id, Some(body_id));
|
||||
check_fn(cx, &sig.decl, item.hir_id(), Some(body_id));
|
||||
}
|
||||
}
|
||||
|
||||
@ -147,7 +147,7 @@ impl<'tcx> LateLintPass<'tcx> for Ptr {
|
||||
} else {
|
||||
None
|
||||
};
|
||||
check_fn(cx, &sig.decl, item.hir_id, body_id);
|
||||
check_fn(cx, &sig.decl, item.hir_id(), body_id);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -42,11 +42,10 @@ impl_lint_pass!(RedundantPubCrate => [REDUNDANT_PUB_CRATE]);
|
||||
impl<'tcx> LateLintPass<'tcx> for RedundantPubCrate {
|
||||
fn check_item(&mut self, cx: &LateContext<'tcx>, item: &'tcx Item<'tcx>) {
|
||||
if let VisibilityKind::Crate { .. } = item.vis.node {
|
||||
if !cx.access_levels.is_exported(item.hir_id) {
|
||||
if !cx.access_levels.is_exported(item.hir_id()) {
|
||||
if let Some(false) = self.is_exported.last() {
|
||||
let span = item.span.with_hi(item.ident.span.hi());
|
||||
let def_id = cx.tcx.hir().local_def_id(item.hir_id);
|
||||
let descr = cx.tcx.def_kind(def_id).descr(def_id.to_def_id());
|
||||
let descr = cx.tcx.def_kind(item.def_id).descr(item.def_id.to_def_id());
|
||||
span_lint_and_then(
|
||||
cx,
|
||||
REDUNDANT_PUB_CRATE,
|
||||
@ -66,7 +65,7 @@ impl<'tcx> LateLintPass<'tcx> for RedundantPubCrate {
|
||||
}
|
||||
|
||||
if let ItemKind::Mod { .. } = item.kind {
|
||||
self.is_exported.push(cx.access_levels.is_exported(item.hir_id));
|
||||
self.is_exported.push(cx.access_levels.is_exported(item.hir_id()));
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -2567,7 +2567,7 @@ impl<'tcx> LateLintPass<'tcx> for ImplicitHasher {
|
||||
}
|
||||
}
|
||||
|
||||
if !cx.access_levels.is_exported(item.hir_id) {
|
||||
if !cx.access_levels.is_exported(item.hir_id()) {
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -42,10 +42,9 @@ impl<'tcx> LateLintPass<'tcx> for UnusedSelf {
|
||||
if impl_item.span.from_expansion() {
|
||||
return;
|
||||
}
|
||||
let parent = cx.tcx.hir().get_parent_item(impl_item.hir_id);
|
||||
let parent = cx.tcx.hir().get_parent_item(impl_item.hir_id());
|
||||
let parent_item = cx.tcx.hir().expect_item(parent);
|
||||
let def_id = cx.tcx.hir().local_def_id(impl_item.hir_id);
|
||||
let assoc_item = cx.tcx.associated_item(def_id);
|
||||
let assoc_item = cx.tcx.associated_item(impl_item.def_id);
|
||||
if_chain! {
|
||||
if let ItemKind::Impl(Impl { of_trait: None, .. }) = parent_item.kind;
|
||||
if assoc_item.fn_has_self_parameter;
|
||||
|
@ -57,8 +57,8 @@ impl<'tcx> LateLintPass<'tcx> for UnwrapInResult {
|
||||
// first check if it's a method or function
|
||||
if let hir::ImplItemKind::Fn(ref _signature, _) = impl_item.kind;
|
||||
// checking if its return type is `result` or `option`
|
||||
if is_type_diagnostic_item(cx, return_ty(cx, impl_item.hir_id), sym::result_type)
|
||||
|| is_type_diagnostic_item(cx, return_ty(cx, impl_item.hir_id), sym::option_type);
|
||||
if is_type_diagnostic_item(cx, return_ty(cx, impl_item.hir_id()), sym::result_type)
|
||||
|| is_type_diagnostic_item(cx, return_ty(cx, impl_item.hir_id()), sym::option_type);
|
||||
then {
|
||||
lint_impl_body(cx, impl_item.span, impl_item);
|
||||
}
|
||||
@ -114,10 +114,9 @@ fn lint_impl_body<'tcx>(cx: &LateContext<'tcx>, impl_span: Span, impl_item: &'tc
|
||||
if let ImplItemKind::Fn(_, body_id) = impl_item.kind;
|
||||
then {
|
||||
let body = cx.tcx.hir().body(body_id);
|
||||
let impl_item_def_id = cx.tcx.hir().local_def_id(impl_item.hir_id);
|
||||
let mut fpu = FindExpectUnwrap {
|
||||
lcx: cx,
|
||||
typeck_results: cx.tcx.typeck(impl_item_def_id),
|
||||
typeck_results: cx.tcx.typeck(impl_item.def_id),
|
||||
result: Vec::new(),
|
||||
};
|
||||
fpu.visit_expr(&body.value);
|
||||
|
@ -111,7 +111,7 @@ impl<'tcx> LateLintPass<'tcx> for UseSelf {
|
||||
} else {
|
||||
false
|
||||
};
|
||||
let impl_trait_ref_def_id = of_trait.as_ref().map(|_| cx.tcx.hir().local_def_id(item.hir_id));
|
||||
let impl_trait_ref_def_id = of_trait.as_ref().map(|_| cx.tcx.hir().local_def_id(item.hir_id()));
|
||||
if should_check {
|
||||
self.stack.push(StackItem::Check {
|
||||
hir_id: hir_self_ty.hir_id,
|
||||
|
@ -130,7 +130,7 @@ impl<'tcx> LateLintPass<'tcx> for Author {
|
||||
}
|
||||
|
||||
fn check_stmt(&mut self, cx: &LateContext<'tcx>, stmt: &'tcx hir::Stmt<'_>) {
|
||||
if !has_attr(cx.sess(), stmt.kind.attrs(|id| cx.tcx.hir().item(id.id))) {
|
||||
if !has_attr(cx.sess(), stmt.kind.attrs(|id| cx.tcx.hir().item(id))) {
|
||||
return;
|
||||
}
|
||||
prelude();
|
||||
|
@ -109,7 +109,7 @@ impl<'tcx> LateLintPass<'tcx> for DeepCodeInspector {
|
||||
}
|
||||
|
||||
fn check_stmt(&mut self, cx: &LateContext<'tcx>, stmt: &'tcx hir::Stmt<'_>) {
|
||||
if !has_attr(cx.sess(), stmt.kind.attrs(|id| cx.tcx.hir().item(id.id))) {
|
||||
if !has_attr(cx.sess(), stmt.kind.attrs(|id| cx.tcx.hir().item(id))) {
|
||||
return;
|
||||
}
|
||||
match stmt.kind {
|
||||
@ -370,7 +370,7 @@ fn print_expr(cx: &LateContext<'_>, expr: &hir::Expr<'_>, indent: usize) {
|
||||
}
|
||||
|
||||
fn print_item(cx: &LateContext<'_>, item: &hir::Item<'_>) {
|
||||
let did = cx.tcx.hir().local_def_id(item.hir_id);
|
||||
let did = item.def_id;
|
||||
println!("item `{}`", item.ident.name);
|
||||
match item.vis.node {
|
||||
hir::VisibilityKind::Public => println!("public"),
|
||||
@ -383,8 +383,7 @@ fn print_item(cx: &LateContext<'_>, item: &hir::Item<'_>) {
|
||||
}
|
||||
match item.kind {
|
||||
hir::ItemKind::ExternCrate(ref _renamed_from) => {
|
||||
let def_id = cx.tcx.hir().local_def_id(item.hir_id);
|
||||
if let Some(crate_id) = cx.tcx.extern_mod_stmt_cnum(def_id) {
|
||||
if let Some(crate_id) = cx.tcx.extern_mod_stmt_cnum(did) {
|
||||
let source = cx.tcx.used_crate_source(crate_id);
|
||||
if let Some(ref src) = source.dylib {
|
||||
println!("extern crate dylib source: {:?}", src.0);
|
||||
|
@ -4,7 +4,7 @@ use crate::utils::{
|
||||
span_lint, span_lint_and_help, span_lint_and_sugg, SpanlessEq,
|
||||
};
|
||||
use if_chain::if_chain;
|
||||
use rustc_ast::ast::{Crate as AstCrate, ItemKind, LitKind, NodeId};
|
||||
use rustc_ast::ast::{Crate as AstCrate, ItemKind, LitKind, ModKind, NodeId};
|
||||
use rustc_ast::visit::FnKind;
|
||||
use rustc_data_structures::fx::{FxHashMap, FxHashSet};
|
||||
use rustc_errors::Applicability;
|
||||
@ -301,17 +301,12 @@ declare_lint_pass!(ClippyLintsInternal => [CLIPPY_LINTS_INTERNAL]);
|
||||
|
||||
impl EarlyLintPass for ClippyLintsInternal {
|
||||
fn check_crate(&mut self, cx: &EarlyContext<'_>, krate: &AstCrate) {
|
||||
if let Some(utils) = krate
|
||||
.module
|
||||
.items
|
||||
.iter()
|
||||
.find(|item| item.ident.name.as_str() == "utils")
|
||||
{
|
||||
if let ItemKind::Mod(ref utils_mod) = utils.kind {
|
||||
if let Some(paths) = utils_mod.items.iter().find(|item| item.ident.name.as_str() == "paths") {
|
||||
if let ItemKind::Mod(ref paths_mod) = paths.kind {
|
||||
if let Some(utils) = krate.items.iter().find(|item| item.ident.name.as_str() == "utils") {
|
||||
if let ItemKind::Mod(_, ModKind::Loaded(ref items, ..)) = utils.kind {
|
||||
if let Some(paths) = items.iter().find(|item| item.ident.name.as_str() == "paths") {
|
||||
if let ItemKind::Mod(_, ModKind::Loaded(ref items, ..)) = paths.kind {
|
||||
let mut last_name: Option<SymbolStr> = None;
|
||||
for item in &*paths_mod.items {
|
||||
for item in items {
|
||||
let name = item.ident.as_str();
|
||||
if let Some(ref last_name) = last_name {
|
||||
if **last_name > *name {
|
||||
@ -343,7 +338,7 @@ impl_lint_pass!(LintWithoutLintPass => [DEFAULT_LINT, LINT_WITHOUT_LINT_PASS]);
|
||||
|
||||
impl<'tcx> LateLintPass<'tcx> for LintWithoutLintPass {
|
||||
fn check_item(&mut self, cx: &LateContext<'tcx>, item: &'tcx Item<'_>) {
|
||||
if !run_lints(cx, &[DEFAULT_LINT], item.hir_id) {
|
||||
if !run_lints(cx, &[DEFAULT_LINT], item.hir_id()) {
|
||||
return;
|
||||
}
|
||||
|
||||
@ -393,7 +388,7 @@ impl<'tcx> LateLintPass<'tcx> for LintWithoutLintPass {
|
||||
.find(|iiref| iiref.ident.as_str() == "get_lints")
|
||||
.expect("LintPass needs to implement get_lints")
|
||||
.id
|
||||
.hir_id,
|
||||
.hir_id(),
|
||||
);
|
||||
collector.visit_expr(&cx.tcx.hir().body(body_id).value);
|
||||
}
|
||||
@ -861,7 +856,7 @@ declare_lint_pass!(InvalidPaths => [INVALID_PATHS]);
|
||||
|
||||
impl<'tcx> LateLintPass<'tcx> for InvalidPaths {
|
||||
fn check_item(&mut self, cx: &LateContext<'tcx>, item: &'tcx Item<'_>) {
|
||||
let local_def_id = &cx.tcx.parent_module(item.hir_id);
|
||||
let local_def_id = &cx.tcx.parent_module(item.hir_id());
|
||||
let mod_name = &cx.tcx.item_name(local_def_id.to_def_id());
|
||||
if_chain! {
|
||||
if mod_name.as_str() == "paths";
|
||||
|
@ -113,7 +113,7 @@ impl LateLintPass<'_> for WildcardImports {
|
||||
if_chain! {
|
||||
if let ItemKind::Use(use_path, UseKind::Glob) = &item.kind;
|
||||
if self.warn_on_all || !self.check_exceptions(item, use_path.segments);
|
||||
let used_imports = cx.tcx.names_imported_by_glob_use(item.hir_id.owner);
|
||||
let used_imports = cx.tcx.names_imported_by_glob_use(item.def_id);
|
||||
if !used_imports.is_empty(); // Already handled by `unused_imports`
|
||||
then {
|
||||
let mut applicability = Applicability::MachineApplicable;
|
||||
|
@ -234,7 +234,16 @@ pub fn eq_item_kind(l: &ItemKind, r: &ItemKind) -> bool {
|
||||
(Fn(box FnKind(ld, lf, lg, lb)), Fn(box FnKind(rd, rf, rg, rb))) => {
|
||||
eq_defaultness(*ld, *rd) && eq_fn_sig(lf, rf) && eq_generics(lg, rg) && both(lb, rb, |l, r| eq_block(l, r))
|
||||
},
|
||||
(Mod(l), Mod(r)) => l.inline == r.inline && over(&l.items, &r.items, |l, r| eq_item(l, r, eq_item_kind)),
|
||||
(Mod(lu, lmk), Mod(ru, rmk)) => {
|
||||
lu == ru
|
||||
&& match (lmk, rmk) {
|
||||
(ModKind::Loaded(litems, linline, _), ModKind::Loaded(ritems, rinline, _)) => {
|
||||
linline == rinline && over(litems, ritems, |l, r| eq_item(l, r, eq_item_kind))
|
||||
},
|
||||
(ModKind::Unloaded, ModKind::Unloaded) => true,
|
||||
_ => false,
|
||||
}
|
||||
},
|
||||
(ForeignMod(l), ForeignMod(r)) => {
|
||||
both(&l.abi, &r.abi, |l, r| eq_str_lit(l, r))
|
||||
&& over(&l.items, &r.items, |l, r| eq_item(l, r, eq_foreign_item_kind))
|
||||
|
@ -20,8 +20,8 @@ pub const CLONE_TRAIT: [&str; 3] = ["core", "clone", "Clone"];
|
||||
pub const CLONE_TRAIT_METHOD: [&str; 4] = ["core", "clone", "Clone", "clone"];
|
||||
pub const CMP_MAX: [&str; 3] = ["core", "cmp", "max"];
|
||||
pub const CMP_MIN: [&str; 3] = ["core", "cmp", "min"];
|
||||
pub const COPY: [&str; 3] = ["core", "intrinsics", "copy_nonoverlapping"];
|
||||
pub const COPY_NONOVERLAPPING: [&str; 3] = ["core", "intrinsics", "copy"];
|
||||
pub const COPY: [&str; 4] = ["core", "intrinsics", "", "copy_nonoverlapping"];
|
||||
pub const COPY_NONOVERLAPPING: [&str; 4] = ["core", "intrinsics", "", "copy"];
|
||||
pub const COW: [&str; 3] = ["alloc", "borrow", "Cow"];
|
||||
pub const CSTRING_AS_C_STR: [&str; 5] = ["std", "ffi", "c_str", "CString", "as_c_str"];
|
||||
pub const DEFAULT_TRAIT: [&str; 3] = ["core", "default", "Default"];
|
||||
|
@ -1,3 +1,3 @@
|
||||
[toolchain]
|
||||
channel = "nightly-2021-02-11"
|
||||
channel = "nightly-2021-02-25"
|
||||
components = ["llvm-tools-preview", "rustc-dev", "rust-src"]
|
||||
|
@ -11,10 +11,8 @@
|
||||
extern crate rustc_driver;
|
||||
extern crate rustc_errors;
|
||||
extern crate rustc_interface;
|
||||
extern crate rustc_middle;
|
||||
|
||||
use rustc_interface::interface;
|
||||
use rustc_middle::ty::TyCtxt;
|
||||
use rustc_tools_util::VersionInfo;
|
||||
|
||||
use std::borrow::Cow;
|
||||
@ -168,7 +166,7 @@ fn report_clippy_ice(info: &panic::PanicInfo<'_>, bug_report_url: &str) {
|
||||
|
||||
let num_frames = if backtrace { None } else { Some(2) };
|
||||
|
||||
TyCtxt::try_print_query_stack(&handler, num_frames);
|
||||
interface::try_print_query_stack(&handler, num_frames);
|
||||
}
|
||||
|
||||
fn toolchain_path(home: Option<String>, toolchain: Option<String>) -> Option<PathBuf> {
|
||||
|
Loading…
x
Reference in New Issue
Block a user