@@ -44,7 +44,7 @@ fn type_with_bounds_cond(p: &mut Parser, allow_bounds: bool) {
44
44
T ! [ & ] => ref_type ( p) ,
45
45
T ! [ _] => infer_type ( p) ,
46
46
T ! [ fn ] | T ! [ unsafe ] | T ! [ extern] => fn_ptr_type ( p) ,
47
- T ! [ for ] => for_type ( p) ,
47
+ T ! [ for ] => for_type ( p, allow_bounds ) ,
48
48
T ! [ impl ] => impl_trait_type ( p) ,
49
49
T ! [ dyn] => dyn_trait_type ( p) ,
50
50
// Some path types are not allowed to have bounds (no plus)
@@ -227,7 +227,7 @@ pub(super) fn for_binder(p: &mut Parser) {
227
227
// type A = for<'a> fn() -> ();
228
228
// type B = for<'a> unsafe extern "C" fn(&'a ()) -> ();
229
229
// type Obj = for<'a> PartialEq<&'a i32>;
230
- pub ( super ) fn for_type ( p : & mut Parser ) {
230
+ pub ( super ) fn for_type ( p : & mut Parser , allow_bounds : bool ) {
231
231
assert ! ( p. at( T ![ for ] ) ) ;
232
232
let m = p. start ( ) ;
233
233
for_binder ( p) ;
@@ -240,7 +240,13 @@ pub(super) fn for_type(p: &mut Parser) {
240
240
}
241
241
}
242
242
type_no_bounds ( p) ;
243
- m. complete ( p, FOR_TYPE ) ;
243
+ let completed = m. complete ( p, FOR_TYPE ) ;
244
+
245
+ // test no_dyn_trait_leading_for
246
+ // type A = for<'a> Test<'a> + Send;
247
+ if allow_bounds {
248
+ opt_type_bounds_as_dyn_trait_type ( p, completed) ;
249
+ }
244
250
}
245
251
246
252
// test impl_trait_type
@@ -290,7 +296,7 @@ fn path_or_macro_type_(p: &mut Parser, allow_bounds: bool) {
290
296
let path = m. complete ( p, kind) ;
291
297
292
298
if allow_bounds {
293
- opt_path_type_bounds_as_dyn_trait_type ( p, path) ;
299
+ opt_type_bounds_as_dyn_trait_type ( p, path) ;
294
300
}
295
301
}
296
302
@@ -304,19 +310,23 @@ pub(super) fn path_type_(p: &mut Parser, allow_bounds: bool) {
304
310
// fn foo() -> Box<dyn T + 'f> {}
305
311
let path = m. complete ( p, PATH_TYPE ) ;
306
312
if allow_bounds {
307
- opt_path_type_bounds_as_dyn_trait_type ( p, path) ;
313
+ opt_type_bounds_as_dyn_trait_type ( p, path) ;
308
314
}
309
315
}
310
316
311
- /// This turns a parsed PATH_TYPE optionally into a DYN_TRAIT_TYPE
317
+ /// This turns a parsed PATH_TYPE or FOR_TYPE optionally into a DYN_TRAIT_TYPE
312
318
/// with a TYPE_BOUND_LIST
313
- fn opt_path_type_bounds_as_dyn_trait_type ( p : & mut Parser , path_type_marker : CompletedMarker ) {
319
+ fn opt_type_bounds_as_dyn_trait_type ( p : & mut Parser , type_marker : CompletedMarker ) {
320
+ assert ! ( matches!(
321
+ type_marker. kind( ) ,
322
+ SyntaxKind :: PATH_TYPE | SyntaxKind :: FOR_TYPE | SyntaxKind :: MACRO_CALL
323
+ ) ) ;
314
324
if !p. at ( T ! [ +] ) {
315
325
return ;
316
326
}
317
327
318
328
// First create a TYPE_BOUND from the completed PATH_TYPE
319
- let m = path_type_marker . precede ( p) . complete ( p, TYPE_BOUND ) ;
329
+ let m = type_marker . precede ( p) . complete ( p, TYPE_BOUND ) ;
320
330
321
331
// Next setup a marker for the TYPE_BOUND_LIST
322
332
let m = m. precede ( p) ;
0 commit comments