@@ -66,7 +66,15 @@ impl BoundKind {
6666#[ derive( Copy , Clone , Debug ) ]
6767pub enum FnKind < ' a > {
6868 /// E.g., `fn foo()`, `fn foo(&self)`, or `extern "Abi" fn foo()`.
69- Fn ( FnCtxt , & ' a Ident , & ' a FnSig , & ' a Visibility , & ' a Generics , & ' a Option < P < Block > > ) ,
69+ Fn (
70+ FnCtxt ,
71+ & ' a Ident ,
72+ & ' a FnSig ,
73+ & ' a Visibility ,
74+ & ' a Generics ,
75+ & ' a Option < P < FnContract > > ,
76+ & ' a Option < P < Block > > ,
77+ ) ,
7078
7179 /// E.g., `|x, y| body`.
7280 Closure ( & ' a ClosureBinder , & ' a Option < CoroutineKind > , & ' a FnDecl , & ' a Expr ) ,
@@ -75,7 +83,7 @@ pub enum FnKind<'a> {
7583impl < ' a > FnKind < ' a > {
7684 pub fn header ( & self ) -> Option < & ' a FnHeader > {
7785 match * self {
78- FnKind :: Fn ( _, _, sig, _, _, _) => Some ( & sig. header ) ,
86+ FnKind :: Fn ( _, _, sig, _, _, _, _ ) => Some ( & sig. header ) ,
7987 FnKind :: Closure ( ..) => None ,
8088 }
8189 }
@@ -89,7 +97,7 @@ impl<'a> FnKind<'a> {
8997
9098 pub fn decl ( & self ) -> & ' a FnDecl {
9199 match self {
92- FnKind :: Fn ( _, _, sig, _, _, _) => & sig. decl ,
100+ FnKind :: Fn ( _, _, sig, _, _, _, _ ) => & sig. decl ,
93101 FnKind :: Closure ( _, _, decl, _) => decl,
94102 }
95103 }
@@ -189,6 +197,9 @@ pub trait Visitor<'ast>: Sized {
189197 fn visit_closure_binder ( & mut self , b : & ' ast ClosureBinder ) -> Self :: Result {
190198 walk_closure_binder ( self , b)
191199 }
200+ fn visit_contract ( & mut self , c : & ' ast FnContract ) -> Self :: Result {
201+ walk_contract ( self , c)
202+ }
192203 fn visit_where_predicate ( & mut self , p : & ' ast WherePredicate ) -> Self :: Result {
193204 walk_where_predicate ( self , p)
194205 }
@@ -375,8 +386,8 @@ impl WalkItemKind for ItemKind {
375386 try_visit ! ( visitor. visit_ty( ty) ) ;
376387 visit_opt ! ( visitor, visit_expr, expr) ;
377388 }
378- ItemKind :: Fn ( box Fn { defaultness : _, generics, sig, body } ) => {
379- let kind = FnKind :: Fn ( FnCtxt :: Free , ident, sig, vis, generics, body) ;
389+ ItemKind :: Fn ( box Fn { defaultness : _, generics, sig, contract , body } ) => {
390+ let kind = FnKind :: Fn ( FnCtxt :: Free , ident, sig, vis, generics, contract , body) ;
380391 try_visit ! ( visitor. visit_fn( kind, span, id) ) ;
381392 }
382393 ItemKind :: Mod ( _unsafety, mod_kind) => match mod_kind {
@@ -708,8 +719,8 @@ impl WalkItemKind for ForeignItemKind {
708719 try_visit ! ( visitor. visit_ty( ty) ) ;
709720 visit_opt ! ( visitor, visit_expr, expr) ;
710721 }
711- ForeignItemKind :: Fn ( box Fn { defaultness : _, generics, sig, body } ) => {
712- let kind = FnKind :: Fn ( FnCtxt :: Foreign , ident, sig, vis, generics, body) ;
722+ ForeignItemKind :: Fn ( box Fn { defaultness : _, generics, sig, contract , body } ) => {
723+ let kind = FnKind :: Fn ( FnCtxt :: Foreign , ident, sig, vis, generics, contract , body) ;
713724 try_visit ! ( visitor. visit_fn( kind, span, id) ) ;
714725 }
715726 ForeignItemKind :: TyAlias ( box TyAlias {
@@ -793,6 +804,17 @@ pub fn walk_closure_binder<'a, V: Visitor<'a>>(
793804 V :: Result :: output ( )
794805}
795806
807+ pub fn walk_contract < ' a , V : Visitor < ' a > > ( visitor : & mut V , c : & ' a FnContract ) -> V :: Result {
808+ let FnContract { requires, ensures } = c;
809+ if let Some ( pred) = requires {
810+ visitor. visit_expr ( pred) ;
811+ }
812+ if let Some ( pred) = ensures {
813+ visitor. visit_expr ( pred) ;
814+ }
815+ V :: Result :: output ( )
816+ }
817+
796818pub fn walk_where_predicate < ' a , V : Visitor < ' a > > (
797819 visitor : & mut V ,
798820 predicate : & ' a WherePredicate ,
@@ -851,11 +873,20 @@ pub fn walk_fn_decl<'a, V: Visitor<'a>>(
851873
852874pub fn walk_fn < ' a , V : Visitor < ' a > > ( visitor : & mut V , kind : FnKind < ' a > ) -> V :: Result {
853875 match kind {
854- FnKind :: Fn ( _ctxt, _ident, FnSig { header, decl, span : _ } , _vis, generics, body) => {
876+ FnKind :: Fn (
877+ _ctxt,
878+ _ident,
879+ FnSig { header, decl, span : _ } ,
880+ _vis,
881+ generics,
882+ contract,
883+ body,
884+ ) => {
855885 // Identifier and visibility are visited as a part of the item.
856886 try_visit ! ( visitor. visit_fn_header( header) ) ;
857887 try_visit ! ( visitor. visit_generics( generics) ) ;
858888 try_visit ! ( visitor. visit_fn_decl( decl) ) ;
889+ visit_opt ! ( visitor, visit_contract, contract) ;
859890 visit_opt ! ( visitor, visit_block, body) ;
860891 }
861892 FnKind :: Closure ( binder, coroutine_kind, decl, body) => {
@@ -885,8 +916,9 @@ impl WalkItemKind for AssocItemKind {
885916 try_visit ! ( visitor. visit_ty( ty) ) ;
886917 visit_opt ! ( visitor, visit_expr, expr) ;
887918 }
888- AssocItemKind :: Fn ( box Fn { defaultness : _, generics, sig, body } ) => {
889- let kind = FnKind :: Fn ( FnCtxt :: Assoc ( ctxt) , ident, sig, vis, generics, body) ;
919+ AssocItemKind :: Fn ( box Fn { defaultness : _, generics, sig, contract, body } ) => {
920+ let kind =
921+ FnKind :: Fn ( FnCtxt :: Assoc ( ctxt) , ident, sig, vis, generics, contract, body) ;
890922 try_visit ! ( visitor. visit_fn( kind, span, id) ) ;
891923 }
892924 AssocItemKind :: Type ( box TyAlias {
0 commit comments