Skip to content

Commit 5678531

Browse files
committed
Auto merge of rust-lang#13564 - GnomedDev:fix-manualbits-in-macro, r=blyxyas
Stop linting manual_bits in any macro invoke Closes rust-lang#13563. changelog: [`manual_bits`] No longer lints in macro-generated code
2 parents f2f0175 + a739cc3 commit 5678531

File tree

3 files changed

+24
-3
lines changed

3 files changed

+24
-3
lines changed

clippy_lints/src/manual_bits.rs

+2-3
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,7 @@ use rustc_ast::ast::LitKind;
77
use rustc_data_structures::packed::Pu128;
88
use rustc_errors::Applicability;
99
use rustc_hir::{BinOpKind, Expr, ExprKind, GenericArg, QPath};
10-
use rustc_lint::{LateContext, LateLintPass, LintContext};
11-
use rustc_middle::lint::in_external_macro;
10+
use rustc_lint::{LateContext, LateLintPass};
1211
use rustc_middle::ty::{self, Ty};
1312
use rustc_session::impl_lint_pass;
1413
use rustc_span::sym;
@@ -53,7 +52,7 @@ impl<'tcx> LateLintPass<'tcx> for ManualBits {
5352
fn check_expr(&mut self, cx: &LateContext<'tcx>, expr: &'tcx Expr<'_>) {
5453
if let ExprKind::Binary(bin_op, left_expr, right_expr) = expr.kind
5554
&& let BinOpKind::Mul = &bin_op.node
56-
&& !in_external_macro(cx.sess(), expr.span)
55+
&& !expr.span.from_expansion()
5756
&& self.msrv.meets(msrvs::MANUAL_BITS)
5857
&& let ctxt = expr.span.ctxt()
5958
&& left_expr.span.ctxt() == ctxt

tests/ui/manual_bits.fixed

+11
Original file line numberDiff line numberDiff line change
@@ -56,3 +56,14 @@ fn main() {
5656
let _ = (u128::BITS as usize).pow(5);
5757
let _ = &(u128::BITS as usize);
5858
}
59+
60+
fn should_not_lint() {
61+
macro_rules! bits_via_macro {
62+
($T: ty) => {
63+
size_of::<$T>() * 8;
64+
};
65+
}
66+
67+
bits_via_macro!(u8);
68+
bits_via_macro!(String);
69+
}

tests/ui/manual_bits.rs

+11
Original file line numberDiff line numberDiff line change
@@ -56,3 +56,14 @@ fn main() {
5656
let _ = (size_of::<u128>() * 8).pow(5);
5757
let _ = &(size_of::<u128>() * 8);
5858
}
59+
60+
fn should_not_lint() {
61+
macro_rules! bits_via_macro {
62+
($T: ty) => {
63+
size_of::<$T>() * 8;
64+
};
65+
}
66+
67+
bits_via_macro!(u8);
68+
bits_via_macro!(String);
69+
}

0 commit comments

Comments
 (0)