Auto merge of #4254 - lzutao:hiridification-62168, r=Manishearth

Rustup HirIdification

Rustup https://github.com/rust-lang/rust/pull/62168

changelog: none
This commit is contained in:
bors 2019-07-06 06:30:15 +00:00
commit 8744e8ed26
24 changed files with 53 additions and 65 deletions

View File

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

View File

@ -34,7 +34,7 @@ declare_lint_pass!(CopyIterator => [COPY_ITERATOR]);
impl<'a, 'tcx> LateLintPass<'a, 'tcx> for CopyIterator {
fn check_item(&mut self, cx: &LateContext<'a, 'tcx>, item: &'tcx Item) {
if let ItemKind::Impl(_, _, _, _, Some(ref trait_ref), _, _) = item.node {
let ty = cx.tcx.type_of(cx.tcx.hir().local_def_id_from_hir_id(item.hir_id));
let ty = cx.tcx.type_of(cx.tcx.hir().local_def_id(item.hir_id));
if is_copy(cx, ty) && match_path(&trait_ref.path, &paths::ITERATOR) {
span_note_and_lint(

View File

@ -67,7 +67,7 @@ declare_lint_pass!(Derive => [EXPL_IMPL_CLONE_ON_COPY, DERIVE_HASH_XOR_EQ]);
impl<'a, 'tcx> LateLintPass<'a, 'tcx> for Derive {
fn check_item(&mut self, cx: &LateContext<'a, 'tcx>, item: &'tcx Item) {
if let ItemKind::Impl(_, _, _, _, Some(ref trait_ref), _, _) = item.node {
let ty = cx.tcx.type_of(cx.tcx.hir().local_def_id_from_hir_id(item.hir_id));
let ty = cx.tcx.type_of(cx.tcx.hir().local_def_id(item.hir_id));
let is_automatically_derived = is_automatically_derived(&*item.attrs);
check_hash_peq(cx, item.span, trait_ref, ty, is_automatically_derived);

View File

@ -27,7 +27,7 @@ declare_lint_pass!(EmptyEnum => [EMPTY_ENUM]);
impl<'a, 'tcx> LateLintPass<'a, 'tcx> for EmptyEnum {
fn check_item(&mut self, cx: &LateContext<'_, '_>, item: &Item) {
let did = cx.tcx.hir().local_def_id_from_hir_id(item.hir_id);
let did = cx.tcx.hir().local_def_id(item.hir_id);
if let ItemKind::Enum(..) = item.node {
let ty = cx.tcx.type_of(did);
let adt = ty.ty_adt_def().expect("already checked whether this is an enum");

View File

@ -77,7 +77,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for BoxedLocal {
too_large_for_stack: self.too_large_for_stack,
};
let fn_def_id = cx.tcx.hir().local_def_id_from_hir_id(hir_id);
let fn_def_id = cx.tcx.hir().local_def_id(hir_id);
let region_scope_tree = &cx.tcx.region_scope_tree(fn_def_id);
ExprUseVisitor::new(
&mut v,

View File

@ -33,7 +33,7 @@ declare_lint_pass!(FallibleImplFrom => [FALLIBLE_IMPL_FROM]);
impl<'a, 'tcx> LateLintPass<'a, 'tcx> for FallibleImplFrom {
fn check_item(&mut self, cx: &LateContext<'a, 'tcx>, item: &'tcx hir::Item) {
// check for `impl From<???> for ..`
let impl_def_id = cx.tcx.hir().local_def_id_from_hir_id(item.hir_id);
let impl_def_id = cx.tcx.hir().local_def_id(item.hir_id);
if_chain! {
if let hir::ItemKind::Impl(.., ref impl_items) = item.node;
if let Some(impl_trait_ref) = cx.tcx.impl_trait_ref(impl_def_id);
@ -95,7 +95,7 @@ fn lint_impl_body<'a, 'tcx>(cx: &LateContext<'a, 'tcx>, impl_span: Span, impl_it
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_from_hir_id(impl_item.id.hir_id);
let impl_item_def_id = cx.tcx.hir().local_def_id(impl_item.id.hir_id);
let mut fpu = FindPanicUnwrap {
lcx: cx,
tables: cx.tcx.typeck_tables_of(impl_item_def_id),

View File

@ -46,7 +46,7 @@ impl_lint_pass!(LargeEnumVariant => [LARGE_ENUM_VARIANT]);
impl<'a, 'tcx> LateLintPass<'a, 'tcx> for LargeEnumVariant {
fn check_item(&mut self, cx: &LateContext<'_, '_>, item: &Item) {
let did = cx.tcx.hir().local_def_id_from_hir_id(item.hir_id);
let did = cx.tcx.hir().local_def_id(item.hir_id);
if let ItemKind::Enum(ref def, _) = item.node {
let ty = cx.tcx.type_of(did);
let adt = ty.ty_adt_def().expect("already checked whether this is an enum");

View File

@ -122,7 +122,7 @@ fn check_trait_items(cx: &LateContext<'_, '_>, visited_trait: &Item, trait_items
item.ident.name.as_str() == name
&& if let AssocItemKind::Method { has_self } = item.kind {
has_self && {
let did = cx.tcx.hir().local_def_id_from_hir_id(item.id.hir_id);
let did = cx.tcx.hir().local_def_id(item.id.hir_id);
cx.tcx.fn_sig(did).inputs().skip_binder().len() == 1
}
} else {
@ -141,7 +141,7 @@ 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")) {
let mut current_and_super_traits = FxHashSet::default();
let visited_trait_def_id = cx.tcx.hir().local_def_id_from_hir_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);
let is_empty_method_found = current_and_super_traits
@ -173,7 +173,7 @@ fn check_impl_items(cx: &LateContext<'_, '_>, item: &Item, impl_items: &[ImplIte
item.ident.name.as_str() == name
&& if let AssocItemKind::Method { has_self } = item.kind {
has_self && {
let did = cx.tcx.hir().local_def_id_from_hir_id(item.id.hir_id);
let did = cx.tcx.hir().local_def_id(item.id.hir_id);
cx.tcx.fn_sig(did).inputs().skip_binder().len() == 1
}
} else {
@ -193,7 +193,7 @@ 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_from_hir_id(item.hir_id);
let def_id = cx.tcx.hir().local_def_id(item.hir_id);
let ty = cx.tcx.type_of(def_id);
span_lint(

View File

@ -1102,7 +1102,7 @@ fn check_for_loop_range<'a, 'tcx>(
// ensure that the indexed variable was declared before the loop, see #601
if let Some(indexed_extent) = indexed_extent {
let parent_id = cx.tcx.hir().get_parent_item(expr.hir_id);
let parent_def_id = cx.tcx.hir().local_def_id_from_hir_id(parent_id);
let parent_def_id = cx.tcx.hir().local_def_id(parent_id);
let region_scope_tree = cx.tcx.region_scope_tree(parent_def_id);
let pat_extent = region_scope_tree.var_scope(pat.hir_id.local_id);
if region_scope_tree.is_subscope_of(indexed_extent, pat_extent) {
@ -1792,7 +1792,7 @@ impl<'a, 'tcx> VarVisitor<'a, 'tcx> {
match res {
Res::Local(hir_id) => {
let parent_id = self.cx.tcx.hir().get_parent_item(expr.hir_id);
let parent_def_id = self.cx.tcx.hir().local_def_id_from_hir_id(parent_id);
let parent_def_id = self.cx.tcx.hir().local_def_id(parent_id);
let extent = self.cx.tcx.region_scope_tree(parent_def_id).var_scope(hir_id.local_id);
if indexed_indirectly {
self.indexed_indirectly.insert(seqvar.segments[0].ident.name, Some(extent));

View File

@ -948,7 +948,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for Methods {
let name = implitem.ident.name.as_str();
let parent = cx.tcx.hir().get_parent_item(implitem.hir_id);
let item = cx.tcx.hir().expect_item(parent);
let def_id = cx.tcx.hir().local_def_id_from_hir_id(item.hir_id);
let def_id = cx.tcx.hir().local_def_id(item.hir_id);
let ty = cx.tcx.type_of(def_id);
if_chain! {
if let hir::ImplItemKind::Method(ref sig, id) = implitem.node;

View File

@ -69,7 +69,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for MissingConstForFn {
span: Span,
hir_id: HirId,
) {
let def_id = cx.tcx.hir().local_def_id_from_hir_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) {
return;

View File

@ -133,7 +133,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for MissingDoc {
hir::ItemKind::Fn(..) => {
// ignore main()
if it.ident.name == sym!(main) {
let def_id = cx.tcx.hir().local_def_id_from_hir_id(it.hir_id);
let def_id = cx.tcx.hir().local_def_id(it.hir_id);
let def_key = cx.tcx.hir().def_key(def_id);
if def_key.parent == Some(hir::def_id::CRATE_DEF_INDEX) {
return;
@ -171,7 +171,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for MissingDoc {
fn check_impl_item(&mut self, cx: &LateContext<'a, '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_from_hir_id(impl_item.hir_id);
let def_id = cx.tcx.hir().local_def_id(impl_item.hir_id);
match cx.tcx.associated_item(def_id).container {
ty::TraitContainer(_) => return,
ty::ImplContainer(cid) => {

View File

@ -145,7 +145,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for MissingInline {
hir::ImplItemKind::Const(..) | hir::ImplItemKind::Type(_) | hir::ImplItemKind::Existential(_) => return,
};
let def_id = cx.tcx.hir().local_def_id_from_hir_id(impl_item.hir_id);
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 {
TraitContainer(cid) => Some(cid),
ImplContainer(cid) => cx.tcx.impl_trait_ref(cid).map(|t| t.def_id),

View File

@ -107,7 +107,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for NeedlessPassByValue {
let sized_trait = need!(cx.tcx.lang_items().sized_trait());
let fn_def_id = cx.tcx.hir().local_def_id_from_hir_id(hir_id);
let fn_def_id = cx.tcx.hir().local_def_id(hir_id);
let preds = traits::elaborate_predicates(cx.tcx, cx.param_env.caller_bounds.to_vec())
.filter(|p| !p.is_global())

View File

@ -121,7 +121,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for NewWithoutDefault {
return;
}
if sig.decl.inputs.is_empty() && name == sym!(new) && cx.access_levels.is_reachable(id) {
let self_did = cx.tcx.hir().local_def_id_from_hir_id(cx.tcx.hir().get_parent_item(id));
let self_did = cx.tcx.hir().local_def_id(cx.tcx.hir().get_parent_item(id));
let self_ty = cx.tcx.type_of(self_did);
if_chain! {
if same_tys(cx, self_ty, return_ty(cx, id));

View File

@ -142,7 +142,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for Ptr {
#[allow(clippy::too_many_lines)]
fn check_fn(cx: &LateContext<'_, '_>, decl: &FnDecl, fn_id: HirId, opt_body_id: Option<BodyId>) {
let fn_def_id = cx.tcx.hir().local_def_id_from_hir_id(fn_id);
let fn_def_id = cx.tcx.hir().local_def_id(fn_id);
let sig = cx.tcx.fn_sig(fn_def_id);
let fn_ty = sig.skip_binder();

View File

@ -56,9 +56,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for ReplaceConsts {
}
}
const REPLACEMENTS: [([&str; 3], &str); 25] = [
// Once
(["core", "sync", "ONCE_INIT"], "Once::new()"),
const REPLACEMENTS: [([&str; 3], &str); 24] = [
// Min
(["core", "isize", "MIN"], "isize::min_value()"),
(["core", "i8", "MIN"], "i8::min_value()"),

View File

@ -73,7 +73,7 @@ impl<'a, 'tcx> TriviallyCopyPassByRef {
}
fn check_poly_fn(&mut self, cx: &LateContext<'_, 'tcx>, hir_id: HirId, decl: &FnDecl, span: Option<Span>) {
let fn_def_id = cx.tcx.hir().local_def_id_from_hir_id(hir_id);
let fn_def_id = cx.tcx.hir().local_def_id(hir_id);
let fn_sig = cx.tcx.fn_sig(fn_def_id);
let fn_sig = cx.tcx.erase_late_bound_regions(&fn_sig);

View File

@ -129,7 +129,7 @@ fn check_trait_method_impl_decl<'a, 'tcx>(
let trait_method_sig = cx.tcx.fn_sig(trait_method.def_id);
let trait_method_sig = cx.tcx.erase_late_bound_regions(&trait_method_sig);
let impl_method_def_id = cx.tcx.hir().local_def_id_from_hir_id(impl_item.hir_id);
let impl_method_def_id = cx.tcx.hir().local_def_id(impl_item.hir_id);
let impl_method_sig = cx.tcx.fn_sig(impl_method_def_id);
let impl_method_sig = cx.tcx.erase_late_bound_regions(&impl_method_sig);
@ -184,7 +184,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for UseSelf {
item_path,
cx,
};
let impl_def_id = cx.tcx.hir().local_def_id_from_hir_id(item.hir_id);
let impl_def_id = cx.tcx.hir().local_def_id(item.hir_id);
let impl_trait_ref = cx.tcx.impl_trait_ref(impl_def_id);
if let Some(impl_trait_ref) = impl_trait_ref {

View File

@ -329,7 +329,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_from_hir_id(item.hir_id);
let did = cx.tcx.hir().local_def_id(item.hir_id);
println!("item `{}`", item.ident.name);
match item.vis.node {
hir::VisibilityKind::Public => println!("public"),
@ -342,7 +342,7 @@ fn print_item(cx: &LateContext<'_, '_>, item: &hir::Item) {
}
match item.node {
hir::ItemKind::ExternCrate(ref _renamed_from) => {
let def_id = cx.tcx.hir().local_def_id_from_hir_id(item.hir_id);
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) {
let source = cx.tcx.used_crate_source(crate_id);
if let Some(ref src) = source.dylib {

View File

@ -716,7 +716,7 @@ pub fn is_direct_expn_of(span: Span, name: &str) -> Option<Span> {
/// Convenience function to get the return type of a function.
pub fn return_ty<'a, 'tcx>(cx: &LateContext<'a, 'tcx>, fn_item: hir::HirId) -> Ty<'tcx> {
let fn_def_id = cx.tcx.hir().local_def_id_from_hir_id(fn_item);
let fn_def_id = cx.tcx.hir().local_def_id(fn_item);
let ret_ty = cx.tcx.fn_sig(fn_def_id).output();
cx.tcx.erase_late_bound_regions(&ret_ty)
}

View File

@ -4,12 +4,9 @@
#![deny(clippy::replace_consts)]
use std::sync::atomic::*;
use std::sync::{Once, ONCE_INIT};
#[rustfmt::skip]
fn bad() {
// Once
{ let foo = ONCE_INIT; };
// Min
{ let foo = isize::min_value(); };
{ let foo = i8::min_value(); };
@ -40,8 +37,6 @@ fn bad() {
#[rustfmt::skip]
fn good() {
// Once
{ let foo = Once::new(); };
// Atomic
{ let foo = AtomicBool::new(false); };
{ let foo = AtomicIsize::new(0); };

View File

@ -4,12 +4,9 @@
#![deny(clippy::replace_consts)]
use std::sync::atomic::*;
use std::sync::{Once, ONCE_INIT};
#[rustfmt::skip]
fn bad() {
// Once
{ let foo = ONCE_INIT; };
// Min
{ let foo = std::isize::MIN; };
{ let foo = std::i8::MIN; };
@ -40,8 +37,6 @@ fn bad() {
#[rustfmt::skip]
fn good() {
// Once
{ let foo = Once::new(); };
// Atomic
{ let foo = AtomicBool::new(false); };
{ let foo = AtomicIsize::new(0); };

View File

@ -1,5 +1,5 @@
error: using `MIN`
--> $DIR/replace_consts.rs:14:17
--> $DIR/replace_consts.rs:11:17
|
LL | { let foo = std::isize::MIN; };
| ^^^^^^^^^^^^^^^ help: try this: `isize::min_value()`
@ -11,139 +11,139 @@ LL | #![deny(clippy::replace_consts)]
| ^^^^^^^^^^^^^^^^^^^^^^
error: using `MIN`
--> $DIR/replace_consts.rs:15:17
--> $DIR/replace_consts.rs:12:17
|
LL | { let foo = std::i8::MIN; };
| ^^^^^^^^^^^^ help: try this: `i8::min_value()`
error: using `MIN`
--> $DIR/replace_consts.rs:16:17
--> $DIR/replace_consts.rs:13:17
|
LL | { let foo = std::i16::MIN; };
| ^^^^^^^^^^^^^ help: try this: `i16::min_value()`
error: using `MIN`
--> $DIR/replace_consts.rs:17:17
--> $DIR/replace_consts.rs:14:17
|
LL | { let foo = std::i32::MIN; };
| ^^^^^^^^^^^^^ help: try this: `i32::min_value()`
error: using `MIN`
--> $DIR/replace_consts.rs:18:17
--> $DIR/replace_consts.rs:15:17
|
LL | { let foo = std::i64::MIN; };
| ^^^^^^^^^^^^^ help: try this: `i64::min_value()`
error: using `MIN`
--> $DIR/replace_consts.rs:19:17
--> $DIR/replace_consts.rs:16:17
|
LL | { let foo = std::i128::MIN; };
| ^^^^^^^^^^^^^^ help: try this: `i128::min_value()`
error: using `MIN`
--> $DIR/replace_consts.rs:20:17
--> $DIR/replace_consts.rs:17:17
|
LL | { let foo = std::usize::MIN; };
| ^^^^^^^^^^^^^^^ help: try this: `usize::min_value()`
error: using `MIN`
--> $DIR/replace_consts.rs:21:17
--> $DIR/replace_consts.rs:18:17
|
LL | { let foo = std::u8::MIN; };
| ^^^^^^^^^^^^ help: try this: `u8::min_value()`
error: using `MIN`
--> $DIR/replace_consts.rs:22:17
--> $DIR/replace_consts.rs:19:17
|
LL | { let foo = std::u16::MIN; };
| ^^^^^^^^^^^^^ help: try this: `u16::min_value()`
error: using `MIN`
--> $DIR/replace_consts.rs:23:17
--> $DIR/replace_consts.rs:20:17
|
LL | { let foo = std::u32::MIN; };
| ^^^^^^^^^^^^^ help: try this: `u32::min_value()`
error: using `MIN`
--> $DIR/replace_consts.rs:24:17
--> $DIR/replace_consts.rs:21:17
|
LL | { let foo = std::u64::MIN; };
| ^^^^^^^^^^^^^ help: try this: `u64::min_value()`
error: using `MIN`
--> $DIR/replace_consts.rs:25:17
--> $DIR/replace_consts.rs:22:17
|
LL | { let foo = std::u128::MIN; };
| ^^^^^^^^^^^^^^ help: try this: `u128::min_value()`
error: using `MAX`
--> $DIR/replace_consts.rs:27:17
--> $DIR/replace_consts.rs:24:17
|
LL | { let foo = std::isize::MAX; };
| ^^^^^^^^^^^^^^^ help: try this: `isize::max_value()`
error: using `MAX`
--> $DIR/replace_consts.rs:28:17
--> $DIR/replace_consts.rs:25:17
|
LL | { let foo = std::i8::MAX; };
| ^^^^^^^^^^^^ help: try this: `i8::max_value()`
error: using `MAX`
--> $DIR/replace_consts.rs:29:17
--> $DIR/replace_consts.rs:26:17
|
LL | { let foo = std::i16::MAX; };
| ^^^^^^^^^^^^^ help: try this: `i16::max_value()`
error: using `MAX`
--> $DIR/replace_consts.rs:30:17
--> $DIR/replace_consts.rs:27:17
|
LL | { let foo = std::i32::MAX; };
| ^^^^^^^^^^^^^ help: try this: `i32::max_value()`
error: using `MAX`
--> $DIR/replace_consts.rs:31:17
--> $DIR/replace_consts.rs:28:17
|
LL | { let foo = std::i64::MAX; };
| ^^^^^^^^^^^^^ help: try this: `i64::max_value()`
error: using `MAX`
--> $DIR/replace_consts.rs:32:17
--> $DIR/replace_consts.rs:29:17
|
LL | { let foo = std::i128::MAX; };
| ^^^^^^^^^^^^^^ help: try this: `i128::max_value()`
error: using `MAX`
--> $DIR/replace_consts.rs:33:17
--> $DIR/replace_consts.rs:30:17
|
LL | { let foo = std::usize::MAX; };
| ^^^^^^^^^^^^^^^ help: try this: `usize::max_value()`
error: using `MAX`
--> $DIR/replace_consts.rs:34:17
--> $DIR/replace_consts.rs:31:17
|
LL | { let foo = std::u8::MAX; };
| ^^^^^^^^^^^^ help: try this: `u8::max_value()`
error: using `MAX`
--> $DIR/replace_consts.rs:35:17
--> $DIR/replace_consts.rs:32:17
|
LL | { let foo = std::u16::MAX; };
| ^^^^^^^^^^^^^ help: try this: `u16::max_value()`
error: using `MAX`
--> $DIR/replace_consts.rs:36:17
--> $DIR/replace_consts.rs:33:17
|
LL | { let foo = std::u32::MAX; };
| ^^^^^^^^^^^^^ help: try this: `u32::max_value()`
error: using `MAX`
--> $DIR/replace_consts.rs:37:17
--> $DIR/replace_consts.rs:34:17
|
LL | { let foo = std::u64::MAX; };
| ^^^^^^^^^^^^^ help: try this: `u64::max_value()`
error: using `MAX`
--> $DIR/replace_consts.rs:38:17
--> $DIR/replace_consts.rs:35:17
|
LL | { let foo = std::u128::MAX; };
| ^^^^^^^^^^^^^^ help: try this: `u128::max_value()`