Lex binary and octal literals more eagerly.
Previously 0b12 was considered two tokens, 0b1 and 2, as 2 isn't a valid base 2 digit. This patch changes that to collapse them into one (and makes `0b12` etc. an error: 2 isn't a valid base 2 digit). This may break some macro invocations of macros with `tt` (or syntax extensions) that rely on adjacent digits being separate tokens and hence is a [breaking-change] The fix is to separate the tokens, e.g. `0b12` -> `0b1 2`. cc https://github.com/rust-lang/rfcs/pull/879
This commit is contained in:
parent
f00264074f
commit
606f50c46d
5 changed files with 75 additions and 15 deletions
|
|
@ -10,5 +10,5 @@
|
|||
|
||||
// error-pattern:no valid digits found for number
|
||||
fn main() {
|
||||
log(error, 0b42);
|
||||
log(error, 0b);
|
||||
}
|
||||
|
|
|
|||
21
src/test/parse-fail/lex-bad-binary-literal.rs
Normal file
21
src/test/parse-fail/lex-bad-binary-literal.rs
Normal file
|
|
@ -0,0 +1,21 @@
|
|||
// Copyright 2014 The Rust Project Developers. See the COPYRIGHT
|
||||
// file at the top-level directory of this distribution and at
|
||||
// http://rust-lang.org/COPYRIGHT.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
|
||||
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
|
||||
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
|
||||
// option. This file may not be copied, modified, or distributed
|
||||
// except according to those terms.
|
||||
|
||||
fn main() {
|
||||
0b121; //~ ERROR invalid digit for a base 2 literal
|
||||
0b10_10301; //~ ERROR invalid digit for a base 2 literal
|
||||
0b30; //~ ERROR invalid digit for a base 2 literal
|
||||
0b41; //~ ERROR invalid digit for a base 2 literal
|
||||
0b5; //~ ERROR invalid digit for a base 2 literal
|
||||
0b6; //~ ERROR invalid digit for a base 2 literal
|
||||
0b7; //~ ERROR invalid digit for a base 2 literal
|
||||
0b8; //~ ERROR invalid digit for a base 2 literal
|
||||
0b9; //~ ERROR invalid digit for a base 2 literal
|
||||
}
|
||||
14
src/test/parse-fail/lex-bad-octal-literal.rs
Normal file
14
src/test/parse-fail/lex-bad-octal-literal.rs
Normal file
|
|
@ -0,0 +1,14 @@
|
|||
// Copyright 2014 The Rust Project Developers. See the COPYRIGHT
|
||||
// file at the top-level directory of this distribution and at
|
||||
// http://rust-lang.org/COPYRIGHT.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
|
||||
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
|
||||
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
|
||||
// option. This file may not be copied, modified, or distributed
|
||||
// except according to those terms.
|
||||
|
||||
fn main() {
|
||||
0o18; //~ ERROR invalid digit for a base 8 literal
|
||||
0o1234_9_5670; //~ ERROR invalid digit for a base 8 literal
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue