@@ -7,7 +7,6 @@ use std::fmt::Write;
77use itertools:: { EitherOrBoth , Itertools } ;
88
99use crate :: * ;
10- use BindingMode :: * ;
1110
1211#[ derive( Clone , PartialEq , Eq , Hash ) ]
1312pub struct TypingRule < ' a > {
@@ -124,15 +123,13 @@ pub fn compute_joint_rules<'a>(
124123
125124/// Extra constraints to display as preconditions.
126125#[ derive( Default ) ]
127- pub struct SideConstraints < ' a > {
128- /// The binding mode of the abstract expression.
129- pub binding_mode : Option < BindingMode > ,
126+ struct SideConstraints < ' a > {
130127 /// Whether the abstract expression is known not to be a reference.
131- pub abstract_expr_is_not_ref : bool ,
128+ abstract_expr_is_not_ref : bool ,
132129 /// Type variables that are known not to be references.
133- pub non_ref_types : HashSet < & ' a str > ,
130+ non_ref_types : HashSet < & ' a str > ,
134131 /// What access the abstract expression has of the scrutinee.
135- pub scrutinee_mutability : Option < Mutability > ,
132+ scrutinee_mutability : Option < Mutability > ,
136133}
137134
138135impl < ' a > Type < ' a > {
@@ -162,29 +159,6 @@ impl<'a> Expression<'a> {
162159 _ => { }
163160 } )
164161 }
165-
166- /// Interprets the expression as a binding mode, or returns `None` if that doesn't make sense.
167- fn as_binding_mode ( & self ) -> Result < Option < BindingMode > , IncompatibleStyle > {
168- match self . kind {
169- ExprKind :: Abstract {
170- not_a_ref : false , ..
171- } => Ok ( None ) ,
172- ExprKind :: Abstract {
173- not_a_ref : true , ..
174- } => Ok ( Some ( ByMove ) ) ,
175- ExprKind :: Ref (
176- mtbl,
177- Expression {
178- kind :
179- ExprKind :: Abstract {
180- not_a_ref : false , ..
181- } ,
182- ..
183- } ,
184- ) => Ok ( Some ( ByRef ( mtbl) ) ) ,
185- _ => Err ( IncompatibleStyle ) ,
186- }
187- }
188162}
189163
190164/// Which type is shown in the sequent.
@@ -369,35 +343,48 @@ impl<'a> TypingRule<'a> {
369343 use TypeOfInterest :: * ;
370344 let abstract_expr = ExprKind :: ABSTRACT ;
371345
372- let mut cstrs = self . collect_side_constraints ( ) ;
373- if matches ! (
374- style,
375- Sequent {
376- ty: UserVisible ,
377- ..
378- }
379- ) {
380- // Interpret the expression as a binding mode if possible.
381- cstrs. binding_mode = self . postcondition . expr . as_binding_mode ( ) ?;
382- }
383-
346+ // Ensure the postcondition (the one that is branched on) has a shape compatible with the
347+ // selected style.
384348 match style {
349+ // This style can display all expressions.
350+ Expression => { }
351+ // In this style, only a few select expressions can be branched on (i.e. in the
352+ // postcondition). We error if the expression is not of an appropriate shape.
385353 Sequent {
386- show_reference_state : false ,
387- ..
388- } if cstrs. binding_mode . is_some ( ) => return Err ( IncompatibleStyle ) ,
389- Sequent {
390- ty : InMemory ,
391- show_reference_state : true ,
354+ ty : UserVisible ,
355+ show_reference_state,
392356 ..
393- } if self . postcondition . expr . binding_mode ( ) . is_err ( )
394- && matches ! ( self . postcondition. expr. ty, Type :: Ref ( ..) ) =>
395- {
396- return Err ( IncompatibleStyle )
357+ } => match self . postcondition . expr . kind {
358+ ExprKind :: Abstract {
359+ not_a_ref : false , ..
360+ } => { }
361+ ExprKind :: Abstract {
362+ not_a_ref : true , ..
363+ }
364+ | ExprKind :: Ref (
365+ _,
366+ crate :: Expression {
367+ kind :
368+ ExprKind :: Abstract {
369+ not_a_ref : false , ..
370+ } ,
371+ ..
372+ } ,
373+ ) if show_reference_state => { }
374+ _ => return Err ( IncompatibleStyle ) ,
375+ } ,
376+ // In this style, the binding mode must be known unless the rule doesn't depend on it
377+ // at all.
378+ Sequent { ty : InMemory , .. } => {
379+ if self . postcondition . expr . binding_mode ( ) . is_err ( )
380+ && matches ! ( self . postcondition. expr. ty, Type :: Ref ( ..) )
381+ {
382+ return Err ( IncompatibleStyle ) ;
383+ }
397384 }
398- _ => { }
399385 }
400386
387+ let cstrs = self . collect_side_constraints ( ) ;
401388 let mut postconditions = vec ! [ RenderablePredicate :: Pred ( self . postcondition) ] ;
402389 match style {
403390 Expression => {
@@ -416,7 +403,7 @@ impl<'a> TypingRule<'a> {
416403 postconditions. push ( RenderablePredicate :: Mutability ( abstract_expr, mtbl) ) ;
417404 }
418405 Sequent {
419- show_reference_state : false ,
406+ show_scrut_access : false ,
420407 ..
421408 } => return Err ( IncompatibleStyle ) ,
422409 // We already print this information with the predicate.
0 commit comments