mirror of
https://github.com/rust-lang/rust.git
synced 2025-02-23 20:34:06 +00:00
Rollup merge of #92420 - dtolnay:patrange, r=Mark-Simulacrum
Fix whitespace in pretty printed PatKind::Range
Follow-up to #92238 fixing one of the FIXMEs.
```rust
macro_rules! repro {
($pat:pat) => {
stringify!($pat)
};
}
fn main() {
println!("{}", repro!(0..=1));
}
```
Before: `0 ..=1`
After: `0..=1`
The canonical spacing applied by rustfmt has no space after the lower expr. Rustc's parser diagnostics also do not put a space there:
df96fb166f/compiler/rustc_parse/src/parser/pat.rs (L754)
This commit is contained in:
commit
efe415878b
@ -2516,7 +2516,6 @@ impl<'a> State<'a> {
|
|||||||
PatKind::Range(ref begin, ref end, Spanned { node: ref end_kind, .. }) => {
|
PatKind::Range(ref begin, ref end, Spanned { node: ref end_kind, .. }) => {
|
||||||
if let Some(e) = begin {
|
if let Some(e) = begin {
|
||||||
self.print_expr(e);
|
self.print_expr(e);
|
||||||
self.space();
|
|
||||||
}
|
}
|
||||||
match *end_kind {
|
match *end_kind {
|
||||||
RangeEnd::Included(RangeSyntax::DotDotDot) => self.word("..."),
|
RangeEnd::Included(RangeSyntax::DotDotDot) => self.word("..."),
|
||||||
|
@ -1948,7 +1948,6 @@ impl<'a> State<'a> {
|
|||||||
PatKind::Range(ref begin, ref end, ref end_kind) => {
|
PatKind::Range(ref begin, ref end, ref end_kind) => {
|
||||||
if let Some(expr) = begin {
|
if let Some(expr) = begin {
|
||||||
self.print_expr(expr);
|
self.print_expr(expr);
|
||||||
self.space();
|
|
||||||
}
|
}
|
||||||
match *end_kind {
|
match *end_kind {
|
||||||
RangeEnd::Included => self.word("..."),
|
RangeEnd::Included => self.word("..."),
|
||||||
|
@ -2,7 +2,7 @@ error: the range pattern here has ambiguous interpretation
|
|||||||
--> $DIR/half-open-range-pats-ref-ambiguous-interp.rs:8:10
|
--> $DIR/half-open-range-pats-ref-ambiguous-interp.rs:8:10
|
||||||
|
|
|
|
||||||
LL | &0.. | _ => {}
|
LL | &0.. | _ => {}
|
||||||
| ^^^ help: add parentheses to clarify the precedence: `(0 ..)`
|
| ^^^ help: add parentheses to clarify the precedence: `(0..)`
|
||||||
|
|
||||||
error[E0586]: inclusive range with no end
|
error[E0586]: inclusive range with no end
|
||||||
--> $DIR/half-open-range-pats-ref-ambiguous-interp.rs:10:11
|
--> $DIR/half-open-range-pats-ref-ambiguous-interp.rs:10:11
|
||||||
@ -16,7 +16,7 @@ error: the range pattern here has ambiguous interpretation
|
|||||||
--> $DIR/half-open-range-pats-ref-ambiguous-interp.rs:10:10
|
--> $DIR/half-open-range-pats-ref-ambiguous-interp.rs:10:10
|
||||||
|
|
|
|
||||||
LL | &0..= | _ => {}
|
LL | &0..= | _ => {}
|
||||||
| ^^^^ help: add parentheses to clarify the precedence: `(0 ..=)`
|
| ^^^^ help: add parentheses to clarify the precedence: `(0..=)`
|
||||||
|
|
||||||
error[E0586]: inclusive range with no end
|
error[E0586]: inclusive range with no end
|
||||||
--> $DIR/half-open-range-pats-ref-ambiguous-interp.rs:13:11
|
--> $DIR/half-open-range-pats-ref-ambiguous-interp.rs:13:11
|
||||||
|
@ -712,10 +712,10 @@ fn test_pat() {
|
|||||||
|
|
||||||
// PatKind::Range
|
// PatKind::Range
|
||||||
assert_eq!(stringify_pat!(..1), "..1");
|
assert_eq!(stringify_pat!(..1), "..1");
|
||||||
assert_eq!(stringify_pat!(0..), "0 .."); // FIXME
|
assert_eq!(stringify_pat!(0..), "0..");
|
||||||
assert_eq!(stringify_pat!(0..1), "0 ..1");
|
assert_eq!(stringify_pat!(0..1), "0..1");
|
||||||
assert_eq!(stringify_pat!(0..=1), "0 ..=1");
|
assert_eq!(stringify_pat!(0..=1), "0..=1");
|
||||||
assert_eq!(stringify_pat!(-2..=-1), "-2 ..=-1");
|
assert_eq!(stringify_pat!(-2..=-1), "-2..=-1");
|
||||||
|
|
||||||
// PatKind::Slice
|
// PatKind::Slice
|
||||||
assert_eq!(stringify_pat!([]), "[]");
|
assert_eq!(stringify_pat!([]), "[]");
|
||||||
|
@ -34,7 +34,7 @@ fn main() {
|
|||||||
//~| pattern on the left, should be on the right
|
//~| pattern on the left, should be on the right
|
||||||
//~| binding on the right, should be on the left
|
//~| binding on the right, should be on the left
|
||||||
//~| HELP switch the order
|
//~| HELP switch the order
|
||||||
//~| SUGGESTION e @ 1 ..=5
|
//~| SUGGESTION e @ 1..=5
|
||||||
_ => {}
|
_ => {}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -27,7 +27,7 @@ LL | 1 ..= 5 @ e => {}
|
|||||||
| | |
|
| | |
|
||||||
| | binding on the right, should be on the left
|
| | binding on the right, should be on the left
|
||||||
| pattern on the left, should be on the right
|
| pattern on the left, should be on the right
|
||||||
| help: switch the order: `e @ 1 ..=5`
|
| help: switch the order: `e @ 1..=5`
|
||||||
|
|
||||||
error: aborting due to 3 previous errors
|
error: aborting due to 3 previous errors
|
||||||
|
|
||||||
|
@ -12,7 +12,7 @@ pub fn main() {
|
|||||||
//~^ WARN `...` range patterns are deprecated
|
//~^ WARN `...` range patterns are deprecated
|
||||||
//~| WARN this is accepted in the current edition
|
//~| WARN this is accepted in the current edition
|
||||||
//~| HELP use `..=` for an inclusive range
|
//~| HELP use `..=` for an inclusive range
|
||||||
&(10 ..=15) => {}
|
&(10..=15) => {}
|
||||||
//~^ ERROR the range pattern here has ambiguous interpretation
|
//~^ ERROR the range pattern here has ambiguous interpretation
|
||||||
//~| HELP add parentheses to clarify the precedence
|
//~| HELP add parentheses to clarify the precedence
|
||||||
&(16..=20) => {}
|
&(16..=20) => {}
|
||||||
|
@ -2,7 +2,7 @@ error: the range pattern here has ambiguous interpretation
|
|||||||
--> $DIR/range-inclusive-pattern-precedence.rs:15:10
|
--> $DIR/range-inclusive-pattern-precedence.rs:15:10
|
||||||
|
|
|
|
||||||
LL | &10..=15 => {}
|
LL | &10..=15 => {}
|
||||||
| ^^^^^^^ help: add parentheses to clarify the precedence: `(10 ..=15)`
|
| ^^^^^^^ help: add parentheses to clarify the precedence: `(10..=15)`
|
||||||
|
|
||||||
warning: `...` range patterns are deprecated
|
warning: `...` range patterns are deprecated
|
||||||
--> $DIR/range-inclusive-pattern-precedence.rs:11:9
|
--> $DIR/range-inclusive-pattern-precedence.rs:11:9
|
||||||
|
@ -2,7 +2,7 @@ error: the range pattern here has ambiguous interpretation
|
|||||||
--> $DIR/range-inclusive-pattern-precedence2.rs:14:13
|
--> $DIR/range-inclusive-pattern-precedence2.rs:14:13
|
||||||
|
|
|
|
||||||
LL | box 10..=15 => {}
|
LL | box 10..=15 => {}
|
||||||
| ^^^^^^^ help: add parentheses to clarify the precedence: `(10 ..=15)`
|
| ^^^^^^^ help: add parentheses to clarify the precedence: `(10..=15)`
|
||||||
|
|
||||||
warning: `...` range patterns are deprecated
|
warning: `...` range patterns are deprecated
|
||||||
--> $DIR/range-inclusive-pattern-precedence2.rs:10:14
|
--> $DIR/range-inclusive-pattern-precedence2.rs:10:14
|
||||||
|
@ -14,4 +14,4 @@ extern crate std;
|
|||||||
|
|
||||||
fn main() ({ } as ())
|
fn main() ({ } as ())
|
||||||
|
|
||||||
fn foo((-(128 as i8) as i8) ...(127 as i8): i8) ({ } as ())
|
fn foo((-(128 as i8) as i8)...(127 as i8): i8) ({ } as ())
|
||||||
|
Loading…
Reference in New Issue
Block a user