Skip to content

Commit 90d15e7

Browse files
committed
syntax: Some code cleanup
1 parent ca2a50f commit 90d15e7

File tree

9 files changed

+177
-228
lines changed

9 files changed

+177
-228
lines changed

Diff for: src/libsyntax/parse/literal.rs

+146-204
Large diffs are not rendered by default.

Diff for: src/libsyntax/parse/token.rs

+9-7
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,7 @@ pub enum LitKind {
7373
Err,
7474
}
7575

76+
/// A literal token.
7677
#[derive(Clone, Copy, PartialEq, RustcEncodable, RustcDecodable, Debug)]
7778
pub struct Lit {
7879
pub kind: LitKind,
@@ -81,6 +82,7 @@ pub struct Lit {
8182
}
8283

8384
impl LitKind {
85+
/// An English article for the literal token kind.
8486
crate fn article(self) -> &'static str {
8587
match self {
8688
Integer | Err => "an",
@@ -91,13 +93,13 @@ impl LitKind {
9193
crate fn descr(self) -> &'static str {
9294
match self {
9395
Bool => panic!("literal token contains `Lit::Bool`"),
94-
Byte => "byte literal",
95-
Char => "char literal",
96-
Integer => "integer literal",
97-
Float => "float literal",
98-
Str | StrRaw(..) => "string literal",
99-
ByteStr | ByteStrRaw(..) => "byte string literal",
100-
Err => "invalid literal",
96+
Byte => "byte",
97+
Char => "char",
98+
Integer => "integer",
99+
Float => "float",
100+
Str | StrRaw(..) => "string",
101+
ByteStr | ByteStrRaw(..) => "byte string",
102+
Err => "error",
101103
}
102104
}
103105

Diff for: src/libsyntax/print/pprust.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -163,7 +163,8 @@ fn binop_to_string(op: BinOpToken) -> &'static str {
163163
}
164164
}
165165

166-
pub fn literal_to_string(token::Lit { kind, symbol, suffix }: token::Lit) -> String {
166+
pub fn literal_to_string(lit: token::Lit) -> String {
167+
let token::Lit { kind, symbol, suffix } = lit;
167168
let mut out = match kind {
168169
token::Byte => format!("b'{}'", symbol),
169170
token::Char => format!("'{}'", symbol),

Diff for: src/libsyntax_ext/proc_macro_server.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -379,7 +379,7 @@ impl<'a> Rustc<'a> {
379379
}
380380
}
381381

382-
pub fn lit(&mut self, kind: token::LitKind, symbol: Symbol, suffix: Option<Symbol>) -> Literal {
382+
fn lit(&mut self, kind: token::LitKind, symbol: Symbol, suffix: Option<Symbol>) -> Literal {
383383
Literal {
384384
lit: token::Lit::new(kind, symbol, suffix),
385385
span: server::Span::call_site(self),

Diff for: src/libsyntax_pos/symbol.rs

+2
Original file line numberDiff line numberDiff line change
@@ -246,6 +246,8 @@ symbols! {
246246
extern_prelude,
247247
extern_types,
248248
f16c_target_feature,
249+
f32,
250+
f64,
249251
feature,
250252
ffi_returns_twice,
251253
field_init_shorthand,

Diff for: src/test/ui/parser/lex-bad-numeric-literals.rs

+4-2
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,10 @@ fn main() {
1313
0o; //~ ERROR: no valid digits
1414
1e+; //~ ERROR: expected at least one digit in exponent
1515
0x539.0; //~ ERROR: hexadecimal float literal is not supported
16-
9900000000000000000000000000999999999999999999999999999999; //~ ERROR: integer literal is too large
17-
9900000000000000000000000000999999999999999999999999999999; //~ ERROR: integer literal is too large
16+
9900000000000000000000000000999999999999999999999999999999;
17+
//~^ ERROR: integer literal is too large
18+
9900000000000000000000000000999999999999999999999999999999;
19+
//~^ ERROR: integer literal is too large
1820
0x; //~ ERROR: no valid digits
1921
0xu32; //~ ERROR: no valid digits
2022
0ou32; //~ ERROR: no valid digits

Diff for: src/test/ui/parser/lex-bad-numeric-literals.stderr

+10-10
Original file line numberDiff line numberDiff line change
@@ -65,43 +65,43 @@ LL | 0x539.0;
6565
| ^^^^^^^
6666

6767
error: no valid digits found for number
68-
--> $DIR/lex-bad-numeric-literals.rs:18:5
68+
--> $DIR/lex-bad-numeric-literals.rs:20:5
6969
|
7070
LL | 0x;
7171
| ^^
7272

7373
error: no valid digits found for number
74-
--> $DIR/lex-bad-numeric-literals.rs:19:5
74+
--> $DIR/lex-bad-numeric-literals.rs:21:5
7575
|
7676
LL | 0xu32;
7777
| ^^
7878

7979
error: no valid digits found for number
80-
--> $DIR/lex-bad-numeric-literals.rs:20:5
80+
--> $DIR/lex-bad-numeric-literals.rs:22:5
8181
|
8282
LL | 0ou32;
8383
| ^^
8484

8585
error: no valid digits found for number
86-
--> $DIR/lex-bad-numeric-literals.rs:21:5
86+
--> $DIR/lex-bad-numeric-literals.rs:23:5
8787
|
8888
LL | 0bu32;
8989
| ^^
9090

9191
error: no valid digits found for number
92-
--> $DIR/lex-bad-numeric-literals.rs:22:5
92+
--> $DIR/lex-bad-numeric-literals.rs:24:5
9393
|
9494
LL | 0b;
9595
| ^^
9696

9797
error: octal float literal is not supported
98-
--> $DIR/lex-bad-numeric-literals.rs:24:5
98+
--> $DIR/lex-bad-numeric-literals.rs:26:5
9999
|
100100
LL | 0o123.456;
101101
| ^^^^^^^^^
102102

103103
error: binary float literal is not supported
104-
--> $DIR/lex-bad-numeric-literals.rs:26:5
104+
--> $DIR/lex-bad-numeric-literals.rs:28:5
105105
|
106106
LL | 0b111.101;
107107
| ^^^^^^^^^
@@ -119,19 +119,19 @@ LL | 9900000000000000000000000000999999999999999999999999999999;
119119
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
120120

121121
error: integer literal is too large
122-
--> $DIR/lex-bad-numeric-literals.rs:17:5
122+
--> $DIR/lex-bad-numeric-literals.rs:18:5
123123
|
124124
LL | 9900000000000000000000000000999999999999999999999999999999;
125125
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
126126

127127
error: octal float literal is not supported
128-
--> $DIR/lex-bad-numeric-literals.rs:23:5
128+
--> $DIR/lex-bad-numeric-literals.rs:25:5
129129
|
130130
LL | 0o123f64;
131131
| ^^^^^^^^ not supported
132132

133133
error: binary float literal is not supported
134-
--> $DIR/lex-bad-numeric-literals.rs:25:5
134+
--> $DIR/lex-bad-numeric-literals.rs:27:5
135135
|
136136
LL | 0b101f64;
137137
| ^^^^^^^^ not supported

Diff for: src/test/ui/parser/no-hex-float-literal.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,6 @@ fn main() {
44
0x567.89;
55
//~^ ERROR hexadecimal float literal is not supported
66
0xDEAD.BEEFp-2f;
7-
//~^ ERROR invalid suffix `f` for integer literal
7+
//~^ ERROR invalid suffix `f` for float literal
88
//~| ERROR `{integer}` is a primitive type and therefore doesn't have fields
99
}

Diff for: src/test/ui/parser/no-hex-float-literal.stderr

+2-2
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,13 @@ error: hexadecimal float literal is not supported
44
LL | 0x567.89;
55
| ^^^^^^^^
66

7-
error: invalid suffix `f` for integer literal
7+
error: invalid suffix `f` for float literal
88
--> $DIR/no-hex-float-literal.rs:6:18
99
|
1010
LL | 0xDEAD.BEEFp-2f;
1111
| ^^ invalid suffix `f`
1212
|
13-
= help: the suffix must be one of the integral types (`u32`, `isize`, etc)
13+
= help: valid suffixes are `f32` and `f64`
1414

1515
error[E0610]: `{integer}` is a primitive type and therefore doesn't have fields
1616
--> $DIR/no-hex-float-literal.rs:2:11

0 commit comments

Comments
 (0)