@@ -10,8 +10,8 @@ use formality_rust::grammar::minirust::{
10
10
ValueExpression ,
11
11
} ;
12
12
use formality_rust:: grammar:: FnBoundData ;
13
- use formality_types:: grammar:: { CrateId , FnId , RigidName } ;
14
- use formality_types:: grammar:: { Relation , Ty , TyData , VariantId , Wcs } ;
13
+ use formality_types:: grammar:: { CrateId , FnId } ;
14
+ use formality_types:: grammar:: { Relation , Ty , VariantId , Wcs } ;
15
15
16
16
use crate :: { Check , CrateItem } ;
17
17
use anyhow:: bail;
@@ -281,23 +281,11 @@ impl Check<'_> {
281
281
bail ! ( "Only Local is allowed as the root of FieldProjection" )
282
282
} ;
283
283
284
- // Check if the index is valid for the tuple.
285
- // FIXME: use let chain here?
286
-
287
284
let Some ( ty) = env. local_variables . get ( & local_id) else {
288
285
bail ! ( "The local id used in PlaceExpression::Field is invalid." )
289
286
} ;
290
287
291
- // Get the ADT type information.
292
- let TyData :: RigidTy ( rigid_ty) = ty. data ( ) else {
293
- bail ! ( "The type for field projection must be rigid ty" )
294
- } ;
295
-
296
- // FIXME: directly get the adt_id information from ty
297
-
298
- let RigidName :: AdtId ( ref adt_id) = rigid_ty. name else {
299
- bail ! ( "The type for field projection must be adt" )
300
- } ;
288
+ let adt_id = ty. get_adt_id ( ) . unwrap ( ) ;
301
289
302
290
let (
303
291
_,
@@ -312,6 +300,7 @@ impl Check<'_> {
312
300
bail ! ( "The local used for field projection must be struct." )
313
301
}
314
302
303
+ // Check if the index is valid for the tuple.
315
304
if field_projection. index >= fields. len ( ) {
316
305
bail ! ( "The field index used in PlaceExpression::Field is invalid." )
317
306
}
@@ -353,13 +342,13 @@ impl Check<'_> {
353
342
. unwrap ( ) ;
354
343
355
344
// Find the callee from current crate.
345
+ // FIXME: get the information from decl too
356
346
let callee = curr_crate. items . iter ( ) . find ( |item| {
357
347
match item {
358
348
CrateItem :: Fn ( fn_declared) => {
359
349
if fn_declared. id == * fn_id {
360
350
let fn_bound_data =
361
351
typeck_env. env . instantiate_universally ( & fn_declared. binder ) ;
362
- // FIXME: maybe we should store the information somewhere else, like in the value expression?
363
352
// Store the callee information in typeck_env, we will need this when type checking Terminator::Call.
364
353
typeck_env
365
354
. callee_input_tys
@@ -385,28 +374,25 @@ impl Check<'_> {
385
374
Ok ( constant. get_ty ( ) )
386
375
}
387
376
Struct ( value_expressions, ty) => {
388
- let mut struct_field_ty = Vec :: new ( ) ;
377
+ let adt_id = ty . get_adt_id ( ) . unwrap ( ) ;
389
378
390
379
// Check the validity of the struct.
391
- if let TyData :: RigidTy ( rigid_ty) = ty. data ( ) {
392
- if let RigidName :: AdtId ( adt_id) = & rigid_ty. name {
393
- let (
394
- _,
395
- AdtDeclBoundData {
396
- where_clause : _,
397
- variants,
398
- } ,
399
- ) = self . decls . adt_decl ( & adt_id) . binder . open ( ) ;
400
- let AdtDeclVariant { name, fields } = variants. last ( ) . unwrap ( ) ;
401
-
402
- if * name != VariantId :: for_struct ( ) {
403
- bail ! ( "This type used in ValueExpression::Struct should be a struct" )
404
- }
380
+ let (
381
+ _,
382
+ AdtDeclBoundData {
383
+ where_clause : _,
384
+ variants,
385
+ } ,
386
+ ) = self . decls . adt_decl ( & adt_id) . binder . open ( ) ;
387
+ let AdtDeclVariant { name, fields } = variants. last ( ) . unwrap ( ) ;
405
388
406
- struct_field_ty = fields . iter ( ) . map ( |field| field . ty . clone ( ) ) . collect ( ) ;
407
- }
389
+ if * name != VariantId :: for_struct ( ) {
390
+ bail ! ( "This type used in ValueExpression::Struct should be a struct" )
408
391
}
409
392
393
+ let struct_field_ty: Vec < Ty > =
394
+ fields. iter ( ) . map ( |field| field. ty . clone ( ) ) . collect ( ) ;
395
+
410
396
if value_expressions. len ( ) != struct_field_ty. len ( ) {
411
397
bail ! ( "The length of ValueExpression::Tuple does not match the type of the ADT declared" )
412
398
}
0 commit comments