@@ -198,13 +198,14 @@ impl<'a, 'tcx> MemCategorizationContext<'a, 'tcx> {
198198 }
199199
200200 /// Like `pat_ty`, but ignores implicit `&` patterns.
201+ #[ instrument( level = "debug" , skip( self ) , ret) ]
201202 fn pat_ty_unadjusted ( & self , pat : & hir:: Pat < ' _ > ) -> McResult < Ty < ' tcx > > {
202203 let base_ty = self . node_ty ( pat. hir_id ) ?;
203- debug ! ( "pat_ty(pat={:?}) base_ty={:?}" , pat , base_ty) ;
204+ trace ! ( ? base_ty) ;
204205
205206 // This code detects whether we are looking at a `ref x`,
206207 // and if so, figures out what the type *being borrowed* is.
207- let ret_ty = match pat. kind {
208+ match pat. kind {
208209 PatKind :: Binding ( ..) => {
209210 let bm = * self
210211 . typeck_results
@@ -217,21 +218,18 @@ impl<'a, 'tcx> MemCategorizationContext<'a, 'tcx> {
217218 // but what we want here is the type of the underlying value being borrowed.
218219 // So peel off one-level, turning the &T into T.
219220 match base_ty. builtin_deref ( false ) {
220- Some ( t) => t. ty ,
221+ Some ( t) => Ok ( t. ty ) ,
221222 None => {
222- debug ! ( "By-ref binding of non-derefable type {:?}" , base_ty ) ;
223- return Err ( ( ) ) ;
223+ debug ! ( "By-ref binding of non-derefable type" ) ;
224+ Err ( ( ) )
224225 }
225226 }
226227 } else {
227- base_ty
228+ Ok ( base_ty)
228229 }
229230 }
230- _ => base_ty,
231- } ;
232- debug ! ( "pat_ty(pat={:?}) ret_ty={:?}" , pat, ret_ty) ;
233-
234- Ok ( ret_ty)
231+ _ => Ok ( base_ty) ,
232+ }
235233 }
236234
237235 pub ( crate ) fn cat_expr ( & self , expr : & hir:: Expr < ' _ > ) -> McResult < PlaceWithHirId < ' tcx > > {
@@ -299,13 +297,11 @@ impl<'a, 'tcx> MemCategorizationContext<'a, 'tcx> {
299297 }
300298 }
301299
302- #[ instrument( level = "debug" , skip( self ) ) ]
300+ #[ instrument( level = "debug" , skip( self ) , ret ) ]
303301 pub ( crate ) fn cat_expr_unadjusted (
304302 & self ,
305303 expr : & hir:: Expr < ' _ > ,
306304 ) -> McResult < PlaceWithHirId < ' tcx > > {
307- debug ! ( "cat_expr: id={} expr={:?}" , expr. hir_id, expr) ;
308-
309305 let expr_ty = self . expr_ty ( expr) ?;
310306 match expr. kind {
311307 hir:: ExprKind :: Unary ( hir:: UnOp :: Deref , ref e_base) => {
@@ -319,7 +315,7 @@ impl<'a, 'tcx> MemCategorizationContext<'a, 'tcx> {
319315
320316 hir:: ExprKind :: Field ( ref base, _) => {
321317 let base = self . cat_expr ( base) ?;
322- debug ! ( "cat_expr(cat_field): id={} expr={:?} base={:?}" , expr . hir_id , expr , base) ;
318+ debug ! ( ? base) ;
323319
324320 let field_idx = self
325321 . typeck_results
@@ -389,7 +385,7 @@ impl<'a, 'tcx> MemCategorizationContext<'a, 'tcx> {
389385 }
390386 }
391387
392- #[ instrument( level = "debug" , skip( self , span) ) ]
388+ #[ instrument( level = "debug" , skip( self , span) , ret ) ]
393389 pub ( crate ) fn cat_res (
394390 & self ,
395391 hir_id : hir:: HirId ,
@@ -430,6 +426,7 @@ impl<'a, 'tcx> MemCategorizationContext<'a, 'tcx> {
430426 /// Note: the actual upvar access contains invisible derefs of closure
431427 /// environment and upvar reference as appropriate. Only regionck cares
432428 /// about these dereferences, so we let it compute them as needed.
429+ #[ instrument( level = "debug" , skip( self ) , ret) ]
433430 fn cat_upvar ( & self , hir_id : hir:: HirId , var_id : hir:: HirId ) -> McResult < PlaceWithHirId < ' tcx > > {
434431 let closure_expr_def_id = self . body_owner ;
435432
@@ -439,41 +436,44 @@ impl<'a, 'tcx> MemCategorizationContext<'a, 'tcx> {
439436 } ;
440437 let var_ty = self . node_ty ( var_id) ?;
441438
442- let ret = PlaceWithHirId :: new ( hir_id, var_ty, PlaceBase :: Upvar ( upvar_id) , Vec :: new ( ) ) ;
443-
444- debug ! ( "cat_upvar ret={:?}" , ret) ;
445- Ok ( ret)
439+ Ok ( PlaceWithHirId :: new ( hir_id, var_ty, PlaceBase :: Upvar ( upvar_id) , Vec :: new ( ) ) )
446440 }
447441
442+ #[ instrument( level = "debug" , skip( self ) , ret) ]
448443 pub ( crate ) fn cat_rvalue (
449444 & self ,
450445 hir_id : hir:: HirId ,
451446 span : Span ,
452447 expr_ty : Ty < ' tcx > ,
453448 ) -> PlaceWithHirId < ' tcx > {
454- debug ! ( "cat_rvalue hir_id={:?}, expr_ty={:?}, span={:?}" , hir_id, expr_ty, span) ;
455- let ret = PlaceWithHirId :: new ( hir_id, expr_ty, PlaceBase :: Rvalue , Vec :: new ( ) ) ;
456- debug ! ( "cat_rvalue ret={:?}" , ret) ;
457- ret
449+ PlaceWithHirId :: new ( hir_id, expr_ty, PlaceBase :: Rvalue , Vec :: new ( ) )
458450 }
459451
452+ #[ instrument( level = "debug" , skip( self , node) , ret) ]
460453 pub ( crate ) fn cat_projection < N : HirNode > (
461454 & self ,
462455 node : & N ,
463456 base_place : PlaceWithHirId < ' tcx > ,
464457 ty : Ty < ' tcx > ,
465458 kind : ProjectionKind ,
466459 ) -> PlaceWithHirId < ' tcx > {
460+ let place_ty = base_place. place . ty ( ) ;
467461 let mut projections = base_place. place . projections ;
462+
463+ let node_ty = self . typeck_results . node_type ( node. hir_id ( ) ) ;
464+ // Opaque types can't have field projections, but we can instead convert
465+ // the current place in-place (heh) to the hidden type, and then apply all
466+ // follow up projections on that.
467+ if node_ty != place_ty && place_ty. has_opaque_types ( ) {
468+ projections. push ( Projection { kind : ProjectionKind :: OpaqueCast , ty : node_ty } ) ;
469+ }
468470 projections. push ( Projection { kind, ty } ) ;
469- let ret = PlaceWithHirId :: new (
471+ PlaceWithHirId :: new (
470472 node. hir_id ( ) ,
471473 base_place. place . base_ty ,
472474 base_place. place . base ,
473475 projections,
474- ) ;
475- debug ! ( "cat_field ret {:?}" , ret) ;
476- ret
476+ )
477477 }
478478
479479 #[ instrument( level = "debug" , skip( self ) ) ]
@@ -497,7 +497,7 @@ impl<'a, 'tcx> MemCategorizationContext<'a, 'tcx> {
497497 self . cat_deref ( expr, base)
498498 }
499499
500- #[ instrument( level = "debug" , skip( self , node) ) ]
500+ #[ instrument( level = "debug" , skip( self , node) , ret ) ]
501501 fn cat_deref (
502502 & self ,
503503 node : & impl HirNode ,
@@ -514,14 +514,12 @@ impl<'a, 'tcx> MemCategorizationContext<'a, 'tcx> {
514514 let mut projections = base_place. place . projections ;
515515 projections. push ( Projection { kind : ProjectionKind :: Deref , ty : deref_ty } ) ;
516516
517- let ret = PlaceWithHirId :: new (
517+ Ok ( PlaceWithHirId :: new (
518518 node. hir_id ( ) ,
519519 base_place. place . base_ty ,
520520 base_place. place . base ,
521521 projections,
522- ) ;
523- debug ! ( "cat_deref ret {:?}" , ret) ;
524- Ok ( ret)
522+ ) )
525523 }
526524
527525 pub ( crate ) fn cat_pattern < F > (
@@ -603,6 +601,13 @@ impl<'a, 'tcx> MemCategorizationContext<'a, 'tcx> {
603601 }
604602 }
605603
604+ /// Here, `place` is the `PlaceWithHirId` being matched and pat is the pattern it
605+ /// is being matched against.
606+ ///
607+ /// In general, the way that this works is that we walk down the pattern,
608+ /// constructing a `PlaceWithHirId` that represents the path that will be taken
609+ /// to reach the value being matched.
610+ #[ instrument( skip( self , op) , ret, level = "debug" ) ]
606611 fn cat_pattern_ < F > (
607612 & self ,
608613 mut place_with_id : PlaceWithHirId < ' tcx > ,
@@ -612,15 +617,6 @@ impl<'a, 'tcx> MemCategorizationContext<'a, 'tcx> {
612617 where
613618 F : FnMut ( & PlaceWithHirId < ' tcx > , & hir:: Pat < ' _ > ) ,
614619 {
615- // Here, `place` is the `PlaceWithHirId` being matched and pat is the pattern it
616- // is being matched against.
617- //
618- // In general, the way that this works is that we walk down the pattern,
619- // constructing a `PlaceWithHirId` that represents the path that will be taken
620- // to reach the value being matched.
621-
622- debug ! ( "cat_pattern(pat={:?}, place_with_id={:?})" , pat, place_with_id) ;
623-
624620 // If (pattern) adjustments are active for this pattern, adjust the `PlaceWithHirId` correspondingly.
625621 // `PlaceWithHirId`s are constructed differently from patterns. For example, in
626622 //
@@ -654,11 +650,11 @@ impl<'a, 'tcx> MemCategorizationContext<'a, 'tcx> {
654650 // `deref { deref { place_foo }}` instead of `place_foo` since the pattern is now `Some(x,)`
655651 // and not `&&Some(x,)`, even though its assigned type is that of `&&Some(x,)`.
656652 for _ in 0 ..self . typeck_results . pat_adjustments ( ) . get ( pat. hir_id ) . map_or ( 0 , |v| v. len ( ) ) {
657- debug ! ( "cat_pattern: applying adjustment to place_with_id={:?}" , place_with_id) ;
653+ debug ! ( "applying adjustment to place_with_id={:?}" , place_with_id) ;
658654 place_with_id = self . cat_deref ( pat, place_with_id) ?;
659655 }
660656 let place_with_id = place_with_id; // lose mutability
661- debug ! ( "cat_pattern: applied adjustment derefs to get place_with_id={:?}" , place_with_id) ;
657+ debug ! ( "applied adjustment derefs to get place_with_id={:?}" , place_with_id) ;
662658
663659 // Invoke the callback, but only now, after the `place_with_id` has adjusted.
664660 //
0 commit comments