Skip to content

Commit 608e12b

Browse files
committed
test: 💍 add ui tests and some docs
1 parent 2fe09a5 commit 608e12b

File tree

4 files changed

+66
-0
lines changed

4 files changed

+66
-0
lines changed

compiler/rustc_lexer/src/lib.rs

+2
Original file line numberDiff line numberDiff line change
@@ -604,6 +604,8 @@ impl Cursor<'_> {
604604
}
605605
}
606606

607+
/// Parses a number and in `.1` returns the offset of the literal suffix
608+
/// (this will be at the end of the token if there is no suffix)
607609
fn number(&mut self, first_digit: char) -> (LiteralKind, u32) {
608610
debug_assert!('0' <= self.prev() && self.prev() <= '9');
609611
let mut base = Base::Decimal;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
const _A: f64 = 1em;
2+
//~^ ERROR invalid suffix `em` for number literal
3+
const _B: f64 = 1e0m;
4+
//~^ ERROR invalid suffix `m` for float literal
5+
const _C: f64 = 1e_______________0m;
6+
//~^ ERROR invalid suffix `m` for float literal
7+
const _D: f64 = 1e_______________m;
8+
//~^ ERROR invalid suffix `e_______________m` for number literal
9+
10+
fn main() {}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
error: invalid suffix `em` for number literal
2+
--> $DIR/custom-suffixes-exponent-like.rs:1:17
3+
|
4+
LL | const _A: f64 = 1em;
5+
| ^^^ invalid suffix `em`
6+
|
7+
= help: the suffix must be one of the numeric types (`u32`, `isize`, `f32`, etc.)
8+
9+
error: invalid suffix `m` for float literal
10+
--> $DIR/custom-suffixes-exponent-like.rs:3:17
11+
|
12+
LL | const _B: f64 = 1e0m;
13+
| ^^^^ invalid suffix `m`
14+
|
15+
= help: valid suffixes are `f32` and `f64`
16+
17+
error: invalid suffix `m` for float literal
18+
--> $DIR/custom-suffixes-exponent-like.rs:5:17
19+
|
20+
LL | const _C: f64 = 1e_______________0m;
21+
| ^^^^^^^^^^^^^^^^^^^ invalid suffix `m`
22+
|
23+
= help: valid suffixes are `f32` and `f64`
24+
25+
error: invalid suffix `e_______________m` for number literal
26+
--> $DIR/custom-suffixes-exponent-like.rs:7:17
27+
|
28+
LL | const _D: f64 = 1e_______________m;
29+
| ^^^^^^^^^^^^^^^^^^ invalid suffix `e_______________m`
30+
|
31+
= help: the suffix must be one of the numeric types (`u32`, `isize`, `f32`, etc.)
32+
33+
error: aborting due to 4 previous errors
34+

tests/ui/consts/custom-suffixes.rs

+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
//@ run-pass
2+
3+
// This tests different kinds of valid suffixes.
4+
5+
fn main() {
6+
const _A: f64 = 1.;
7+
const _B: f64 = 1f64;
8+
const _C: f64 = 1.0f64;
9+
const _D: f64 = 1e6;
10+
const _E: f64 = 1e-6;
11+
const _F: f64 = 1.0e-6;
12+
const _G: f64 = 1.0e06;
13+
const _H: f64 = 1.0e+6;
14+
const _I: f64 = 1.0e-6;
15+
// these ones are perhaps more suprising.
16+
const _J: f64 = 1.0e0________________________6;
17+
const _K: f64 = 1.0e________________________6;
18+
const _L: f64 = 1.0e+________________________6;
19+
const _M: f64 = 1.0e-________________________6;
20+
}

0 commit comments

Comments
 (0)