From 7b688e21d62609d59467b78b5b6f4a2dd40f3c80 Mon Sep 17 00:00:00 2001 From: bors Date: Tue, 15 Oct 2024 20:02:57 +0000 Subject: [PATCH 1/2] Auto merge of #13553 - SpriteOvO:manual_is_power_of_two-change-category, r=llogiq Change the category of `manual_is_power_of_two` to `pedantic` Fixes #13547. The value being checked might be a bit flag, suggesting `is_power_of_two` for it would make the code unreadable. changelog: [`manual_is_power_of_two`]: Change the category to `pedantic` --- src/tools/clippy/clippy_lints/src/manual_is_power_of_two.rs | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/tools/clippy/clippy_lints/src/manual_is_power_of_two.rs b/src/tools/clippy/clippy_lints/src/manual_is_power_of_two.rs index da2a982ee17..738201b8fe4 100644 --- a/src/tools/clippy/clippy_lints/src/manual_is_power_of_two.rs +++ b/src/tools/clippy/clippy_lints/src/manual_is_power_of_two.rs @@ -11,10 +11,12 @@ use rustc_session::declare_lint_pass; declare_clippy_lint! { /// ### What it does - /// Checks for expressions like `x.count_ones() == 1` or `x & (x - 1) == 0`, with x and unsigned integer, which are manual + /// Checks for expressions like `x.count_ones() == 1` or `x & (x - 1) == 0`, with x and unsigned integer, which may be manual /// reimplementations of `x.is_power_of_two()`. + /// /// ### Why is this bad? /// Manual reimplementations of `is_power_of_two` increase code complexity for little benefit. + /// /// ### Example /// ```no_run /// let a: u32 = 4; @@ -27,7 +29,7 @@ declare_clippy_lint! { /// ``` #[clippy::version = "1.82.0"] pub MANUAL_IS_POWER_OF_TWO, - complexity, + pedantic, "manually reimplementing `is_power_of_two`" } From 5f4dd1deeb5f23458fe58457f457cc2769e14951 Mon Sep 17 00:00:00 2001 From: bors Date: Sun, 27 Oct 2024 12:37:40 +0000 Subject: [PATCH 2/2] Auto merge of #13600 - samueltardieu:push-tzuvnutssmrs, r=xFrednet borrow_deref_ref: do not trigger on `&raw` references changelog: [`borrow_deref_ref`]: do not trigger on `&raw` references Fix #13584 --- src/tools/clippy/clippy_lints/src/borrow_deref_ref.rs | 4 ++-- src/tools/clippy/tests/ui/borrow_deref_ref.fixed | 6 ++++++ src/tools/clippy/tests/ui/borrow_deref_ref.rs | 6 ++++++ 3 files changed, 14 insertions(+), 2 deletions(-) diff --git a/src/tools/clippy/clippy_lints/src/borrow_deref_ref.rs b/src/tools/clippy/clippy_lints/src/borrow_deref_ref.rs index cba8224b84c..f2551a05b1a 100644 --- a/src/tools/clippy/clippy_lints/src/borrow_deref_ref.rs +++ b/src/tools/clippy/clippy_lints/src/borrow_deref_ref.rs @@ -4,7 +4,7 @@ use clippy_utils::source::SpanRangeExt; use clippy_utils::ty::implements_trait; use clippy_utils::{get_parent_expr, is_from_proc_macro, is_lint_allowed}; use rustc_errors::Applicability; -use rustc_hir::{ExprKind, UnOp}; +use rustc_hir::{BorrowKind, ExprKind, UnOp}; use rustc_lint::{LateContext, LateLintPass}; use rustc_middle::mir::Mutability; use rustc_middle::ty; @@ -49,7 +49,7 @@ declare_lint_pass!(BorrowDerefRef => [BORROW_DEREF_REF]); impl<'tcx> LateLintPass<'tcx> for BorrowDerefRef { fn check_expr(&mut self, cx: &LateContext<'tcx>, e: &rustc_hir::Expr<'tcx>) { - if let ExprKind::AddrOf(_, Mutability::Not, addrof_target) = e.kind + if let ExprKind::AddrOf(BorrowKind::Ref, Mutability::Not, addrof_target) = e.kind && let ExprKind::Unary(UnOp::Deref, deref_target) = addrof_target.kind && !matches!(deref_target.kind, ExprKind::Unary(UnOp::Deref, ..)) && !e.span.from_expansion() diff --git a/src/tools/clippy/tests/ui/borrow_deref_ref.fixed b/src/tools/clippy/tests/ui/borrow_deref_ref.fixed index ea5e983de3b..22e984c46d2 100644 --- a/src/tools/clippy/tests/ui/borrow_deref_ref.fixed +++ b/src/tools/clippy/tests/ui/borrow_deref_ref.fixed @@ -71,3 +71,9 @@ mod false_negative { assert_ne!(addr_x, addr_y); } } + +fn issue_13584() { + let s = "Hello, world!\n"; + let p = &raw const *s; + let _ = p as *const i8; +} diff --git a/src/tools/clippy/tests/ui/borrow_deref_ref.rs b/src/tools/clippy/tests/ui/borrow_deref_ref.rs index 8c8905b150e..61d89193f42 100644 --- a/src/tools/clippy/tests/ui/borrow_deref_ref.rs +++ b/src/tools/clippy/tests/ui/borrow_deref_ref.rs @@ -71,3 +71,9 @@ mod false_negative { assert_ne!(addr_x, addr_y); } } + +fn issue_13584() { + let s = "Hello, world!\n"; + let p = &raw const *s; + let _ = p as *const i8; +}