Change:
I'm seeing an internal compiler error on the following input, found by : Affected versions: I tried nightly 2021-12-01 and stable 1.57 and they both show the same ICE. <details<summary<strongBacktrace</strong</summary<p</p</details<!-- TRIAGEBOTSTART --<!-- TRIAGEBOTASSIGNSTART --<!-- TRIAGEBOTASSIGNDATASTARTTRIAGEBOTASSIGNDATAEND --<!-- TRIAGEBOTASSIGNEND --<!-- TRIAGEBOTEND --
slightly simpler example not using attributes the name outside the parentheses and the name between the two colons can be arbitrary, the parentheses, underscore, and comma all appear to matter
I found a fix for this, but currently i am only emitting a suggestion for transforming the input into a struct: how do you guys think should i do a function suggestion? Should i just remove the parameter? Or should i remove the function suggestion altogether and just emit the struct suggestion? or something completely different? here is an example how the same diagnostic's output looks like for a more sane input:
I wouldn't give much thought to suggestions, as it's unlikely that a human will enter this input. So I would just remove the suggestions if they are most likely wrong. For example the struct suggestion is invalid code because structs cannot use as a field name (right?). And I'm not sure what kind of code would use two colons , it's most likely a weird typo, so a generic "unexpected token" error should be fine.
claim

Discussion:
snapshot.bump(); // `(` match snapshot.parse_struct_fields(path, false, token::Paren) { Ok((fields, ..)) if snapshot.eat(&token::CloseDelim(token::Paren)) => { <del> // We have are certain we have `Enum::Foo(a: 3, b: 4)`, suggest </del> <ins> // We are certain we have `Enum::Foo(a: 3, b: 4)`, suggest </ins> // `Enum::Foo { a: 3, b: 4 }` or `Enum::Foo(3, 4)`. *self = snapshot; let close_paren = self.prev_token.span; let span = lo.to(self.prev_token.span); <del> err.cancel(); self.struct_span_err( span, "invalid `struct` delimiters or `fn` call arguments", ) .multipart_suggestion( &format!("if `{}` is a struct, use braces as delimiters", name), vec![(open_paren, " { ".to_string()), (close_paren, " }".to_string())], Applicability::MaybeIncorrect, ) .multipart_suggestion( &format!("if `{}` is a function, use the arguments directly", name), fields .into_iter() .map(|field| (field.span.until(field.expr.span), String::new())) .collect(), Applicability::MaybeIncorrect, ) .emit(); </del> <ins> if !fields.is_empty() { err.cancel(); let mut err = self.struct_span_err( span, "invalid `struct` delimiters or `fn` call arguments", ); err.multipart_suggestion( &format!("if `{}` is a struct, use braces as delimiters", name), vec![ (open_paren, " { ".to_string()), (close_paren, " }".to_string()), ], Applicability::MaybeIncorrect, ); err.multipart_suggestion( &format!("if `{}` is a function, use the arguments directly", name), fields .into_iter() .map(|field| (field.span.until(field.expr.span), String::new())) .collect(), Applicability::MaybeIncorrect, ); err.emit(); } else { err.emit(); } </ins> return Some(self.mk_expr_err(span)); } Ok(_) => {}

<ins> fn main() { a(_:b:,) //~^ ERROR: expected identifier, found reserved identifier `_` //~| ERROR: expected type, found `,` //~| ERROR: expected type, found `,` } </ins>

<ins> error: expected identifier, found reserved identifier `_` --> $DIR/issue-91461.rs:2:7 | LL |     a(_:b:,) |       ^ expected identifier, found reserved identifier error: expected type, found `,` --> $DIR/issue-91461.rs:2:11 | LL |     a(_:b:,) |     -    -^ expected type |     |    | |     |    tried to parse a type due to this type ascription |     while parsing this struct | = note: `#![feature(type_ascription)]` lets you annotate an expression with a type: `<expr>: <type>` = note: see issue #23416 <https://github.com/rust-lang/rust/issues/23416> for more information error: expected type, found `,` --> $DIR/issue-91461.rs:2:11 | LL |     a(_:b:,) |          -^ expected type |          | |          tried to parse a type due to this type ascription | = note: `#![feature(type_ascription)]` lets you annotate an expression with a type: `<expr>: <type>` = note: see issue #23416 <https://github.com/rust-lang/rust/issues/23416> for more information error: aborting due to 3 previous errors </ins>