Skip to content

Commit c1a238c

Browse files
committed
Add tests for newly introduced syntax
Also add some (regression) tests for discovered parser oddities
1 parent 662082c commit c1a238c

File tree

6 files changed

+62
-6
lines changed

6 files changed

+62
-6
lines changed

src/libsyntax/parse/parser.rs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -50,8 +50,7 @@ use ast::{BiSub, StrStyle};
5050
use ast::{SelfExplicit, SelfRegion, SelfStatic, SelfValue};
5151
use ast::{Delimited, SequenceRepetition, TokenTree, TraitItem, TraitRef};
5252
use ast::{TtDelimited, TtSequence, TtToken};
53-
use ast::{Ty, Ty_, TypeBinding};
54-
use ast::{TyMac};
53+
use ast::{Ty, Ty_, TypeBinding, TyMac};
5554
use ast::{TyFixedLengthVec, TyBareFn, TyTypeof, TyInfer};
5655
use ast::{TyParam, TyParamBound, TyParen, TyPath, TyPolyTraitRef, TyPtr};
5756
use ast::{TyRptr, TyTup, TyU32, TyVec};
@@ -2658,7 +2657,10 @@ impl<'a> Parser<'a> {
26582657
}
26592658

26602659
/// Parse an associative expression with operators of at least `min_prec` precedence
2661-
pub fn parse_assoc_expr_with(&mut self, min_prec: usize, lhs: Option<P<Expr>>) -> PResult<P<Expr>> {
2660+
pub fn parse_assoc_expr_with(&mut self,
2661+
min_prec: usize,
2662+
lhs: Option<P<Expr>>)
2663+
-> PResult<P<Expr>> {
26622664
let mut lhs = if lhs.is_some() {
26632665
lhs.unwrap()
26642666
} else if self.token == token::DotDot {

src/test/compile-fail/placement-expr-unsafe.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,8 @@ fn main() {
1717
use std::boxed::HEAP;
1818

1919
let p: *const i32 = &42;
20-
let _ = in HEAP { *p }; //~ ERROR requires unsafe
20+
let _ = HEAP <- *p; //~ ERROR requires unsafe
2121

2222
let p: *const _ = &HEAP;
23-
let _ = in *p { 42 }; //~ ERROR requires unsafe
23+
let _ = *p <- 42; //~ ERROR requires unsafe
2424
}

src/test/compile-fail/placement-expr-unstable.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ extern crate core;
1818
fn main() {
1919
use std::boxed::HEAP; //~ ERROR use of unstable library feature
2020

21-
let _ = in HEAP { //~ ERROR use of unstable library feature
21+
let _ = HEAP <- { //~ ERROR use of unstable library feature
2222
::core::raw::Slice { //~ ERROR use of unstable library feature
2323
data: &42, //~ ERROR use of unstable library feature
2424
len: 1 //~ ERROR use of unstable library feature
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
// Copyright 2015 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+
// compile-flags: -Z parse-only
12+
13+
fn that_odd_parse() {
14+
// following lines below parse and must not fail
15+
x = if c { a } else { b }();
16+
x <- if c { a } else { b }[n];
17+
x = if true { 1 } else { 0 } as *mut _;
18+
// however this does not parse and probably should fail to retain compat?
19+
// NB: `..` here is arbitrary, failure happens/should happen ∀ops that aren’t `=` or `<-`
20+
// see assoc-oddities-2 and assoc-oddities-3
21+
..if c { a } else { b }[n]; //~ ERROR expected one of
22+
}
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
// Copyright 2015 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+
// compile-flags: -Z parse-only
12+
13+
fn that_odd_parse() {
14+
// see assoc-oddities-1 for explanation
15+
x..if c { a } else { b }[n]; //~ ERROR expected one of
16+
}
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
// Copyright 2015 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+
// compile-flags: -Z parse-only
12+
13+
fn that_odd_parse() {
14+
// see assoc-oddities-1 for explanation
15+
x + if c { a } else { b }[n]; //~ ERROR expected one of
16+
}

0 commit comments

Comments
 (0)