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_data_structures:: sorted_map:: SortedIndexMultiMap ;
9
8
use rustc_errors:: ErrorGuaranteed ;
10
9
use rustc_hir as hir;
11
10
use rustc_hir:: def_id:: { DefId , LocalDefId } ;
12
- use rustc_hir:: lang_items:: LangItem ;
13
11
use rustc_hir:: { GeneratorKind , ImplicitSelfKind , Node } ;
14
12
use rustc_index:: vec:: { Idx , IndexVec } ;
15
13
use rustc_infer:: infer:: { InferCtxt , TyCtxtInferExt } ;
@@ -18,8 +16,7 @@ use rustc_middle::middle::region;
18
16
use rustc_middle:: mir:: interpret:: ConstValue ;
19
17
use rustc_middle:: mir:: interpret:: Scalar ;
20
18
use rustc_middle:: mir:: * ;
21
- use rustc_middle:: thir:: { BindingMode , Expr , ExprId , LintLevel , LocalVarId , PatKind , Thir } ;
22
- use rustc_middle:: ty:: subst:: Subst ;
19
+ use rustc_middle:: thir:: { BindingMode , Expr , ExprId , LintLevel , LocalVarId , Param , PatKind , Thir } ;
23
20
use rustc_middle:: ty:: { self , Ty , TyCtxt , TypeVisitable , TypeckResults } ;
24
21
use rustc_span:: symbol:: sym;
25
22
use rustc_span:: Span ;
@@ -449,10 +446,10 @@ macro_rules! unpack {
449
446
///////////////////////////////////////////////////////////////////////////
450
447
/// the main entry point for building MIR for a function
451
448
452
- struct ArgInfo < ' tcx > (
449
+ struct ArgInfo < ' thir , ' tcx > (
453
450
Ty < ' tcx > ,
454
451
Option < Span > ,
455
- Option < & ' tcx hir :: Param < ' tcx > > ,
452
+ Option < & ' thir Param < ' tcx > > ,
456
453
Option < ImplicitSelfKind > ,
457
454
) ;
458
455
@@ -510,38 +507,8 @@ fn construct_fn<'tcx>(
510
507
_ => vec ! [ ] ,
511
508
} ;
512
509
513
- let explicit_arguments = body. params . iter ( ) . enumerate ( ) . map ( |( index, arg) | {
514
- let owner_id = tcx. hir ( ) . body_owner ( body_id) ;
515
- let opt_ty_info;
516
- let self_arg;
517
- if let Some ( ref fn_decl) = tcx. hir ( ) . fn_decl_by_hir_id ( owner_id) {
518
- opt_ty_info = fn_decl
519
- . inputs
520
- . get ( index)
521
- // Make sure that inferred closure args have no type span
522
- . and_then ( |ty| if arg. pat . span != ty. span { Some ( ty. span ) } else { None } ) ;
523
- self_arg = if index == 0 && fn_decl. implicit_self . has_implicit_self ( ) {
524
- Some ( fn_decl. implicit_self )
525
- } else {
526
- None
527
- } ;
528
- } else {
529
- opt_ty_info = None ;
530
- self_arg = None ;
531
- }
532
-
533
- // C-variadic fns also have a `VaList` input that's not listed in `fn_sig`
534
- // (as it's created inside the body itself, not passed in from outside).
535
- let ty = if fn_sig. c_variadic && index == fn_sig. inputs ( ) . len ( ) {
536
- let va_list_did = tcx. require_lang_item ( LangItem :: VaList , Some ( arg. span ) ) ;
537
-
538
- tcx. bound_type_of ( va_list_did) . subst ( tcx, & [ tcx. lifetimes . re_erased . into ( ) ] )
539
- } else {
540
- fn_sig. inputs ( ) [ index]
541
- } ;
542
-
543
- ArgInfo ( ty, opt_ty_info, Some ( & arg) , self_arg)
544
- } ) ;
510
+ let explicit_arguments =
511
+ thir. params . iter ( ) . map ( |arg| ArgInfo ( arg. ty , arg. ty_span , Some ( & arg) , arg. self_kind ) ) ;
545
512
546
513
let arguments = implicit_argument. into_iter ( ) . chain ( explicit_arguments) ;
547
514
@@ -852,7 +819,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
852
819
& mut self ,
853
820
mut block : BasicBlock ,
854
821
fn_def_id : LocalDefId ,
855
- arguments : & [ ArgInfo < ' tcx > ] ,
822
+ arguments : & [ ArgInfo < ' _ , ' tcx > ] ,
856
823
argument_scope : region:: Scope ,
857
824
expr : & Expr < ' tcx > ,
858
825
) -> BlockAnd < ( ) > {
@@ -863,9 +830,9 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
863
830
let arg_local = self . local_decls . push ( LocalDecl :: with_source_info ( ty, source_info) ) ;
864
831
865
832
// If this is a simple binding pattern, give debuginfo a nice name.
866
- if let Some ( arg) = arg_opt && let Some ( ident ) = arg. pat . simple_ident ( ) {
833
+ if let Some ( arg) = arg_opt && let Some ( name ) = arg. pat . simple_ident ( ) {
867
834
self . var_debug_info . push ( VarDebugInfo {
868
- name : ident . name ,
835
+ name,
869
836
source_info,
870
837
value : VarDebugInfoContents :: Place ( arg_local. into ( ) ) ,
871
838
} ) ;
@@ -955,15 +922,10 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
955
922
let Some ( arg) = arg_opt else {
956
923
continue ;
957
924
} ;
958
- let pat = match tcx. hir ( ) . get ( arg. pat . hir_id ) {
959
- Node :: Pat ( pat) => pat,
960
- node => bug ! ( "pattern became {:?}" , node) ,
961
- } ;
962
- let pattern = pat_from_hir ( tcx, self . param_env , self . typeck_results , pat) ;
963
925
let original_source_scope = self . source_scope ;
964
- let span = pattern . span ;
926
+ let span = arg . pat . span ;
965
927
self . set_correct_source_scope_for_arg ( arg. hir_id , original_source_scope, span) ;
966
- match pattern . kind {
928
+ match arg . pat . kind {
967
929
// Don't introduce extra copies for simple bindings
968
930
PatKind :: Binding {
969
931
mutability,
@@ -995,15 +957,12 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
995
957
scope = self . declare_bindings (
996
958
scope,
997
959
expr. span ,
998
- & pattern ,
960
+ & arg . pat ,
999
961
matches:: ArmHasGuard ( false ) ,
1000
962
Some ( ( Some ( & place) , span) ) ,
1001
963
) ;
1002
964
let place_builder = PlaceBuilder :: from ( local) ;
1003
- unpack ! (
1004
- block =
1005
- self . place_into_pattern( block, pattern. as_ref( ) , place_builder, false )
1006
- ) ;
965
+ unpack ! ( block = self . place_into_pattern( block, & arg. pat, place_builder, false ) ) ;
1007
966
}
1008
967
}
1009
968
self . source_scope = original_source_scope;
0 commit comments