1
Fork 0
This commit is contained in:
Matthias Krüger 2020-04-24 11:57:34 +02:00 committed by flip1995
parent 02c94352d4
commit f9c1acbc45
No known key found for this signature in database
GPG key ID: 2CEFCDB27ED0BE79
11 changed files with 27 additions and 22 deletions

View file

@ -123,7 +123,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for CognitiveComplexity {
hir_id: HirId, hir_id: HirId,
) { ) {
let def_id = cx.tcx.hir().local_def_id(hir_id); let def_id = cx.tcx.hir().local_def_id(hir_id);
if !cx.tcx.has_attr(def_id, sym!(test)) { if !cx.tcx.has_attr(def_id.to_def_id(), sym!(test)) {
self.check(cx, kind, decl, body, span); self.check(cx, kind, decl, body, span);
} }
} }

View file

@ -160,16 +160,20 @@ fn check_hash_peq<'a, 'tcx>(
}; };
span_lint_and_then( span_lint_and_then(
cx, DERIVE_HASH_XOR_EQ, span, cx,
DERIVE_HASH_XOR_EQ,
span,
mess, mess,
|diag| { |diag| {
if let Some(hir_id) = cx.tcx.hir().as_local_hir_id(impl_id) { if let Some(local_def_id) = impl_id.as_local() {
let hir_id = cx.tcx.hir().as_local_hir_id(local_def_id);
diag.span_note( diag.span_note(
cx.tcx.hir().span(hir_id), cx.tcx.hir().span(hir_id),
"`PartialEq` implemented here" "`PartialEq` implemented here"
); );
} }
}); }
);
} }
}); });
} }
@ -225,7 +229,7 @@ fn check_unsafe_derive_deserialize<'a, 'tcx>(
ty: Ty<'tcx>, ty: Ty<'tcx>,
) { ) {
fn item_from_def_id<'tcx>(cx: &LateContext<'_, 'tcx>, def_id: DefId) -> &'tcx Item<'tcx> { fn item_from_def_id<'tcx>(cx: &LateContext<'_, 'tcx>, def_id: DefId) -> &'tcx Item<'tcx> {
let hir_id = cx.tcx.hir().as_local_hir_id(def_id).unwrap(); let hir_id = cx.tcx.hir().as_local_hir_id(def_id.expect_local());
cx.tcx.hir().expect_item(hir_id) cx.tcx.hir().expect_item(hir_id)
} }

View file

