@@ -333,7 +333,12 @@ pub(super) fn type_of(tcx: TyCtxt<'_>, def_id: DefId) -> Ty<'_> {
333
333
find_opaque_ty_constraints_for_tait ( tcx, def_id)
334
334
}
335
335
// Opaque types desugared from `impl Trait`.
336
- ItemKind :: OpaqueTy ( OpaqueTy { origin : hir:: OpaqueTyOrigin :: FnReturn ( owner) | hir:: OpaqueTyOrigin :: AsyncFn ( owner) , in_trait, .. } ) => {
336
+ ItemKind :: OpaqueTy ( OpaqueTy {
337
+ origin :
338
+ hir:: OpaqueTyOrigin :: FnReturn ( owner) | hir:: OpaqueTyOrigin :: AsyncFn ( owner) ,
339
+ in_trait,
340
+ ..
341
+ } ) => {
337
342
if in_trait {
338
343
span_bug ! ( item. span, "impl-trait in trait has no default" )
339
344
} else {
@@ -378,7 +383,9 @@ pub(super) fn type_of(tcx: TyCtxt<'_>, def_id: DefId) -> Ty<'_> {
378
383
379
384
Node :: Field ( field) => icx. to_ty ( field. ty ) ,
380
385
381
- Node :: Expr ( & Expr { kind : ExprKind :: Closure { ..} , .. } ) => tcx. typeck ( def_id) . node_type ( hir_id) ,
386
+ Node :: Expr ( & Expr { kind : ExprKind :: Closure { .. } , .. } ) => {
387
+ tcx. typeck ( def_id) . node_type ( hir_id)
388
+ }
382
389
383
390
Node :: AnonConst ( _) if let Some ( param) = tcx. opt_const_param_of ( def_id) => {
384
391
// We defer to `type_of` of the corresponding parameter
@@ -410,40 +417,42 @@ pub(super) fn type_of(tcx: TyCtxt<'_>, def_id: DefId) -> Ty<'_> {
410
417
| Node :: Item ( & Item { kind : ItemKind :: GlobalAsm ( asm) , .. } )
411
418
if asm. operands . iter ( ) . any ( |( op, _op_sp) | match op {
412
419
hir:: InlineAsmOperand :: Const { anon_const }
413
- | hir:: InlineAsmOperand :: SymFn { anon_const } => anon_const. hir_id == hir_id,
420
+ | hir:: InlineAsmOperand :: SymFn { anon_const } => {
421
+ anon_const. hir_id == hir_id
422
+ }
414
423
_ => false ,
415
424
} ) =>
416
425
{
417
426
tcx. typeck ( def_id) . node_type ( hir_id)
418
427
}
419
428
420
- Node :: Variant ( Variant { disr_expr : Some ( ref e) , .. } ) if e. hir_id == hir_id => tcx
421
- . adt_def ( tcx. hir ( ) . get_parent_item ( hir_id) )
422
- . repr ( )
423
- . discr_type ( )
424
- . to_ty ( tcx) ,
429
+ Node :: Variant ( Variant { disr_expr : Some ( ref e) , .. } ) if e. hir_id == hir_id => {
430
+ tcx. adt_def ( tcx. hir ( ) . get_parent_item ( hir_id) ) . repr ( ) . discr_type ( ) . to_ty ( tcx)
431
+ }
425
432
426
- Node :: TypeBinding ( binding @ & TypeBinding { hir_id : binding_id, .. } )
427
- if let Node :: TraitRef ( trait_ref) = tcx. hir ( ) . get (
428
- tcx. hir ( ) . get_parent_node ( binding_id)
429
- ) =>
433
+ Node :: TypeBinding ( binding @ & TypeBinding { hir_id : binding_id, .. } )
434
+ if let Node :: TraitRef ( trait_ref) =
435
+ tcx. hir ( ) . get ( tcx. hir ( ) . get_parent_node ( binding_id) ) =>
430
436
{
431
- let Some ( trait_def_id) = trait_ref. trait_def_id ( ) else {
437
+ let Some ( trait_def_id) = trait_ref. trait_def_id ( ) else {
432
438
return tcx. ty_error_with_message ( DUMMY_SP , "Could not find trait" ) ;
433
439
} ;
434
- let assoc_items = tcx. associated_items ( trait_def_id) ;
435
- let assoc_item = assoc_items. find_by_name_and_kind (
436
- tcx, binding. ident , ty:: AssocKind :: Const , def_id. to_def_id ( ) ,
437
- ) ;
438
- if let Some ( assoc_item) = assoc_item {
439
- tcx. type_of ( assoc_item. def_id )
440
- } else {
441
- // FIXME(associated_const_equality): add a useful error message here.
442
- tcx. ty_error_with_message (
443
- DUMMY_SP ,
444
- "Could not find associated const on trait" ,
445
- )
446
- }
440
+ let assoc_items = tcx. associated_items ( trait_def_id) ;
441
+ let assoc_item = assoc_items. find_by_name_and_kind (
442
+ tcx,
443
+ binding. ident ,
444
+ ty:: AssocKind :: Const ,
445
+ def_id. to_def_id ( ) ,
446
+ ) ;
447
+ if let Some ( assoc_item) = assoc_item {
448
+ tcx. type_of ( assoc_item. def_id )
449
+ } else {
450
+ // FIXME(associated_const_equality): add a useful error message here.
451
+ tcx. ty_error_with_message (
452
+ DUMMY_SP ,
453
+ "Could not find associated const on trait" ,
454
+ )
455
+ }
447
456
}
448
457
449
458
Node :: GenericParam ( & GenericParam {
@@ -452,8 +461,7 @@ pub(super) fn type_of(tcx: TyCtxt<'_>, def_id: DefId) -> Ty<'_> {
452
461
..
453
462
} ) if ct. hir_id == hir_id => tcx. type_of ( tcx. hir ( ) . local_def_id ( param_hir_id) ) ,
454
463
455
- x =>
456
- tcx. ty_error_with_message (
464
+ x => tcx. ty_error_with_message (
457
465
DUMMY_SP ,
458
466
& format ! ( "unexpected const parent in type_of(): {x:?}" ) ,
459
467
) ,
0 commit comments