mirror of
https://github.com/rust-lang/rust.git
synced 2025-01-31 09:04:18 +00:00
Implement support for implicit start and end
This commit is contained in:
parent
2e6903ccf9
commit
0409306bb0
@ -75,15 +75,13 @@ fn check_for_parens(cx: &LateContext<'_>, e: &Expr<'_>, is_start: bool) {
|
||||
|
||||
impl<'tcx> LateLintPass<'tcx> for NeedlessParensOnRangeLiteral {
|
||||
fn check_expr(&mut self, cx: &LateContext<'tcx>, expr: &'tcx Expr<'_>) {
|
||||
// if let higher::Range { start, end, limits } = &e.kind {
|
||||
if let Some(higher::Range {
|
||||
start: Some(start),
|
||||
end: Some(end),
|
||||
..
|
||||
}) = higher::Range::hir(expr)
|
||||
{
|
||||
check_for_parens(cx, start, true);
|
||||
check_for_parens(cx, end, false);
|
||||
if let Some(higher::Range { start, end, .. }) = higher::Range::hir(expr) {
|
||||
if let Some(start) = start {
|
||||
check_for_parens(cx, start, true);
|
||||
}
|
||||
if let Some(end) = end {
|
||||
check_for_parens(cx, end, false);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -6,7 +6,9 @@
|
||||
|
||||
fn main() {
|
||||
let _ = 'a'..='z';
|
||||
let _ = 'a'..='z';
|
||||
let _ = 'a'..'z';
|
||||
let _ = (1.)..2.;
|
||||
let _ = (1.)..2.;
|
||||
let _ = 'a'..;
|
||||
let _ = ..'z';
|
||||
}
|
||||
|
@ -6,7 +6,9 @@
|
||||
|
||||
fn main() {
|
||||
let _ = ('a')..=('z');
|
||||
let _ = 'a'..='z';
|
||||
let _ = 'a'..('z');
|
||||
let _ = (1.)..2.;
|
||||
let _ = (1.)..(2.);
|
||||
let _ = ('a')..;
|
||||
let _ = ..('z');
|
||||
}
|
||||
|
@ -12,11 +12,29 @@ error: needless parenthesis on range literal can be removed
|
||||
LL | let _ = ('a')..=('z');
|
||||
| ^^^^^ help: try: `'z'`
|
||||
|
||||
error: needless parenthesis on range literal can be removed
|
||||
--> $DIR/needless_parens_on_range_literal.rs:9:18
|
||||
|
|
||||
LL | let _ = 'a'..('z');
|
||||
| ^^^^^ help: try: `'z'`
|
||||
|
||||
error: needless parenthesis on range literal can be removed
|
||||
--> $DIR/needless_parens_on_range_literal.rs:11:19
|
||||
|
|
||||
LL | let _ = (1.)..(2.);
|
||||
| ^^^^ help: try: `2.`
|
||||
|
||||
error: aborting due to 3 previous errors
|
||||
error: needless parenthesis on range literal can be removed
|
||||
--> $DIR/needless_parens_on_range_literal.rs:12:13
|
||||
|
|
||||
LL | let _ = ('a')..;
|
||||
| ^^^^^ help: try: `'a'`
|
||||
|
||||
error: needless parenthesis on range literal can be removed
|
||||
--> $DIR/needless_parens_on_range_literal.rs:13:15
|
||||
|
|
||||
LL | let _ = ..('z');
|
||||
| ^^^^^ help: try: `'z'`
|
||||
|
||||
error: aborting due to 6 previous errors
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user