@@ -65,7 +65,8 @@ use core::result;
6565use core:: vec;
6666use syntax:: ast;
6767use syntax:: codemap:: span;
68- use syntax:: print:: pprust:: { region_to_str, path_to_str} ;
68+ use syntax:: print:: pprust:: { lifetime_to_str, path_to_str} ;
69+ use syntax:: parse:: token:: special_idents;
6970use util:: common:: indenter;
7071
7172pub trait AstConv {
@@ -79,21 +80,16 @@ pub trait AstConv {
7980pub fn get_region_reporting_err (
8081 tcx : ty:: ctxt ,
8182 span : span ,
82- a_r : Option < @ast:: region > ,
83+ a_r : Option < @ast:: Lifetime > ,
8384 res : Result < ty:: Region , RegionError > ) -> ty:: Region
8485{
8586 match res {
8687 result:: Ok ( r) => r,
8788 result:: Err ( ref e) => {
8889 let descr = match a_r {
8990 None => ~"anonymous lifetime",
90- Some ( a) if a. node == ast:: re_anon => {
91- ~"anonymous lifetime"
92- }
93- Some ( a) => {
94- fmt ! ( "lifetime %s" ,
95- region_to_str( a, tcx. sess. intr( ) ) )
96- }
91+ Some ( a) => fmt ! ( "lifetime %s" ,
92+ lifetime_to_str( a, tcx. sess. intr( ) ) )
9793 } ;
9894 tcx. sess . span_err (
9995 span,
@@ -105,19 +101,28 @@ pub fn get_region_reporting_err(
105101}
106102
107103pub fn ast_region_to_region < AC : AstConv , RS : region_scope + Copy + Durable > (
108- self : & AC ,
109- rscope : & RS ,
110- span : span ,
111- a_r : @ast:: region )
112- -> ty:: Region {
113- let res = match a_r. node {
114- ast:: re_static => Ok ( ty:: re_static) ,
115- ast:: re_anon => rscope. anon_region ( span) ,
116- ast:: re_self => rscope. self_region ( span) ,
117- ast:: re_named( id) => rscope. named_region ( span, id)
104+ self : & AC ,
105+ rscope : & RS ,
106+ default_span : span ,
107+ opt_lifetime : Option < @ast:: Lifetime > ) -> ty:: Region
108+ {
109+ let ( span, res) = match opt_lifetime {
110+ None => {
111+ ( default_span, rscope. anon_region ( default_span) )
112+ }
113+ Some ( ref lifetime) if lifetime. ident == special_idents:: static => {
114+ ( lifetime. span , Ok ( ty:: re_static) )
115+ }
116+ Some ( ref lifetime) if lifetime. ident == special_idents:: self_ => {
117+ ( lifetime. span , rscope. self_region ( lifetime. span ) )
118+ }
119+ Some ( ref lifetime) => {
120+ ( lifetime. span , rscope. named_region ( lifetime. span ,
121+ lifetime. ident ) )
122+ }
118123 } ;
119124
120- get_region_reporting_err ( self . tcx ( ) , span, Some ( a_r ) , res)
125+ get_region_reporting_err ( self . tcx ( ) , span, opt_lifetime , res)
121126}
122127
123128pub fn ast_path_to_substs_and_ty < AC : AstConv , RS : region_scope + Copy + Durable > (
@@ -156,8 +161,8 @@ pub fn ast_path_to_substs_and_ty<AC:AstConv,RS:region_scope + Copy + Durable>(
156161 let r = get_region_reporting_err ( self . tcx ( ) , path. span , None , res) ;
157162 Some ( r)
158163 }
159- ( Some ( _) , Some ( r ) ) => {
160- Some ( ast_region_to_region ( self , rscope, path. span , r ) )
164+ ( Some ( _) , Some ( _ ) ) => {
165+ Some ( ast_region_to_region ( self , rscope, path. span , path . rp ) )
161166 }
162167 } ;
163168
@@ -504,7 +509,7 @@ pub fn ty_of_closure<AC:AstConv,RS:region_scope + Copy + Durable>(
504509 sigil : ast:: Sigil ,
505510 purity : ast:: purity ,
506511 onceness : ast:: Onceness ,
507- opt_region : Option < @ast:: region > ,
512+ opt_lifetime : Option < @ast:: Lifetime > ,
508513 decl : & ast:: fn_decl ,
509514 expected_tys : Option < ty:: FnSig > ,
510515 span : span )
@@ -514,9 +519,9 @@ pub fn ty_of_closure<AC:AstConv,RS:region_scope + Copy + Durable>(
514519
515520 // resolve the function bound region in the original region
516521 // scope `rscope`, not the scope of the function parameters
517- let bound_region = match opt_region {
518- Some ( region ) => {
519- ast_region_to_region ( self , rscope, span, region )
522+ let bound_region = match opt_lifetime {
523+ Some ( _ ) => {
524+ ast_region_to_region ( self , rscope, span, opt_lifetime )
520525 }
521526 None => {
522527 match sigil {
@@ -526,9 +531,8 @@ pub fn ty_of_closure<AC:AstConv,RS:region_scope + Copy + Durable>(
526531 ty:: re_static
527532 }
528533 ast:: BorrowedSigil => {
529- // &fn() defaults to an anonymous region:
530- let r_result = rscope. anon_region ( span) ;
531- get_region_reporting_err ( self . tcx ( ) , span, None , r_result)
534+ // &fn() defaults as normal for an omitted lifetime:
535+ ast_region_to_region ( self , rscope, span, opt_lifetime)
532536 }
533537 }
534538 }
0 commit comments