forked from rust-lang/rust
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
inclusive range syntax lint (
...
→ ..=
)
Our implementation ends up changing the `PatKind::Range` variant in the AST to take a `Spanned<RangeEnd>` instead of just a `RangeEnd`, because the alternative would be to try to infer the span of the range operator from the spans of the start and end subexpressions, which is both hideous and nontrivial to get right (whereas getting the change to the AST right was a simple game of type tennis). This is concerning rust-lang#51043.
- Loading branch information
1 parent
0577155
commit 3fb76f4
Showing
13 changed files
with
154 additions
and
22 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
// Copyright 2018 The Rust Project Developers. See the COPYRIGHT | ||
// file at the top-level directory of this distribution and at | ||
// http://rust-lang.org/COPYRIGHT. | ||
// | ||
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or | ||
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license | ||
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your | ||
// option. This file may not be copied, modified, or distributed | ||
// except according to those terms. | ||
|
||
// compile-pass | ||
// run-rustfix | ||
|
||
#![warn(ellipsis_inclusive_range_patterns)] | ||
|
||
fn main() { | ||
let despondency = 2; | ||
match despondency { | ||
1..=2 => {} | ||
//~^ WARN `...` range patterns are deprecated | ||
_ => {} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
// Copyright 2018 The Rust Project Developers. See the COPYRIGHT | ||
// file at the top-level directory of this distribution and at | ||
// http://rust-lang.org/COPYRIGHT. | ||
// | ||
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or | ||
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license | ||
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your | ||
// option. This file may not be copied, modified, or distributed | ||
// except according to those terms. | ||
|
||
// compile-pass | ||
// run-rustfix | ||
|
||
#![warn(ellipsis_inclusive_range_patterns)] | ||
|
||
fn main() { | ||
let despondency = 2; | ||
match despondency { | ||
1...2 => {} | ||
//~^ WARN `...` range patterns are deprecated | ||
_ => {} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
warning: `...` range patterns are deprecated | ||
--> $DIR/inclusive-range-pattern-syntax.rs:19:10 | ||
| | ||
LL | 1...2 => {} | ||
| ^^^ help: use `..=` for an inclusive range | ||
| | ||
note: lint level defined here | ||
--> $DIR/inclusive-range-pattern-syntax.rs:14:9 | ||
| | ||
LL | #![warn(ellipsis_inclusive_range_patterns)] | ||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1,32 @@ | ||
error: the range pattern here has ambiguous interpretation | ||
--> $DIR/range-inclusive-pattern-precedence.rs:23:10 | ||
--> $DIR/range-inclusive-pattern-precedence.rs:27:10 | ||
| | ||
LL | &10..=15 => {} | ||
| ^^^^^^^ help: add parentheses to clarify the precedence: `(10 ..=15)` | ||
|
||
error: the range pattern here has ambiguous interpretation | ||
--> $DIR/range-inclusive-pattern-precedence.rs:32:13 | ||
--> $DIR/range-inclusive-pattern-precedence.rs:38:13 | ||
| | ||
LL | box 10..=15 => {} | ||
| ^^^^^^^ help: add parentheses to clarify the precedence: `(10 ..=15)` | ||
|
||
warning: `...` range patterns are deprecated | ||
--> $DIR/range-inclusive-pattern-precedence.rs:24:11 | ||
| | ||
LL | &0...9 => {} | ||
| ^^^ help: use `..=` for an inclusive range | ||
| | ||
note: lint level defined here | ||
--> $DIR/range-inclusive-pattern-precedence.rs:19:9 | ||
| | ||
LL | #![warn(ellipsis_inclusive_range_patterns)] | ||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | ||
|
||
warning: `...` range patterns are deprecated | ||
--> $DIR/range-inclusive-pattern-precedence.rs:35:14 | ||
| | ||
LL | box 0...9 => {} | ||
| ^^^ help: use `..=` for an inclusive range | ||
|
||
error: aborting due to 2 previous errors | ||
|