@@ -21,10 +21,9 @@ use rustc_middle::{bug, span_bug};
2121use rustc_span:: { Span , sym} ;
2222use tracing:: { debug, info, instrument, trace} ;
2323
24- use crate :: thir:: cx:: Cx ;
25- use crate :: thir:: util:: UserAnnotatedTyHelpers ;
24+ use crate :: thir:: cx:: ThirBuildCx ;
2625
27- impl < ' tcx > Cx < ' tcx > {
26+ impl < ' tcx > ThirBuildCx < ' tcx > {
2827 /// Create a THIR expression for the given HIR expression. This expands all
2928 /// adjustments and directly adds the type information from the
3029 /// `typeck_results`. See the [dev-guide] for more details.
@@ -142,9 +141,9 @@ impl<'tcx> Cx<'tcx> {
142141 Adjust :: Deref ( Some ( deref) ) => {
143142 // We don't need to do call adjust_span here since
144143 // deref coercions always start with a built-in deref.
145- let call_def_id = deref. method_call ( self . tcx ( ) ) ;
144+ let call_def_id = deref. method_call ( self . tcx ) ;
146145 let overloaded_callee =
147- Ty :: new_fn_def ( self . tcx ( ) , call_def_id, self . tcx ( ) . mk_args ( & [ expr. ty . into ( ) ] ) ) ;
146+ Ty :: new_fn_def ( self . tcx , call_def_id, self . tcx . mk_args ( & [ expr. ty . into ( ) ] ) ) ;
148147
149148 expr = Expr {
150149 temp_lifetime,
@@ -253,10 +252,10 @@ impl<'tcx> Cx<'tcx> {
253252
254253 // Check to see if this cast is a "coercion cast", where the cast is actually done
255254 // using a coercion (or is a no-op).
256- if self . typeck_results ( ) . is_coercion_cast ( source. hir_id ) {
255+ if self . typeck_results . is_coercion_cast ( source. hir_id ) {
257256 // Convert the lexpr to a vexpr.
258257 ExprKind :: Use { source : self . mirror_expr ( source) }
259- } else if self . typeck_results ( ) . expr_ty ( source) . is_ref ( ) {
258+ } else if self . typeck_results . expr_ty ( source) . is_ref ( ) {
260259 // Special cased so that we can type check that the element
261260 // type of the source matches the pointed to type of the
262261 // destination.
@@ -266,8 +265,8 @@ impl<'tcx> Cx<'tcx> {
266265 is_from_as_cast : true ,
267266 }
268267 } else if let hir:: ExprKind :: Path ( ref qpath) = source. kind
269- && let res = self . typeck_results ( ) . qpath_res ( qpath, source. hir_id )
270- && let ty = self . typeck_results ( ) . node_type ( source. hir_id )
268+ && let res = self . typeck_results . qpath_res ( qpath, source. hir_id )
269+ && let ty = self . typeck_results . node_type ( source. hir_id )
271270 && let ty:: Adt ( adt_def, args) = ty. kind ( )
272271 && let Res :: Def ( DefKind :: Ctor ( CtorOf :: Variant , CtorKind :: Const ) , variant_ctor_id) = res
273272 {
@@ -330,7 +329,7 @@ impl<'tcx> Cx<'tcx> {
330329 #[ instrument( level = "debug" , skip( self ) , ret) ]
331330 fn make_mirror_unadjusted ( & mut self , expr : & ' tcx hir:: Expr < ' tcx > ) -> Expr < ' tcx > {
332331 let tcx = self . tcx ;
333- let expr_ty = self . typeck_results ( ) . expr_ty ( expr) ;
332+ let expr_ty = self . typeck_results . expr_ty ( expr) ;
334333 let ( temp_lifetime, backwards_incompatible) =
335334 self . rvalue_scopes . temporary_scope ( self . region_scope_tree , expr. hir_id . local_id ) ;
336335
@@ -354,7 +353,7 @@ impl<'tcx> Cx<'tcx> {
354353 }
355354
356355 hir:: ExprKind :: Call ( fun, ref args) => {
357- if self . typeck_results ( ) . is_method_call ( expr) {
356+ if self . typeck_results . is_method_call ( expr) {
358357 // The callee is something implementing Fn, FnMut, or FnOnce.
359358 // Find the actual method implementation being called and
360359 // build the appropriate UFCS call expression with the
@@ -364,7 +363,7 @@ impl<'tcx> Cx<'tcx> {
364363
365364 let method = self . method_callee ( expr, fun. span , None ) ;
366365
367- let arg_tys = args. iter ( ) . map ( |e| self . typeck_results ( ) . expr_ty_adjusted ( e) ) ;
366+ let arg_tys = args. iter ( ) . map ( |e| self . typeck_results . expr_ty_adjusted ( e) ) ;
368367 let tupled_args = Expr {
369368 ty : Ty :: new_tup_from_iter ( tcx, arg_tys) ,
370369 temp_lifetime : TempLifetime { temp_lifetime, backwards_incompatible } ,
@@ -380,7 +379,7 @@ impl<'tcx> Cx<'tcx> {
380379 from_hir_call : true ,
381380 fn_span : expr. span ,
382381 }
383- } else if let ty:: FnDef ( def_id, _) = self . typeck_results ( ) . expr_ty ( fun) . kind ( )
382+ } else if let ty:: FnDef ( def_id, _) = self . typeck_results . expr_ty ( fun) . kind ( )
384383 && let Some ( intrinsic) = self . tcx . intrinsic ( def_id)
385384 && intrinsic. name == sym:: box_new
386385 {
@@ -413,7 +412,7 @@ impl<'tcx> Cx<'tcx> {
413412 } ,
414413 hir:: QPath :: TypeRelative ( _ty, _) => {
415414 if let Some ( ( DefKind :: Ctor ( _, CtorKind :: Fn ) , ctor_id) ) =
416- self . typeck_results ( ) . type_dependent_def ( fun. hir_id )
415+ self . typeck_results . type_dependent_def ( fun. hir_id )
417416 {
418417 Some ( ( adt_def, adt_def. variant_index_with_ctor_id ( ctor_id) ) )
419418 } else {
@@ -426,8 +425,8 @@ impl<'tcx> Cx<'tcx> {
426425 None
427426 } ;
428427 if let Some ( ( adt_def, index) ) = adt_data {
429- let node_args = self . typeck_results ( ) . node_args ( fun. hir_id ) ;
430- let user_provided_types = self . typeck_results ( ) . user_provided_types ( ) ;
428+ let node_args = self . typeck_results . node_args ( fun. hir_id ) ;
429+ let user_provided_types = self . typeck_results . user_provided_types ( ) ;
431430 let user_ty =
432431 user_provided_types. get ( fun. hir_id ) . copied ( ) . map ( |mut u_ty| {
433432 if let ty:: UserTypeKind :: TypeOf ( ref mut did, _) =
@@ -457,7 +456,7 @@ impl<'tcx> Cx<'tcx> {
457456 } ) )
458457 } else {
459458 ExprKind :: Call {
460- ty : self . typeck_results ( ) . node_type ( fun. hir_id ) ,
459+ ty : self . typeck_results . node_type ( fun. hir_id ) ,
461460 fun : self . mirror_expr ( fun) ,
462461 args : self . mirror_exprs ( args) ,
463462 from_hir_call : true ,
@@ -482,7 +481,7 @@ impl<'tcx> Cx<'tcx> {
482481 }
483482
484483 hir:: ExprKind :: AssignOp ( op, lhs, rhs) => {
485- if self . typeck_results ( ) . is_method_call ( expr) {
484+ if self . typeck_results . is_method_call ( expr) {
486485 let lhs = self . mirror_expr ( lhs) ;
487486 let rhs = self . mirror_expr ( rhs) ;
488487 self . overloaded_operator ( expr, Box :: new ( [ lhs, rhs] ) )
@@ -498,7 +497,7 @@ impl<'tcx> Cx<'tcx> {
498497 hir:: ExprKind :: Lit ( lit) => ExprKind :: Literal { lit, neg : false } ,
499498
500499 hir:: ExprKind :: Binary ( op, lhs, rhs) => {
501- if self . typeck_results ( ) . is_method_call ( expr) {
500+ if self . typeck_results . is_method_call ( expr) {
502501 let lhs = self . mirror_expr ( lhs) ;
503502 let rhs = self . mirror_expr ( rhs) ;
504503 self . overloaded_operator ( expr, Box :: new ( [ lhs, rhs] ) )
@@ -527,7 +526,7 @@ impl<'tcx> Cx<'tcx> {
527526 }
528527
529528 hir:: ExprKind :: Index ( lhs, index, brackets_span) => {
530- if self . typeck_results ( ) . is_method_call ( expr) {
529+ if self . typeck_results . is_method_call ( expr) {
531530 let lhs = self . mirror_expr ( lhs) ;
532531 let index = self . mirror_expr ( index) ;
533532 self . overloaded_place (
@@ -543,7 +542,7 @@ impl<'tcx> Cx<'tcx> {
543542 }
544543
545544 hir:: ExprKind :: Unary ( hir:: UnOp :: Deref , arg) => {
546- if self . typeck_results ( ) . is_method_call ( expr) {
545+ if self . typeck_results . is_method_call ( expr) {
547546 let arg = self . mirror_expr ( arg) ;
548547 self . overloaded_place ( expr, expr_ty, None , Box :: new ( [ arg] ) , expr. span )
549548 } else {
@@ -552,7 +551,7 @@ impl<'tcx> Cx<'tcx> {
552551 }
553552
554553 hir:: ExprKind :: Unary ( hir:: UnOp :: Not , arg) => {
555- if self . typeck_results ( ) . is_method_call ( expr) {
554+ if self . typeck_results . is_method_call ( expr) {
556555 let arg = self . mirror_expr ( arg) ;
557556 self . overloaded_operator ( expr, Box :: new ( [ arg] ) )
558557 } else {
@@ -561,7 +560,7 @@ impl<'tcx> Cx<'tcx> {
561560 }
562561
563562 hir:: ExprKind :: Unary ( hir:: UnOp :: Neg , arg) => {
564- if self . typeck_results ( ) . is_method_call ( expr) {
563+ if self . typeck_results . is_method_call ( expr) {
565564 let arg = self . mirror_expr ( arg) ;
566565 self . overloaded_operator ( expr, Box :: new ( [ arg] ) )
567566 } else if let hir:: ExprKind :: Lit ( lit) = arg. kind {
@@ -574,7 +573,7 @@ impl<'tcx> Cx<'tcx> {
574573 hir:: ExprKind :: Struct ( qpath, fields, ref base) => match expr_ty. kind ( ) {
575574 ty:: Adt ( adt, args) => match adt. adt_kind ( ) {
576575 AdtKind :: Struct | AdtKind :: Union => {
577- let user_provided_types = self . typeck_results ( ) . user_provided_types ( ) ;
576+ let user_provided_types = self . typeck_results . user_provided_types ( ) ;
578577 let user_ty = user_provided_types. get ( expr. hir_id ) . copied ( ) . map ( Box :: new) ;
579578 debug ! ( "make_mirror_unadjusted: (struct/union) user_ty={:?}" , user_ty) ;
580579 ExprKind :: Adt ( Box :: new ( AdtExpr {
@@ -586,15 +585,14 @@ impl<'tcx> Cx<'tcx> {
586585 base : match base {
587586 hir:: StructTailExpr :: Base ( base) => AdtExprBase :: Base ( FruInfo {
588587 base : self . mirror_expr ( base) ,
589- field_types : self . typeck_results ( ) . fru_field_types ( )
590- [ expr. hir_id ]
588+ field_types : self . typeck_results . fru_field_types ( ) [ expr. hir_id ]
591589 . iter ( )
592590 . copied ( )
593591 . collect ( ) ,
594592 } ) ,
595593 hir:: StructTailExpr :: DefaultFields ( _) => {
596594 AdtExprBase :: DefaultFields (
597- self . typeck_results ( ) . fru_field_types ( ) [ expr. hir_id ]
595+ self . typeck_results . fru_field_types ( ) [ expr. hir_id ]
598596 . iter ( )
599597 . copied ( )
600598 . collect ( ) ,
@@ -605,7 +603,7 @@ impl<'tcx> Cx<'tcx> {
605603 } ) )
606604 }
607605 AdtKind :: Enum => {
608- let res = self . typeck_results ( ) . qpath_res ( qpath, expr. hir_id ) ;
606+ let res = self . typeck_results . qpath_res ( qpath, expr. hir_id ) ;
609607 match res {
610608 Res :: Def ( DefKind :: Variant , variant_id) => {
611609 assert ! ( matches!(
@@ -615,8 +613,7 @@ impl<'tcx> Cx<'tcx> {
615613 ) ) ;
616614
617615 let index = adt. variant_index_with_id ( variant_id) ;
618- let user_provided_types =
619- self . typeck_results ( ) . user_provided_types ( ) ;
616+ let user_provided_types = self . typeck_results . user_provided_types ( ) ;
620617 let user_ty =
621618 user_provided_types. get ( expr. hir_id ) . copied ( ) . map ( Box :: new) ;
622619 debug ! ( "make_mirror_unadjusted: (variant) user_ty={:?}" , user_ty) ;
@@ -629,8 +626,7 @@ impl<'tcx> Cx<'tcx> {
629626 base : match base {
630627 hir:: StructTailExpr :: DefaultFields ( _) => {
631628 AdtExprBase :: DefaultFields (
632- self . typeck_results ( ) . fru_field_types ( )
633- [ expr. hir_id ]
629+ self . typeck_results . fru_field_types ( ) [ expr. hir_id ]
634630 . iter ( )
635631 . copied ( )
636632 . collect ( ) ,
@@ -655,7 +651,7 @@ impl<'tcx> Cx<'tcx> {
655651 } ,
656652
657653 hir:: ExprKind :: Closure { .. } => {
658- let closure_ty = self . typeck_results ( ) . expr_ty ( expr) ;
654+ let closure_ty = self . typeck_results . expr_ty ( expr) ;
659655 let ( def_id, args, movability) = match * closure_ty. kind ( ) {
660656 ty:: Closure ( def_id, args) => ( def_id, UpvarArgs :: Closure ( args) , None ) ,
661657 ty:: Coroutine ( def_id, args) => {
@@ -703,7 +699,7 @@ impl<'tcx> Cx<'tcx> {
703699 }
704700
705701 hir:: ExprKind :: Path ( ref qpath) => {
706- let res = self . typeck_results ( ) . qpath_res ( qpath, expr. hir_id ) ;
702+ let res = self . typeck_results . qpath_res ( qpath, expr. hir_id ) ;
707703 self . convert_path_expr ( expr, res)
708704 }
709705
@@ -772,7 +768,7 @@ impl<'tcx> Cx<'tcx> {
772768 }
773769
774770 hir:: ExprKind :: ConstBlock ( ref anon_const) => {
775- let ty = self . typeck_results ( ) . node_type ( anon_const. hir_id ) ;
771+ let ty = self . typeck_results . node_type ( anon_const. hir_id ) ;
776772 let did = anon_const. def_id . to_def_id ( ) ;
777773 let typeck_root_def_id = tcx. typeck_root_def_id ( did) ;
778774 let parent_args =
@@ -783,7 +779,7 @@ impl<'tcx> Cx<'tcx> {
783779 }
784780 // Now comes the rote stuff:
785781 hir:: ExprKind :: Repeat ( v, _) => {
786- let ty = self . typeck_results ( ) . expr_ty ( expr) ;
782+ let ty = self . typeck_results . expr_ty ( expr) ;
787783 let ty:: Array ( _, count) = ty. kind ( ) else {
788784 span_bug ! ( expr. span, "unexpected repeat expr ty: {:?}" , ty) ;
789785 } ;
@@ -837,7 +833,7 @@ impl<'tcx> Cx<'tcx> {
837833 match_source,
838834 } ,
839835 hir:: ExprKind :: Loop ( body, ..) => {
840- let block_ty = self . typeck_results ( ) . node_type ( body. hir_id ) ;
836+ let block_ty = self . typeck_results . node_type ( body. hir_id ) ;
841837 let ( temp_lifetime, backwards_incompatible) = self
842838 . rvalue_scopes
843839 . temporary_scope ( self . region_scope_tree , body. hir_id . local_id ) ;
@@ -957,7 +953,7 @@ impl<'tcx> Cx<'tcx> {
957953 | Res :: Def ( DefKind :: Ctor ( _, CtorKind :: Fn ) , _)
958954 | Res :: Def ( DefKind :: Const , _)
959955 | Res :: Def ( DefKind :: AssocConst , _) => {
960- self . typeck_results ( ) . user_provided_types ( ) . get ( hir_id) . copied ( ) . map ( Box :: new)
956+ self . typeck_results . user_provided_types ( ) . get ( hir_id) . copied ( ) . map ( Box :: new)
961957 }
962958
963959 // A unit struct/variant which is used as a value (e.g.,
@@ -989,17 +985,13 @@ impl<'tcx> Cx<'tcx> {
989985 Some ( fn_def) => ( fn_def, None ) ,
990986 None => {
991987 let ( kind, def_id) =
992- self . typeck_results ( ) . type_dependent_def ( expr. hir_id ) . unwrap_or_else ( || {
988+ self . typeck_results . type_dependent_def ( expr. hir_id ) . unwrap_or_else ( || {
993989 span_bug ! ( expr. span, "no type-dependent def for method callee" )
994990 } ) ;
995991 let user_ty = self . user_args_applied_to_res ( expr. hir_id , Res :: Def ( kind, def_id) ) ;
996992 debug ! ( "method_callee: user_ty={:?}" , user_ty) ;
997993 (
998- Ty :: new_fn_def (
999- self . tcx ( ) ,
1000- def_id,
1001- self . typeck_results ( ) . node_args ( expr. hir_id ) ,
1002- ) ,
994+ Ty :: new_fn_def ( self . tcx , def_id, self . typeck_results . node_args ( expr. hir_id ) ) ,
1003995 user_ty,
1004996 )
1005997 }
@@ -1025,7 +1017,7 @@ impl<'tcx> Cx<'tcx> {
10251017 }
10261018
10271019 fn convert_path_expr ( & mut self , expr : & ' tcx hir:: Expr < ' tcx > , res : Res ) -> ExprKind < ' tcx > {
1028- let args = self . typeck_results ( ) . node_args ( expr. hir_id ) ;
1020+ let args = self . typeck_results . node_args ( expr. hir_id ) ;
10291021 match res {
10301022 // A regular function, constructor function or a constant.
10311023 Res :: Def ( DefKind :: Fn , _)
@@ -1060,7 +1052,7 @@ impl<'tcx> Cx<'tcx> {
10601052 let user_provided_types = self . typeck_results . user_provided_types ( ) ;
10611053 let user_ty = user_provided_types. get ( expr. hir_id ) . copied ( ) . map ( Box :: new) ;
10621054 debug ! ( "convert_path_expr: user_ty={:?}" , user_ty) ;
1063- let ty = self . typeck_results ( ) . node_type ( expr. hir_id ) ;
1055+ let ty = self . typeck_results . node_type ( expr. hir_id ) ;
10641056 match ty. kind ( ) {
10651057 // A unit struct/variant which is used as a value.
10661058 // We return a completely different ExprKind here to account for this special case.
0 commit comments