@ -155,7 +155,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for DocMarkdown {
let headers = check_attrs(cx, &self.valid_idents, &item.attrs); let headers = check_attrs(cx, &self.valid_idents, &item.attrs);
match item.kind { match item.kind {
hir::ItemKind::Fn(ref sig, _, body_id) => { hir::ItemKind::Fn(ref sig, _, body_id) => {
if !(is_entrypoint_fn(cx, cx.tcx.hir().local_def_id(item.hir_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)) || in_external_macro(cx.tcx.sess, item.span))
{ {
lint_for_missing_headers(cx, item.hir_id, item.span, sig, headers, Some(body_id)); lint_for_missing_headers(cx, item.hir_id, item.span, sig, headers, Some(body_id));

View file

@ -77,7 +77,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for BoxedLocal {
let fn_def_id = cx.tcx.hir().local_def_id(hir_id); let fn_def_id = cx.tcx.hir().local_def_id(hir_id);
cx.tcx.infer_ctxt().enter(|infcx| { cx.tcx.infer_ctxt().enter(|infcx| {
ExprUseVisitor::new(&mut v, &infcx, fn_def_id, cx.param_env, cx.tables).consume_body(body); ExprUseVisitor::new(&mut v, &infcx, fn_def_id.to_def_id(), cx.param_env, cx.tables).consume_body(body);
}); });
for node in v.set { for node in v.set {

View file

@ -37,7 +37,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for Exit {
// If the next item up is a function we check if it is an entry point // If the next item up is a function we check if it is an entry point
// and only then emit a linter warning // and only then emit a linter warning
let def_id = cx.tcx.hir().local_def_id(parent); let def_id = cx.tcx.hir().local_def_id(parent);
if !is_entrypoint_fn(cx, def_id) { if !is_entrypoint_fn(cx, def_id.to_def_id()) {
span_lint(cx, EXIT, e.span, "usage of `process::exit`"); span_lint(cx, EXIT, e.span, "usage of `process::exit`");
} }
} }

View file

@ -143,7 +143,7 @@ fn check_trait_items(cx: &LateContext<'_, '_>, visited_trait: &Item<'_>, trait_i
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 mut current_and_super_traits = FxHashSet::default();
let visited_trait_def_id = cx.tcx.hir().local_def_id(visited_trait.hir_id); let visited_trait_def_id = cx.tcx.hir().local_def_id(visited_trait.hir_id);
fill_trait_set(visited_trait_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 let is_empty_method_found = current_and_super_traits
.iter() .iter()

View file

@ -83,12 +83,12 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for MissingConstForFn {
) { ) {
let def_id = cx.tcx.hir().local_def_id(hir_id); let def_id = cx.tcx.hir().local_def_id(hir_id);
if in_external_macro(cx.tcx.sess, span) || is_entrypoint_fn(cx, def_id) { if in_external_macro(cx.tcx.sess, span) || is_entrypoint_fn(cx, def_id.to_def_id()) {
return; return;
} }
// Building MIR for `fn`s with unsatisfiable preds results in ICE. // Building MIR for `fn`s with unsatisfiable preds results in ICE.
if fn_has_unsatisfiable_preds(cx, def_id) { if fn_has_unsatisfiable_preds(cx, def_id.to_def_id()) {
return; return;
} }
@ -118,8 +118,8 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for MissingConstForFn {
let mir = cx.tcx.optimized_mir(def_id); let mir = cx.tcx.optimized_mir(def_id);
if let Err((span, err)) = is_min_const_fn(cx.tcx, def_id, &mir) { if let Err((span, err)) = is_min_const_fn(cx.tcx, def_id.to_def_id(), &mir) {
if rustc_mir::const_eval::is_min_const_fn(cx.tcx, def_id) { if rustc_mir::const_eval::is_min_const_fn(cx.tcx, def_id.to_def_id()) {
cx.tcx.sess.span_err(span, &err); cx.tcx.sess.span_err(span, &err);
} }
} else { } else {

View file

@ -152,7 +152,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for MissingInline {
}; };
if let Some(trait_def_id) = trait_def_id { if let Some(trait_def_id) = trait_def_id {
if cx.tcx.hir().as_local_hir_id(trait_def_id).is_some() && !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 // If a trait is being implemented for an item, and the
// trait is not exported, we don't need #[inline] // trait is not exported, we don't need #[inline]
return; return;

View file

@ -135,7 +135,8 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for NeedlessPassByValue {
} = { } = {
let mut ctx = MovedVariablesCtxt::default(); let mut ctx = MovedVariablesCtxt::default();
cx.tcx.infer_ctxt().enter(|infcx| { cx.tcx.infer_ctxt().enter(|infcx| {
euv::ExprUseVisitor::new(&mut ctx, &infcx, fn_def_id, cx.param_env, cx.tables).consume_body(body); euv::ExprUseVisitor::new(&mut ctx, &infcx, fn_def_id.to_def_id(), cx.param_env, cx.tables)
.consume_body(body);
}); });
ctx ctx
}; };

View file

@ -136,8 +136,8 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for NewWithoutDefault {
let mut impls = HirIdSet::default(); let mut impls = HirIdSet::default();
cx.tcx.for_each_impl(default_trait_id, |d| { cx.tcx.for_each_impl(default_trait_id, |d| {
if let Some(ty_def) = cx.tcx.type_of(d).ty_adt_def() { if let Some(ty_def) = cx.tcx.type_of(d).ty_adt_def() {
if let Some(hir_id) = cx.tcx.hir().as_local_hir_id(ty_def.did) { if let Some(local_def_id) = ty_def.did.as_local() {
impls.insert(hir_id); impls.insert(cx.tcx.hir().as_local_hir_id(local_def_id));
} }
} }
}); });

View file

@ -378,7 +378,7 @@ fn print_item(cx: &LateContext<'_, '_>, item: &hir::Item<'_>) {
}, },
hir::ItemKind::Trait(..) => { hir::ItemKind::Trait(..) => {
println!("trait decl"); println!("trait decl");
if cx.tcx.trait_is_auto(did) { if cx.tcx.trait_is_auto(did.to_def_id()) {
println!("trait is auto"); println!("trait is auto");
} else { } else {
println!("trait is not auto"); println!("trait is not auto");