Skip to content

Commit f8b3046

Browse files
committed
Refactor Parser::break_up_float, fix fractional part's span
1 parent a9fbb22 commit f8b3046

File tree

3 files changed

+40
-44
lines changed

3 files changed

+40
-44
lines changed

compiler/rustc_parse/src/parser/expr.rs

+16-20
Original file line numberDiff line numberDiff line change
@@ -1059,34 +1059,30 @@ impl<'a> Parser<'a> {
10591059
DestructuredFloat::Single(Symbol::intern(i), span)
10601060
}
10611061
// 1.
1062-
[IdentLike(i), Punct('.')] => {
1063-
let (ident_span, dot_span) = if can_take_span_apart() {
1064-
let (span, ident_len) = (span.data(), BytePos::from_usize(i.len()));
1065-
let ident_span = span.with_hi(span.lo + ident_len);
1066-
let dot_span = span.with_lo(span.lo + ident_len);
1067-
(ident_span, dot_span)
1062+
[IdentLike(left), Punct('.')] => {
1063+
let (left_span, dot_span) = if can_take_span_apart() {
1064+
let left_span = span.with_hi(span.lo() + BytePos::from_usize(left.len()));
1065+
let dot_span = span.with_lo(left_span.hi());
1066+
(left_span, dot_span)
10681067
} else {
10691068
(span, span)
10701069
};
1071-
let symbol = Symbol::intern(i);
1072-
DestructuredFloat::TrailingDot(symbol, ident_span, dot_span)
1070+
let left = Symbol::intern(left);
1071+
DestructuredFloat::TrailingDot(left, left_span, dot_span)
10731072
}
10741073
// 1.2 | 1.2e3
1075-
[IdentLike(i1), Punct('.'), IdentLike(i2)] => {
1076-
let (ident1_span, dot_span, ident2_span) = if can_take_span_apart() {
1077-
let (span, ident1_len) = (span.data(), BytePos::from_usize(i1.len()));
1078-
let ident1_span = span.with_hi(span.lo + ident1_len);
1079-
let dot_span = span
1080-
.with_lo(span.lo + ident1_len)
1081-
.with_hi(span.lo + ident1_len + BytePos(1));
1082-
let ident2_span = self.token.span.with_lo(span.lo + ident1_len + BytePos(1));
1083-
(ident1_span, dot_span, ident2_span)
1074+
[IdentLike(left), Punct('.'), IdentLike(right)] => {
1075+
let (left_span, dot_span, right_span) = if can_take_span_apart() {
1076+
let left_span = span.with_hi(span.lo() + BytePos::from_usize(left.len()));
1077+
let dot_span = span.with_lo(left_span.hi()).with_hi(left_span.hi() + BytePos(1));
1078+
let right_span = span.with_lo(dot_span.hi());
1079+
(left_span, dot_span, right_span)
10841080
} else {
10851081
(span, span, span)
10861082
};
1087-
let symbol1 = Symbol::intern(i1);
1088-
let symbol2 = Symbol::intern(i2);
1089-
DestructuredFloat::MiddleDot(symbol1, ident1_span, dot_span, symbol2, ident2_span)
1083+
let left = Symbol::intern(left);
1084+
let right = Symbol::intern(right);
1085+
DestructuredFloat::MiddleDot(left, left_span, dot_span, right, right_span)
10901086
}
10911087
// 1e+ | 1e- (recovered)
10921088
[IdentLike(_), Punct('+' | '-')] |

tests/ui/offset-of/offset-of-tuple.rs

+1
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ fn nested() {
3030
offset_of!(((u8, u16), (u32, u16, u8)), 0.2); //~ ERROR no field `2`
3131
offset_of!(((u8, u16), (u32, u16, u8)), 1.2);
3232
offset_of!(((u8, u16), (u32, u16, u8)), 1.2.0); //~ ERROR no field `0`
33+
offset_of!(((u8, u16), (u32, u16, u8)), 0.1e2); //~ ERROR no field `1e2`
3334

3435
// All combinations of spaces (this sends different tokens to the parser)
3536
offset_of!(ComplexTup, 0.0.1.); //~ ERROR unexpected token: `)`

tests/ui/offset-of/offset-of-tuple.stderr

+23-24
Original file line numberDiff line numberDiff line change
@@ -29,43 +29,43 @@ LL | { builtin # offset_of((u8, u8), 1 .) };
2929
| ^
3030

3131
error: unexpected token: `)`
32-
--> $DIR/offset-of-tuple.rs:46:45
32+
--> $DIR/offset-of-tuple.rs:47:45
3333
|
3434
LL | { builtin # offset_of(ComplexTup, 0.0.1.) };
3535
| ^
3636

3737
error: unexpected token: `)`
38-
--> $DIR/offset-of-tuple.rs:47:46
38+
--> $DIR/offset-of-tuple.rs:48:46
3939
|
4040
LL | { builtin # offset_of(ComplexTup, 0 .0.1.) };
4141
| ^
4242

4343
error: unexpected token: `)`
44-
--> $DIR/offset-of-tuple.rs:48:47
44+
--> $DIR/offset-of-tuple.rs:49:47
4545
|
4646
LL | { builtin # offset_of(ComplexTup, 0 . 0.1.) };
4747
| ^
4848

4949
error: unexpected token: `)`
50-
--> $DIR/offset-of-tuple.rs:49:46
50+
--> $DIR/offset-of-tuple.rs:50:46
5151
|
5252
LL | { builtin # offset_of(ComplexTup, 0. 0.1.) };
5353
| ^
5454

5555
error: unexpected token: `)`
56-
--> $DIR/offset-of-tuple.rs:50:46
56+
--> $DIR/offset-of-tuple.rs:51:46
5757
|
5858
LL | { builtin # offset_of(ComplexTup, 0.0 .1.) };
5959
| ^
6060

6161
error: unexpected token: `)`
62-
--> $DIR/offset-of-tuple.rs:51:47
62+
--> $DIR/offset-of-tuple.rs:52:47
6363
|
6464
LL | { builtin # offset_of(ComplexTup, 0.0 . 1.) };
6565
| ^
6666

6767
error: unexpected token: `)`
68-
--> $DIR/offset-of-tuple.rs:52:46
68+
--> $DIR/offset-of-tuple.rs:53:46
6969
|
7070
LL | { builtin # offset_of(ComplexTup, 0.0. 1.) };
7171
| ^
@@ -104,43 +104,43 @@ LL | offset_of!((u8, u8), 1 .);
104104
| ^
105105

106106
error: unexpected token: `)`
107-
--> $DIR/offset-of-tuple.rs:35:34
107+
--> $DIR/offset-of-tuple.rs:36:34
108108
|
109109
LL | offset_of!(ComplexTup, 0.0.1.);
110110
| ^
111111

112112
error: unexpected token: `)`
113-
--> $DIR/offset-of-tuple.rs:36:35
113+
--> $DIR/offset-of-tuple.rs:37:35
114114
|
115115
LL | offset_of!(ComplexTup, 0 .0.1.);
116116
| ^
117117

118118
error: unexpected token: `)`
119-
--> $DIR/offset-of-tuple.rs:37:36
119+
--> $DIR/offset-of-tuple.rs:38:36
120120
|
121121
LL | offset_of!(ComplexTup, 0 . 0.1.);
122122
| ^
123123

124124
error: unexpected token: `)`
125-
--> $DIR/offset-of-tuple.rs:38:35
125+
--> $DIR/offset-of-tuple.rs:39:35
126126
|
127127
LL | offset_of!(ComplexTup, 0. 0.1.);
128128
| ^
129129

130130
error: unexpected token: `)`
131-
--> $DIR/offset-of-tuple.rs:39:35
131+
--> $DIR/offset-of-tuple.rs:40:35
132132
|
133133
LL | offset_of!(ComplexTup, 0.0 .1.);
134134
| ^
135135

136136
error: unexpected token: `)`
137-
--> $DIR/offset-of-tuple.rs:40:36
137+
--> $DIR/offset-of-tuple.rs:41:36
138138
|
139139
LL | offset_of!(ComplexTup, 0.0 . 1.);
140140
| ^
141141

142142
error: unexpected token: `)`
143-
--> $DIR/offset-of-tuple.rs:41:35
143+
--> $DIR/offset-of-tuple.rs:42:35
144144
|
145145
LL | offset_of!(ComplexTup, 0.0. 1.);
146146
| ^
@@ -196,22 +196,21 @@ LL | builtin # offset_of((u8, u8), 1_u8);
196196
error[E0609]: no field `2` on type `(u8, u16)`
197197
--> $DIR/offset-of-tuple.rs:30:47
198198
|
199-
LL | offset_of!(((u8, u16), (u32, u16, u8)), 0.2);
200-
| _____------------------------------------------^-
201-
| | |
202-
| | in this macro invocation
203-
LL | | offset_of!(((u8, u16), (u32, u16, u8)), 1.2);
204-
LL | | offset_of!(((u8, u16), (u32, u16, u8)), 1.2.0);
205-
... |
206-
|
207-
= note: this error originates in the macro `offset_of` (in Nightly builds, run with -Z macro-backtrace for more info)
199+
LL | offset_of!(((u8, u16), (u32, u16, u8)), 0.2);
200+
| ^
208201

209202
error[E0609]: no field `0` on type `u8`
210203
--> $DIR/offset-of-tuple.rs:32:49
211204
|
212205
LL | offset_of!(((u8, u16), (u32, u16, u8)), 1.2.0);
213206
| ^
214207

215-
error: aborting due to 33 previous errors
208+
error[E0609]: no field `1e2` on type `(u8, u16)`
209+
--> $DIR/offset-of-tuple.rs:33:47
210+
|
211+
LL | offset_of!(((u8, u16), (u32, u16, u8)), 0.1e2);
212+
| ^^^
213+
214+
error: aborting due to 34 previous errors
216215

217216
For more information about this error, try `rustc --explain E0609`.

0 commit comments

Comments
 (0)