Update for hir renamings in rustc

This commit is contained in:
Oliver Schneider 2018-07-16 15:07:39 +02:00
parent 8e929946fd
commit 6992937002
41 changed files with 181 additions and 153 deletions

View file

@ -142,9 +142,9 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for AssignOps {
$cx:expr,
$ty:expr,
$rty:expr,
$($trait_name:ident:$full_trait_name:ident),+) => {
$($trait_name:ident),+) => {
match $op {
$(hir::$full_trait_name => {
$(hir::BinOpKind::$trait_name => {
let [krate, module] = crate::utils::paths::OPS_MODULE;
let path = [krate, module, concat!(stringify!($trait_name), "Assign")];
let trait_id = if let Some(trait_id) = get_trait_def_id($cx, &path) {
@ -159,7 +159,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for AssignOps {
if_chain! {
if parent_impl != ast::CRATE_NODE_ID;
if let hir::map::Node::NodeItem(item) = cx.tcx.hir.get(parent_impl);
if let hir::Item_::ItemImpl(_, _, _, _, Some(ref trait_ref), _, _) =
if let hir::ItemKind::Impl(_, _, _, _, Some(ref trait_ref), _, _) =
item.node;
if trait_ref.path.def.def_id() == trait_id;
then { return; }
@ -175,18 +175,18 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for AssignOps {
cx,
ty,
rty.into(),
Add: BinOpKind::Add,
Sub: BinOpKind::Sub,
Mul: BinOpKind::Mul,
Div: BinOpKind::Div,
Rem: BinOpKind::Rem,
And: BinOpKind::And,
Or: BinOpKind::Or,
BitAnd: BinOpKind::BitAnd,
BitOr: BinOpKind::BitOr,
BitXor: BinOpKind::BitXor,
Shr: BinOpKind::Shr,
Shl: BinOpKind::Shl
Add,
Sub,
Mul,
Div,
Rem,
And,
Or,
BitAnd,
BitOr,
BitXor,
Shr,
Shl
) {
span_lint_and_then(
cx,

View file

@ -154,7 +154,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for AttrPass {
check_attrs(cx, item.span, item.name, &item.attrs)
}
match item.node {
ItemExternCrate(_) | ItemUse(_, _) => {
ItemKind::ExternCrate(_) | ItemKind::Use(_, _) => {
for attr in &item.attrs {
if let Some(ref lint_list) = attr.meta_item_list() {
match &*attr.name().as_str() {
@ -162,7 +162,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for AttrPass {
// whitelist `unused_imports` and `deprecated`
for lint in lint_list {
if is_word(lint, "unused_imports") || is_word(lint, "deprecated") {
if let ItemUse(_, _) = item.node {
if let ItemKind::Use(_, _) = item.node {
return;
}
}
@ -207,7 +207,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for AttrPass {
}
fn is_relevant_item(tcx: TyCtxt, item: &Item) -> bool {
if let ItemFn(_, _, _, eid) = item.node {
if let ItemKind::Fn(_, _, _, eid) = item.node {
is_relevant_expr(tcx, tcx.body_tables(eid), &tcx.hir.body(eid).value)
} else {
true

View file

@ -70,7 +70,7 @@ impl LintPass for Derive {
impl<'a, 'tcx> LateLintPass<'a, 'tcx> for Derive {
fn check_item(&mut self, cx: &LateContext<'a, 'tcx>, item: &'tcx Item) {
if let ItemImpl(_, _, _, _, Some(ref trait_ref), _, _) = item.node {
if let ItemKind::Impl(_, _, _, _, Some(ref trait_ref), _, _) = item.node {
let ty = cx.tcx.type_of(cx.tcx.hir.local_def_id(item.id));
let is_automatically_derived = is_automatically_derived(&*item.attrs);

View file

@ -34,7 +34,7 @@ impl LintPass for EmptyEnum {
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(item.id);
if let ItemEnum(..) = item.node {
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

@ -47,7 +47,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for UnportableVariant {
if cx.tcx.data_layout.pointer_size.bits() != 64 {
return;
}
if let ItemEnum(ref def, _) = item.node {
if let ItemKind::Enum(ref def, _) = item.node {
for var in &def.variants {
let variant = &var.node;
if let Some(ref anon_const) = variant.disr_expr {

View file

@ -47,7 +47,7 @@ impl EnumGlobUse {
if item.vis.node.is_pub() {
return; // re-exports are fine
}
if let ItemUse(ref path, UseKind::Glob) = item.node {
if let ItemKind::Use(ref path, UseKind::Glob) = item.node {
if let Def::Enum(_) = path.def {
span_lint(
cx,

View file

@ -111,7 +111,7 @@ impl<'a, 'tcx> Delegate<'tcx> for EscapeDelegate<'a, 'tcx> {
let id = map.hir_to_node_id(cmt.hir_id);
if let Some(NodeStmt(st)) = map.find(map.get_parent_node(id)) {
if let StmtKind::Decl(ref decl, _) = st.node {
if let DeclLocal(ref loc) = decl.node {
if let DeclKind::Local(ref loc) = decl.node {
if let Some(ref ex) = loc.init {
if let ExprKind::Box(..) = ex.node {
if is_non_trait_box(cmt.ty) && !self.is_large_box(cmt.ty) {

View file

@ -83,7 +83,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for EvalOrderDependence {
fn check_stmt(&mut self, cx: &LateContext<'a, 'tcx>, stmt: &'tcx Stmt) {
match stmt.node {
StmtKind::Expr(ref e, _) | StmtKind::Semi(ref e, _) => DivergenceVisitor { cx }.maybe_walk_expr(e),
StmtKind::Decl(ref d, _) => if let DeclLocal(ref local) = d.node {
StmtKind::Decl(ref d, _) => if let DeclKind::Local(ref local) = d.node {
if let Local {
init: Some(ref e), ..
} = **local
@ -267,7 +267,7 @@ fn check_stmt<'a, 'tcx>(vis: &mut ReadVisitor<'a, 'tcx>, stmt: &'tcx Stmt) -> St
// If the declaration is of a local variable, check its initializer
// expression if it has one. Otherwise, keep going.
let local = match decl.node {
DeclLocal(ref local) => Some(local),
DeclKind::Local(ref local) => Some(local),
_ => None,
};
local

View file

@ -39,7 +39,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for FallibleImplFrom {
// check for `impl From<???> for ..`
let impl_def_id = cx.tcx.hir.local_def_id(item.id);
if_chain! {
if let hir::ItemImpl(.., ref impl_items) = item.node;
if let hir::ItemKind::Impl(.., ref impl_items) = item.node;
if let Some(impl_trait_ref) = cx.tcx.impl_trait_ref(impl_def_id);
if match_def_path(cx.tcx, impl_trait_ref.def_id, &FROM_TRAIT);
then {

View file

@ -86,7 +86,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for Functions {
use rustc::hir::map::Node::*;
let is_impl = if let Some(NodeItem(item)) = cx.tcx.hir.find(cx.tcx.hir.get_parent_node(nodeid)) {
matches!(item.node, hir::ItemImpl(_, _, _, _, Some(_), _, _))
matches!(item.node, hir::ItemKind::Impl(_, _, _, _, Some(_), _, _))
} else {
false
};

View file

@ -56,7 +56,7 @@ impl LintPass for Pass {
impl<'a, 'tcx> LateLintPass<'a, 'tcx> for Pass {
fn check_item(&mut self, _: &LateContext<'a, 'tcx>, item: &'tcx Item) {
if let Item_::ItemImpl(_, _, _, ref generics, None, _, _) = item.node {
if let ItemKind::Impl(_, _, _, ref generics, None, _, _) = item.node {
// Remember for each inherent implementation encoutered its span and generics
self.impls
.insert(item.hir_id.owner_def_id(), (item.span, generics.clone()));

View file

@ -49,7 +49,7 @@ impl LintPass for LargeEnumVariant {
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(item.id);
if let ItemEnum(ref def, _) = item.node {
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

@ -68,8 +68,8 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for LenZero {
}
match item.node {
ItemTrait(_, _, _, _, ref trait_items) => check_trait_items(cx, item, trait_items),
ItemImpl(_, _, _, _, None, _, ref impl_items) => check_impl_items(cx, item, impl_items),
ItemKind::Trait(_, _, _, _, ref trait_items) => check_trait_items(cx, item, trait_items),
ItemKind::Impl(_, _, _, _, None, _, ref impl_items) => check_impl_items(cx, item, impl_items),
_ => (),
}
}

View file

@ -66,7 +66,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for LetIfSeq {
if_chain! {
if let Some(expr) = it.peek();
if let hir::StmtKind::Decl(ref decl, _) = stmt.node;
if let hir::DeclLocal(ref decl) = decl.node;
if let hir::DeclKind::Local(ref decl) = decl.node;
if let hir::PatKind::Binding(mode, canonical_id, ident, None) = decl.pat.node;
if let hir::StmtKind::Expr(ref if_, _) = expr.node;
if let hir::ExprKind::If(ref cond, ref then, ref else_) = if_.node;

View file

@ -59,7 +59,7 @@ impl LintPass for LifetimePass {
impl<'a, 'tcx> LateLintPass<'a, 'tcx> for LifetimePass {
fn check_item(&mut self, cx: &LateContext<'a, 'tcx>, item: &'tcx Item) {
if let ItemFn(ref decl, _, ref generics, id) = item.node {
if let ItemKind::Fn(ref decl, _, ref generics, id) = item.node {
check_fn_inner(cx, decl, Some(id), generics, item.span);
}
}
@ -345,7 +345,7 @@ impl<'a, 'tcx> Visitor<'tcx> for RefVisitor<'a, 'tcx> {
if let QPath::Resolved(_, ref path) = *path {
if let Def::Existential(def_id) = path.def {
let node_id = self.cx.tcx.hir.as_local_node_id(def_id).unwrap();
if let ItemExistential(ref exist_ty) = self.cx.tcx.hir.expect_item(node_id).node {
if let ItemKind::Existential(ref exist_ty) = self.cx.tcx.hir.expect_item(node_id).node {
for bound in &exist_ty.bounds {
if let GenericBound::Outlives(_) = *bound {
self.record(&None);
@ -360,7 +360,7 @@ impl<'a, 'tcx> Visitor<'tcx> for RefVisitor<'a, 'tcx> {
}
self.collect_anonymous_lifetimes(path, ty);
}
TyTraitObject(ref bounds, ref lt) => {
TyKind::TraitObject(ref bounds, ref lt) => {
if !lt.is_elided() {
self.abort = true;
}

View file

@ -591,7 +591,7 @@ fn stmt_to_expr(stmt: &Stmt) -> Option<&Expr> {
fn decl_to_expr(decl: &Decl) -> Option<&Expr> {
match decl.node {
DeclLocal(ref local) => local.init.as_ref().map(|p| &**p),
DeclKind::Local(ref local) => local.init.as_ref().map(|p| &**p),
_ => None,
}
}
@ -771,7 +771,7 @@ fn get_fixed_offset_var<'a, 'tcx>(cx: &LateContext<'a, 'tcx>, expr: &Expr, var:
let offset = match idx.node {
ExprKind::Binary(op, ref lhs, ref rhs) => match op.node {
BinOpKindAdd => {
BinOpKind::Add => {
let offset_opt = if same_var(cx, lhs, var) {
extract_offset(cx, rhs, var)
} else if same_var(cx, rhs, var) {
@ -1810,7 +1810,7 @@ fn extract_expr_from_first_stmt(block: &Block) -> Option<&Expr> {
return None;
}
if let StmtKind::Decl(ref decl, _) = block.stmts[0].node {
if let DeclLocal(ref local) = decl.node {
if let DeclKind::Local(ref local) = decl.node {
if let Some(ref expr) = local.init {
Some(expr)
} else {
@ -1931,7 +1931,7 @@ struct InitializeVisitor<'a, 'tcx: 'a> {
impl<'a, 'tcx> Visitor<'tcx> for InitializeVisitor<'a, 'tcx> {
fn visit_decl(&mut self, decl: &'tcx Decl) {
// Look for declarations of the variable
if let DeclLocal(ref local) = decl.node {
if let DeclKind::Local(ref local) = decl.node {
if local.pat.id == self.var_id {
if let PatKind::Binding(_, _, ident, _) = local.pat.node {
self.name = Some(ident.name);

View file

@ -813,7 +813,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for Pass {
if let hir::ImplItemKind::Method(ref sig, id) = implitem.node;
if let Some(first_arg_ty) = sig.decl.inputs.get(0);
if let Some(first_arg) = iter_input_pats(&sig.decl, cx.tcx.hir.body(id)).next();
if let hir::ItemImpl(_, _, _, _, None, ref self_ty, _) = item.node;
if let hir::ItemKind::Impl(_, _, _, _, None, ref self_ty, _) = item.node;
then {
if cx.access_levels.is_exported(implitem.id) {
// check missing trait implementations
@ -1140,7 +1140,7 @@ fn lint_clone_on_copy(cx: &LateContext, expr: &hir::Expr, arg: &hir::Expr, arg_t
}
hir::map::NodeStmt(stmt) => {
if let hir::StmtKind::Decl(ref decl, _) = stmt.node {
if let hir::DeclLocal(ref loc) = decl.node {
if let hir::DeclKind::Local(ref loc) = decl.node {
if let hir::PatKind::Ref(..) = loc.pat.node {
// let ref y = *x borrows x, let ref y = x.clone() does not
return;
@ -1338,7 +1338,7 @@ fn lint_unnecessary_fold(cx: &LateContext, expr: &hir::Expr, fold_args: &[hir::E
cx, fold_args, hir::BinOpKind::And, "all", true
),
ast::LitKind::Int(0, _) => check_fold_with_op(
cx, fold_args, hir::BinOpKindAdd, "sum", false
cx, fold_args, hir::BinOpKind::Add, "sum", false
),
ast::LitKind::Int(1, _) => check_fold_with_op(
cx, fold_args, hir::BinOpKind::Mul, "product", false
@ -2175,7 +2175,7 @@ enum OutType {
impl OutType {
fn matches(self, cx: &LateContext, ty: &hir::FunctionRetTy) -> bool {
let is_unit = |ty: &hir::Ty| SpanlessEq::new(cx).eq_ty_kind(&ty.node, &hir::TyTup(vec![].into()));
let is_unit = |ty: &hir::Ty| SpanlessEq::new(cx).eq_ty_kind(&ty.node, &hir::TyKind::Tup(vec![].into()));
match (self, ty) {
(OutType::Unit, &hir::DefaultReturn(_)) => true,
(OutType::Unit, &hir::Return(ref ty)) if is_unit(ty) => true,

View file

@ -270,7 +270,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for Pass {
fn check_stmt(&mut self, cx: &LateContext<'a, 'tcx>, s: &'tcx Stmt) {
if_chain! {
if let StmtKind::Decl(ref d, _) = s.node;
if let DeclLocal(ref l) = d.node;
if let DeclKind::Local(ref l) = d.node;
if let PatKind::Binding(an, _, i, None) = l.pat.node;
if let Some(ref init) = l.init;
then {
@ -520,7 +520,7 @@ fn check_to_owned(cx: &LateContext, expr: &Expr, other: &Expr) {
let parent_impl = cx.tcx.hir.get_parent(parent_fn);
if parent_impl != CRATE_NODE_ID {
if let map::NodeItem(item) = cx.tcx.hir.get(parent_impl) {
if let ItemImpl(.., Some(ref trait_ref), _, _) = item.node {
if let ItemKind::Impl(.., Some(ref trait_ref), _, _) = item.node {
if trait_ref.path.def.def_id() == partial_eq_trait_id {
// we are implementing PartialEq, don't suggest not doing `to_owned`, otherwise
// we go into

View file

@ -122,9 +122,9 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for MissingDoc {
fn check_item(&mut self, cx: &LateContext<'a, 'tcx>, it: &'tcx hir::Item) {
let desc = match it.node {
hir::ItemConst(..) => "a constant",
hir::ItemEnum(..) => "an enum",
hir::ItemFn(..) => {
hir::ItemKind::Const(..) => "a constant",
hir::ItemKind::Enum(..) => "an enum",
hir::ItemKind::Fn(..) => {
// ignore main()
if it.name == "main" {
let def_id = cx.tcx.hir.local_def_id(it.id);
@ -135,19 +135,19 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for MissingDoc {
}
"a function"
},
hir::ItemMod(..) => "a module",
hir::ItemStatic(..) => "a static",
hir::ItemStruct(..) => "a struct",
hir::ItemTrait(..) => "a trait",
hir::ItemTraitAlias(..) => "a trait alias",
hir::ItemGlobalAsm(..) => "an assembly blob",
hir::ItemTy(..) => "a type alias",
hir::ItemUnion(..) => "a union",
hir::ItemExistential(..) => "an existential type",
hir::ItemExternCrate(..) |
hir::ItemForeignMod(..) |
hir::ItemImpl(..) |
hir::ItemUse(..) => return,
hir::ItemKind::Mod(..) => "a module",
hir::ItemKind::Static(..) => "a static",
hir::ItemKind::Struct(..) => "a struct",
hir::ItemKind::Trait(..) => "a trait",
hir::ItemKind::TraitAlias(..) => "a trait alias",
hir::ItemKind::GlobalAsm(..) => "an assembly blob",
hir::ItemKind::Ty(..) => "a type alias",
hir::ItemKind::Union(..) => "a union",
hir::ItemKind::Existential(..) => "an existential type",
hir::ItemKind::ExternCrate(..) |
hir::ItemKind::ForeignMod(..) |
hir::ItemKind::Impl(..) |
hir::ItemKind::Use(..) => return,
};
self.check_missing_docs_attrs(cx, &it.attrs, it.span, desc);

View file

@ -108,11 +108,11 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for MissingInline {
return;
}
match it.node {
hir::ItemFn(..) => {
hir::ItemKind::Fn(..) => {
let desc = "a function";
check_missing_inline_attrs(cx, &it.attrs, it.span, desc);
},
hir::ItemTrait(ref _is_auto, ref _unsafe, ref _generics,
hir::ItemKind::Trait(ref _is_auto, ref _unsafe, ref _generics,
ref _bounds, ref trait_items) => {
// note: we need to check if the trait is exported so we can't use
// `LateLintPass::check_trait_item` here.
@ -134,20 +134,20 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for MissingInline {
}
}
}
hir::ItemConst(..) |
hir::ItemEnum(..) |
hir::ItemMod(..) |
hir::ItemStatic(..) |
hir::ItemStruct(..) |
hir::ItemTraitAlias(..) |
hir::ItemGlobalAsm(..) |
hir::ItemTy(..) |
hir::ItemUnion(..) |
hir::ItemExistential(..) |
hir::ItemExternCrate(..) |
hir::ItemForeignMod(..) |
hir::ItemImpl(..) |
hir::ItemUse(..) => {},
hir::ItemKind::Const(..) |
hir::ItemKind::Enum(..) |
hir::ItemKind::Mod(..) |
hir::ItemKind::Static(..) |
hir::ItemKind::Struct(..) |
hir::ItemKind::TraitAlias(..) |
hir::ItemKind::GlobalAsm(..) |
hir::ItemKind::Ty(..) |
hir::ItemKind::Union(..) |
hir::ItemKind::Existential(..) |
hir::ItemKind::ExternCrate(..) |
hir::ItemKind::ForeignMod(..) |
hir::ItemKind::Impl(..) |
hir::ItemKind::Use(..) => {},
};
}

View file

@ -88,8 +88,8 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for NeedlessPassByValue {
// Exclude non-inherent impls
if let Some(NodeItem(item)) = cx.tcx.hir.find(cx.tcx.hir.get_parent_node(node_id)) {
if matches!(item.node, ItemImpl(_, _, _, _, Some(_), _, _) |
ItemTrait(..))
if matches!(item.node, ItemKind::Impl(_, _, _, _, Some(_), _, _) |
ItemKind::Trait(..))
{
return;
}
@ -351,7 +351,7 @@ impl<'a, 'tcx> MovedVariablesCtxt<'a, 'tcx> {
// `let <pat> = x;`
if_chain! {
if let StmtKind::Decl(ref decl, _) = s.node;
if let DeclLocal(ref local) = decl.node;
if let DeclKind::Local(ref local) = decl.node;
then {
self.spans_need_deref
.entry(vid)

View file

@ -89,7 +89,7 @@ impl LintPass for NewWithoutDefault {
impl<'a, 'tcx> LateLintPass<'a, 'tcx> for NewWithoutDefault {
fn check_item(&mut self, cx: &LateContext<'a, 'tcx>, item: &'tcx hir::Item) {
if let hir::ItemImpl(_, _, _, _, None, _, ref items) = item.node {
if let hir::ItemKind::Impl(_, _, _, _, None, _, ref items) = item.node {
for assoc_item in items {
if let hir::AssociatedItemKind::Method { has_self: false } = assoc_item.kind {
let impl_item = cx.tcx.hir.impl_item(assoc_item.id);

View file

@ -164,7 +164,7 @@ impl LintPass for NonCopyConst {
impl<'a, 'tcx> LateLintPass<'a, 'tcx> for NonCopyConst {
fn check_item(&mut self, cx: &LateContext<'a, 'tcx>, it: &'tcx Item) {
if let ItemConst(hir_ty, ..) = &it.node {
if let ItemKind::Const(hir_ty, ..) = &it.node {
let ty = hir_ty_to_ty(cx.tcx, hir_ty);
verify_ty_bound(cx, ty, Source::Item { item: it.span });
}
@ -182,7 +182,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for NonCopyConst {
let item_node_id = cx.tcx.hir.get_parent_node(impl_item.id);
let item = cx.tcx.hir.expect_item(item_node_id);
// ensure the impl is an inherent impl.
if let ItemImpl(_, _, _, _, None, _, _) = item.node {
if let ItemKind::Impl(_, _, _, _, None, _, _) = item.node {
let ty = hir_ty_to_ty(cx.tcx, hir_ty);
verify_ty_bound(cx, ty, Source::Assoc { ty: hir_ty.span, item: impl_item.span });
}

View file

@ -43,7 +43,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for OverflowCheckConditional {
if cx.tables.expr_ty(ident2).is_integral();
then {
if let BinOpKind::Lt = op.node {
if let BinOpKindAdd = op2.node {
if let BinOpKind::Add = op2.node {
span_lint(cx, OVERFLOW_CHECK_CONDITIONAL, expr.span,
"You are trying to use classic C overflow conditions that will fail in Rust.");
}
@ -68,7 +68,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for OverflowCheckConditional {
if cx.tables.expr_ty(ident2).is_integral();
then {
if let BinOpKind::Gt = op.node {
if let BinOpKindAdd = op2.node {
if let BinOpKind::Add = op2.node {
span_lint(cx, OVERFLOW_CHECK_CONDITIONAL, expr.span,
"You are trying to use classic C overflow conditions that will fail in Rust.");
}

View file

@ -38,7 +38,7 @@ impl LintPass for Pass {
impl<'a, 'tcx> LateLintPass<'a, 'tcx> for Pass {
fn check_item(&mut self, cx: &LateContext<'a, 'tcx>, item: &'tcx Item) {
if_chain! {
if let ItemImpl(_, _, _, _, Some(ref trait_ref), _, ref impl_items) = item.node;
if let ItemKind::Impl(_, _, _, _, Some(ref trait_ref), _, ref impl_items) = item.node;
if !is_automatically_derived(&*item.attrs);
if let Some(eq_trait) = cx.tcx.lang_items().eq_trait();
if trait_ref.path.def.def_id() == eq_trait;

View file

@ -103,7 +103,7 @@ impl LintPass for PointerPass {
impl<'a, 'tcx> LateLintPass<'a, 'tcx> for PointerPass {
fn check_item(&mut self, cx: &LateContext<'a, 'tcx>, item: &'tcx Item) {
if let ItemFn(ref decl, _, _, body_id) = item.node {
if let ItemKind::Fn(ref decl, _, _, body_id) = item.node {
check_fn(cx, decl, item.id, Some(body_id));
}
}
@ -111,7 +111,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for PointerPass {
fn check_impl_item(&mut self, cx: &LateContext<'a, 'tcx>, item: &'tcx ImplItem) {
if let ImplItemKind::Method(ref sig, body_id) = item.node {
if let Some(NodeItem(it)) = cx.tcx.hir.find(cx.tcx.hir.get_parent(item.id)) {
if let ItemImpl(_, _, _, _, Some(_), _, _) = it.node {
if let ItemKind::Impl(_, _, _, _, Some(_), _, _) = it.node {
return; // ignore trait impls
}
}

View file

@ -29,7 +29,7 @@ impl LintPass for Serde {
impl<'a, 'tcx> LateLintPass<'a, 'tcx> for Serde {
fn check_item(&mut self, cx: &LateContext<'a, 'tcx>, item: &'tcx Item) {
if let ItemImpl(_, _, _, _, Some(ref trait_ref), _, ref items) = item.node {
if let ItemKind::Impl(_, _, _, _, Some(ref trait_ref), _, ref items) = item.node {
let did = trait_ref.path.def.def_id();
if let Some(visit_did) = get_trait_def_id(cx, &paths::SERDE_DE_VISITOR) {
if did == visit_did {

View file

@ -127,7 +127,7 @@ fn check_decl<'a, 'tcx>(cx: &LateContext<'a, 'tcx>, decl: &'tcx Decl, bindings:
if higher::is_from_for_desugar(decl) {
return;
}
if let DeclLocal(ref local) = decl.node {
if let DeclKind::Local(ref local) = decl.node {
let Local {
ref pat,
ref ty,

View file

@ -59,10 +59,15 @@ impl LintPass for SuspiciousImpl {
impl<'a, 'tcx> LateLintPass<'a, 'tcx> for SuspiciousImpl {
fn check_expr(&mut self, cx: &LateContext<'a, 'tcx>, expr: &'tcx hir::Expr) {
use rustc::hir::BinOpKind::*;
if let hir::ExprKind::Binary(binop, _, _) = expr.node {
match binop.node {
BinOpKind::Eq | BinOpKind::Lt | BinOpKind::Le | BinOpKind::Ne | BinOpKind::Ge | BinOpKind::Gt => return,
| hir::BinOpKind::Eq
| hir::BinOpKind::Lt
| hir::BinOpKind::Le
| hir::BinOpKind::Ne
| hir::BinOpKind::Ge
| hir::BinOpKind::Gt
=> return,
_ => {},
}
// Check if the binary expression is part of another bi/unary expression
@ -94,7 +99,12 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for SuspiciousImpl {
expr,
binop.node,
&["Add", "Sub", "Mul", "Div"],
&[BinOpKind::Add, BinOpKind::Sub, BinOpKind::Mul, BinOpKind::Div],
&[
hir::BinOpKind::Add,
hir::BinOpKind::Sub,
hir::BinOpKind::Mul,
hir::BinOpKind::Div,
],
) {
span_lint(
cx,
@ -124,7 +134,16 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for SuspiciousImpl {
"ShrAssign",
],
&[
BinOpKind::Add, BinOpKind::Sub, BinOpKind::Mul, BinOpKind::Div, BinOpKind::BitAnd, BinOpKind::BitOr, BinOpKind::BitXor, BinOpKind::Rem, BinOpKind::Shl, BinOpKind::Shr
hir::BinOpKind::Add,
hir::BinOpKind::Sub,
hir::BinOpKind::Mul,
hir::BinOpKind::Div,
hir::BinOpKind::BitAnd,
hir::BinOpKind::BitOr,
hir::BinOpKind::BitXor,
hir::BinOpKind::Rem,
hir::BinOpKind::Shl,
hir::BinOpKind::Shr,
],
) {
span_lint(
@ -167,7 +186,7 @@ fn check_binop<'a>(
if_chain! {
if parent_impl != ast::CRATE_NODE_ID;
if let hir::map::Node::NodeItem(item) = cx.tcx.hir.get(parent_impl);
if let hir::Item_::ItemImpl(_, _, _, _, Some(ref trait_ref), _, _) = item.node;
if let hir::ItemKind::Impl(_, _, _, _, Some(ref trait_ref), _, _) = item.node;
if let Some(idx) = trait_ids.iter().position(|&tid| tid == trait_ref.path.def.def_id());
if binop != expected_ops[idx];
then{

View file

@ -62,7 +62,7 @@ fn check_manual_swap(cx: &LateContext, block: &Block) {
if_chain! {
// let t = foo();
if let StmtKind::Decl(ref tmp, _) = w[0].node;
if let DeclLocal(ref tmp) = tmp.node;
if let DeclKind::Local(ref tmp) = tmp.node;
if let Some(ref tmp_init) = tmp.init;
if let PatKind::Binding(_, _, ident, None) = tmp.pat.node;
@ -90,7 +90,7 @@ fn check_manual_swap(cx: &LateContext, block: &Block) {
if SpanlessEq::new(cx).ignore_fn().eq_expr(lhs1, lhs2) {
let ty = walk_ptrs_ty(cx.tables.expr_ty(lhs1));
if matches!(ty.sty, ty::TyKind::Slice(_)) ||
if matches!(ty.sty, ty::TySlice(_)) ||
matches!(ty.sty, ty::TyArray(_, _)) ||
match_type(cx, ty, &paths::VEC) ||
match_type(cx, ty, &paths::VEC_DEQUE) {

View file

@ -100,8 +100,8 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for TriviallyCopyPassByRef {
// Exclude non-inherent impls
if let Some(NodeItem(item)) = cx.tcx.hir.find(cx.tcx.hir.get_parent_node(node_id)) {
if matches!(item.node, ItemImpl(_, _, _, _, Some(_), _, _) |
ItemTrait(..))
if matches!(item.node, ItemKind::Impl(_, _, _, _, Some(_), _, _) |
ItemKind::Trait(..))
{
return;
}

View file

@ -139,7 +139,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for TypePass {
fn check_fn(&mut self, cx: &LateContext, _: FnKind, decl: &FnDecl, _: &Body, _: Span, id: NodeId) {
// skip trait implementations, see #605
if let Some(map::NodeItem(item)) = cx.tcx.hir.find(cx.tcx.hir.get_parent(id)) {
if let ItemImpl(_, _, _, _, Some(..), _, _) = item.node {
if let ItemKind::Impl(_, _, _, _, Some(..), _, _) = item.node {
return;
}
}
@ -343,7 +343,7 @@ fn check_ty_rptr(cx: &LateContext, ast_ty: &hir::Ty, is_local: bool, lt: &Lifeti
// Returns true if given type is `Any` trait.
fn is_any_trait(t: &hir::Ty) -> bool {
if_chain! {
if let TyTraitObject(ref traits, _) = t.node;
if let TyKind::TraitObject(ref traits, _) = t.node;
if traits.len() >= 1;
// Only Send/Sync can be used as additional traits, so it is enough to
// check only the first trait.
@ -377,7 +377,7 @@ declare_clippy_lint! {
}
fn check_let_unit(cx: &LateContext, decl: &Decl) {
if let DeclLocal(ref local) = decl.node {
if let DeclKind::Local(ref local) = decl.node {
if is_unit(cx.tables.pat_ty(&local.pat)) {
if in_external_macro(cx, decl.span) || in_macro(local.pat.span) {
return;
@ -1141,7 +1141,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for TypeComplexityPass {
fn check_item(&mut self, cx: &LateContext<'a, 'tcx>, item: &'tcx Item) {
match item.node {
ItemStatic(ref ty, _, _) | ItemConst(ref ty, _) => self.check_type(cx, ty),
ItemKind::Static(ref ty, _, _) | ItemKind::Const(ref ty, _) => self.check_type(cx, ty),
// functions, enums, structs, impls and traits are covered
_ => (),
}
@ -1222,7 +1222,7 @@ impl<'tcx> Visitor<'tcx> for TypeComplexityVisitor {
// function types bring a lot of overhead
TyKind::BareFn(..) => (50 * self.nest, 1),
TyTraitObject(ref param_bounds, _) => {
TyKind::TraitObject(ref param_bounds, _) => {
let has_lifetime_parameters = param_bounds
.iter()
.any(|bound| bound.bound_generic_params.iter().any(|gen| match gen.kind {
@ -1797,7 +1797,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for ImplicitHasher {
}
match item.node {
ItemImpl(_, _, _, ref generics, _, ref ty, ref items) => {
ItemKind::Impl(_, _, _, ref generics, _, ref ty, ref items) => {
let mut vis = ImplicitHasherTypeVisitor::new(cx);
vis.visit_ty(ty);
@ -1829,7 +1829,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for ImplicitHasher {
);
}
},
ItemFn(ref decl, .., ref generics, body_id) => {
ItemKind::Fn(ref decl, .., ref generics, body_id) => {
let body = cx.tcx.hir.body(body_id);
for ty in &decl.inputs {

View file

@ -55,7 +55,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for UseSelf {
return;
}
if_chain! {
if let ItemImpl(.., ref item_type, ref refs) = item.node;
if let ItemKind::Impl(.., ref item_type, ref refs) = item.node;
if let TyKind::Path(QPath::Resolved(_, ref item_path)) = item_type.node;
then {
let parameters = &item_path.segments.last().expect(SEGMENTS_MSG).args;

View file

@ -588,20 +588,20 @@ impl<'tcx> Visitor<'tcx> for PrintVisitor {
}
fn visit_stmt(&mut self, s: &Stmt) {
print!(" if let Stmt_::");
print!(" if let StmtKind::");
let current = format!("{}.node", self.current);
match s.node {
// Could be an item or a local (let) binding:
StmtKind::Decl(ref decl, _) => {
let decl_pat = self.next("decl");
println!("StmtKind::Decl(ref {}, _) = {}", decl_pat, current);
print!(" if let Decl_::");
println!("Decl(ref {}, _) = {}", decl_pat, current);
print!(" if let DeclKind::");
let current = format!("{}.node", decl_pat);
match decl.node {
// A local (let) binding:
DeclKind::Local(ref local) => {
let local_pat = self.next("local");
println!("DeclLocal(ref {}) = {};", local_pat, current);
println!("Local(ref {}) = {};", local_pat, current);
if let Some(ref init) = local.init {
let init_pat = self.next("init");
println!(" if let Some(ref {}) = {}.init", init_pat, local_pat);
@ -613,7 +613,7 @@ impl<'tcx> Visitor<'tcx> for PrintVisitor {
},
// An item binding:
DeclKind::Item(_) => {
println!("DeclItem(item_id) = {};", current);
println!("Item(item_id) = {};", current);
},
}
}
@ -621,7 +621,7 @@ impl<'tcx> Visitor<'tcx> for PrintVisitor {
// Expr without trailing semi-colon (must have unit type):
StmtKind::Expr(ref e, _) => {
let e_pat = self.next("e");
println!("StmtKind::Expr(ref {}, _) = {}", e_pat, current);
println!("Expr(ref {}, _) = {}", e_pat, current);
self.current = e_pat;
self.visit_expr(e);
},
@ -629,7 +629,7 @@ impl<'tcx> Visitor<'tcx> for PrintVisitor {
// Expr with trailing semi-colon (may have any type):
StmtKind::Semi(ref e, _) => {
let e_pat = self.next("e");
println!("StmtKind::Semi(ref {}, _) = {}", e_pat, current);
println!("Semi(ref {}, _) = {}", e_pat, current);
self.current = e_pat;
self.visit_expr(e);
},

View file

@ -154,7 +154,7 @@ pub fn is_from_for_desugar(decl: &hir::Decl) -> bool {
// }
// ```
if_chain! {
if let hir::DeclLocal(ref loc) = decl.node;
if let hir::DeclKind::Local(ref loc) = decl.node;
if let Some(ref expr) = loc.init;
if let hir::ExprKind::Match(_, _, hir::MatchSource::ForLoopDesugar) = expr.node;
then {
@ -171,7 +171,7 @@ pub fn is_from_for_desugar(decl: &hir::Decl) -> bool {
// }
// ```
if_chain! {
if let hir::DeclLocal(ref loc) = decl.node;
if let hir::DeclKind::Local(ref loc) = decl.node;
if let hir::LocalSource::ForLoopDesugar = loc.source;
then {
return true;
@ -192,7 +192,7 @@ pub fn for_loop(expr: &hir::Expr) -> Option<(&hir::Pat, &hir::Expr, &hir::Expr)>
if block.expr.is_none();
if let [ _, _, ref let_stmt, ref body ] = *block.stmts;
if let hir::StmtKind::Decl(ref decl, _) = let_stmt.node;
if let hir::DeclLocal(ref decl) = decl.node;
if let hir::DeclKind::Local(ref decl) = decl.node;
if let hir::StmtKind::Expr(ref expr, _) = body.node;
then {
return Some((&*decl.pat, &iterargs[0], expr));

View file

@ -44,7 +44,7 @@ impl<'a, 'tcx: 'a> SpanlessEq<'a, 'tcx> {
pub fn eq_stmt(&mut self, left: &Stmt, right: &Stmt) -> bool {
match (&left.node, &right.node) {
(&StmtKind::Decl(ref l, _), &StmtKind::Decl(ref r, _)) => {
if let (&DeclLocal(ref l), &DeclLocal(ref r)) = (&l.node, &r.node) {
if let (&DeclKind::Local(ref l), &DeclKind::Local(ref r)) = (&l.node, &r.node) {
both(&l.ty, &r.ty, |l, r| self.eq_ty(l, r)) && both(&l.init, &r.init, |l, r| self.eq_expr(l, r))
} else {
false
@ -617,7 +617,7 @@ impl<'a, 'tcx: 'a> SpanlessHash<'a, 'tcx> {
let c: fn(_, _) -> _ = StmtKind::Decl;
c.hash(&mut self.s);
if let DeclLocal(ref local) = decl.node {
if let DeclKind::Local(ref local) = decl.node {
if let Some(ref init) = local.init {
self.hash_expr(init);
}

View file

@ -141,7 +141,7 @@ fn has_attr(attrs: &[Attribute]) -> bool {
fn print_decl(cx: &LateContext, decl: &hir::Decl) {
match decl.node {
hir::DeclLocal(ref local) => {
hir::DeclKind::Local(ref local) => {
println!("local variable of type {}", cx.tables.node_id_to_type(local.hir_id));
println!("pattern:");
print_pat(cx, &local.pat, 0);
@ -150,7 +150,7 @@ fn print_decl(cx: &LateContext, decl: &hir::Decl) {
print_expr(cx, e, 0);
}
},
hir::DeclItem(_) => println!("item decl"),
hir::DeclKind::Item(_) => println!("item decl"),
}
}
@ -353,7 +353,7 @@ fn print_item(cx: &LateContext, item: &hir::Item) {
hir::VisibilityKind::Inherited => println!("visibility inherited from outer item"),
}
match item.node {
hir::ItemExternCrate(ref _renamed_from) => {
hir::ItemKind::ExternCrate(ref _renamed_from) => {
let def_id = cx.tcx.hir.local_def_id(item.id);
if let Some(crate_id) = cx.tcx.extern_mod_stmt_cnum(def_id) {
let source = cx.tcx.used_crate_source(crate_id);
@ -367,32 +367,32 @@ fn print_item(cx: &LateContext, item: &hir::Item) {
println!("weird extern crate without a crate id");
}
},
hir::ItemUse(ref path, ref kind) => println!("{:?}, {:?}", path, kind),
hir::ItemStatic(..) => println!("static item of type {:#?}", cx.tcx.type_of(did)),
hir::ItemConst(..) => println!("const item of type {:#?}", cx.tcx.type_of(did)),
hir::ItemFn(..) => {
hir::ItemKind::Use(ref path, ref kind) => println!("{:?}, {:?}", path, kind),
hir::ItemKind::Static(..) => println!("static item of type {:#?}", cx.tcx.type_of(did)),
hir::ItemKind::Const(..) => println!("const item of type {:#?}", cx.tcx.type_of(did)),
hir::ItemKind::Fn(..) => {
let item_ty = cx.tcx.type_of(did);
println!("function of type {:#?}", item_ty);
},
hir::ItemMod(..) => println!("module"),
hir::ItemForeignMod(ref fm) => println!("foreign module with abi: {}", fm.abi),
hir::ItemGlobalAsm(ref asm) => println!("global asm: {:?}", asm),
hir::ItemTy(..) => {
hir::ItemKind::Mod(..) => println!("module"),
hir::ItemKind::ForeignMod(ref fm) => println!("foreign module with abi: {}", fm.abi),
hir::ItemKind::GlobalAsm(ref asm) => println!("global asm: {:?}", asm),
hir::ItemKind::Ty(..) => {
println!("type alias for {:?}", cx.tcx.type_of(did));
},
hir::ItemExistential(..) => {
hir::ItemKind::Existential(..) => {
println!("existential type with real type {:?}", cx.tcx.type_of(did));
},
hir::ItemEnum(..) => {
hir::ItemKind::Enum(..) => {
println!("enum definition of type {:?}", cx.tcx.type_of(did));
},
hir::ItemStruct(..) => {
hir::ItemKind::Struct(..) => {
println!("struct definition of type {:?}", cx.tcx.type_of(did));
},
hir::ItemUnion(..) => {
hir::ItemKind::Union(..) => {
println!("union definition of type {:?}", cx.tcx.type_of(did));
},
hir::ItemTrait(..) => {
hir::ItemKind::Trait(..) => {
println!("trait decl");
if cx.tcx.trait_is_auto(did) {
println!("trait is auto");
@ -400,13 +400,13 @@ fn print_item(cx: &LateContext, item: &hir::Item) {
println!("trait is not auto");
}
},
hir::ItemTraitAlias(..) => {
hir::ItemKind::TraitAlias(..) => {
println!("trait alias");
}
hir::ItemImpl(_, _, _, _, Some(ref _trait_ref), _, _) => {
hir::ItemKind::Impl(_, _, _, _, Some(ref _trait_ref), _, _) => {
println!("trait impl");
},
hir::ItemImpl(_, _, _, _, None, _, _) => {
hir::ItemKind::Impl(_, _, _, _, None, _, _) => {
println!("impl");
},
}

View file

@ -1,5 +1,6 @@
use rustc::lint::*;
use rustc::hir::*;
use rustc::hir;
use rustc::hir::intravisit::{walk_expr, NestedVisitorMap, Visitor};
use crate::utils::{match_qpath, paths, span_lint};
use syntax::symbol::LocalInternedString;
@ -117,7 +118,7 @@ impl LintPass for LintWithoutLintPass {
impl<'a, 'tcx> LateLintPass<'a, 'tcx> for LintWithoutLintPass {
fn check_item(&mut self, cx: &LateContext<'a, 'tcx>, item: &'tcx Item) {
if let ItemStatic(ref ty, MutImmutable, body_id) = item.node {
if let hir::ItemKind::Static(ref ty, MutImmutable, body_id) = item.node {
if is_lint_ref_type(ty) {
self.declared_lints.insert(item.name, item.span);
} else if is_lint_array_type(ty) && item.name == "ARRAY" {

View file

@ -524,7 +524,7 @@ pub fn get_enclosing_block<'a, 'tcx: 'a>(cx: &LateContext<'a, 'tcx>, node: NodeI
match node {
Node::NodeBlock(block) => Some(block),
Node::NodeItem(&Item {
node: ItemFn(_, _, _, eid),
node: ItemKind::Fn(_, _, _, eid),
..
}) | Node::NodeImplItem(&ImplItem {
node: ImplItemKind::Method(_, eid),

View file

@ -382,21 +382,29 @@ fn associativity(op: &AssocOp) -> Associativity {
/// Convert a `hir::BinOp` to the corresponding assigning binary operator.
fn hirbinop2assignop(op: hir::BinOp) -> AssocOp {
use rustc::hir::BinOpKind::*;
use syntax::parse::token::BinOpToken::*;
AssocOp::AssignOp(match op.node {
BinOpKind::Add => Plus,
BinOpKind::BitAnd => And,
BinOpKind::BitOr => Or,
BinOpKind::BitXor => Caret,
BinOpKind::Div => Slash,
BinOpKind::Mul => Star,
BinOpKind::Rem => Percent,
BinOpKind::Shl => Shl,
BinOpKind::Shr => Shr,
BinOpKind::Sub => Minus,
BinOpKind::And | BinOpKind::Eq | BinOpKind::Ge | BinOpKind::Gt | BinOpKind::Le | BinOpKind::Lt | BinOpKind::Ne | BinOpKind::Or => panic!("This operator does not exist"),
hir::BinOpKind::Add => Plus,
hir::BinOpKind::BitAnd => And,
hir::BinOpKind::BitOr => Or,
hir::BinOpKind::BitXor => Caret,
hir::BinOpKind::Div => Slash,
hir::BinOpKind::Mul => Star,
hir::BinOpKind::Rem => Percent,
hir::BinOpKind::Shl => Shl,
hir::BinOpKind::Shr => Shr,
hir::BinOpKind::Sub => Minus,
| hir::BinOpKind::And
| hir::BinOpKind::Eq
| hir::BinOpKind::Ge
| hir::BinOpKind::Gt
| hir::BinOpKind::Le
| hir::BinOpKind::Lt
| hir::BinOpKind::Ne
| hir::BinOpKind::Or
=> panic!("This operator does not exist"),
})
}

View file

@ -448,7 +448,7 @@ fn is_in_debug_impl(cx: &LateContext, expr: &Expr) -> bool {
if let Some(NodeImplItem(item)) = map.find(map.get_parent(expr.id)) {
// `Debug` impl
if let Some(NodeItem(item)) = map.find(map.get_parent(item.id)) {
if let ItemImpl(_, _, _, _, Some(ref tr), _, _) = item.node {
if let ItemKind::Impl(_, _, _, _, Some(ref tr), _, _) = item.node {
return match_path(&tr.path, &["Debug"]);
}
}