@@ -43,6 +43,16 @@ pub(super) enum RecoverQPath {
43
43
No ,
44
44
}
45
45
46
+ /// Signals whether parsing a type should recover `->`.
47
+ ///
48
+ /// More specifically, when parsing a function like:
49
+ /// ```rust
50
+ /// fn foo() => u8 { 0 }
51
+ /// fn bar(): u8 { 0 }
52
+ /// ```
53
+ /// The compiler will try to recover interpreting `foo() => u8` as `foo() -> u8` when calling
54
+ /// `parse_ty` with anything except `RecoverReturnSign::No`, and it will try to recover `bar(): u8`
55
+ /// as `bar() -> u8` when passing `RecoverReturnSign::Yes` to `parse_ty`
46
56
#[ derive( Copy , Clone , PartialEq ) ]
47
57
pub ( super ) enum RecoverReturnSign {
48
58
Yes ,
@@ -51,6 +61,10 @@ pub(super) enum RecoverReturnSign {
51
61
}
52
62
53
63
impl RecoverReturnSign {
64
+ /// [RecoverReturnSign::Yes] allows for recovering `fn foo() => u8` and `fn foo(): u8`,
65
+ /// [RecoverReturnSign::OnlyFatArrow] allows for recovering only `fn foo() => u8` (recovering
66
+ /// colons can cause problems when parsing where clauses), and
67
+ /// [RecoverReturnSign::No] doesn't allow for any recovery of the return type arrow
54
68
fn can_recover ( self , token : & TokenKind ) -> bool {
55
69
match self {
56
70
Self :: Yes => matches ! ( token, token:: FatArrow | token:: Colon ) ,
@@ -81,8 +95,8 @@ impl<'a> Parser<'a> {
81
95
pub fn parse_ty ( & mut self ) -> PResult < ' a , P < Ty > > {
82
96
self . parse_ty_common (
83
97
AllowPlus :: Yes ,
84
- RecoverQPath :: Yes ,
85
98
AllowCVariadic :: No ,
99
+ RecoverQPath :: Yes ,
86
100
RecoverReturnSign :: Yes ,
87
101
)
88
102
}
@@ -93,8 +107,8 @@ impl<'a> Parser<'a> {
93
107
pub ( super ) fn parse_ty_for_param ( & mut self ) -> PResult < ' a , P < Ty > > {
94
108
self . parse_ty_common (
95
109
AllowPlus :: Yes ,
96
- RecoverQPath :: Yes ,
97
110
AllowCVariadic :: Yes ,
111
+ RecoverQPath :: Yes ,
98
112
RecoverReturnSign :: Yes ,
99
113
)
100
114
}
@@ -108,8 +122,8 @@ impl<'a> Parser<'a> {
108
122
pub ( super ) fn parse_ty_no_plus ( & mut self ) -> PResult < ' a , P < Ty > > {
109
123
self . parse_ty_common (
110
124
AllowPlus :: No ,
111
- RecoverQPath :: Yes ,
112
125
AllowCVariadic :: No ,
126
+ RecoverQPath :: Yes ,
113
127
RecoverReturnSign :: Yes ,
114
128
)
115
129
}
@@ -118,8 +132,8 @@ impl<'a> Parser<'a> {
118
132
pub ( super ) fn parse_ty_for_where_clause ( & mut self ) -> PResult < ' a , P < Ty > > {
119
133
self . parse_ty_common (
120
134
AllowPlus :: Yes ,
121
- RecoverQPath :: Yes ,
122
135
AllowCVariadic :: Yes ,
136
+ RecoverQPath :: Yes ,
123
137
RecoverReturnSign :: OnlyFatArrow ,
124
138
)
125
139
}
@@ -135,8 +149,8 @@ impl<'a> Parser<'a> {
135
149
// FIXME(Centril): Can we unconditionally `allow_plus`?
136
150
let ty = self . parse_ty_common (
137
151
allow_plus,
138
- recover_qpath,
139
152
AllowCVariadic :: No ,
153
+ recover_qpath,
140
154
recover_return_sign,
141
155
) ?;
142
156
FnRetTy :: Ty ( ty)
@@ -154,8 +168,8 @@ impl<'a> Parser<'a> {
154
168
. emit ( ) ;
155
169
let ty = self . parse_ty_common (
156
170
allow_plus,
157
- recover_qpath,
158
171
AllowCVariadic :: No ,
172
+ recover_qpath,
159
173
recover_return_sign,
160
174
) ?;
161
175
FnRetTy :: Ty ( ty)
@@ -167,8 +181,8 @@ impl<'a> Parser<'a> {
167
181
fn parse_ty_common (
168
182
& mut self ,
169
183
allow_plus : AllowPlus ,
170
- recover_qpath : RecoverQPath ,
171
184
allow_c_variadic : AllowCVariadic ,
185
+ recover_qpath : RecoverQPath ,
172
186
recover_return_sign : RecoverReturnSign ,
173
187
) -> PResult < ' a , P < Ty > > {
174
188
let allow_qpath_recovery = recover_qpath == RecoverQPath :: Yes ;
0 commit comments