@@ -21,10 +21,9 @@ use rustc_middle::{bug, span_bug};
21
21
use rustc_span:: { Span , sym} ;
22
22
use tracing:: { debug, info, instrument, trace} ;
23
23
24
- use crate :: thir:: cx:: Cx ;
25
- use crate :: thir:: util:: UserAnnotatedTyHelpers ;
24
+ use crate :: thir:: cx:: ThirBuildCx ;
26
25
27
- impl < ' tcx > Cx < ' tcx > {
26
+ impl < ' tcx > ThirBuildCx < ' tcx > {
28
27
/// Create a THIR expression for the given HIR expression. This expands all
29
28
/// adjustments and directly adds the type information from the
30
29
/// `typeck_results`. See the [dev-guide] for more details.
@@ -142,9 +141,9 @@ impl<'tcx> Cx<'tcx> {
142
141
Adjust :: Deref ( Some ( deref) ) => {
143
142
// We don't need to do call adjust_span here since
144
143
// 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 ) ;
146
145
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 ( ) ] ) ) ;
148
147
149
148
expr = Expr {
150
149
temp_lifetime,
@@ -253,10 +252,10 @@ impl<'tcx> Cx<'tcx> {
253
252
254
253
// Check to see if this cast is a "coercion cast", where the cast is actually done
255
254
// 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 ) {
257
256
// Convert the lexpr to a vexpr.
258
257
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 ( ) {
260
259
// Special cased so that we can type check that the element
261
260
// type of the source matches the pointed to type of the
262
261
// destination.
@@ -266,8 +265,8 @@ impl<'tcx> Cx<'tcx> {
266
265
is_from_as_cast : true ,
267
266
}
268
267
} 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 )
271
270
&& let ty:: Adt ( adt_def, args) = ty. kind ( )
272
271
&& let Res :: Def ( DefKind :: Ctor ( CtorOf :: Variant , CtorKind :: Const ) , variant_ctor_id) = res
273
272
{
@@ -330,7 +329,7 @@ impl<'tcx> Cx<'tcx> {
330
329
#[ instrument( level = "debug" , skip( self ) , ret) ]
331
330
fn make_mirror_unadjusted ( & mut self , expr : & ' tcx hir:: Expr < ' tcx > ) -> Expr < ' tcx > {
332
331
let tcx = self . tcx ;
333
- let expr_ty = self . typeck_results ( ) . expr_ty ( expr) ;
332
+ let expr_ty = self . typeck_results . expr_ty ( expr) ;
334
333
let ( temp_lifetime, backwards_incompatible) =
335
334
self . rvalue_scopes . temporary_scope ( self . region_scope_tree , expr. hir_id . local_id ) ;
336
335
@@ -354,7 +353,7 @@ impl<'tcx> Cx<'tcx> {
354
353
}
355
354
356
355
hir:: ExprKind :: Call ( fun, ref args) => {
357
- if self . typeck_results ( ) . is_method_call ( expr) {
356
+ if self . typeck_results . is_method_call ( expr) {
358
357
// The callee is something implementing Fn, FnMut, or FnOnce.
359
358
// Find the actual method implementation being called and
360
359
// build the appropriate UFCS call expression with the
@@ -364,7 +363,7 @@ impl<'tcx> Cx<'tcx> {
364
363
365
364
let method = self . method_callee ( expr, fun. span , None ) ;
366
365
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) ) ;
368
367
let tupled_args = Expr {
369
368
ty : Ty :: new_tup_from_iter ( tcx, arg_tys) ,
370
369
temp_lifetime : TempLifetime { temp_lifetime, backwards_incompatible } ,
@@ -380,7 +379,7 @@ impl<'tcx> Cx<'tcx> {
380
379
from_hir_call : true ,
381
380
fn_span : expr. span ,
382
381
}
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 ( )
384
383
&& let Some ( intrinsic) = self . tcx . intrinsic ( def_id)
385
384
&& intrinsic. name == sym:: box_new
386
385
{
@@ -413,7 +412,7 @@ impl<'tcx> Cx<'tcx> {
413
412
} ,
414
413
hir:: QPath :: TypeRelative ( _ty, _) => {
415
414
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 )
417
416
{
418
417
Some ( ( adt_def, adt_def. variant_index_with_ctor_id ( ctor_id) ) )
419
418
} else {
@@ -426,8 +425,8 @@ impl<'tcx> Cx<'tcx> {
426
425
None
427
426
} ;
428
427
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 ( ) ;
431
430
let user_ty =
432
431
user_provided_types. get ( fun. hir_id ) . copied ( ) . map ( |mut u_ty| {
433
432
if let ty:: UserTypeKind :: TypeOf ( ref mut did, _) =
@@ -457,7 +456,7 @@ impl<'tcx> Cx<'tcx> {
457
456
} ) )
458
457
} else {
459
458
ExprKind :: Call {
460
- ty : self . typeck_results ( ) . node_type ( fun. hir_id ) ,
459
+ ty : self . typeck_results . node_type ( fun. hir_id ) ,
461
460
fun : self . mirror_expr ( fun) ,
462
461
args : self . mirror_exprs ( args) ,
463
462
from_hir_call : true ,
@@ -482,7 +481,7 @@ impl<'tcx> Cx<'tcx> {
482
481
}
483
482
484
483
hir:: ExprKind :: AssignOp ( op, lhs, rhs) => {
485
- if self . typeck_results ( ) . is_method_call ( expr) {
484
+ if self . typeck_results . is_method_call ( expr) {
486
485
let lhs = self . mirror_expr ( lhs) ;
487
486
let rhs = self . mirror_expr ( rhs) ;
488
487
self . overloaded_operator ( expr, Box :: new ( [ lhs, rhs] ) )
@@ -498,7 +497,7 @@ impl<'tcx> Cx<'tcx> {
498
497
hir:: ExprKind :: Lit ( lit) => ExprKind :: Literal { lit, neg : false } ,
499
498
500
499
hir:: ExprKind :: Binary ( op, lhs, rhs) => {
501
- if self . typeck_results ( ) . is_method_call ( expr) {
500
+ if self . typeck_results . is_method_call ( expr) {
502
501
let lhs = self . mirror_expr ( lhs) ;
503
502
let rhs = self . mirror_expr ( rhs) ;
504
503
self . overloaded_operator ( expr, Box :: new ( [ lhs, rhs] ) )
@@ -527,7 +526,7 @@ impl<'tcx> Cx<'tcx> {
527
526
}
528
527
529
528
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) {
531
530
let lhs = self . mirror_expr ( lhs) ;
532
531
let index = self . mirror_expr ( index) ;
533
532
self . overloaded_place (
@@ -543,7 +542,7 @@ impl<'tcx> Cx<'tcx> {
543
542
}
544
543
545
544
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) {
547
546
let arg = self . mirror_expr ( arg) ;
548
547
self . overloaded_place ( expr, expr_ty, None , Box :: new ( [ arg] ) , expr. span )
549
548
} else {
@@ -552,7 +551,7 @@ impl<'tcx> Cx<'tcx> {
552
551
}
553
552
554
553
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) {
556
555
let arg = self . mirror_expr ( arg) ;
557
556
self . overloaded_operator ( expr, Box :: new ( [ arg] ) )
558
557
} else {
@@ -561,7 +560,7 @@ impl<'tcx> Cx<'tcx> {
561
560
}
562
561
563
562
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) {
565
564
let arg = self . mirror_expr ( arg) ;
566
565
self . overloaded_operator ( expr, Box :: new ( [ arg] ) )
567
566
} else if let hir:: ExprKind :: Lit ( lit) = arg. kind {
@@ -574,7 +573,7 @@ impl<'tcx> Cx<'tcx> {
574
573
hir:: ExprKind :: Struct ( qpath, fields, ref base) => match expr_ty. kind ( ) {
575
574
ty:: Adt ( adt, args) => match adt. adt_kind ( ) {
576
575
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 ( ) ;
578
577
let user_ty = user_provided_types. get ( expr. hir_id ) . copied ( ) . map ( Box :: new) ;
579
578
debug ! ( "make_mirror_unadjusted: (struct/union) user_ty={:?}" , user_ty) ;
580
579
ExprKind :: Adt ( Box :: new ( AdtExpr {
@@ -586,15 +585,14 @@ impl<'tcx> Cx<'tcx> {
586
585
base : match base {
587
586
hir:: StructTailExpr :: Base ( base) => AdtExprBase :: Base ( FruInfo {
588
587
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 ]
591
589
. iter ( )
592
590
. copied ( )
593
591
. collect ( ) ,
594
592
} ) ,
595
593
hir:: StructTailExpr :: DefaultFields ( _) => {
596
594
AdtExprBase :: DefaultFields (
597
- self . typeck_results ( ) . fru_field_types ( ) [ expr. hir_id ]
595
+ self . typeck_results . fru_field_types ( ) [ expr. hir_id ]
598
596
. iter ( )
599
597
. copied ( )
600
598
. collect ( ) ,
@@ -605,7 +603,7 @@ impl<'tcx> Cx<'tcx> {
605
603
} ) )
606
604
}
607
605
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 ) ;
609
607
match res {
610
608
Res :: Def ( DefKind :: Variant , variant_id) => {
611
609
assert ! ( matches!(
@@ -615,8 +613,7 @@ impl<'tcx> Cx<'tcx> {
615
613
) ) ;
616
614
617
615
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 ( ) ;
620
617
let user_ty =
621
618
user_provided_types. get ( expr. hir_id ) . copied ( ) . map ( Box :: new) ;
622
619
debug ! ( "make_mirror_unadjusted: (variant) user_ty={:?}" , user_ty) ;
@@ -629,8 +626,7 @@ impl<'tcx> Cx<'tcx> {
629
626
base : match base {
630
627
hir:: StructTailExpr :: DefaultFields ( _) => {
631
628
AdtExprBase :: DefaultFields (
632
- self . typeck_results ( ) . fru_field_types ( )
633
- [ expr. hir_id ]
629
+ self . typeck_results . fru_field_types ( ) [ expr. hir_id ]
634
630
. iter ( )
635
631
. copied ( )
636
632
. collect ( ) ,
@@ -655,7 +651,7 @@ impl<'tcx> Cx<'tcx> {
655
651
} ,
656
652
657
653
hir:: ExprKind :: Closure { .. } => {
658
- let closure_ty = self . typeck_results ( ) . expr_ty ( expr) ;
654
+ let closure_ty = self . typeck_results . expr_ty ( expr) ;
659
655
let ( def_id, args, movability) = match * closure_ty. kind ( ) {
660
656
ty:: Closure ( def_id, args) => ( def_id, UpvarArgs :: Closure ( args) , None ) ,
661
657
ty:: Coroutine ( def_id, args) => {
@@ -703,7 +699,7 @@ impl<'tcx> Cx<'tcx> {
703
699
}
704
700
705
701
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 ) ;
707
703
self . convert_path_expr ( expr, res)
708
704
}
709
705
@@ -772,7 +768,7 @@ impl<'tcx> Cx<'tcx> {
772
768
}
773
769
774
770
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 ) ;
776
772
let did = anon_const. def_id . to_def_id ( ) ;
777
773
let typeck_root_def_id = tcx. typeck_root_def_id ( did) ;
778
774
let parent_args =
@@ -783,7 +779,7 @@ impl<'tcx> Cx<'tcx> {
783
779
}
784
780
// Now comes the rote stuff:
785
781
hir:: ExprKind :: Repeat ( v, _) => {
786
- let ty = self . typeck_results ( ) . expr_ty ( expr) ;
782
+ let ty = self . typeck_results . expr_ty ( expr) ;
787
783
let ty:: Array ( _, count) = ty. kind ( ) else {
788
784
span_bug ! ( expr. span, "unexpected repeat expr ty: {:?}" , ty) ;
789
785
} ;
@@ -837,7 +833,7 @@ impl<'tcx> Cx<'tcx> {
837
833
match_source,
838
834
} ,
839
835
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 ) ;
841
837
let ( temp_lifetime, backwards_incompatible) = self
842
838
. rvalue_scopes
843
839
. temporary_scope ( self . region_scope_tree , body. hir_id . local_id ) ;
@@ -957,7 +953,7 @@ impl<'tcx> Cx<'tcx> {
957
953
| Res :: Def ( DefKind :: Ctor ( _, CtorKind :: Fn ) , _)
958
954
| Res :: Def ( DefKind :: Const , _)
959
955
| 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)
961
957
}
962
958
963
959
// A unit struct/variant which is used as a value (e.g.,
@@ -989,17 +985,13 @@ impl<'tcx> Cx<'tcx> {
989
985
Some ( fn_def) => ( fn_def, None ) ,
990
986
None => {
991
987
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 ( || {
993
989
span_bug ! ( expr. span, "no type-dependent def for method callee" )
994
990
} ) ;
995
991
let user_ty = self . user_args_applied_to_res ( expr. hir_id , Res :: Def ( kind, def_id) ) ;
996
992
debug ! ( "method_callee: user_ty={:?}" , user_ty) ;
997
993
(
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 ) ) ,
1003
995
user_ty,
1004
996
)
1005
997
}
@@ -1025,7 +1017,7 @@ impl<'tcx> Cx<'tcx> {
1025
1017
}
1026
1018
1027
1019
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 ) ;
1029
1021
match res {
1030
1022
// A regular function, constructor function or a constant.
1031
1023
Res :: Def ( DefKind :: Fn , _)
@@ -1060,7 +1052,7 @@ impl<'tcx> Cx<'tcx> {
1060
1052
let user_provided_types = self . typeck_results . user_provided_types ( ) ;
1061
1053
let user_ty = user_provided_types. get ( expr. hir_id ) . copied ( ) . map ( Box :: new) ;
1062
1054
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 ) ;
1064
1056
match ty. kind ( ) {
1065
1057
// A unit struct/variant which is used as a value.
1066
1058
// We return a completely different ExprKind here to account for this special case.
0 commit comments