From 01cc9ecafeb235ad3c12aa2222c3911b2b450052 Mon Sep 17 00:00:00 2001 From: Kang Seonghoon Date: Wed, 6 Feb 2013 16:49:24 +0900 Subject: [PATCH 1/2] libsyntax: no binary/hex float literals --- src/libsyntax/parse/lexer.rs | 7 +++++++ .../compile-fail/no-binary-float-literal.rs | 18 ++++++++++++++++++ src/test/compile-fail/no-hex-float-literal.rs | 18 ++++++++++++++++++ 3 files changed, 43 insertions(+) create mode 100644 src/test/compile-fail/no-binary-float-literal.rs create mode 100644 src/test/compile-fail/no-hex-float-literal.rs diff --git a/src/libsyntax/parse/lexer.rs b/src/libsyntax/parse/lexer.rs index 381183e736cf7..0f672d1de81fd 100644 --- a/src/libsyntax/parse/lexer.rs +++ b/src/libsyntax/parse/lexer.rs @@ -431,6 +431,13 @@ fn scan_number(c: char, rdr: string_reader) -> token::Token { let dec_part = scan_digits(rdr, 10u); num_str += ~"." + dec_part; } + if is_float { + match base { + 16u => rdr.fatal(~"hexadecimal float literal is not supported"), + 2u => rdr.fatal(~"binary float literal is not supported"), + _ => () + } + } match scan_exponent(rdr) { Some(ref s) => { is_float = true; diff --git a/src/test/compile-fail/no-binary-float-literal.rs b/src/test/compile-fail/no-binary-float-literal.rs new file mode 100644 index 0000000000000..58afd5ba349e8 --- /dev/null +++ b/src/test/compile-fail/no-binary-float-literal.rs @@ -0,0 +1,18 @@ +// Copyright 2013 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. + +// error-pattern:binary float literal is not supported + +fn main() { + 0b101010f; + 0b101.010; + 0b101p4f; +} + diff --git a/src/test/compile-fail/no-hex-float-literal.rs b/src/test/compile-fail/no-hex-float-literal.rs new file mode 100644 index 0000000000000..3bc52e029d7c0 --- /dev/null +++ b/src/test/compile-fail/no-hex-float-literal.rs @@ -0,0 +1,18 @@ +// Copyright 2013 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. + +// error-pattern:hexadecimal float literal is not supported + +fn main() { + 0xABC.Df; + 0x567.89; + 0xDEAD.BEEFp-2f; +} + From 2600bcc05dcd51a5f6fe3404c60a5c1891a22dfe Mon Sep 17 00:00:00 2001 From: Kang Seonghoon Date: Wed, 6 Feb 2013 17:43:14 +0900 Subject: [PATCH 2/2] got rid of last empty lines --- src/test/compile-fail/no-binary-float-literal.rs | 1 - src/test/compile-fail/no-hex-float-literal.rs | 1 - 2 files changed, 2 deletions(-) diff --git a/src/test/compile-fail/no-binary-float-literal.rs b/src/test/compile-fail/no-binary-float-literal.rs index 58afd5ba349e8..0fa61b1af52ef 100644 --- a/src/test/compile-fail/no-binary-float-literal.rs +++ b/src/test/compile-fail/no-binary-float-literal.rs @@ -15,4 +15,3 @@ fn main() { 0b101.010; 0b101p4f; } - diff --git a/src/test/compile-fail/no-hex-float-literal.rs b/src/test/compile-fail/no-hex-float-literal.rs index 3bc52e029d7c0..4abb6093b2443 100644 --- a/src/test/compile-fail/no-hex-float-literal.rs +++ b/src/test/compile-fail/no-hex-float-literal.rs @@ -15,4 +15,3 @@ fn main() { 0x567.89; 0xDEAD.BEEFp-2f; } -