Skip to content

Commit

Permalink
Add tests for newly introduced syntax
Browse files Browse the repository at this point in the history
Also add some (regression) tests for discovered parser oddities
  • Loading branch information
nagisa committed Oct 27, 2015
1 parent 662082c commit c1a238c
Show file tree
Hide file tree
Showing 6 changed files with 62 additions and 6 deletions.
8 changes: 5 additions & 3 deletions src/libsyntax/parse/parser.rs
Expand Up @@ -50,8 +50,7 @@ use ast::{BiSub, StrStyle};
use ast::{SelfExplicit, SelfRegion, SelfStatic, SelfValue};
use ast::{Delimited, SequenceRepetition, TokenTree, TraitItem, TraitRef};
use ast::{TtDelimited, TtSequence, TtToken};
use ast::{Ty, Ty_, TypeBinding};
use ast::{TyMac};
use ast::{Ty, Ty_, TypeBinding, TyMac};
use ast::{TyFixedLengthVec, TyBareFn, TyTypeof, TyInfer};
use ast::{TyParam, TyParamBound, TyParen, TyPath, TyPolyTraitRef, TyPtr};
use ast::{TyRptr, TyTup, TyU32, TyVec};
Expand Down Expand Up @@ -2658,7 +2657,10 @@ impl<'a> Parser<'a> {
}

/// Parse an associative expression with operators of at least `min_prec` precedence
pub fn parse_assoc_expr_with(&mut self, min_prec: usize, lhs: Option<P<Expr>>) -> PResult<P<Expr>> {
pub fn parse_assoc_expr_with(&mut self,
min_prec: usize,
lhs: Option<P<Expr>>)
-> PResult<P<Expr>> {
let mut lhs = if lhs.is_some() {
lhs.unwrap()
} else if self.token == token::DotDot {
Expand Down
4 changes: 2 additions & 2 deletions src/test/compile-fail/placement-expr-unsafe.rs
Expand Up @@ -17,8 +17,8 @@ fn main() {
use std::boxed::HEAP;

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

let p: *const _ = &HEAP;
let _ = in *p { 42 }; //~ ERROR requires unsafe
let _ = *p <- 42; //~ ERROR requires unsafe
}
2 changes: 1 addition & 1 deletion src/test/compile-fail/placement-expr-unstable.rs
Expand Up @@ -18,7 +18,7 @@ extern crate core;
fn main() {
use std::boxed::HEAP; //~ ERROR use of unstable library feature

let _ = in HEAP { //~ ERROR use of unstable library feature
let _ = HEAP <- { //~ ERROR use of unstable library feature
::core::raw::Slice { //~ ERROR use of unstable library feature
data: &42, //~ ERROR use of unstable library feature
len: 1 //~ ERROR use of unstable library feature
Expand Down
22 changes: 22 additions & 0 deletions src/test/parse-fail/assoc-oddities-1.rs
@@ -0,0 +1,22 @@
// Copyright 2015 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.

// compile-flags: -Z parse-only

fn that_odd_parse() {
// following lines below parse and must not fail
x = if c { a } else { b }();
x <- if c { a } else { b }[n];
x = if true { 1 } else { 0 } as *mut _;
// however this does not parse and probably should fail to retain compat?
// NB: `..` here is arbitrary, failure happens/should happen ∀ops that aren’t `=` or `<-`
// see assoc-oddities-2 and assoc-oddities-3
..if c { a } else { b }[n]; //~ ERROR expected one of
}
16 changes: 16 additions & 0 deletions src/test/parse-fail/assoc-oddities-2.rs
@@ -0,0 +1,16 @@
// Copyright 2015 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.

// compile-flags: -Z parse-only

fn that_odd_parse() {
// see assoc-oddities-1 for explanation
x..if c { a } else { b }[n]; //~ ERROR expected one of
}
16 changes: 16 additions & 0 deletions src/test/parse-fail/assoc-oddities-3.rs
@@ -0,0 +1,16 @@
// Copyright 2015 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.

// compile-flags: -Z parse-only

fn that_odd_parse() {
// see assoc-oddities-1 for explanation
x + if c { a } else { b }[n]; //~ ERROR expected one of
}

0 comments on commit c1a238c

Please sign in to comment.