Skip to content

Commit

Permalink
Fix whitespace in pretty printed PatKind::Range
Browse files Browse the repository at this point in the history
  • Loading branch information
dtolnay committed Dec 29, 2021
1 parent df96fb1 commit bc1a1ff
Show file tree
Hide file tree
Showing 10 changed files with 12 additions and 14 deletions.
1 change: 0 additions & 1 deletion compiler/rustc_ast_pretty/src/pprust/state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2515,7 +2515,6 @@ impl<'a> State<'a> {
PatKind::Range(ref begin, ref end, Spanned { node: ref end_kind, .. }) => {
if let Some(e) = begin {
self.print_expr(e);
self.space();
}
match *end_kind {
RangeEnd::Included(RangeSyntax::DotDotDot) => self.word("..."),
Expand Down
1 change: 0 additions & 1 deletion compiler/rustc_hir_pretty/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1948,7 +1948,6 @@ impl<'a> State<'a> {
PatKind::Range(ref begin, ref end, ref end_kind) => {
if let Some(expr) = begin {
self.print_expr(expr);
self.space();
}
match *end_kind {
RangeEnd::Included => self.word("..."),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ error: the range pattern here has ambiguous interpretation
--> $DIR/half-open-range-pats-ref-ambiguous-interp.rs:8:10
|
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
--> $DIR/half-open-range-pats-ref-ambiguous-interp.rs:10:11
Expand All @@ -16,7 +16,7 @@ error: the range pattern here has ambiguous interpretation
--> $DIR/half-open-range-pats-ref-ambiguous-interp.rs:10:10
|
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
--> $DIR/half-open-range-pats-ref-ambiguous-interp.rs:13:11
Expand Down
8 changes: 4 additions & 4 deletions src/test/ui/macros/stringify.rs
Original file line number Diff line number Diff line change
Expand Up @@ -712,10 +712,10 @@ fn test_pat() {

// PatKind::Range
assert_eq!(stringify_pat!(..1), "..1");
assert_eq!(stringify_pat!(0..), "0 .."); // FIXME
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!(0..), "0..");
assert_eq!(stringify_pat!(0..1), "0..1");
assert_eq!(stringify_pat!(0..=1), "0..=1");
assert_eq!(stringify_pat!(-2..=-1), "-2..=-1");

// PatKind::Slice
assert_eq!(stringify_pat!([]), "[]");
Expand Down
2 changes: 1 addition & 1 deletion src/test/ui/parser/intersection-patterns.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ fn main() {
//~| pattern on the left, should be on the right
//~| binding on the right, should be on the left
//~| HELP switch the order
//~| SUGGESTION e @ 1 ..=5
//~| SUGGESTION e @ 1..=5
_ => {}
}
}
2 changes: 1 addition & 1 deletion src/test/ui/parser/intersection-patterns.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ LL | 1 ..= 5 @ e => {}
| | |
| | binding on the right, should be on the left
| 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

2 changes: 1 addition & 1 deletion src/test/ui/range/range-inclusive-pattern-precedence.fixed
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ pub fn main() {
//~^ WARN `...` range patterns are deprecated
//~| WARN this is accepted in the current edition
//~| HELP use `..=` for an inclusive range
&(10 ..=15) => {}
&(10..=15) => {}
//~^ ERROR the range pattern here has ambiguous interpretation
//~| HELP add parentheses to clarify the precedence
&(16..=20) => {}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ error: the range pattern here has ambiguous interpretation
--> $DIR/range-inclusive-pattern-precedence.rs:15:10
|
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
--> $DIR/range-inclusive-pattern-precedence.rs:11:9
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ error: the range pattern here has ambiguous interpretation
--> $DIR/range-inclusive-pattern-precedence2.rs:14:13
|
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
--> $DIR/range-inclusive-pattern-precedence2.rs:10:14
Expand Down
2 changes: 1 addition & 1 deletion src/test/ui/unpretty-expr-fn-arg.stdout
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,4 @@ extern crate std;

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 ())

0 comments on commit bc1a1ff

Please sign in to comment.