Only ignore external macros.
This commit is contained in:
parent
4a6f7abeeb
commit
69c7d2cca2
|
@ -4,6 +4,7 @@ use clippy_utils::{meets_msrv, msrvs};
|
|||
use rustc_ast::ast::{Expr, ExprKind, LitKind, Pat, PatKind, RangeEnd, RangeLimits};
|
||||
use rustc_errors::Applicability;
|
||||
use rustc_lint::{EarlyContext, EarlyLintPass, LintContext};
|
||||
use rustc_middle::lint::in_external_macro;
|
||||
use rustc_semver::RustcVersion;
|
||||
use rustc_session::{declare_tool_lint, impl_lint_pass};
|
||||
use rustc_span::Span;
|
||||
|
@ -79,7 +80,7 @@ fn check_range(cx: &EarlyContext<'_>, span: Span, start: &Expr, end: &Expr, sugg
|
|||
(LitKind::Byte(b'a') | LitKind::Char('a'), LitKind::Byte(b'z') | LitKind::Char('z'))
|
||||
| (LitKind::Byte(b'A') | LitKind::Char('A'), LitKind::Byte(b'Z') | LitKind::Char('Z'))
|
||||
)
|
||||
&& !span.from_expansion()
|
||||
&& !in_external_macro(cx.sess(), span)
|
||||
{
|
||||
span_lint_and_then(
|
||||
cx,
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
// run-rustfix
|
||||
// edition:2018
|
||||
// aux-build:macro_rules.rs
|
||||
|
||||
#![feature(custom_inner_attributes)]
|
||||
#![feature(exclusive_range_pattern)]
|
||||
|
@ -8,6 +9,9 @@
|
|||
#![allow(ellipsis_inclusive_range_patterns)]
|
||||
#![allow(clippy::needless_parens_on_range_literals)]
|
||||
|
||||
#[macro_use]
|
||||
extern crate macro_rules;
|
||||
|
||||
macro_rules! a {
|
||||
() => {
|
||||
'a'
|
||||
|
@ -16,7 +20,7 @@ macro_rules! a {
|
|||
|
||||
macro_rules! b {
|
||||
() => {
|
||||
let _ = 'a'..'z';
|
||||
let _ = 'a'..='z';
|
||||
};
|
||||
}
|
||||
|
||||
|
@ -37,7 +41,6 @@ fn main() {
|
|||
let _ = b'B'..b'Z';
|
||||
|
||||
let _ = a!()..='z';
|
||||
b!();
|
||||
|
||||
let _ = match 0u8 {
|
||||
b'a'..=b'z' if true => 1,
|
||||
|
@ -54,6 +57,9 @@ fn main() {
|
|||
'B'..'Z' => 4,
|
||||
_ => 5,
|
||||
};
|
||||
|
||||
almost_complete_letter_range!();
|
||||
b!();
|
||||
}
|
||||
|
||||
fn _under_msrv() {
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
// run-rustfix
|
||||
// edition:2018
|
||||
// aux-build:macro_rules.rs
|
||||
|
||||
#![feature(custom_inner_attributes)]
|
||||
#![feature(exclusive_range_pattern)]
|
||||
|
@ -8,6 +9,9 @@
|
|||
#![allow(ellipsis_inclusive_range_patterns)]
|
||||
#![allow(clippy::needless_parens_on_range_literals)]
|
||||
|
||||
#[macro_use]
|
||||
extern crate macro_rules;
|
||||
|
||||
macro_rules! a {
|
||||
() => {
|
||||
'a'
|
||||
|
@ -37,7 +41,6 @@ fn main() {
|
|||
let _ = b'B'..b'Z';
|
||||
|
||||
let _ = a!()..'z';
|
||||
b!();
|
||||
|
||||
let _ = match 0u8 {
|
||||
b'a'..b'z' if true => 1,
|
||||
|
@ -54,6 +57,9 @@ fn main() {
|
|||
'B'..'Z' => 4,
|
||||
_ => 5,
|
||||
};
|
||||
|
||||
almost_complete_letter_range!();
|
||||
b!();
|
||||
}
|
||||
|
||||
fn _under_msrv() {
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
error: almost complete ascii letter range
|
||||
--> $DIR/almost_complete_letter_range.rs:26:17
|
||||
--> $DIR/almost_complete_letter_range.rs:30:17
|
||||
|
|
||||
LL | let _ = ('a') ..'z';
|
||||
| ^^^^^^--^^^
|
||||
|
@ -9,7 +9,7 @@ LL | let _ = ('a') ..'z';
|
|||
= note: `-D clippy::almost-complete-letter-range` implied by `-D warnings`
|
||||
|
||||
error: almost complete ascii letter range
|
||||
--> $DIR/almost_complete_letter_range.rs:27:17
|
||||
--> $DIR/almost_complete_letter_range.rs:31:17
|
||||
|
|
||||
LL | let _ = 'A' .. ('Z');
|
||||
| ^^^^--^^^^^^
|
||||
|
@ -17,7 +17,7 @@ LL | let _ = 'A' .. ('Z');
|
|||
| help: use an inclusive range: `..=`
|
||||
|
||||
error: almost complete ascii letter range
|
||||
--> $DIR/almost_complete_letter_range.rs:33:13
|
||||
--> $DIR/almost_complete_letter_range.rs:37:13
|
||||
|
|
||||
LL | let _ = (b'a')..(b'z');
|
||||
| ^^^^^^--^^^^^^
|
||||
|
@ -25,7 +25,7 @@ LL | let _ = (b'a')..(b'z');
|
|||
| help: use an inclusive range: `..=`
|
||||
|
||||
error: almost complete ascii letter range
|
||||
--> $DIR/almost_complete_letter_range.rs:34:13
|
||||
--> $DIR/almost_complete_letter_range.rs:38:13
|
||||
|
|
||||
LL | let _ = b'A'..b'Z';
|
||||
| ^^^^--^^^^
|
||||
|
@ -33,7 +33,7 @@ LL | let _ = b'A'..b'Z';
|
|||
| help: use an inclusive range: `..=`
|
||||
|
||||
error: almost complete ascii letter range
|
||||
--> $DIR/almost_complete_letter_range.rs:39:13
|
||||
--> $DIR/almost_complete_letter_range.rs:43:13
|
||||
|
|
||||
LL | let _ = a!()..'z';
|
||||
| ^^^^--^^^
|
||||
|
@ -41,7 +41,7 @@ LL | let _ = a!()..'z';
|
|||
| help: use an inclusive range: `..=`
|
||||
|
||||
error: almost complete ascii letter range
|
||||
--> $DIR/almost_complete_letter_range.rs:43:9
|
||||
--> $DIR/almost_complete_letter_range.rs:46:9
|
||||
|
|
||||
LL | b'a'..b'z' if true => 1,
|
||||
| ^^^^--^^^^
|
||||
|
@ -49,7 +49,7 @@ LL | b'a'..b'z' if true => 1,
|
|||
| help: use an inclusive range: `..=`
|
||||
|
||||
error: almost complete ascii letter range
|
||||
--> $DIR/almost_complete_letter_range.rs:44:9
|
||||
--> $DIR/almost_complete_letter_range.rs:47:9
|
||||
|
|
||||
LL | b'A'..b'Z' if true => 2,
|
||||
| ^^^^--^^^^
|
||||
|
@ -57,7 +57,7 @@ LL | b'A'..b'Z' if true => 2,
|
|||
| help: use an inclusive range: `..=`
|
||||
|
||||
error: almost complete ascii letter range
|
||||
--> $DIR/almost_complete_letter_range.rs:51:9
|
||||
--> $DIR/almost_complete_letter_range.rs:54:9
|
||||
|
|
||||
LL | 'a'..'z' if true => 1,
|
||||
| ^^^--^^^
|
||||
|
@ -65,7 +65,7 @@ LL | 'a'..'z' if true => 1,
|
|||
| help: use an inclusive range: `..=`
|
||||
|
||||
error: almost complete ascii letter range
|
||||
--> $DIR/almost_complete_letter_range.rs:52:9
|
||||
--> $DIR/almost_complete_letter_range.rs:55:9
|
||||
|
|
||||
LL | 'A'..'Z' if true => 2,
|
||||
| ^^^--^^^
|
||||
|
@ -73,7 +73,20 @@ LL | 'A'..'Z' if true => 2,
|
|||
| help: use an inclusive range: `..=`
|
||||
|
||||
error: almost complete ascii letter range
|
||||
--> $DIR/almost_complete_letter_range.rs:62:9
|
||||
--> $DIR/almost_complete_letter_range.rs:23:17
|
||||
|
|
||||
LL | let _ = 'a'..'z';
|
||||
| ^^^--^^^
|
||||
| |
|
||||
| help: use an inclusive range: `..=`
|
||||
...
|
||||
LL | b!();
|
||||
| ---- in this macro invocation
|
||||
|
|
||||
= note: this error originates in the macro `b` (in Nightly builds, run with -Z macro-backtrace for more info)
|
||||
|
||||
error: almost complete ascii letter range
|
||||
--> $DIR/almost_complete_letter_range.rs:68:9
|
||||
|
|
||||
LL | 'a'..'z' => 1,
|
||||
| ^^^--^^^
|
||||
|
@ -81,7 +94,7 @@ LL | 'a'..'z' => 1,
|
|||
| help: use an inclusive range: `...`
|
||||
|
||||
error: almost complete ascii letter range
|
||||
--> $DIR/almost_complete_letter_range.rs:69:13
|
||||
--> $DIR/almost_complete_letter_range.rs:75:13
|
||||
|
|
||||
LL | let _ = 'a'..'z';
|
||||
| ^^^--^^^
|
||||
|
@ -89,12 +102,12 @@ LL | let _ = 'a'..'z';
|
|||
| help: use an inclusive range: `..=`
|
||||
|
||||
error: almost complete ascii letter range
|
||||
--> $DIR/almost_complete_letter_range.rs:71:9
|
||||
--> $DIR/almost_complete_letter_range.rs:77:9
|
||||
|
|
||||
LL | 'a'..'z' => 1,
|
||||
| ^^^--^^^
|
||||
| |
|
||||
| help: use an inclusive range: `..=`
|
||||
|
||||
error: aborting due to 12 previous errors
|
||||
error: aborting due to 13 previous errors
|
||||
|
||||
|
|
|
@ -140,3 +140,10 @@ macro_rules! manual_rem_euclid {
|
|||
macro_rules! equatable_if_let {
|
||||
($a:ident) => {{ if let 2 = $a {} }};
|
||||
}
|
||||
|
||||
#[macro_export]
|
||||
macro_rules! almost_complete_letter_range {
|
||||
() => {
|
||||
let _ = 'a'..'z';
|
||||
};
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue