Skip to content

Commit 00c48d3

Browse files
committed
Auto merge of #24547 - bombless:comma, r=pnkfelix
Closes #20616 It breaks code such as <https://github.com/rust-lang/rust/blob/c64feb63418fd05bd6e5adc6f9ad763aa6a594b1/src/librustc_typeck/check/method/suggest.rs#L367>, so this is a [breaking-change], you have to add missing comma after the last lifetime arguement now.
2 parents 0d8309e + 0ad48e4 commit 00c48d3

File tree

13 files changed

+507
-2
lines changed

13 files changed

+507
-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

+32-1
Original file line numberDiff line numberDiff line change
@@ -902,7 +902,9 @@ impl<'a> Parser<'a> {
902902
pub fn bump(&mut self) -> PResult<()> {
903903
self.last_span = self.span;
904904
// Stash token for error recovery (sometimes; clone is not necessarily cheap).
905-
self.last_token = if self.token.is_ident() || self.token.is_path() {
905+
self.last_token = if self.token.is_ident() ||
906+
self.token.is_path() ||
907+
self.token == token::Comma {
906908
Some(Box::new(self.token.clone()))
907909
} else {
908910
None
@@ -3807,8 +3809,37 @@ impl<'a> Parser<'a> {
38073809
fn parse_generic_values_after_lt(&mut self) -> PResult<(Vec<ast::Lifetime>,
38083810
Vec<P<Ty>>,
38093811
Vec<P<TypeBinding>>)> {
3812+
let span_lo = self.span.lo;
38103813
let lifetimes = try!(self.parse_lifetimes(token::Comma));
38113814

3815+
let missing_comma = !lifetimes.is_empty() &&
3816+
!self.token.is_like_gt() &&
3817+
self.last_token
3818+
.as_ref().map_or(true,
3819+
|x| &**x != &token::Comma);
3820+
3821+
if missing_comma {
3822+
3823+
let msg = format!("expected `,` or `>` after lifetime \
3824+
name, found `{}`",
3825+
self.this_token_to_string());
3826+
self.span_err(self.span, &msg);
3827+
3828+
let span_hi = self.span.hi;
3829+
let span_hi = if self.parse_ty_nopanic().is_ok() {
3830+
self.span.hi
3831+
} else {
3832+
span_hi
3833+
};
3834+
3835+
let msg = format!("did you mean a single argument type &'a Type, \
3836+
or did you mean the comma-separated arguments \
3837+
'a, Type?");
3838+
self.span_note(mk_sp(span_lo, span_hi), &msg);
3839+
3840+
self.abort_if_errors()
3841+
}
3842+
38123843
// First parse types.
38133844
let (types, returned) = try!(self.parse_seq_to_gt_or_return(
38143845
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)