1
1
pub ( crate ) use crate :: build:: expr:: as_constant:: lit_to_mir_constant;
2
2
use crate :: build:: expr:: as_place:: PlaceBuilder ;
3
3
use crate :: build:: scope:: DropKind ;
4
- use crate :: thir:: pattern:: pat_from_hir;
5
4
use rustc_apfloat:: ieee:: { Double , Single } ;
6
5
use rustc_apfloat:: Float ;
7
6
use rustc_data_structures:: fx:: FxHashMap ;
8
7
use rustc_errors:: ErrorGuaranteed ;
9
8
use rustc_hir as hir;
10
9
use rustc_hir:: def_id:: { DefId , LocalDefId } ;
11
- use rustc_hir:: lang_items:: LangItem ;
12
10
use rustc_hir:: { GeneratorKind , ImplicitSelfKind , Node } ;
13
11
use rustc_index:: vec:: { Idx , IndexVec } ;
14
12
use rustc_infer:: infer:: { InferCtxt , TyCtxtInferExt } ;
@@ -17,8 +15,7 @@ use rustc_middle::middle::region;
17
15
use rustc_middle:: mir:: interpret:: ConstValue ;
18
16
use rustc_middle:: mir:: interpret:: Scalar ;
19
17
use rustc_middle:: mir:: * ;
20
- use rustc_middle:: thir:: { BindingMode , Expr , ExprId , LintLevel , LocalVarId , PatKind , Thir } ;
21
- use rustc_middle:: ty:: subst:: Subst ;
18
+ use rustc_middle:: thir:: { BindingMode , Expr , ExprId , LintLevel , LocalVarId , Param , PatKind , Thir } ;
22
19
use rustc_middle:: ty:: { self , Ty , TyCtxt , TypeVisitable , TypeckResults } ;
23
20
use rustc_span:: symbol:: sym;
24
21
use rustc_span:: Span ;
@@ -439,10 +436,10 @@ macro_rules! unpack {
439
436
///////////////////////////////////////////////////////////////////////////
440
437
/// the main entry point for building MIR for a function
441
438
442
- struct ArgInfo < ' tcx > (
439
+ struct ArgInfo < ' thir , ' tcx > (
443
440
Ty < ' tcx > ,
444
441
Option < Span > ,
445
- Option < & ' tcx hir :: Param < ' tcx > > ,
442
+ Option < & ' thir Param < ' tcx > > ,
446
443
Option < ImplicitSelfKind > ,
447
444
) ;
448
445
@@ -500,38 +497,8 @@ fn construct_fn<'tcx>(
500
497
_ => vec ! [ ] ,
501
498
} ;
502
499
503
- let explicit_arguments = body. params . iter ( ) . enumerate ( ) . map ( |( index, arg) | {
504
- let owner_id = tcx. hir ( ) . body_owner ( body_id) ;
505
- let opt_ty_info;
506
- let self_arg;
507
- if let Some ( ref fn_decl) = tcx. hir ( ) . fn_decl_by_hir_id ( owner_id) {
508
- opt_ty_info = fn_decl
509
- . inputs
510
- . get ( index)
511
- // Make sure that inferred closure args have no type span
512
- . and_then ( |ty| if arg. pat . span != ty. span { Some ( ty. span ) } else { None } ) ;
513
- self_arg = if index == 0 && fn_decl. implicit_self . has_implicit_self ( ) {
514
- Some ( fn_decl. implicit_self )
515
- } else {
516
- None
517
- } ;
518
- } else {
519
- opt_ty_info = None ;
520
- self_arg = None ;
521
- }
522
-
523
- // C-variadic fns also have a `VaList` input that's not listed in `fn_sig`
524
- // (as it's created inside the body itself, not passed in from outside).
525
- let ty = if fn_sig. c_variadic && index == fn_sig. inputs ( ) . len ( ) {
526
- let va_list_did = tcx. require_lang_item ( LangItem :: VaList , Some ( arg. span ) ) ;
527
-
528
- tcx. bound_type_of ( va_list_did) . subst ( tcx, & [ tcx. lifetimes . re_erased . into ( ) ] )
529
- } else {
530
- fn_sig. inputs ( ) [ index]
531
- } ;
532
-
533
- ArgInfo ( ty, opt_ty_info, Some ( & arg) , self_arg)
534
- } ) ;
500
+ let explicit_arguments =
501
+ thir. params . iter ( ) . map ( |arg| ArgInfo ( arg. ty , arg. ty_span , Some ( & arg) , arg. self_kind ) ) ;
535
502
536
503
let arguments = implicit_argument. into_iter ( ) . chain ( explicit_arguments) ;
537
504
@@ -842,7 +809,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
842
809
& mut self ,
843
810
mut block : BasicBlock ,
844
811
fn_def_id : LocalDefId ,
845
- arguments : & [ ArgInfo < ' tcx > ] ,
812
+ arguments : & [ ArgInfo < ' _ , ' tcx > ] ,
846
813
argument_scope : region:: Scope ,
847
814
expr : & Expr < ' tcx > ,
848
815
) -> BlockAnd < ( ) > {
@@ -853,9 +820,9 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
853
820
let arg_local = self . local_decls . push ( LocalDecl :: with_source_info ( ty, source_info) ) ;
854
821
855
822
// If this is a simple binding pattern, give debuginfo a nice name.
856
- if let Some ( arg) = arg_opt && let Some ( ident ) = arg. pat . simple_ident ( ) {
823
+ if let Some ( arg) = arg_opt && let Some ( name ) = arg. pat . simple_ident ( ) {
857
824
self . var_debug_info . push ( VarDebugInfo {
858
- name : ident . name ,
825
+ name,
859
826
source_info,
860
827
value : VarDebugInfoContents :: Place ( arg_local. into ( ) ) ,
861
828
} ) ;
@@ -943,15 +910,10 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
943
910
let Some ( arg) = arg_opt else {
944
911
continue ;
945
912
} ;
946
- let pat = match tcx. hir ( ) . get ( arg. pat . hir_id ) {
947
- Node :: Pat ( pat) => pat,
948
- node => bug ! ( "pattern became {:?}" , node) ,
949
- } ;
950
- let pattern = pat_from_hir ( tcx, self . param_env , self . typeck_results , pat) ;
951
913
let original_source_scope = self . source_scope ;
952
- let span = pattern . span ;
914
+ let span = arg . pat . span ;
953
915
self . set_correct_source_scope_for_arg ( arg. hir_id , original_source_scope, span) ;
954
- match * pattern . kind {
916
+ match * arg . pat . kind {
955
917
// Don't introduce extra copies for simple bindings
956
918
PatKind :: Binding {
957
919
mutability,
@@ -983,12 +945,12 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
983
945
scope = self . declare_bindings (
984
946
scope,
985
947
expr. span ,
986
- & pattern ,
948
+ & arg . pat ,
987
949
matches:: ArmHasGuard ( false ) ,
988
950
Some ( ( Some ( & place) , span) ) ,
989
951
) ;
990
952
let place_builder = PlaceBuilder :: from ( local) ;
991
- unpack ! ( block = self . place_into_pattern( block, pattern , place_builder, false ) ) ;
953
+ unpack ! ( block = self . place_into_pattern( block, & arg . pat , place_builder, false ) ) ;
992
954
}
993
955
}
994
956
self . source_scope = original_source_scope;
0 commit comments