Skip to content

Commit f9c2695

Browse files
committed
Auto merge of #133299 - flip1995:clippy-beta-backport, r=Mark-Simulacrum
[beta] Clippy backports r? `@Mark-Simulacrum` Backports: - rust-lang/rust-clippy#13553 - rust-lang/rust-clippy#13600 The first is just a regrouping to a allow-by-default group, as we figured that the lint would be too noisy as a warn-by-default lint. That lint was added last release cycle, so we want to do the re-grouping before it hits stable. The second is a bug fix for `&raw` references that are already stable in `1.82`, but we don't want to wait another release cycle for the fix to land on stable. Both commits are already synced to the current `master branch`.
2 parents b35ad72 + 5f4dd1d commit f9c2695

File tree

4 files changed

+18
-4
lines changed

4 files changed

+18
-4
lines changed

src/tools/clippy/clippy_lints/src/borrow_deref_ref.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ use clippy_utils::source::SpanRangeExt;
44
use clippy_utils::ty::implements_trait;
55
use clippy_utils::{get_parent_expr, is_from_proc_macro, is_lint_allowed};
66
use rustc_errors::Applicability;
7-
use rustc_hir::{ExprKind, UnOp};
7+
use rustc_hir::{BorrowKind, ExprKind, UnOp};
88
use rustc_lint::{LateContext, LateLintPass};
99
use rustc_middle::mir::Mutability;
1010
use rustc_middle::ty;
@@ -49,7 +49,7 @@ declare_lint_pass!(BorrowDerefRef => [BORROW_DEREF_REF]);
4949

5050
impl<'tcx> LateLintPass<'tcx> for BorrowDerefRef {
5151
fn check_expr(&mut self, cx: &LateContext<'tcx>, e: &rustc_hir::Expr<'tcx>) {
52-
if let ExprKind::AddrOf(_, Mutability::Not, addrof_target) = e.kind
52+
if let ExprKind::AddrOf(BorrowKind::Ref, Mutability::Not, addrof_target) = e.kind
5353
&& let ExprKind::Unary(UnOp::Deref, deref_target) = addrof_target.kind
5454
&& !matches!(deref_target.kind, ExprKind::Unary(UnOp::Deref, ..))
5555
&& !e.span.from_expansion()

src/tools/clippy/clippy_lints/src/manual_is_power_of_two.rs

+4-2
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,12 @@ use rustc_session::declare_lint_pass;
1111

1212
declare_clippy_lint! {
1313
/// ### What it does
14-
/// Checks for expressions like `x.count_ones() == 1` or `x & (x - 1) == 0`, with x and unsigned integer, which are manual
14+
/// Checks for expressions like `x.count_ones() == 1` or `x & (x - 1) == 0`, with x and unsigned integer, which may be manual
1515
/// reimplementations of `x.is_power_of_two()`.
16+
///
1617
/// ### Why is this bad?
1718
/// Manual reimplementations of `is_power_of_two` increase code complexity for little benefit.
19+
///
1820
/// ### Example
1921
/// ```no_run
2022
/// let a: u32 = 4;
@@ -27,7 +29,7 @@ declare_clippy_lint! {
2729
/// ```
2830
#[clippy::version = "1.82.0"]
2931
pub MANUAL_IS_POWER_OF_TWO,
30-
complexity,
32+
pedantic,
3133
"manually reimplementing `is_power_of_two`"
3234
}
3335

src/tools/clippy/tests/ui/borrow_deref_ref.fixed

+6
Original file line numberDiff line numberDiff line change
@@ -71,3 +71,9 @@ mod false_negative {
7171
assert_ne!(addr_x, addr_y);
7272
}
7373
}
74+
75+
fn issue_13584() {
76+
let s = "Hello, world!\n";
77+
let p = &raw const *s;
78+
let _ = p as *const i8;
79+
}

src/tools/clippy/tests/ui/borrow_deref_ref.rs

+6
Original file line numberDiff line numberDiff line change
@@ -71,3 +71,9 @@ mod false_negative {
7171
assert_ne!(addr_x, addr_y);
7272
}
7373
}
74+
75+
fn issue_13584() {
76+
let s = "Hello, world!\n";
77+
let p = &raw const *s;
78+
let _ = p as *const i8;
79+
}

0 commit comments

Comments
 (0)