Skip to content

Commit 6760149

Browse files
committed
Add check for line!
1 parent 269a258 commit 6760149

File tree

3 files changed

+23
-4
lines changed

3 files changed

+23
-4
lines changed

clippy_lints/src/misc_early.rs

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
use crate::utils::{
2-
constants, snippet, snippet_opt, span_help_and_lint, span_lint, span_lint_and_sugg, span_lint_and_then,
2+
constants, is_direct_expn_of, snippet, snippet_opt, span_help_and_lint, span_lint, span_lint_and_sugg,
3+
span_lint_and_then,
34
};
45
use if_chain::if_chain;
56
use rustc::lint::{in_external_macro, EarlyContext, EarlyLintPass, LintArray, LintContext, LintPass};
@@ -390,6 +391,22 @@ impl EarlyLintPass for MiscEarlyLints {
390391

391392
impl MiscEarlyLints {
392393
fn check_lit(self, cx: &EarlyContext<'_>, lit: &Lit) {
394+
use crate::utils::is_expn_of;
395+
396+
// The `line!()` macro is compiler built-in and a special case for these lints.
397+
if is_expn_of(lit.span, "line").is_some() {
398+
span_lint_and_sugg(
399+
cx,
400+
UNSEPARATED_LITERAL_SUFFIX,
401+
lit.span,
402+
"well! that weird",
403+
"add an underscore",
404+
"DEBUG: ok dookey".to_string(),
405+
Applicability::MachineApplicable,
406+
);
407+
return;
408+
}
409+
393410
let lit_snip = match snippet_opt(cx, lit.span) {
394411
Some(snip) => snip,
395412
None => return,

tests/ui/unseparated_prefix_literals.fixed

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
macro_rules! lit_from_macro {
77
() => {
8-
42_usize
8+
42_usize // <| Lint here instead
99
};
1010
}
1111

tests/ui/unseparated_prefix_literals.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
macro_rules! lit_from_macro {
77
() => {
8-
42usize
8+
42usize // <| Lint here instead
99
};
1010
}
1111

@@ -24,7 +24,9 @@ fn main() {
2424
let _failf1 = 1.5f32;
2525
let _failf2 = 1f32;
2626

27+
// Test for macro
28+
let _ = lit_from_macro!(); // Do NOT lint here |^
29+
2730
// Counter example
2831
let _ = line!();
29-
let _ = lit_from_macro!();
3032
}

0 commit comments

Comments
 (0)