From a5f4d3ce294f24d825080f48507ccdcce3d3e1fb Mon Sep 17 00:00:00 2001 From: Lzu Tao Date: Fri, 6 Sep 2019 17:00:53 +0700 Subject: [PATCH] Fix regression in case of proc-macro attribute expansion --- clippy_lints/src/lib.rs | 1 + clippy_lints/src/misc_early.rs | 14 ++++++-------- 2 files changed, 7 insertions(+), 8 deletions(-) diff --git a/clippy_lints/src/lib.rs b/clippy_lints/src/lib.rs index 9d0a91c5318..7fcd9b7734c 100644 --- a/clippy_lints/src/lib.rs +++ b/clippy_lints/src/lib.rs @@ -1,5 +1,6 @@ // error-pattern:cargo-clippy +#![feature(bind_by_move_pattern_guards)] // proposed to be stabilized in Rust v1.39 #![feature(box_syntax)] #![feature(box_patterns)] #![feature(never_type)] diff --git a/clippy_lints/src/misc_early.rs b/clippy_lints/src/misc_early.rs index 47446edac54..a9907ed132d 100644 --- a/clippy_lints/src/misc_early.rs +++ b/clippy_lints/src/misc_early.rs @@ -430,15 +430,13 @@ fn check_block(&mut self, cx: &EarlyContext<'_>, block: &Block) { impl MiscEarlyLints { fn check_lit(self, cx: &EarlyContext<'_>, lit: &Lit) { - // The `line!()` macro is compiler built-in and a special case for these lints. + // We test if first character in snippet is a number, because the snippet could be an expansion + // from a built-in macro like `line!()` or a proc-macro like `#[wasm_bindgen]`. + // Note that this check also covers special case that `line!()` is eagerly expanded by compiler. + // See for a regression. + // FIXME: Find a better way to detect those cases. let lit_snip = match snippet_opt(cx, lit.span) { - Some(snip) => { - // The snip could be empty in case of expand from procedure macro - if snip.is_empty() || snip.contains('!') { - return; - } - snip - }, + Some(snip) if snip.chars().next().map_or(false, |c| c.is_digit(10)) => snip, _ => return, }; -- 2.44.0