Skip to content

Commit

Permalink
Use LitKind::Err for floats with unsupported bases.
Browse files Browse the repository at this point in the history
This slightly changes error messages in `float-field.rs`, but nothing of
real importance.
  • Loading branch information
nnethercote committed Feb 28, 2024
1 parent 7976609 commit 840c8d3
Show file tree
Hide file tree
Showing 3 changed files with 77 additions and 67 deletions.
4 changes: 3 additions & 1 deletion compiler/rustc_parse/src/lexer/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -515,7 +515,9 @@ impl<'sess, 'src> StringReader<'sess, 'src> {
};
if let Some(base) = base {
let span = self.mk_sp(start, end);
self.dcx().emit_err(errors::FloatLiteralUnsupportedBase { span, base });
let guar =
self.dcx().emit_err(errors::FloatLiteralUnsupportedBase { span, base });
kind = token::Err(guar)
}
(kind, self.symbol_from_to(start, end))
}
Expand Down
16 changes: 9 additions & 7 deletions tests/ui/parser/float-field.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,15 +33,17 @@ fn main() {

{ s.0x1e1; } //~ ERROR no field `0x1e1` on type `S`

{ s.0x1.; } //~ ERROR no field `0x1` on type `S`
//~| ERROR hexadecimal float literal is not supported
//~| ERROR unexpected token: `;`
{ s.0x1.; } //~ ERROR hexadecimal float literal is not supported
//~| ERROR unexpected token: `0x1.`
//~| ERROR expected one of `.`, `;`, `?`, `}`, or an operator, found `0x1.`

{ s.0x1.1; } //~ ERROR no field `0x1` on type `S`
//~| ERROR hexadecimal float literal is not supported
{ s.0x1.1; } //~ ERROR hexadecimal float literal is not supported
//~| ERROR unexpected token: `0x1.1`
//~| expected one of `.`, `;`, `?`, `}`, or an operator, found `0x1.1`

{ s.0x1.1e1; } //~ ERROR no field `0x1` on type `S`
//~| ERROR hexadecimal float literal is not supported
{ s.0x1.1e1; } //~ ERROR hexadecimal float literal is not supported
//~| ERROR unexpected token: `0x1.1e1`
//~| expected one of `.`, `;`, `?`, `}`, or an operator, found `0x1.1e1`

{ s.0x1e+; } //~ ERROR expected expression, found `;`

Expand Down
124 changes: 65 additions & 59 deletions tests/ui/parser/float-field.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -23,31 +23,31 @@ LL | { s.0x1.1; }
| ^^^^^

error: hexadecimal float literal is not supported
--> $DIR/float-field.rs:43:9
--> $DIR/float-field.rs:44:9
|
LL | { s.0x1.1e1; }
| ^^^^^^^

error: hexadecimal float literal is not supported
--> $DIR/float-field.rs:54:9
--> $DIR/float-field.rs:56:9
|
LL | { s.0x1.1e+1; }
| ^^^^^^^^

error: hexadecimal float literal is not supported
--> $DIR/float-field.rs:58:9
--> $DIR/float-field.rs:60:9
|
LL | { s.0x1.1e-1; }
| ^^^^^^^^

error: expected at least one digit in exponent
--> $DIR/float-field.rs:72:9
--> $DIR/float-field.rs:74:9
|
LL | { s.1e+f32; }
| ^^^^^^

error: expected at least one digit in exponent
--> $DIR/float-field.rs:76:9
--> $DIR/float-field.rs:78:9
|
LL | { s.1e-f32; }
| ^^^^^^
Expand Down Expand Up @@ -130,134 +130,164 @@ error: expected one of `.`, `;`, `?`, `}`, or an operator, found `1.1e-1`
LL | { s.1.1e-1; }
| ^^^^^^ expected one of `.`, `;`, `?`, `}`, or an operator

error: unexpected token: `;`
--> $DIR/float-field.rs:36:13
error: unexpected token: `0x1.`
--> $DIR/float-field.rs:36:9
|
LL | { s.0x1.; }
| ^^^^

error: expected one of `.`, `;`, `?`, `}`, or an operator, found `0x1.`
--> $DIR/float-field.rs:36:9
|
LL | { s.0x1.; }
| ^
| ^^^^ expected one of `.`, `;`, `?`, `}`, or an operator

error: unexpected token: `0x1.1`
--> $DIR/float-field.rs:40:9
|
LL | { s.0x1.1; }
| ^^^^^

error: expected one of `.`, `;`, `?`, `}`, or an operator, found `0x1.1`
--> $DIR/float-field.rs:40:9
|
LL | { s.0x1.1; }
| ^^^^^ expected one of `.`, `;`, `?`, `}`, or an operator

error: unexpected token: `0x1.1e1`
--> $DIR/float-field.rs:44:9
|
LL | { s.0x1.1e1; }
| ^^^^^^^

error: expected one of `.`, `;`, `?`, `}`, or an operator, found `0x1.1e1`
--> $DIR/float-field.rs:44:9
|
LL | { s.0x1.1e1; }
| ^^^^^^^ expected one of `.`, `;`, `?`, `}`, or an operator

error: expected expression, found `;`
--> $DIR/float-field.rs:46:14
--> $DIR/float-field.rs:48:14
|
LL | { s.0x1e+; }
| ^ expected expression

error: expected expression, found `;`
--> $DIR/float-field.rs:48:14
--> $DIR/float-field.rs:50:14
|
LL | { s.0x1e-; }
| ^ expected expression

error: unexpected token: `0x1.1e+1`
--> $DIR/float-field.rs:54:9
--> $DIR/float-field.rs:56:9
|
LL | { s.0x1.1e+1; }
| ^^^^^^^^

error: expected one of `.`, `;`, `?`, `}`, or an operator, found `0x1.1e+1`
--> $DIR/float-field.rs:54:9
--> $DIR/float-field.rs:56:9
|
LL | { s.0x1.1e+1; }
| ^^^^^^^^ expected one of `.`, `;`, `?`, `}`, or an operator

error: unexpected token: `0x1.1e-1`
--> $DIR/float-field.rs:58:9
--> $DIR/float-field.rs:60:9
|
LL | { s.0x1.1e-1; }
| ^^^^^^^^

error: expected one of `.`, `;`, `?`, `}`, or an operator, found `0x1.1e-1`
--> $DIR/float-field.rs:58:9
--> $DIR/float-field.rs:60:9
|
LL | { s.0x1.1e-1; }
| ^^^^^^^^ expected one of `.`, `;`, `?`, `}`, or an operator

error: suffixes on a tuple index are invalid
--> $DIR/float-field.rs:62:9
--> $DIR/float-field.rs:64:9
|
LL | { s.1e1f32; }
| ^^^^^^ invalid suffix `f32`

error: suffixes on a tuple index are invalid
--> $DIR/float-field.rs:67:9
--> $DIR/float-field.rs:69:9
|
LL | { s.1.1f32; }
| ^^^^^^ invalid suffix `f32`

error: suffixes on a tuple index are invalid
--> $DIR/float-field.rs:69:9
--> $DIR/float-field.rs:71:9
|
LL | { s.1.1e1f32; }
| ^^^^^^^^ invalid suffix `f32`

error: unexpected token: `1e+f32`
--> $DIR/float-field.rs:72:9
--> $DIR/float-field.rs:74:9
|
LL | { s.1e+f32; }
| ^^^^^^

error: expected one of `.`, `;`, `?`, `}`, or an operator, found `1e+f32`
--> $DIR/float-field.rs:72:9
--> $DIR/float-field.rs:74:9
|
LL | { s.1e+f32; }
| ^^^^^^ expected one of `.`, `;`, `?`, `}`, or an operator

error: unexpected token: `1e-f32`
--> $DIR/float-field.rs:76:9
--> $DIR/float-field.rs:78:9
|
LL | { s.1e-f32; }
| ^^^^^^

error: expected one of `.`, `;`, `?`, `}`, or an operator, found `1e-f32`
--> $DIR/float-field.rs:76:9
--> $DIR/float-field.rs:78:9
|
LL | { s.1e-f32; }
| ^^^^^^ expected one of `.`, `;`, `?`, `}`, or an operator

error: unexpected token: `1e+1f32`
--> $DIR/float-field.rs:80:9
--> $DIR/float-field.rs:82:9
|
LL | { s.1e+1f32; }
| ^^^^^^^

error: expected one of `.`, `;`, `?`, `}`, or an operator, found `1e+1f32`
--> $DIR/float-field.rs:80:9
--> $DIR/float-field.rs:82:9
|
LL | { s.1e+1f32; }
| ^^^^^^^ expected one of `.`, `;`, `?`, `}`, or an operator

error: unexpected token: `1e-1f32`
--> $DIR/float-field.rs:83:9
--> $DIR/float-field.rs:85:9
|
LL | { s.1e-1f32; }
| ^^^^^^^

error: expected one of `.`, `;`, `?`, `}`, or an operator, found `1e-1f32`
--> $DIR/float-field.rs:83:9
--> $DIR/float-field.rs:85:9
|
LL | { s.1e-1f32; }
| ^^^^^^^ expected one of `.`, `;`, `?`, `}`, or an operator

error: unexpected token: `1.1e+1f32`
--> $DIR/float-field.rs:86:9
--> $DIR/float-field.rs:88:9
|
LL | { s.1.1e+1f32; }
| ^^^^^^^^^

error: expected one of `.`, `;`, `?`, `}`, or an operator, found `1.1e+1f32`
--> $DIR/float-field.rs:86:9
--> $DIR/float-field.rs:88:9
|
LL | { s.1.1e+1f32; }
| ^^^^^^^^^ expected one of `.`, `;`, `?`, `}`, or an operator

error: unexpected token: `1.1e-1f32`
--> $DIR/float-field.rs:89:9
--> $DIR/float-field.rs:91:9
|
LL | { s.1.1e-1f32; }
| ^^^^^^^^^

error: expected one of `.`, `;`, `?`, `}`, or an operator, found `1.1e-1f32`
--> $DIR/float-field.rs:89:9
--> $DIR/float-field.rs:91:9
|
LL | { s.1.1e-1f32; }
| ^^^^^^^^^ expected one of `.`, `;`, `?`, `}`, or an operator
Expand All @@ -284,66 +314,42 @@ LL | { s.0x1e1; }
|
= note: available fields are: `0`, `1`

error[E0609]: no field `0x1` on type `S`
--> $DIR/float-field.rs:36:9
|
LL | { s.0x1.; }
| ^^^ unknown field
|
= note: available fields are: `0`, `1`

error[E0609]: no field `0x1` on type `S`
--> $DIR/float-field.rs:40:9
|
LL | { s.0x1.1; }
| ^^^ unknown field
|
= note: available fields are: `0`, `1`

error[E0609]: no field `0x1` on type `S`
--> $DIR/float-field.rs:43:9
|
LL | { s.0x1.1e1; }
| ^^^ unknown field
|
= note: available fields are: `0`, `1`

error[E0609]: no field `0x1e` on type `S`
--> $DIR/float-field.rs:50:9
--> $DIR/float-field.rs:52:9
|
LL | { s.0x1e+1; }
| ^^^^ unknown field
|
= note: available fields are: `0`, `1`

error[E0609]: no field `0x1e` on type `S`
--> $DIR/float-field.rs:52:9
--> $DIR/float-field.rs:54:9
|
LL | { s.0x1e-1; }
| ^^^^ unknown field
|
= note: available fields are: `0`, `1`

error[E0609]: no field `1e1` on type `S`
--> $DIR/float-field.rs:62:9
--> $DIR/float-field.rs:64:9
|
LL | { s.1e1f32; }
| ^^^^^^ unknown field
|
= note: available fields are: `0`, `1`

error[E0609]: no field `f32` on type `(u8, u8)`
--> $DIR/float-field.rs:65:11
--> $DIR/float-field.rs:67:11
|
LL | { s.1.f32; }
| ^^^ unknown field

error[E0609]: no field `1e1` on type `(u8, u8)`
--> $DIR/float-field.rs:69:9
--> $DIR/float-field.rs:71:9
|
LL | { s.1.1e1f32; }
| ^^^^^^^^ unknown field

error: aborting due to 55 previous errors
error: aborting due to 57 previous errors

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

0 comments on commit 840c8d3

Please sign in to comment.