Skip to content
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
6 changes: 6 additions & 0 deletions clippy_lints/src/casts/cast_lossless.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,12 @@ pub(super) fn check(
return;
}

// If the `as` is from a macro and the casting type is from macro input, whether it is lossless is
// dependent on the input
if expr.span.from_expansion() && !cast_to_hir.span.eq_ctxt(expr.span) {
return;
}

span_lint_and_then(
cx,
CAST_LOSSLESS,
Expand Down
17 changes: 17 additions & 0 deletions tests/ui/cast_lossless_integer_unfixable.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
//@check-pass
#![warn(clippy::cast_lossless)]

fn issue15348() {
macro_rules! zero {
($int:ty) => {{
let data: [u8; 3] = [0, 0, 0];
data[0] as $int
}};
}

let _ = zero!(u8);
let _ = zero!(u16);
let _ = zero!(u32);
let _ = zero!(u64);
let _ = zero!(u128);
}