Fix regression in case of proc-macro attribute expansion

This commit is contained in:
Lzu Tao 2019-09-06 17:00:53 +07:00
parent 58e01ea4d7
commit a5f4d3ce29
2 changed files with 7 additions and 8 deletions

View 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)]

View File

@ -430,15 +430,13 @@ impl EarlyLintPass for MiscEarlyLints {
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,
};