Skip to content

Commit

Permalink
Auto merge of rust-lang#13160 - ChayimFriedman2:parse-parenthesized-t…
Browse files Browse the repository at this point in the history
…ype-path-with-coloncolon, r=jonas-schievink

fix: Parse TypePathFn with preceding `::`

e.g. `impl Fn::() -> ()`.

Fixes rust-lang#13157. This was the problem, not that the path was not at the end.

I could unify the parsing of `::` of TypePathFn with that of generic arg list, but some code relies on the `::` of generic arg list to be inside it.
  • Loading branch information
bors committed Sep 1, 2022
2 parents f23114c + d786a40 commit 93c52e4
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 0 deletions.
5 changes: 5 additions & 0 deletions crates/parser/src/grammar/paths.rs
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,11 @@ fn opt_path_type_args(p: &mut Parser<'_>, mode: Mode) {
match mode {
Mode::Use => {}
Mode::Type => {
// test typepathfn_with_coloncolon
// type F = Start::(Middle) -> (Middle)::End;
if p.at(T![::]) && p.nth_at(2, T!['(']) {
p.bump(T![::]);
}
// test path_fn_trait_args
// type F = Box<Fn(i32) -> ()>;
if p.at(T!['(']) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
SOURCE_FILE
TYPE_ALIAS
TYPE_KW "type"
WHITESPACE " "
NAME
IDENT "F"
WHITESPACE " "
EQ "="
WHITESPACE " "
PATH_TYPE
PATH
PATH
PATH_SEGMENT
NAME_REF
IDENT "Start"
COLON2 "::"
PARAM_LIST
L_PAREN "("
PARAM
PATH_TYPE
PATH
PATH_SEGMENT
NAME_REF
IDENT "Middle"
R_PAREN ")"
WHITESPACE " "
RET_TYPE
THIN_ARROW "->"
WHITESPACE " "
PAREN_TYPE
L_PAREN "("
PATH_TYPE
PATH
PATH_SEGMENT
NAME_REF
IDENT "Middle"
R_PAREN ")"
COLON2 "::"
PATH_SEGMENT
NAME_REF
IDENT "End"
SEMICOLON ";"
WHITESPACE "\n"
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
type F = Start::(Middle) -> (Middle)::End;

0 comments on commit 93c52e4

Please sign in to comment.