Skip to content

Commit d9d985b

Browse files
committed
squash! Fix Parser::break_up_float fractional part's span
1 parent 20303c1 commit d9d985b

File tree

3 files changed

+38
-35
lines changed

3 files changed

+38
-35
lines changed

Diff for: compiler/rustc_parse/src/parser/expr.rs

+16-20
Original file line numberDiff line numberDiff line change
@@ -1072,34 +1072,30 @@ impl<'a> Parser<'a> {
10721072
DestructuredFloat::Single(Symbol::intern(i), span)
10731073
}
10741074
// 1.
1075-
[IdentLike(i), Punct('.')] => {
1076-
let (ident_span, dot_span) = if can_take_span_apart() {
1077-
let (span, ident_len) = (span.data(), BytePos::from_usize(i.len()));
1078-
let ident_span = span.with_hi(span.lo + ident_len);
1079-
let dot_span = span.with_lo(span.lo + ident_len);
1080-
(ident_span, dot_span)
1075+
[IdentLike(left), Punct('.')] => {
1076+
let (left_span, dot_span) = if can_take_span_apart() {
1077+
let left_span = span.with_hi(span.lo() + BytePos::from_usize(left.len()));
1078+
let dot_span = span.with_lo(left_span.hi());
1079+
(left_span, dot_span)
10811080
} else {
10821081
(span, span)
10831082
};
1084-
let symbol = Symbol::intern(i);
1085-
DestructuredFloat::TrailingDot(symbol, ident_span, dot_span)
1083+
let left = Symbol::intern(left);
1084+
DestructuredFloat::TrailingDot(left, left_span, dot_span)
10861085
}
10871086
// 1.2 | 1.2e3
1088-
[IdentLike(i1), Punct('.'), IdentLike(i2)] => {
1089-
let (ident1_span, dot_span, ident2_span) = if can_take_span_apart() {
1090-
let (span, ident1_len) = (span.data(), BytePos::from_usize(i1.len()));
1091-
let ident1_span = span.with_hi(span.lo + ident1_len);
1092-
let dot_span = span
1093-
.with_lo(span.lo + ident1_len)
1094-
.with_hi(span.lo + ident1_len + BytePos(1));
1095-
let ident2_span = span.with_lo(span.lo + ident1_len + BytePos(1));
1096-
(ident1_span, dot_span, ident2_span)
1087+
[IdentLike(left), Punct('.'), IdentLike(right)] => {
1088+
let (left_span, dot_span, right_span) = if can_take_span_apart() {
1089+
let left_span = span.with_hi(span.lo() + BytePos::from_usize(left.len()));
1090+
let dot_span = span.with_lo(left_span.hi()).with_hi(left_span.hi() + BytePos(1));
1091+
let right_span = span.with_lo(dot_span.hi());
1092+
(left_span, dot_span, right_span)
10971093
} else {
10981094
(span, span, span)
10991095
};
1100-
let symbol1 = Symbol::intern(i1);
1101-
let symbol2 = Symbol::intern(i2);
1102-
DestructuredFloat::MiddleDot(symbol1, ident1_span, dot_span, symbol2, ident2_span)
1096+
let left = Symbol::intern(left);
1097+
let right = Symbol::intern(right);
1098+
DestructuredFloat::MiddleDot(left, left_span, dot_span, right, right_span)
11031099
}
11041100
// 1e+ | 1e- (recovered)
11051101
[IdentLike(_), Punct('+' | '-')] |

Diff for: tests/ui/offset-of/offset-of-tuple.rs

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

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

Diff for: tests/ui/offset-of/offset-of-tuple.stderr

+21-15
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:47:45
32+
--> $DIR/offset-of-tuple.rs:48:45
3333
|
3434
LL | { builtin # offset_of(ComplexTup, 0.0.1.) };
3535
| ^
3636

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

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

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

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

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

6767
error: unexpected token: `)`
68-
--> $DIR/offset-of-tuple.rs:53:46
68+
--> $DIR/offset-of-tuple.rs:54: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:36:34
107+
--> $DIR/offset-of-tuple.rs:37:34
108108
|
109109
LL | offset_of!(ComplexTup, 0.0.1.);
110110
| ^
111111

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

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

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

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

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

142142
error: unexpected token: `)`
143-
--> $DIR/offset-of-tuple.rs:42:35
143+
--> $DIR/offset-of-tuple.rs:43:35
144144
|
145145
LL | offset_of!(ComplexTup, 0.0. 1.);
146146
| ^
@@ -205,6 +205,12 @@ error[E0609]: no field `0` on type `u8`
205205
LL | offset_of!(((u8, u16), (u32, u16, u8)), 1.2.0);
206206
| ^
207207

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

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

0 commit comments

Comments
 (0)