From 606f50c46dd9a3852d36456d2015e1ccf832642e Mon Sep 17 00:00:00 2001 From: Huon Wilson Date: Tue, 31 Mar 2015 00:27:13 +1100 Subject: 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 --- src/test/parse-fail/issue-1802-1.rs | 2 +- src/test/parse-fail/lex-bad-binary-literal.rs | 21 +++++++++++++++++++++ src/test/parse-fail/lex-bad-octal-literal.rs | 14 ++++++++++++++ 3 files changed, 36 insertions(+), 1 deletion(-) create mode 100644 src/test/parse-fail/lex-bad-binary-literal.rs create mode 100644 src/test/parse-fail/lex-bad-octal-literal.rs (limited to 'src/test/parse-fail') diff --git a/src/test/parse-fail/issue-1802-1.rs b/src/test/parse-fail/issue-1802-1.rs index 8ce99f517c4..00fb2808faa 100644 --- a/src/test/parse-fail/issue-1802-1.rs +++ b/src/test/parse-fail/issue-1802-1.rs @@ -10,5 +10,5 @@ // error-pattern:no valid digits found for number fn main() { - log(error, 0b42); + log(error, 0b); } diff --git a/src/test/parse-fail/lex-bad-binary-literal.rs b/src/test/parse-fail/lex-bad-binary-literal.rs new file mode 100644 index 00000000000..e92000c54ba --- /dev/null +++ b/src/test/parse-fail/lex-bad-binary-literal.rs @@ -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 or the MIT license +// , 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 +} diff --git a/src/test/parse-fail/lex-bad-octal-literal.rs b/src/test/parse-fail/lex-bad-octal-literal.rs new file mode 100644 index 00000000000..bf9880cb6cf --- /dev/null +++ b/src/test/parse-fail/lex-bad-octal-literal.rs @@ -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 or the MIT license +// , 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 +} -- cgit 1.4.1-3-g733a5