Navigation Menu

Skip to content

Commit

Permalink
Fix #20616
Browse files Browse the repository at this point in the history
  • Loading branch information
bombless committed Apr 25, 2015
1 parent 9d439b4 commit 0ad48e4
Show file tree
Hide file tree
Showing 13 changed files with 507 additions and 2 deletions.
2 changes: 1 addition & 1 deletion src/librustc_typeck/check/method/suggest.rs
Expand Up @@ -364,7 +364,7 @@ pub fn all_traits<'a>(ccx: &'a CrateCtxt) -> AllTraits<'a> {
}

pub struct AllTraits<'a> {
borrow: cell::Ref<'a Option<AllTraitsVec>>,
borrow: cell::Ref<'a, Option<AllTraitsVec>>,
idx: usize
}

Expand Down
33 changes: 32 additions & 1 deletion src/libsyntax/parse/parser.rs
Expand Up @@ -902,7 +902,9 @@ impl<'a> Parser<'a> {
pub fn bump(&mut self) -> PResult<()> {
self.last_span = self.span;
// Stash token for error recovery (sometimes; clone is not necessarily cheap).
self.last_token = if self.token.is_ident() || self.token.is_path() {
self.last_token = if self.token.is_ident() ||
self.token.is_path() ||
self.token == token::Comma {
Some(Box::new(self.token.clone()))
} else {
None
Expand Down Expand Up @@ -3807,8 +3809,37 @@ impl<'a> Parser<'a> {
fn parse_generic_values_after_lt(&mut self) -> PResult<(Vec<ast::Lifetime>,
Vec<P<Ty>>,
Vec<P<TypeBinding>>)> {
let span_lo = self.span.lo;
let lifetimes = try!(self.parse_lifetimes(token::Comma));

let missing_comma = !lifetimes.is_empty() &&
!self.token.is_like_gt() &&
self.last_token
.as_ref().map_or(true,
|x| &**x != &token::Comma);

if missing_comma {

let msg = format!("expected `,` or `>` after lifetime \
name, found `{}`",
self.this_token_to_string());
self.span_err(self.span, &msg);

let span_hi = self.span.hi;
let span_hi = if self.parse_ty_nopanic().is_ok() {
self.span.hi
} else {
span_hi
};

let msg = format!("did you mean a single argument type &'a Type, \
or did you mean the comma-separated arguments \
'a, Type?");
self.span_note(mk_sp(span_lo, span_hi), &msg);

self.abort_if_errors()
}

// First parse types.
let (types, returned) = try!(self.parse_seq_to_gt_or_return(
Some(token::Comma),
Expand Down
8 changes: 8 additions & 0 deletions src/libsyntax/parse/token.rs
Expand Up @@ -173,6 +173,14 @@ pub enum Token {
}

impl Token {
/// Returns `true` if the token starts with '>'.
pub fn is_like_gt(&self) -> bool {
match *self {
BinOp(Shr) | BinOpEq(Shr) | Gt | Ge => true,
_ => false,
}
}

/// Returns `true` if the token can appear at the start of an expression.
pub fn can_begin_expr(&self) -> bool {
match *self {
Expand Down
46 changes: 46 additions & 0 deletions src/test/compile-fail/issue-20616-1.rs
@@ -0,0 +1,46 @@
// 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.

// We need all these 9 issue-20616-N.rs files
// becase we can only catch one parsing error at a time



type Type_1_<'a, T> = &'a T;


type Type_1<'a T> = &'a T; //~ error: expected `,` or `>` after lifetime name, found `T`


//type Type_2 = Type_1_<'static ()>; // error: expected `,` or `>` after lifetime name, found `(`


//type Type_3<T> = Box<T,,>; // error: expected type, found `,`


//type Type_4<T> = Type_1_<'static,, T>; // error: expected type, found `,`


type Type_5_<'a> = Type_1_<'a, ()>;


//type Type_5<'a> = Type_1_<'a, (),,>; // error: expected type, found `,`


//type Type_6 = Type_5_<'a,,>; // error: expected type, found `,`


//type Type_7 = Box<(),,>; // error: expected type, found `,`


//type Type_8<'a,,> = &'a (); // error: expected ident, found `,`


//type Type_9<T,,> = Box<T>; // error: expected ident, found `,`
46 changes: 46 additions & 0 deletions src/test/compile-fail/issue-20616-2.rs
@@ -0,0 +1,46 @@
// 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.

// We need all these 9 issue-20616-N.rs files
// becase we can only catch one parsing error at a time



type Type_1_<'a, T> = &'a T;


//type Type_1<'a T> = &'a T; // error: expected `,` or `>` after lifetime name, found `T`


type Type_2 = Type_1_<'static ()>; //~ error: expected `,` or `>` after lifetime name, found `(`


//type Type_3<T> = Box<T,,>; // error: expected type, found `,`


//type Type_4<T> = Type_1_<'static,, T>; // error: expected type, found `,`


type Type_5_<'a> = Type_1_<'a, ()>;


//type Type_5<'a> = Type_1_<'a, (),,>; // error: expected type, found `,`


//type Type_6 = Type_5_<'a,,>; // error: expected type, found `,`


//type Type_7 = Box<(),,>; // error: expected type, found `,`


//type Type_8<'a,,> = &'a (); // error: expected ident, found `,`


//type Type_9<T,,> = Box<T>; // error: expected ident, found `,`
46 changes: 46 additions & 0 deletions src/test/compile-fail/issue-20616-3.rs
@@ -0,0 +1,46 @@
// 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.

// We need all these 9 issue-20616-N.rs files
// becase we can only catch one parsing error at a time



type Type_1_<'a, T> = &'a T;


//type Type_1<'a T> = &'a T; // error: expected `,` or `>` after lifetime name, found `T`


//type Type_2 = Type_1_<'static ()>; // error: expected `,` or `>` after lifetime name, found `(`


type Type_3<T> = Box<T,,>; //~ error: expected type, found `,`


//type Type_4<T> = Type_1_<'static,, T>; // error: expected type, found `,`


type Type_5_<'a> = Type_1_<'a, ()>;


//type Type_5<'a> = Type_1_<'a, (),,>; // error: expected type, found `,`


//type Type_6 = Type_5_<'a,,>; // error: expected type, found `,`


//type Type_7 = Box<(),,>; // error: expected type, found `,`


//type Type_8<'a,,> = &'a (); // error: expected ident, found `,`


//type Type_9<T,,> = Box<T>; // error: expected ident, found `,`
46 changes: 46 additions & 0 deletions src/test/compile-fail/issue-20616-4.rs
@@ -0,0 +1,46 @@
// 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.

// We need all these 9 issue-20616-N.rs files
// becase we can only catch one parsing error at a time



type Type_1_<'a, T> = &'a T;


//type Type_1<'a T> = &'a T; // error: expected `,` or `>` after lifetime name, found `T`


//type Type_2 = Type_1_<'static ()>; // error: expected `,` or `>` after lifetime name, found `(`


//type Type_3<T> = Box<T,,>; // error: expected type, found `,`


type Type_4<T> = Type_1_<'static,, T>; //~ error: expected type, found `,`


type Type_5_<'a> = Type_1_<'a, ()>;


//type Type_5<'a> = Type_1_<'a, (),,>; // error: expected type, found `,`


//type Type_6 = Type_5_<'a,,>; // error: expected type, found `,`


//type Type_7 = Box<(),,>; // error: expected type, found `,`


//type Type_8<'a,,> = &'a (); // error: expected ident, found `,`


//type Type_9<T,,> = Box<T>; // error: expected ident, found `,`
46 changes: 46 additions & 0 deletions src/test/compile-fail/issue-20616-5.rs
@@ -0,0 +1,46 @@
// 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.

// We need all these 9 issue-20616-N.rs files
// becase we can only catch one parsing error at a time



type Type_1_<'a, T> = &'a T;


//type Type_1<'a T> = &'a T; // error: expected `,` or `>` after lifetime name, found `T`


//type Type_2 = Type_1_<'static ()>; // error: expected `,` or `>` after lifetime name, found `(`


//type Type_3<T> = Box<T,,>; // error: expected type, found `,`


//type Type_4<T> = Type_1_<'static,, T>; // error: expected type, found `,`


type Type_5_<'a> = Type_1_<'a, ()>;


type Type_5<'a> = Type_1_<'a, (),,>; //~ error: expected type, found `,`


//type Type_6 = Type_5_<'a,,>; // error: expected type, found `,`


//type Type_7 = Box<(),,>; // error: expected type, found `,`


//type Type_8<'a,,> = &'a (); // error: expected ident, found `,`


//type Type_9<T,,> = Box<T>; // error: expected ident, found `,`
46 changes: 46 additions & 0 deletions src/test/compile-fail/issue-20616-6.rs
@@ -0,0 +1,46 @@
// 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.

// We need all these 9 issue-20616-N.rs files
// becase we can only catch one parsing error at a time



type Type_1_<'a, T> = &'a T;


//type Type_1<'a T> = &'a T; // error: expected `,` or `>` after lifetime name, found `T`


//type Type_2 = Type_1_<'static ()>; // error: expected `,` or `>` after lifetime name, found `(`


//type Type_3<T> = Box<T,,>; // error: expected type, found `,`


//type Type_4<T> = Type_1_<'static,, T>; // error: expected type, found `,`


type Type_5_<'a> = Type_1_<'a, ()>;


//type Type_5<'a> = Type_1_<'a, (),,>; // error: expected type, found `,`


type Type_6 = Type_5_<'a,,>; //~ error: expected type, found `,`


//type Type_7 = Box<(),,>; // error: expected type, found `,`


//type Type_8<'a,,> = &'a (); // error: expected ident, found `,`


//type Type_9<T,,> = Box<T>; // error: expected ident, found `,`

0 comments on commit 0ad48e4

Please sign in to comment.