Skip to content

Commit a5f4d3c

Browse files
committed
Fix regression in case of proc-macro attribute expansion
1 parent 58e01ea commit a5f4d3c

File tree

2 files changed

+7
-8
lines changed

2 files changed

+7
-8
lines changed

clippy_lints/src/lib.rs

+1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
// error-pattern:cargo-clippy
22

3+
#![feature(bind_by_move_pattern_guards)] // proposed to be stabilized in Rust v1.39
34
#![feature(box_syntax)]
45
#![feature(box_patterns)]
56
#![feature(never_type)]

clippy_lints/src/misc_early.rs

+6-8
Original file line numberDiff line numberDiff line change
@@ -430,15 +430,13 @@ impl EarlyLintPass for MiscEarlyLints {
430430

431431
impl MiscEarlyLints {
432432
fn check_lit(self, cx: &EarlyContext<'_>, lit: &Lit) {
433-
// The `line!()` macro is compiler built-in and a special case for these lints.
433+
// We test if first character in snippet is a number, because the snippet could be an expansion
434+
// from a built-in macro like `line!()` or a proc-macro like `#[wasm_bindgen]`.
435+
// Note that this check also covers special case that `line!()` is eagerly expanded by compiler.
436+
// See <https://github.com/rust-lang/rust-clippy/issues/4507> for a regression.
437+
// FIXME: Find a better way to detect those cases.
434438
let lit_snip = match snippet_opt(cx, lit.span) {
435-
Some(snip) => {
436-
// The snip could be empty in case of expand from procedure macro
437-
if snip.is_empty() || snip.contains('!') {
438-
return;
439-
}
440-
snip
441-
},
439+
Some(snip) if snip.chars().next().map_or(false, |c| c.is_digit(10)) => snip,
442440
_ => return,
443441
};
444442

0 commit comments

Comments
 (0)