Skip to content

Commit 38ccafc

Browse files
Rollup merge of rust-lang#41946 - qnighy:disallow-dot-underscore-in-float, r=petrochenkov
Disallow ._ in float literal. This patch makes lexer stop parsing number literals before `._`, as well as before `.a`. Underscore itself is still allowed like in `4_000_000.000_000_`. Fixes a half part of rust-lang#41723. The other is `""_`.
2 parents effa379 + 7b535e1 commit 38ccafc

File tree

3 files changed

+33
-3
lines changed

3 files changed

+33
-3
lines changed

src/libsyntax/parse/lexer/mod.rs

+1-3
Original file line numberDiff line numberDiff line change
@@ -754,9 +754,7 @@ impl<'a> StringReader<'a> {
754754
// integer literal followed by field/method access or a range pattern
755755
// (`0..2` and `12.foo()`)
756756
if self.ch_is('.') && !self.nextch_is('.') &&
757-
!self.nextch()
758-
.unwrap_or('\0')
759-
.is_xid_start() {
757+
!ident_start(self.nextch()) {
760758
// might have stuff after the ., and if it does, it needs to start
761759
// with a number
762760
self.bump();
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
// Copyright 2017 The Rust Project Developers. See the COPYRIGHT
2+
// file at the top-level directory of this distribution and at
3+
// http://rust-lang.org/COPYRIGHT.
4+
//
5+
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6+
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7+
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8+
// option. This file may not be copied, modified, or distributed
9+
// except according to those terms.
10+
11+
fn main() {
12+
let a = 42._; //~ ERROR unexpected token: `_`
13+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
// Copyright 2017 The Rust Project Developers. See the COPYRIGHT
2+
// file at the top-level directory of this distribution and at
3+
// http://rust-lang.org/COPYRIGHT.
4+
//
5+
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6+
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7+
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8+
// option. This file may not be copied, modified, or distributed
9+
// except according to those terms.
10+
11+
trait Tr : Sized {
12+
fn _method_on_numbers(self) {}
13+
}
14+
15+
impl Tr for i32 {}
16+
17+
fn main() {
18+
42._method_on_numbers();
19+
}

0 commit comments

Comments
 (0)