@@ -7,7 +7,6 @@ use std::fmt::Write;
7
7
use itertools:: { EitherOrBoth , Itertools } ;
8
8
9
9
use crate :: * ;
10
- use BindingMode :: * ;
11
10
12
11
#[ derive( Clone , PartialEq , Eq , Hash ) ]
13
12
pub struct TypingRule < ' a > {
@@ -124,15 +123,13 @@ pub fn compute_joint_rules<'a>(
124
123
125
124
/// Extra constraints to display as preconditions.
126
125
#[ 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 > {
130
127
/// 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 ,
132
129
/// Type variables that are known not to be references.
133
- pub non_ref_types : HashSet < & ' a str > ,
130
+ non_ref_types : HashSet < & ' a str > ,
134
131
/// What access the abstract expression has of the scrutinee.
135
- pub scrutinee_mutability : Option < Mutability > ,
132
+ scrutinee_mutability : Option < Mutability > ,
136
133
}
137
134
138
135
impl < ' a > Type < ' a > {
@@ -162,29 +159,6 @@ impl<'a> Expression<'a> {
162
159
_ => { }
163
160
} )
164
161
}
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
- }
188
162
}
189
163
190
164
/// Which type is shown in the sequent.
@@ -369,35 +343,48 @@ impl<'a> TypingRule<'a> {
369
343
use TypeOfInterest :: * ;
370
344
let abstract_expr = ExprKind :: ABSTRACT ;
371
345
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.
384
348
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.
385
353
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,
392
356
..
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
+ }
397
384
}
398
- _ => { }
399
385
}
400
386
387
+ let cstrs = self . collect_side_constraints ( ) ;
401
388
let mut postconditions = vec ! [ RenderablePredicate :: Pred ( self . postcondition) ] ;
402
389
match style {
403
390
Expression => {
@@ -416,7 +403,7 @@ impl<'a> TypingRule<'a> {
416
403
postconditions. push ( RenderablePredicate :: Mutability ( abstract_expr, mtbl) ) ;
417
404
}
418
405
Sequent {
419
- show_reference_state : false ,
406
+ show_scrut_access : false ,
420
407
..
421
408
} => return Err ( IncompatibleStyle ) ,
422
409
// We already print this information with the predicate.
0 commit comments