Fix some grammar inconsistencies for the '..' range notation.
Grammar changes:
* allow 'for _ in 1..i {}' (fixes #20241)
* allow 'for _ in 1.. {}' as infinite loop
* prevent use of range notation in contexts where only operators of high
precedence are expected (fixes #20811)
Parser code cleanup:
* remove RESTRICTION_NO_DOTS
* make AS_PREC const and follow naming convention
* make min_prec inclusive
This commit is contained in:
parent
b7930d93d9
commit
db013f9f45
6 changed files with 80 additions and 23 deletions
16
src/test/compile-fail/range-3.rs
Normal file
16
src/test/compile-fail/range-3.rs
Normal file
|
|
@ -0,0 +1,16 @@
|
|||
// 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.
|
||||
|
||||
// Test range syntax - syntax errors.
|
||||
|
||||
pub fn main() {
|
||||
let r = 1..2..3;
|
||||
//~^ ERROR expected one of `.`, `;`, or an operator, found `..`
|
||||
}
|
||||
16
src/test/compile-fail/range-4.rs
Normal file
16
src/test/compile-fail/range-4.rs
Normal file
|
|
@ -0,0 +1,16 @@
|
|||
// 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.
|
||||
|
||||
// Test range syntax - syntax errors.
|
||||
|
||||
pub fn main() {
|
||||
let r = ..1..2;
|
||||
//~^ ERROR expected one of `.`, `;`, or an operator, found `..`
|
||||
}
|
||||
|
|
@ -48,5 +48,12 @@ fn main() {
|
|||
assert!(x == &a[3..]);
|
||||
|
||||
for _i in 2+4..10-3 {}
|
||||
|
||||
let i = 42;
|
||||
for _ in 1..i {}
|
||||
for _ in 1.. { break; }
|
||||
|
||||
let x = [1]..[2];
|
||||
assert!(x == (([1])..([2])));
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue