Skip to content

[beta] Clippy backports #133299

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Nov 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/tools/clippy/clippy_lints/src/borrow_deref_ref.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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()
Expand Down
6 changes: 4 additions & 2 deletions src/tools/clippy/clippy_lints/src/manual_is_power_of_two.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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`"
}

Expand Down
6 changes: 6 additions & 0 deletions src/tools/clippy/tests/ui/borrow_deref_ref.fixed
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
6 changes: 6 additions & 0 deletions src/tools/clippy/tests/ui/borrow_deref_ref.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Loading