Skip to content

Commit

Permalink
squash! Fix Parser::break_up_float fractional part's span
Browse files Browse the repository at this point in the history
  • Loading branch information
ShE3py committed Jul 15, 2024
1 parent 27b59b3 commit 8513f07
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 37 deletions.
40 changes: 18 additions & 22 deletions compiler/rustc_parse/src/parser/expr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1081,38 +1081,34 @@ impl<'a> Parser<'a> {

match &*components {
// 1e2
[IdentLike(i)] => {
DestructuredFloat::Single(Symbol::intern(i), span)
[IdentLike(integral_part)] => {
DestructuredFloat::Single(Symbol::intern(integral_part), span)
}
// 1.
[IdentLike(i), Punct('.')] => {
let (ident_span, dot_span) = if can_take_span_apart() {
let (span, ident_len) = (span.data(), BytePos::from_usize(i.len()));
let ident_span = span.with_hi(span.lo + ident_len);
let dot_span = span.with_lo(span.lo + ident_len);
(ident_span, dot_span)
[IdentLike(integral_part), Punct('.')] => {
let (integral_span, dot_span) = if can_take_span_apart() {
let integral_span = span.with_hi(span.lo() + BytePos::from_usize(integral_part.len()));
let dot_span = span.with_lo(integral_span.hi());
(integral_span, dot_span)
} else {
(span, span)
};
let symbol = Symbol::intern(i);
DestructuredFloat::TrailingDot(symbol, ident_span, dot_span)
let integral_part = Symbol::intern(integral_part);
DestructuredFloat::TrailingDot(integral_part, integral_span, dot_span)
}
// 1.2 | 1.2e3
[IdentLike(i1), Punct('.'), IdentLike(i2)] => {
let (ident1_span, dot_span, ident2_span) = if can_take_span_apart() {
let (span, ident1_len) = (span.data(), BytePos::from_usize(i1.len()));
let ident1_span = span.with_hi(span.lo + ident1_len);
let dot_span = span
.with_lo(span.lo + ident1_len)
.with_hi(span.lo + ident1_len + BytePos(1));
let ident2_span = span.with_lo(span.lo + ident1_len + BytePos(1));
(ident1_span, dot_span, ident2_span)
[IdentLike(integral_part), Punct('.'), IdentLike(fractional_part)] => {
let (integral_span, dot_span, fractional_span) = if can_take_span_apart() {
let integral_span = span.with_hi(span.lo() + BytePos::from_usize(integral_part.len()));
let dot_span = span.with_lo(integral_span.hi()).with_hi(integral_span.hi() + BytePos(1));
let fractional_span = span.with_lo(dot_span.hi());
(integral_span, dot_span, fractional_span)
} else {
(span, span, span)
};
let symbol1 = Symbol::intern(i1);
let symbol2 = Symbol::intern(i2);
DestructuredFloat::MiddleDot(symbol1, ident1_span, dot_span, symbol2, ident2_span)
let integral_part = Symbol::intern(integral_part);
let fractional_part = Symbol::intern(fractional_part);
DestructuredFloat::MiddleDot(integral_part, integral_span, dot_span, fractional_part, fractional_span)
}
// 1e+ | 1e- (recovered)
[IdentLike(_), Punct('+' | '-')] |
Expand Down
1 change: 1 addition & 0 deletions tests/ui/offset-of/offset-of-tuple.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ fn nested() {
offset_of!(((u8, u16), (u32, u16, u8)), 0.2); //~ ERROR no field `2`
offset_of!(((u8, u16), (u32, u16, u8)), 1.2);
offset_of!(((u8, u16), (u32, u16, u8)), 1.2.0); //~ ERROR no field `0`
offset_of!(((u8, u16), (u32, u16, u8)), 0.1e2); //~ ERROR no field `1e2`

// All combinations of spaces (this sends different tokens to the parser)
offset_of!(ComplexTup, 0.0.1.); //~ ERROR unexpected token: `)`
Expand Down
36 changes: 21 additions & 15 deletions tests/ui/offset-of/offset-of-tuple.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -29,43 +29,43 @@ LL | { builtin # offset_of((u8, u8), 1 .) };
| ^

error: unexpected token: `)`
--> $DIR/offset-of-tuple.rs:47:45
--> $DIR/offset-of-tuple.rs:48:45
|
LL | { builtin # offset_of(ComplexTup, 0.0.1.) };
| ^

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

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

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

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

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

error: unexpected token: `)`
--> $DIR/offset-of-tuple.rs:53:46
--> $DIR/offset-of-tuple.rs:54:46
|
LL | { builtin # offset_of(ComplexTup, 0.0. 1.) };
| ^
Expand Down Expand Up @@ -104,43 +104,43 @@ LL | offset_of!((u8, u8), 1 .);
| ^

error: unexpected token: `)`
--> $DIR/offset-of-tuple.rs:36:34
--> $DIR/offset-of-tuple.rs:37:34
|
LL | offset_of!(ComplexTup, 0.0.1.);
| ^

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

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

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

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

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

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

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

error: aborting due to 34 previous errors

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

0 comments on commit 8513f07

Please sign in to comment.