]> git.lizzy.rs Git - rust.git/commitdiff
Fix regression in case of proc-macro attribute expansion
authorLzu Tao <taolzu@gmail.com>
Fri, 6 Sep 2019 10:00:53 +0000 (17:00 +0700)
committerLzu Tao <taolzu@gmail.com>
Mon, 9 Sep 2019 09:14:32 +0000 (16:14 +0700)
clippy_lints/src/lib.rs
clippy_lints/src/misc_early.rs

index 9d0a91c531828d5bfc31a1fbce77c7d969db3908..7fcd9b7734c7ecaa338dc843b3242c2c4d4e62b5 100644 (file)
@@ -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)]
index 47446edac54b1cdb09898bbe93f4123ab8eda051..a9907ed132d01bc76a15dd4670d0edfefec4cce3 100644 (file)
@@ -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 <https://github.com/rust-lang/rust-clippy/issues/4507> 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,
         };