Skip to content

Commit

Permalink
Rollup merge of rust-lang#111531 - chenyukang:yukang-fix-111416-ice, …
Browse files Browse the repository at this point in the history
…r=compiler-errors

Fix ice caused by shorthand fields in NoFieldsForFnCall

Fixes rust-lang#111416
  • Loading branch information
matthiaskrgr authored May 15, 2023
2 parents 165914c + 83789b8 commit f259f56
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 0 deletions.
4 changes: 4 additions & 0 deletions compiler/rustc_parse/src/parser/expr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1180,6 +1180,10 @@ impl<'a> Parser<'a> {
self.restore_snapshot(snapshot);
let close_paren = self.prev_token.span;
let span = lo.to(close_paren);
// filter shorthand fields
let fields: Vec<_> =
fields.into_iter().filter(|field| !field.is_shorthand).collect();

if !fields.is_empty() &&
// `token.kind` should not be compared here.
// This is because the `snapshot.token.kind` is treated as the same as
Expand Down
3 changes: 3 additions & 0 deletions tests/ui/parser/issues/issue-111416.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
fn main() {
let my = monad_bind(mx, T: Try); //~ ERROR invalid `struct` delimiters or `fn` call arguments
}
18 changes: 18 additions & 0 deletions tests/ui/parser/issues/issue-111416.stderr
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
error: invalid `struct` delimiters or `fn` call arguments
--> $DIR/issue-111416.rs:2:14
|
LL | let my = monad_bind(mx, T: Try);
| ^^^^^^^^^^^^^^^^^^^^^^
|
help: if `monad_bind` is a struct, use braces as delimiters
|
LL | let my = monad_bind { mx, T: Try };
| ~ ~
help: if `monad_bind` is a function, use the arguments directly
|
LL - let my = monad_bind(mx, T: Try);
LL + let my = monad_bind(mx, Try);
|

error: aborting due to previous error

0 comments on commit f259f56

Please sign in to comment.