@@ -58,7 +58,7 @@ use middle::const_eval;
58
58
use middle:: ty:: { arg, field, substs} ;
59
59
use middle:: ty:: { ty_param_substs_and_ty} ;
60
60
use middle:: ty;
61
- use middle:: typeck:: rscope:: { in_binding_rscope} ;
61
+ use middle:: typeck:: rscope:: { in_binding_rscope, in_binding_rscope_ext } ;
62
62
use middle:: typeck:: rscope:: { region_scope, type_rscope, RegionError } ;
63
63
use middle:: typeck:: rscope:: { RegionParamNames } ;
64
64
@@ -67,7 +67,6 @@ use core::vec;
67
67
use syntax:: { ast, ast_util} ;
68
68
use syntax:: codemap:: span;
69
69
use syntax:: opt_vec:: OptVec ;
70
- use syntax:: opt_vec;
71
70
use syntax:: print:: pprust:: { lifetime_to_str, path_to_str} ;
72
71
use syntax:: parse:: token:: special_idents;
73
72
use util:: common:: indenter;
@@ -348,7 +347,7 @@ pub fn ast_ty_to_ty<AC:AstConv, RS:region_scope + Copy + Durable>(
348
347
}
349
348
ast:: ty_bare_fn ( ref bf) => {
350
349
ty:: mk_bare_fn ( tcx, ty_of_bare_fn ( self , rscope, bf. purity ,
351
- bf. abi , & bf. lifetimes , & bf . decl ) )
350
+ bf. abi , & bf. decl ) )
352
351
}
353
352
ast:: ty_closure( ref f) => {
354
353
let fn_decl = ty_of_closure ( self ,
@@ -509,50 +508,18 @@ pub fn ty_of_arg<AC:AstConv,RS:region_scope + Copy + Durable>(
509
508
arg { mode : mode, ty : ty}
510
509
}
511
510
512
- pub fn bound_lifetimes < AC : AstConv > (
513
- self : & AC ,
514
- ast_lifetimes : & OptVec < ast:: Lifetime > ) -> OptVec < ast:: ident >
515
- {
516
- /*!
517
- *
518
- * Converts a list of lifetimes into a list of bound identifier
519
- * names. Does not permit special names like 'static or 'self to
520
- * be bound. Note that this function is for use in closures,
521
- * methods, and fn definitions. It is legal to bind 'self in a
522
- * type. Eventually this distinction should go away and the same
523
- * rules should apply everywhere ('self would not be a special name
524
- * at that point).
525
- */
526
-
527
- let special_idents = [ special_idents:: static, special_idents:: self_] ;
528
- let mut bound_lifetime_names = opt_vec:: Empty ;
529
- ast_lifetimes. map_to_vec ( |ast_lifetime| {
530
- if special_idents. any ( |& i| i == ast_lifetime. ident ) {
531
- self . tcx ( ) . sess . span_err (
532
- ast_lifetime. span ,
533
- fmt ! ( "illegal lifetime parameter name: `%s`" ,
534
- lifetime_to_str( ast_lifetime, self . tcx( ) . sess. intr( ) ) ) ) ;
535
- } else {
536
- bound_lifetime_names. push ( ast_lifetime. ident ) ;
537
- }
538
- } ) ;
539
- bound_lifetime_names
540
- }
541
-
542
511
pub fn ty_of_bare_fn < AC : AstConv , RS : region_scope + Copy + Durable > (
543
- self : & AC ,
544
- rscope : & RS ,
545
- purity : ast:: purity ,
546
- abi : ast:: Abi ,
547
- lifetimes : & OptVec < ast:: Lifetime > ,
548
- decl : & ast:: fn_decl ) -> ty:: BareFnTy
549
- {
512
+ self : & AC ,
513
+ rscope : & RS ,
514
+ purity : ast:: purity ,
515
+ abi : ast:: Abi ,
516
+ decl : & ast:: fn_decl )
517
+ -> ty:: BareFnTy {
550
518
debug ! ( "ty_of_bare_fn" ) ;
551
519
552
520
// new region names that appear inside of the fn decl are bound to
553
521
// that function type
554
- let bound_lifetime_names = bound_lifetimes ( self , lifetimes) ;
555
- let rb = in_binding_rscope ( rscope, RegionParamNames ( copy bound_lifetime_names) ) ;
522
+ let rb = in_binding_rscope ( rscope) ;
556
523
557
524
let input_tys = decl. inputs . map ( |a| ty_of_arg ( self , & rb, * a, None ) ) ;
558
525
let output_ty = match decl. output . node {
@@ -563,9 +530,34 @@ pub fn ty_of_bare_fn<AC:AstConv,RS:region_scope + Copy + Durable>(
563
530
ty:: BareFnTy {
564
531
purity : purity,
565
532
abi : abi,
566
- sig : ty:: FnSig { bound_lifetime_names : bound_lifetime_names,
567
- inputs : input_tys,
568
- output : output_ty}
533
+ sig : ty:: FnSig { inputs : input_tys, output : output_ty}
534
+ }
535
+ }
536
+
537
+ pub fn ty_of_bare_fn_ext < AC : AstConv , RS : region_scope + Copy + Durable > (
538
+ self : & AC ,
539
+ rscope : & RS ,
540
+ purity : ast:: purity ,
541
+ abi : ast:: Abi ,
542
+ decl : & ast:: fn_decl ,
543
+ +region_param_names : RegionParamNames )
544
+ -> ty:: BareFnTy {
545
+ debug ! ( "ty_of_bare_fn_ext" ) ;
546
+
547
+ // new region names that appear inside of the fn decl are bound to
548
+ // that function type
549
+ let rb = in_binding_rscope_ext ( rscope, region_param_names) ;
550
+
551
+ let input_tys = decl. inputs . map ( |a| ty_of_arg ( self , & rb, * a, None ) ) ;
552
+ let output_ty = match decl. output . node {
553
+ ast:: ty_infer => self . ty_infer ( decl. output . span ) ,
554
+ _ => ast_ty_to_ty ( self , & rb, decl. output )
555
+ } ;
556
+
557
+ ty:: BareFnTy {
558
+ purity : purity,
559
+ abi : abi,
560
+ sig : ty:: FnSig { inputs : input_tys, output : output_ty}
569
561
}
570
562
}
571
563
@@ -577,16 +569,10 @@ pub fn ty_of_closure<AC:AstConv,RS:region_scope + Copy + Durable>(
577
569
onceness : ast:: Onceness ,
578
570
opt_lifetime : Option < @ast:: Lifetime > ,
579
571
decl : & ast:: fn_decl ,
580
- expected_sig : Option < ty:: FnSig > ,
572
+ expected_tys : Option < ty:: FnSig > ,
581
573
lifetimes : & OptVec < ast:: Lifetime > ,
582
574
span : span )
583
- -> ty:: ClosureTy
584
- {
585
- // The caller should not both provide explicit bound lifetime
586
- // names and expected types. Either we infer the bound lifetime
587
- // names or they are provided, but not both.
588
- fail_unless ! ( lifetimes. is_empty( ) || expected_sig. is_none( ) ) ;
589
-
575
+ -> ty:: ClosureTy {
590
576
debug ! ( "ty_of_fn_decl" ) ;
591
577
let _i = indenter ( ) ;
592
578
@@ -613,19 +599,19 @@ pub fn ty_of_closure<AC:AstConv,RS:region_scope + Copy + Durable>(
613
599
614
600
// new region names that appear inside of the fn decl are bound to
615
601
// that function type
616
- let bound_lifetime_names = bound_lifetimes ( self , lifetimes) ;
617
- let rb = in_binding_rscope ( rscope, RegionParamNames ( copy bound_lifetime_names ) ) ;
602
+ let region_param_names = RegionParamNames :: from_lifetimes ( lifetimes) ;
603
+ let rb = in_binding_rscope_ext ( rscope, region_param_names ) ;
618
604
619
605
let input_tys = do decl. inputs . mapi |i, a| {
620
- let expected_arg_ty = do expected_sig . chain_ref |e| {
606
+ let expected_arg_ty = do expected_tys . chain_ref |e| {
621
607
// no guarantee that the correct number of expected args
622
608
// were supplied
623
609
if i < e. inputs . len ( ) { Some ( e. inputs [ i] ) } else { None }
624
610
} ;
625
611
ty_of_arg ( self , & rb, * a, expected_arg_ty)
626
612
} ;
627
613
628
- let expected_ret_ty = expected_sig . map ( |e| e. output ) ;
614
+ let expected_ret_ty = expected_tys . map ( |e| e. output ) ;
629
615
let output_ty = match decl. output . node {
630
616
ast:: ty_infer if expected_ret_ty. is_some ( ) => expected_ret_ty. get ( ) ,
631
617
ast:: ty_infer => self . ty_infer ( decl. output . span ) ,
@@ -637,8 +623,7 @@ pub fn ty_of_closure<AC:AstConv,RS:region_scope + Copy + Durable>(
637
623
sigil : sigil,
638
624
onceness : onceness,
639
625
region : bound_region,
640
- sig : ty:: FnSig { bound_lifetime_names : bound_lifetime_names,
641
- inputs : input_tys,
626
+ sig : ty:: FnSig { inputs : input_tys,
642
627
output : output_ty}
643
628
}
644
629
}
0 commit comments