From 3430bc1bc5bdc24c101c17d0bd0822c7b57d43b9 Mon Sep 17 00:00:00 2001 From: Manish Goregaokar Date: Wed, 27 Nov 2019 14:34:32 -0800 Subject: [PATCH] Re-add wildcards for BorrowKind in some places --- clippy_lints/src/eval_order_dependence.rs | 2 +- clippy_lints/src/functions.rs | 2 +- clippy_lints/src/no_effect.rs | 4 ++-- clippy_lints/src/reference.rs | 4 ++-- clippy_lints/src/shadow.rs | 4 ++-- clippy_lints/src/utils/hir_utils.rs | 11 ++++++++--- clippy_lints/src/utils/inspector.rs | 3 ++- 7 files changed, 18 insertions(+), 12 deletions(-) diff --git a/clippy_lints/src/eval_order_dependence.rs b/clippy_lints/src/eval_order_dependence.rs index 60ed79d8f63..e32e15be053 100644 --- a/clippy_lints/src/eval_order_dependence.rs +++ b/clippy_lints/src/eval_order_dependence.rs @@ -328,7 +328,7 @@ impl<'a, 'tcx> Visitor<'tcx> for ReadVisitor<'a, 'tcx> { // ``` // // TODO: fix this - ExprKind::AddrOf(BorrowKind::Ref, _, _) => { + ExprKind::AddrOf(_, _, _) => { return; } _ => {} diff --git a/clippy_lints/src/functions.rs b/clippy_lints/src/functions.rs index 21ef9e147ff..effd2dc58d4 100644 --- a/clippy_lints/src/functions.rs +++ b/clippy_lints/src/functions.rs @@ -656,7 +656,7 @@ impl<'a, 'tcx> intravisit::Visitor<'tcx> for StaticMutVisitor<'a, 'tcx> { tys.clear(); } }, - Assign(ref target, _) | AssignOp(_, ref target, _) | AddrOf(BorrowKind::Ref, hir::Mutability::Mutable, ref target) => { + Assign(ref target, _) | AssignOp(_, ref target, _) | AddrOf(_, hir::Mutability::Mutable, ref target) => { self.mutates_static |= is_mutated_static(self.cx, target) }, _ => {}, diff --git a/clippy_lints/src/no_effect.rs b/clippy_lints/src/no_effect.rs index df39c632070..63cd44fb2a5 100644 --- a/clippy_lints/src/no_effect.rs +++ b/clippy_lints/src/no_effect.rs @@ -58,7 +58,7 @@ fn has_no_effect(cx: &LateContext<'_, '_>, expr: &Expr) -> bool { | ExprKind::Type(ref inner, _) | ExprKind::Unary(_, ref inner) | ExprKind::Field(ref inner, _) - | ExprKind::AddrOf(BorrowKind::Ref, _, ref inner) + | ExprKind::AddrOf(_, _, ref inner) | ExprKind::Box(ref inner) => has_no_effect(cx, inner), ExprKind::Struct(_, ref fields, ref base) => { !has_drop(cx, cx.tables.expr_ty(expr)) @@ -134,7 +134,7 @@ fn reduce_expression<'a>(cx: &LateContext<'_, '_>, expr: &'a Expr) -> Option reduce_expression(cx, inner).or_else(|| Some(vec![inner])), ExprKind::Struct(_, ref fields, ref base) => { if has_drop(cx, cx.tables.expr_ty(expr)) { diff --git a/clippy_lints/src/reference.rs b/clippy_lints/src/reference.rs index 025e9fad7b3..28ff6907585 100644 --- a/clippy_lints/src/reference.rs +++ b/clippy_lints/src/reference.rs @@ -37,7 +37,7 @@ impl EarlyLintPass for DerefAddrOf { fn check_expr(&mut self, cx: &EarlyContext<'_>, e: &Expr) { if_chain! { if let ExprKind::Unary(UnOp::Deref, ref deref_target) = e.kind; - if let ExprKind::AddrOf(BorrowKind::Ref, _, ref addrof_target) = without_parens(deref_target).kind; + if let ExprKind::AddrOf(_, _, ref addrof_target) = without_parens(deref_target).kind; if !in_macro(addrof_target.span); then { let mut applicability = Applicability::MachineApplicable; @@ -80,7 +80,7 @@ impl EarlyLintPass for RefInDeref { if_chain! { if let ExprKind::Field(ref object, _) = e.kind; if let ExprKind::Paren(ref parened) = object.kind; - if let ExprKind::AddrOf(BorrowKind::Ref, _, ref inner) = parened.kind; + if let ExprKind::AddrOf(_, _, ref inner) = parened.kind; then { let mut applicability = Applicability::MachineApplicable; span_lint_and_sugg( diff --git a/clippy_lints/src/shadow.rs b/clippy_lints/src/shadow.rs index cb72fdcd4af..f6749a31419 100644 --- a/clippy_lints/src/shadow.rs +++ b/clippy_lints/src/shadow.rs @@ -315,7 +315,7 @@ fn check_expr<'a, 'tcx>(cx: &LateContext<'a, 'tcx>, expr: &'tcx Expr, bindings: match expr.kind { ExprKind::Unary(_, ref e) | ExprKind::Field(ref e, _) - | ExprKind::AddrOf(BorrowKind::Ref, _, ref e) + | ExprKind::AddrOf(_, _, ref e) | ExprKind::Box(ref e) => check_expr(cx, e, bindings), ExprKind::Block(ref block, _) | ExprKind::Loop(ref block, _, _) => check_block(cx, block, bindings), // ExprKind::Call @@ -366,7 +366,7 @@ fn check_ty<'a, 'tcx>(cx: &LateContext<'a, 'tcx>, ty: &'tcx Ty, bindings: &mut V fn is_self_shadow(name: Name, expr: &Expr) -> bool { match expr.kind { - ExprKind::Box(ref inner) | ExprKind::AddrOf(BorrowKind::Ref, _, ref inner) => is_self_shadow(name, inner), + ExprKind::Box(ref inner) | ExprKind::AddrOf(_, _, ref inner) => is_self_shadow(name, inner), ExprKind::Block(ref block, _) => { block.stmts.is_empty() && block.expr.as_ref().map_or(false, |e| is_self_shadow(name, e)) }, diff --git a/clippy_lints/src/utils/hir_utils.rs b/clippy_lints/src/utils/hir_utils.rs index 4e4d37cc484..c95287f83d1 100644 --- a/clippy_lints/src/utils/hir_utils.rs +++ b/clippy_lints/src/utils/hir_utils.rs @@ -78,8 +78,8 @@ impl<'a, 'tcx> SpanlessEq<'a, 'tcx> { } match (&left.kind, &right.kind) { - (&ExprKind::AddrOf(BorrowKind::Ref, l_mut, ref le), &ExprKind::AddrOf(BorrowKind::Ref, r_mut, ref re)) => { - l_mut == r_mut && self.eq_expr(le, re) + (&ExprKind::AddrOf(lb, l_mut, ref le), &ExprKind::AddrOf(rb, r_mut, ref re)) => { + lb == rb && l_mut == r_mut && self.eq_expr(le, re) }, (&ExprKind::Continue(li), &ExprKind::Continue(ri)) => { both(&li.label, &ri.label, |l, r| l.ident.as_str() == r.ident.as_str()) @@ -398,7 +398,12 @@ impl<'a, 'tcx> SpanlessHash<'a, 'tcx> { std::mem::discriminant(&e.kind).hash(&mut self.s); match e.kind { - ExprKind::AddrOf(BorrowKind::Ref, m, ref e) => { + ExprKind::AddrOf(kind, m, ref e) => { + match kind { + BorrowKind::Ref => 0, + BorrowKind::Raw => 1, + } + .hash(&mut self.s); m.hash(&mut self.s); self.hash_expr(e); }, diff --git a/clippy_lints/src/utils/inspector.rs b/clippy_lints/src/utils/inspector.rs index c40f3430ab8..285ce1f5fc4 100644 --- a/clippy_lints/src/utils/inspector.rs +++ b/clippy_lints/src/utils/inspector.rs @@ -264,8 +264,9 @@ fn print_expr(cx: &LateContext<'_, '_>, expr: &hir::Expr, indent: usize) { println!("{}Relative Path, {:?}", ind, ty); println!("{}seg: {:?}", ind, seg); }, - hir::ExprKind::AddrOf(BorrowKind::Ref, ref muta, ref e) => { + hir::ExprKind::AddrOf(kind, ref muta, ref e) => { println!("{}AddrOf", ind); + println!("kind: {:?}", kind); println!("mutability: {:?}", muta); print_expr(cx, e, indent + 1); },