@@ -250,24 +250,40 @@ ClosureArgs: Vec<Ty> = {
250
250
"," <args:FnArgs> => args.to_tys(),
251
251
}
252
252
253
+ TraitItem: TraitItem = {
254
+ <assoc:AssocTyDefn> => TraitItem::Assoc(assoc),
255
+ <fndef:FnDefn> => TraitItem::FnDefn(fndef),
256
+ };
257
+
253
258
TraitDefn: TraitDefn = {
254
259
<auto:AutoKeyword?> <marker:MarkerKeyword?> <upstream:UpstreamKeyword?> <fundamental:FundamentalKeyword?> <non_enumerable:NonEnumerableKeyword?> <coinductive:CoinductiveKeyword?> <object_safe:ObjectSafeKeyword?> <well_known:WellKnownTrait?> "trait" <n:Id><p:Angle<VariableKind>>
255
- <w:QuantifiedWhereClauses> "{" <a:AssocTyDefn*> "}" => TraitDefn
256
- {
257
- name: n,
258
- variable_kinds: p,
259
- where_clauses: w,
260
- assoc_ty_defns: a,
261
- well_known,
262
- flags: TraitFlags {
263
- auto: auto.is_some(),
264
- marker: marker.is_some(),
265
- upstream: upstream.is_some(),
266
- fundamental: fundamental.is_some(),
267
- non_enumerable: non_enumerable.is_some(),
268
- coinductive: coinductive.is_some(),
269
- object_safe: object_safe.is_some(),
270
- },
260
+ <w:QuantifiedWhereClauses> "{" <t:TraitItem*> "}" => {
261
+ let mut assoc = vec![];
262
+ let mut fn_defs = vec![];
263
+ for item in t {
264
+ match item {
265
+ TraitItem::Assoc(v) => assoc.push(v),
266
+ TraitItem::FnDefn(v) => fn_defs.push(v),
267
+ }
268
+ }
269
+
270
+ TraitDefn {
271
+ name: n,
272
+ variable_kinds: p,
273
+ where_clauses: w,
274
+ assoc_ty_defns: assoc,
275
+ fn_defs,
276
+ well_known,
277
+ flags: TraitFlags {
278
+ auto: auto.is_some(),
279
+ marker: marker.is_some(),
280
+ upstream: upstream.is_some(),
281
+ fundamental: fundamental.is_some(),
282
+ non_enumerable: non_enumerable.is_some(),
283
+ coinductive: coinductive.is_some(),
284
+ object_safe: object_safe.is_some(),
285
+ },
286
+ }
271
287
}
272
288
};
273
289
@@ -337,13 +353,30 @@ QuantifiedInlineBound: QuantifiedInlineBound = {
337
353
},
338
354
};
339
355
356
+ ImplItem: ImplItem = {
357
+ <assoc:AssocTyValue> => ImplItem::Assoc(assoc),
358
+ <fndef:FnDefn> => ImplItem::FnDefn(fndef),
359
+ };
360
+
361
+
340
362
Impl: Impl = {
341
- <external:UpstreamKeyword?> "impl" <p:Angle<VariableKind>> <mark:"!"?> <t:Id> <a:Angle<GenericArg>> "for" <s:Ty>
342
- <w:QuantifiedWhereClauses> "{" <assoc:AssocTyValue*> "}" =>
363
+ <external:UpstreamKeyword?> "impl" <id:ImplId?> <p:Angle<VariableKind>>
364
+ <mark:"!"?> <t:Id> <a:Angle<GenericArg>> "for" <s:Ty>
365
+ <w:QuantifiedWhereClauses> "{" <items:ImplItem*> "}" =>
343
366
{
344
367
let mut args = vec![GenericArg::Ty(s)];
345
368
args.extend(a);
369
+ let mut assoc = vec![];
370
+ let mut fn_defs = vec![];
371
+ for item in items {
372
+ match item {
373
+ ImplItem::Assoc(v) => assoc.push(v),
374
+ ImplItem::FnDefn(v) => fn_defs.push(v),
375
+ }
376
+ }
377
+
346
378
Impl {
379
+ id,
347
380
variable_kinds: p,
348
381
polarity: Polarity::from_bool(mark.is_none()),
349
382
trait_ref: TraitRef {
@@ -352,6 +385,7 @@ Impl: Impl = {
352
385
},
353
386
where_clauses: w,
354
387
assoc_ty_values: assoc,
388
+ fn_defs,
355
389
impl_type: external.map(|_| ImplType::External).unwrap_or(ImplType::Local),
356
390
}
357
391
},
@@ -424,7 +458,8 @@ TyWithoutId: Ty = {
424
458
lifetime: l,
425
459
},
426
460
<n:Id> "<" <a:Comma<GenericArg>> ">" => Ty::Apply { name: n, args: a },
427
- <p:ProjectionTy> => Ty::Projection { proj: p },
461
+ <p:Projection> => Ty::Projection { proj: p },
462
+ <f:ImplFnRef> => Ty::ImplFn { func: f },
428
463
"(" <t:TupleOrParensInner> ")" => t,
429
464
"*" <m: RawMutability> <t:Ty> => Ty::Raw{ mutability: m, ty: Box::new(t) },
430
465
"&" <l: Lifetime> "mut" <t:Ty> => Ty::Ref{ mutability: Mutability::Mut, lifetime: l, ty: Box::new(t) },
@@ -462,7 +497,7 @@ FloatTy: FloatTy = {
462
497
ScalarType: ScalarType = {
463
498
<i:IntTy> => ScalarType::Int(i),
464
499
<u:UintTy> => ScalarType::Uint(u),
465
- <f:FloatTy> => ScalarType::Float(f),
500
+ <f:FloatTy> => ScalarType::Float(f),
466
501
"bool" => ScalarType::Bool,
467
502
"char" => ScalarType::Char,
468
503
};
@@ -506,8 +541,8 @@ GenericArg: GenericArg = {
506
541
ConstWithoutId => GenericArg::Const(<>),
507
542
};
508
543
509
- ProjectionTy: ProjectionTy = {
510
- "<" <t:TraitRef<"as">> ">" "::" <n:Id> <a:Angle<GenericArg>> => ProjectionTy {
544
+ Projection: Projection = {
545
+ "<" <t:TraitRef<"as">> ">" "::" <n:Id> <a:Angle<GenericArg>> => Projection {
511
546
trait_ref: t, name: n, args: a
512
547
},
513
548
};
@@ -571,7 +606,7 @@ WhereClause: WhereClause = {
571
606
let mut args = vec![GenericArg::Ty(s)];
572
607
if let Some(a) = a { args.extend(a); }
573
608
let trait_ref = TraitRef { trait_name: t, args: args };
574
- let projection = ProjectionTy { trait_ref, name, args: a2 };
609
+ let projection = Projection { trait_ref, name, args: a2 };
575
610
WhereClause::ProjectionEq { projection, ty }
576
611
},
577
612
@@ -615,7 +650,10 @@ DomainGoal: DomainGoal = {
615
650
"FromEnv" "(" <t:TraitRef<":">> ")" => DomainGoal::TraitRefFromEnv { trait_ref: t },
616
651
617
652
// `<T as Foo>::U -> Bar` -- a normalization
618
- "Normalize" "(" <s:ProjectionTy> "->" <t:Ty> ")" => DomainGoal::Normalize { projection: s, ty: t },
653
+ "Normalize" "(" <s:Projection> "->" <t:Ty> ")" => DomainGoal::Normalize { projection: s, ty: t },
654
+
655
+ // `<T as Foo>::some_func -> @SomeImpl::some_func` -- a normalization
656
+ "NormalizeFn" "(" <s:Projection> "->" <t:Ty> ")" => DomainGoal::NormalizeFn { projection: s, ty: t },
619
657
620
658
"IsLocal" "(" <ty:Ty> ")" => DomainGoal::IsLocal { ty },
621
659
"IsUpstream" "(" <ty:Ty> ")" => DomainGoal::IsUpstream { ty },
@@ -639,6 +677,15 @@ LeafGoal: LeafGoal = {
639
677
"Subtype" "(" <a:Ty> "," <b:Ty> ")" => LeafGoal::SubtypeGenericArgs { a, b },
640
678
};
641
679
680
+ // @ImplName::f<A, B>
681
+ ImplFnRef: ImplFnRef = {
682
+ <imp:ImplId> "::" <f:Id> <a:Angle<GenericArg>> => ImplFnRef {
683
+ impl_name: imp,
684
+ fn_name: f,
685
+ args: a,
686
+ },
687
+ }
688
+
642
689
TraitRef<S>: TraitRef = {
643
690
<s:Ty> S <t:Id> <a:Angle<GenericArg>> => {
644
691
let mut args = vec![GenericArg::Ty(s)];
@@ -698,4 +745,11 @@ LifetimeId: Identifier = {
698
745
}
699
746
};
700
747
748
+ ImplId: Identifier = {
749
+ <l:@L> "@" <s:r"([A-Za-z]|_)([A-Za-z0-9]|_)*"> <r:@R> => Identifier {
750
+ str: Atom::from(s),
751
+ span: Span::new(l, r),
752
+ }
753
+ };
754
+
701
755
ConstValue: u32 = <s:r"[0-9]+"> => u32::from_str_radix(s, 10).unwrap();
0 commit comments