Skip to content

Commit 04bcd11

Browse files
committed
Fix #20616
1 parent abf0548 commit 04bcd11

File tree

13 files changed

+511
-2
lines changed

13 files changed

+511
-2
lines changed

src/librustc_typeck/check/method/suggest.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -364,7 +364,7 @@ pub fn all_traits<'a>(ccx: &'a CrateCtxt) -> AllTraits<'a> {
364364
}
365365

366366
pub struct AllTraits<'a> {
367-
borrow: cell::Ref<'a Option<AllTraitsVec>>,
367+
borrow: cell::Ref<'a, Option<AllTraitsVec>>,
368368
idx: usize
369369
}
370370

src/libsyntax/parse/parser.rs

+36-1
Original file line numberDiff line numberDiff line change
@@ -896,7 +896,9 @@ impl<'a> Parser<'a> {
896896
pub fn bump(&mut self) -> PResult<()> {
897897
self.last_span = self.span;
898898
// Stash token for error recovery (sometimes; clone is not necessarily cheap).
899-
self.last_token = if self.token.is_ident() || self.token.is_path() {
899+
self.last_token = if self.token.is_ident() ||
900+
self.token.is_path() ||
901+
self.token == token::Comma {
900902
Some(box self.token.clone())
901903
} else {
902904
None
@@ -3796,8 +3798,41 @@ impl<'a> Parser<'a> {
37963798
fn parse_generic_values_after_lt(&mut self) -> PResult<(Vec<ast::Lifetime>,
37973799
Vec<P<Ty>>,
37983800
Vec<P<TypeBinding>>)> {
3801+
let span_lo = self.span.lo;
37993802
let lifetimes = try!(self.parse_lifetimes(token::Comma));
38003803

3804+
let missing_comma = !lifetimes.is_empty() &&
3805+
!self.token.is_like_gt() &&
3806+
self.last_token
3807+
.as_ref().map_or(true,
3808+
|x| &**x != &token::Comma);
3809+
3810+
if missing_comma {
3811+
3812+
let token_str = self.this_token_to_string();
3813+
let span_fatal = self.span;
3814+
let span_hi = self.span.hi;
3815+
let span_hi = if self.parse_ty_nopanic().is_ok() {
3816+
self.span.hi
3817+
} else {
3818+
span_hi
3819+
};
3820+
3821+
let mut lifetimes = lifetimes;
3822+
let lifetime = lifetimes.pop().unwrap();
3823+
3824+
let msg = format!("did you mean `{lifetime}, {tok}...` or \
3825+
`&{lifetime} {tok}...`?",
3826+
lifetime = lifetime.name.as_str(),
3827+
tok = token_str);
3828+
self.span_note(mk_sp(span_lo, span_hi), &msg);
3829+
3830+
let msg = format!("expected `,` or `>` after lifetime \
3831+
name, found `{}`",
3832+
token_str);
3833+
return Err(self.span_fatal(span_fatal, &msg))
3834+
}
3835+
38013836
// First parse types.
38023837
let (types, returned) = try!(self.parse_seq_to_gt_or_return(
38033838
Some(token::Comma),

src/libsyntax/parse/token.rs

+8
Original file line numberDiff line numberDiff line change
@@ -173,6 +173,14 @@ pub enum Token {
173173
}
174174

175175
impl Token {
176+
/// Returns `true` if the token starts with '>'
177+
pub fn is_like_gt(&self) -> bool {
178+
match *self {
179+
BinOp(Shr) | BinOpEq(Shr) | Gt | Ge => true,
180+
_ => false
181+
}
182+
}
183+
176184
/// Returns `true` if the token can appear at the start of an expression.
177185
pub fn can_begin_expr(&self) -> bool {
178186
match *self {
+46
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
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+
// We need all these 9 issue-20616-N.rs files
12+
// becase we can only catch one parsing error at a time
13+
14+
15+
16+
type Type_1_<'a, T> = &'a T;
17+
18+
19+
type Type_1<'a T> = &'a T; //~ error: expected `,` or `>` after lifetime name, found `T`
20+
21+
22+
//type Type_2 = Type_1_<'static ()>; // error: expected `,` or `>` after lifetime name, found `(`
23+
24+
25+
//type Type_3<T> = Box<T,,>; // error: expected type, found `,`
26+
27+
28+
//type Type_4<T> = Type_1_<'static,, T>; // error: expected type, found `,`
29+
30+
31+
type Type_5_<'a> = Type_1_<'a, ()>;
32+
33+
34+
//type Type_5<'a> = Type_1_<'a, (),,>; // error: expected type, found `,`
35+
36+
37+
//type Type_6 = Type_5_<'a,,>; // error: expected type, found `,`
38+
39+
40+
//type Type_7 = Box<(),,>; // error: expected type, found `,`
41+
42+
43+
//type Type_8<'a,,> = &'a (); // error: expected ident, found `,`
44+
45+
46+
//type Type_9<T,,> = Box<T>; // error: expected ident, found `,`
+46
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
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+
// We need all these 9 issue-20616-N.rs files
12+
// becase we can only catch one parsing error at a time
13+
14+
15+
16+
type Type_1_<'a, T> = &'a T;
17+
18+
19+
//type Type_1<'a T> = &'a T; // error: expected `,` or `>` after lifetime name, found `T`
20+
21+
22+
type Type_2 = Type_1_<'static ()>; //~ error: expected `,` or `>` after lifetime name, found `(`
23+
24+
25+
//type Type_3<T> = Box<T,,>; // error: expected type, found `,`
26+
27+
28+
//type Type_4<T> = Type_1_<'static,, T>; // error: expected type, found `,`
29+
30+
31+
type Type_5_<'a> = Type_1_<'a, ()>;
32+
33+
34+
//type Type_5<'a> = Type_1_<'a, (),,>; // error: expected type, found `,`
35+
36+
37+
//type Type_6 = Type_5_<'a,,>; // error: expected type, found `,`
38+
39+
40+
//type Type_7 = Box<(),,>; // error: expected type, found `,`
41+
42+
43+
//type Type_8<'a,,> = &'a (); // error: expected ident, found `,`
44+
45+
46+
//type Type_9<T,,> = Box<T>; // error: expected ident, found `,`
+46
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
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+
// We need all these 9 issue-20616-N.rs files
12+
// becase we can only catch one parsing error at a time
13+
14+
15+
16+
type Type_1_<'a, T> = &'a T;
17+
18+
19+
//type Type_1<'a T> = &'a T; // error: expected `,` or `>` after lifetime name, found `T`
20+
21+
22+
//type Type_2 = Type_1_<'static ()>; // error: expected `,` or `>` after lifetime name, found `(`
23+
24+
25+
type Type_3<T> = Box<T,,>; //~ error: expected type, found `,`
26+
27+
28+
//type Type_4<T> = Type_1_<'static,, T>; // error: expected type, found `,`
29+
30+
31+
type Type_5_<'a> = Type_1_<'a, ()>;
32+
33+
34+
//type Type_5<'a> = Type_1_<'a, (),,>; // error: expected type, found `,`
35+
36+
37+
//type Type_6 = Type_5_<'a,,>; // error: expected type, found `,`
38+
39+
40+
//type Type_7 = Box<(),,>; // error: expected type, found `,`
41+
42+
43+
//type Type_8<'a,,> = &'a (); // error: expected ident, found `,`
44+
45+
46+
//type Type_9<T,,> = Box<T>; // error: expected ident, found `,`
+46
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
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+
// We need all these 9 issue-20616-N.rs files
12+
// becase we can only catch one parsing error at a time
13+
14+
15+
16+
type Type_1_<'a, T> = &'a T;
17+
18+
19+
//type Type_1<'a T> = &'a T; // error: expected `,` or `>` after lifetime name, found `T`
20+
21+
22+
//type Type_2 = Type_1_<'static ()>; // error: expected `,` or `>` after lifetime name, found `(`
23+
24+
25+
//type Type_3<T> = Box<T,,>; // error: expected type, found `,`
26+
27+
28+
type Type_4<T> = Type_1_<'static,, T>; //~ error: expected type, found `,`
29+
30+
31+
type Type_5_<'a> = Type_1_<'a, ()>;
32+
33+
34+
//type Type_5<'a> = Type_1_<'a, (),,>; // error: expected type, found `,`
35+
36+
37+
//type Type_6 = Type_5_<'a,,>; // error: expected type, found `,`
38+
39+
40+
//type Type_7 = Box<(),,>; // error: expected type, found `,`
41+
42+
43+
//type Type_8<'a,,> = &'a (); // error: expected ident, found `,`
44+
45+
46+
//type Type_9<T,,> = Box<T>; // error: expected ident, found `,`
+46
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
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+
// We need all these 9 issue-20616-N.rs files
12+
// becase we can only catch one parsing error at a time
13+
14+
15+
16+
type Type_1_<'a, T> = &'a T;
17+
18+
19+
//type Type_1<'a T> = &'a T; // error: expected `,` or `>` after lifetime name, found `T`
20+
21+
22+
//type Type_2 = Type_1_<'static ()>; // error: expected `,` or `>` after lifetime name, found `(`
23+
24+
25+
//type Type_3<T> = Box<T,,>; // error: expected type, found `,`
26+
27+
28+
//type Type_4<T> = Type_1_<'static,, T>; // error: expected type, found `,`
29+
30+
31+
type Type_5_<'a> = Type_1_<'a, ()>;
32+
33+
34+
type Type_5<'a> = Type_1_<'a, (),,>; //~ error: expected type, found `,`
35+
36+
37+
//type Type_6 = Type_5_<'a,,>; // error: expected type, found `,`
38+
39+
40+
//type Type_7 = Box<(),,>; // error: expected type, found `,`
41+
42+
43+
//type Type_8<'a,,> = &'a (); // error: expected ident, found `,`
44+
45+
46+
//type Type_9<T,,> = Box<T>; // error: expected ident, found `,`
+46
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
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+
// We need all these 9 issue-20616-N.rs files
12+
// becase we can only catch one parsing error at a time
13+
14+
15+
16+
type Type_1_<'a, T> = &'a T;
17+
18+
19+
//type Type_1<'a T> = &'a T; // error: expected `,` or `>` after lifetime name, found `T`
20+
21+
22+
//type Type_2 = Type_1_<'static ()>; // error: expected `,` or `>` after lifetime name, found `(`
23+
24+
25+
//type Type_3<T> = Box<T,,>; // error: expected type, found `,`
26+
27+
28+
//type Type_4<T> = Type_1_<'static,, T>; // error: expected type, found `,`
29+
30+
31+
type Type_5_<'a> = Type_1_<'a, ()>;
32+
33+
34+
//type Type_5<'a> = Type_1_<'a, (),,>; // error: expected type, found `,`
35+
36+
37+
type Type_6 = Type_5_<'a,,>; //~ error: expected type, found `,`
38+
39+
40+
//type Type_7 = Box<(),,>; // error: expected type, found `,`
41+
42+
43+
//type Type_8<'a,,> = &'a (); // error: expected ident, found `,`
44+
45+
46+
//type Type_9<T,,> = Box<T>; // error: expected ident, found `,`

0 commit comments

Comments
 (0)