1
Fork 0

Update error to reflect that integer literals can have float suffixes

For example, `1` is parsed as an integer literal, but it can be turned
into a float with the suffix `f32`. Now the error calls them "numeric
literals" and notes that you can add a float suffix since they can be
either integers or floats.
This commit is contained in:
Camelid 2020-11-22 14:29:46 -08:00
parent 52e3cf13aa
commit a3cde636fc
7 changed files with 17 additions and 17 deletions

View file

@ -1450,10 +1450,10 @@ impl<'a> Parser<'a> {
.help("valid widths are 8, 16, 32, 64 and 128") .help("valid widths are 8, 16, 32, 64 and 128")
.emit(); .emit();
} else { } else {
let msg = format!("invalid suffix `{}` for integer literal", suf); let msg = format!("invalid suffix `{}` for number literal", suf);
self.struct_span_err(span, &msg) self.struct_span_err(span, &msg)
.span_label(span, format!("invalid suffix `{}`", suf)) .span_label(span, format!("invalid suffix `{}`", suf))
.help("the suffix must be one of the integral types (`u32`, `isize`, etc)") .help("the suffix must be one of the numeric types (`u32`, `isize`, `f32`, etc.)")
.emit(); .emit();
} }
} }

View file

@ -1,18 +1,18 @@
error: invalid suffix `is` for integer literal error: invalid suffix `is` for number literal
--> $DIR/old-suffixes-are-really-forbidden.rs:2:13 --> $DIR/old-suffixes-are-really-forbidden.rs:2:13
| |
LL | let a = 1_is; LL | let a = 1_is;
| ^^^^ invalid suffix `is` | ^^^^ invalid suffix `is`
| |
= help: the suffix must be one of the integral types (`u32`, `isize`, etc) = help: the suffix must be one of the numeric types (`u32`, `isize`, `f32`, etc.)
error: invalid suffix `us` for integer literal error: invalid suffix `us` for number literal
--> $DIR/old-suffixes-are-really-forbidden.rs:3:13 --> $DIR/old-suffixes-are-really-forbidden.rs:3:13
| |
LL | let b = 2_us; LL | let b = 2_us;
| ^^^^ invalid suffix `us` | ^^^^ invalid suffix `us`
| |
= help: the suffix must be one of the integral types (`u32`, `isize`, etc) = help: the suffix must be one of the numeric types (`u32`, `isize`, `f32`, etc.)
error: aborting due to 2 previous errors error: aborting due to 2 previous errors

View file

@ -19,8 +19,8 @@ fn main() {
1234f1024; //~ ERROR invalid width `1024` for float literal 1234f1024; //~ ERROR invalid width `1024` for float literal
1234.5f1024; //~ ERROR invalid width `1024` for float literal 1234.5f1024; //~ ERROR invalid width `1024` for float literal
1234suffix; //~ ERROR invalid suffix `suffix` for integer literal 1234suffix; //~ ERROR invalid suffix `suffix` for number literal
0b101suffix; //~ ERROR invalid suffix `suffix` for integer literal 0b101suffix; //~ ERROR invalid suffix `suffix` for number literal
1.0suffix; //~ ERROR invalid suffix `suffix` for float literal 1.0suffix; //~ ERROR invalid suffix `suffix` for float literal
1.0e10suffix; //~ ERROR invalid suffix `suffix` for float literal 1.0e10suffix; //~ ERROR invalid suffix `suffix` for float literal
} }

View file

@ -78,21 +78,21 @@ LL | 1234.5f1024;
| |
= help: valid widths are 32 and 64 = help: valid widths are 32 and 64
error: invalid suffix `suffix` for integer literal error: invalid suffix `suffix` for number literal
--> $DIR/bad-lit-suffixes.rs:22:5 --> $DIR/bad-lit-suffixes.rs:22:5
| |
LL | 1234suffix; LL | 1234suffix;
| ^^^^^^^^^^ invalid suffix `suffix` | ^^^^^^^^^^ invalid suffix `suffix`
| |
= help: the suffix must be one of the integral types (`u32`, `isize`, etc) = help: the suffix must be one of the numeric types (`u32`, `isize`, `f32`, etc.)
error: invalid suffix `suffix` for integer literal error: invalid suffix `suffix` for number literal
--> $DIR/bad-lit-suffixes.rs:23:5 --> $DIR/bad-lit-suffixes.rs:23:5
| |
LL | 0b101suffix; LL | 0b101suffix;
| ^^^^^^^^^^^ invalid suffix `suffix` | ^^^^^^^^^^^ invalid suffix `suffix`
| |
= help: the suffix must be one of the integral types (`u32`, `isize`, etc) = help: the suffix must be one of the numeric types (`u32`, `isize`, `f32`, etc.)
error: invalid suffix `suffix` for float literal error: invalid suffix `suffix` for float literal
--> $DIR/bad-lit-suffixes.rs:24:5 --> $DIR/bad-lit-suffixes.rs:24:5

View file

@ -4,5 +4,5 @@ fn main() {
0b101.010; 0b101.010;
//~^ ERROR binary float literal is not supported //~^ ERROR binary float literal is not supported
0b101p4f64; 0b101p4f64;
//~^ ERROR invalid suffix `p4f64` for integer literal //~^ ERROR invalid suffix `p4f64` for number literal
} }

View file

@ -10,13 +10,13 @@ error: binary float literal is not supported
LL | 0b101010f64; LL | 0b101010f64;
| ^^^^^^^^^^^ not supported | ^^^^^^^^^^^ not supported
error: invalid suffix `p4f64` for integer literal error: invalid suffix `p4f64` for number literal
--> $DIR/no-binary-float-literal.rs:6:5 --> $DIR/no-binary-float-literal.rs:6:5
| |
LL | 0b101p4f64; LL | 0b101p4f64;
| ^^^^^^^^^^ invalid suffix `p4f64` | ^^^^^^^^^^ invalid suffix `p4f64`
| |
= help: the suffix must be one of the integral types (`u32`, `isize`, etc) = help: the suffix must be one of the numeric types (`u32`, `isize`, `f32`, etc.)
error: aborting due to 3 previous errors error: aborting due to 3 previous errors

View file

@ -1,10 +1,10 @@
error: invalid suffix `x` for integer literal error: invalid suffix `x` for number literal
--> $DIR/ice-3891.rs:2:5 --> $DIR/ice-3891.rs:2:5
| |
LL | 1x; LL | 1x;
| ^^ invalid suffix `x` | ^^ invalid suffix `x`
| |
= help: the suffix must be one of the integral types (`u32`, `isize`, etc) = help: the suffix must be one of the numeric types (`u32`, `isize`, `f32`, etc.)
error: aborting due to previous error error: aborting due to previous error