Skip to content

Commit 157c67b

Browse files
committed
Handle , to ; substitution in arg params
1 parent 6874bd2 commit 157c67b

File tree

4 files changed

+36
-7
lines changed

4 files changed

+36
-7
lines changed

compiler/rustc_parse/src/parser/path.rs

+17
Original file line numberDiff line numberDiff line change
@@ -478,6 +478,23 @@ impl<'a> Parser<'a> {
478478
while let Some(arg) = self.parse_angle_arg(ty_generics)? {
479479
args.push(arg);
480480
if !self.eat(&token::Comma) {
481+
if self.token.kind == token::Semi
482+
&& self.look_ahead(1, |t| t.is_ident() || t.is_lifetime())
483+
{
484+
// Add `>` to the list of expected tokens.
485+
self.check(&token::Gt);
486+
// Handle `,` to `;` substitution
487+
let mut err = self.unexpected::<()>().unwrap_err();
488+
self.bump();
489+
err.span_suggestion_verbose(
490+
self.prev_token.span.until(self.token.span),
491+
"use a comma to separate type parameters",
492+
", ".to_string(),
493+
Applicability::MachineApplicable,
494+
);
495+
err.emit();
496+
continue;
497+
}
481498
if !self.token.kind.should_end_const_arg() {
482499
if self.handle_ambiguous_unbraced_const_arg(&mut args)? {
483500
// We've managed to (partially) recover, so continue trying to parse
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
// run-rustfix
2+
#![allow(unused)]
3+
struct Foo<'a, 'b> {
4+
a: &'a &'b i32
5+
}
6+
7+
fn foo<'a, 'b>(_x: &mut Foo<'a, 'b>) {}
8+
//~^ ERROR expected one of `,`, `:`, `=`, or `>`, found `;`
9+
10+
fn main() {}
+3-1
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
1+
// run-rustfix
2+
#![allow(unused)]
13
struct Foo<'a, 'b> {
24
a: &'a &'b i32
35
}
46

5-
fn foo<'a, 'b>(x: &mut Foo<'a; 'b>) {}
7+
fn foo<'a, 'b>(_x: &mut Foo<'a; 'b>) {}
68
//~^ ERROR expected one of `,`, `:`, `=`, or `>`, found `;`
79

810
fn main() {}
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
error: expected one of `,`, `:`, `=`, or `>`, found `;`
2-
--> $DIR/lifetime-semicolon.rs:5:30
2+
--> $DIR/lifetime-semicolon.rs:7:31
33
|
4-
LL | fn foo<'a, 'b>(x: &mut Foo<'a; 'b>) {}
5-
| ^ expected one of `,`, `:`, `=`, or `>`
4+
LL | fn foo<'a, 'b>(_x: &mut Foo<'a; 'b>) {}
5+
| ^ expected one of `,`, `:`, `=`, or `>`
66
|
7-
help: you might have meant to end the type parameters here
7+
help: use a comma to separate type parameters
88
|
9-
LL | fn foo<'a, 'b>(x: &mut Foo<'a>; 'b>) {}
10-
| +
9+
LL | fn foo<'a, 'b>(_x: &mut Foo<'a, 'b>) {}
10+
| ~
1111

1212
error: aborting due to previous error
1313

0 commit comments

Comments
 (0)