@@ -57,7 +57,7 @@ use middle::resolve_lifetime as rl;
57
57
use middle:: privacy:: { AllPublic , LastMod } ;
58
58
use middle:: subst:: { FnSpace , TypeSpace , SelfSpace , Subst , Substs , ParamSpace } ;
59
59
use middle:: traits;
60
- use middle:: ty:: { self , RegionEscape , Ty , ToPredicate , HasTypeFlags } ;
60
+ use middle:: ty:: { self , Ty , ToPredicate , HasTypeFlags } ;
61
61
use middle:: ty:: wf:: object_region_bounds;
62
62
use require_c_abi_if_variadic;
63
63
use rscope:: { self , UnelidableRscope , RegionScope , ElidableRscope ,
@@ -169,10 +169,8 @@ pub fn ast_region_to_region(tcx: &ty::ctxt, lifetime: &hir::Lifetime)
169
169
ty:: ReLateBound ( debruijn, ty:: BrNamed ( tcx. map . local_def_id ( id) , lifetime. name ) )
170
170
}
171
171
172
- Some ( & rl:: DefEarlyBoundRegion ( space, index, id) ) => {
173
- let def_id = tcx. map . local_def_id ( id) ;
172
+ Some ( & rl:: DefEarlyBoundRegion ( space, index, _) ) => {
174
173
ty:: ReEarlyBound ( ty:: EarlyBoundRegion {
175
- def_id : def_id,
176
174
space : space,
177
175
index : index,
178
176
name : lifetime. name
@@ -1797,75 +1795,31 @@ fn ty_of_method_or_bare_fn<'a, 'tcx>(this: &AstConv<'tcx>,
1797
1795
// lifetime elision, we can determine it in two ways. First (determined
1798
1796
// here), if self is by-reference, then the implied output region is the
1799
1797
// region of the self parameter.
1800
- let mut explicit_self_category_result = None ;
1801
- let ( self_ty, implied_output_region) = match opt_self_info {
1798
+ let ( self_ty, explicit_self_category) = match opt_self_info {
1802
1799
None => ( None , None ) ,
1803
- Some ( self_info) => {
1804
- // This type comes from an impl or trait; no late-bound
1805
- // regions should be present.
1806
- assert ! ( !self_info. untransformed_self_ty. has_escaping_regions( ) ) ;
1807
-
1808
- // Figure out and record the explicit self category.
1809
- let explicit_self_category =
1810
- determine_explicit_self_category ( this, & rb, & self_info) ;
1811
- explicit_self_category_result = Some ( explicit_self_category) ;
1812
- match explicit_self_category {
1813
- ty:: StaticExplicitSelfCategory => {
1814
- ( None , None )
1815
- }
1816
- ty:: ByValueExplicitSelfCategory => {
1817
- ( Some ( self_info. untransformed_self_ty ) , None )
1818
- }
1819
- ty:: ByReferenceExplicitSelfCategory ( region, mutability) => {
1820
- ( Some ( this. tcx ( ) . mk_ref (
1821
- this. tcx ( ) . mk_region ( region) ,
1822
- ty:: TypeAndMut {
1823
- ty : self_info. untransformed_self_ty ,
1824
- mutbl : mutability
1825
- } ) ) ,
1826
- Some ( region) )
1827
- }
1828
- ty:: ByBoxExplicitSelfCategory => {
1829
- ( Some ( this. tcx ( ) . mk_box ( self_info. untransformed_self_ty ) ) , None )
1830
- }
1831
- }
1832
- }
1800
+ Some ( self_info) => determine_self_type ( this, & rb, self_info)
1833
1801
} ;
1834
1802
1835
1803
// HACK(eddyb) replace the fake self type in the AST with the actual type.
1836
- let input_params = if self_ty. is_some ( ) {
1804
+ let arg_params = if self_ty. is_some ( ) {
1837
1805
& decl. inputs [ 1 ..]
1838
1806
} else {
1839
1807
& decl. inputs [ ..]
1840
1808
} ;
1841
- let input_tys = input_params. iter ( ) . map ( |a| ty_of_arg ( this, & rb, a, None ) ) ;
1842
- let input_pats: Vec < String > = input_params. iter ( )
1843
- . map ( |a| pprust:: pat_to_string ( & * a. pat ) )
1844
- . collect ( ) ;
1845
- let self_and_input_tys: Vec < Ty > =
1846
- self_ty. into_iter ( ) . chain ( input_tys) . collect ( ) ;
1847
-
1809
+ let arg_tys: Vec < Ty > =
1810
+ arg_params. iter ( ) . map ( |a| ty_of_arg ( this, & rb, a, None ) ) . collect ( ) ;
1811
+ let arg_pats: Vec < String > =
1812
+ arg_params. iter ( ) . map ( |a| pprust:: pat_to_string ( & * a. pat ) ) . collect ( ) ;
1848
1813
1849
1814
// Second, if there was exactly one lifetime (either a substitution or a
1850
1815
// reference) in the arguments, then any anonymous regions in the output
1851
1816
// have that lifetime.
1852
- let implied_output_region = match implied_output_region {
1853
- Some ( r) => Ok ( r) ,
1854
- None => {
1855
- let input_tys = if self_ty. is_some ( ) {
1856
- // Skip the first argument if `self` is present.
1857
- & self_and_input_tys[ 1 ..]
1858
- } else {
1859
- & self_and_input_tys[ ..]
1860
- } ;
1861
-
1862
- find_implied_output_region ( this. tcx ( ) , input_tys, input_pats)
1863
- }
1817
+ let implied_output_region = match explicit_self_category {
1818
+ Some ( ty:: ByReferenceExplicitSelfCategory ( region, _) ) => Ok ( region) ,
1819
+ _ => find_implied_output_region ( this. tcx ( ) , & arg_tys, arg_pats)
1864
1820
} ;
1865
1821
1866
1822
let output_ty = match decl. output {
1867
- hir:: Return ( ref output) if output. node == hir:: TyInfer =>
1868
- ty:: FnConverging ( this. ty_infer ( None , None , None , output. span ) ) ,
1869
1823
hir:: Return ( ref output) =>
1870
1824
ty:: FnConverging ( convert_ty_with_lifetime_elision ( this,
1871
1825
implied_output_region,
@@ -1878,28 +1832,37 @@ fn ty_of_method_or_bare_fn<'a, 'tcx>(this: &AstConv<'tcx>,
1878
1832
unsafety : unsafety,
1879
1833
abi : abi,
1880
1834
sig : ty:: Binder ( ty:: FnSig {
1881
- inputs : self_and_input_tys ,
1835
+ inputs : self_ty . into_iter ( ) . chain ( arg_tys ) . collect ( ) ,
1882
1836
output : output_ty,
1883
1837
variadic : decl. variadic
1884
1838
} ) ,
1885
- } , explicit_self_category_result )
1839
+ } , explicit_self_category )
1886
1840
}
1887
1841
1888
- fn determine_explicit_self_category < ' a , ' tcx > ( this : & AstConv < ' tcx > ,
1889
- rscope : & RegionScope ,
1890
- self_info : & SelfInfo < ' a , ' tcx > )
1891
- -> ty:: ExplicitSelfCategory
1842
+ fn determine_self_type < ' a , ' tcx > ( this : & AstConv < ' tcx > ,
1843
+ rscope : & RegionScope ,
1844
+ self_info : SelfInfo < ' a , ' tcx > )
1845
+ -> ( Option < Ty < ' tcx > > , Option < ty:: ExplicitSelfCategory > )
1892
1846
{
1847
+ let self_ty = self_info. untransformed_self_ty ;
1893
1848
return match self_info. explicit_self . node {
1894
- hir:: SelfStatic => ty:: StaticExplicitSelfCategory ,
1895
- hir:: SelfValue ( _) => ty:: ByValueExplicitSelfCategory ,
1849
+ hir:: SelfStatic => ( None , Some ( ty:: StaticExplicitSelfCategory ) ) ,
1850
+ hir:: SelfValue ( _) => {
1851
+ ( Some ( self_ty) , Some ( ty:: ByValueExplicitSelfCategory ) )
1852
+ }
1896
1853
hir:: SelfRegion ( ref lifetime, mutability, _) => {
1897
1854
let region =
1898
1855
opt_ast_region_to_region ( this,
1899
1856
rscope,
1900
1857
self_info. explicit_self . span ,
1901
1858
lifetime) ;
1902
- ty:: ByReferenceExplicitSelfCategory ( region, mutability)
1859
+ ( Some ( this. tcx ( ) . mk_ref (
1860
+ this. tcx ( ) . mk_region ( region) ,
1861
+ ty:: TypeAndMut {
1862
+ ty : self_ty,
1863
+ mutbl : mutability
1864
+ } ) ) ,
1865
+ Some ( ty:: ByReferenceExplicitSelfCategory ( region, mutability) ) )
1903
1866
}
1904
1867
hir:: SelfExplicit ( ref ast_type, _) => {
1905
1868
let explicit_type = ast_ty_to_ty ( this, rscope, & * * ast_type) ;
@@ -1944,15 +1907,17 @@ fn determine_explicit_self_category<'a, 'tcx>(this: &AstConv<'tcx>,
1944
1907
impl_modifiers,
1945
1908
method_modifiers) ;
1946
1909
1947
- if impl_modifiers >= method_modifiers {
1910
+ let category = if impl_modifiers >= method_modifiers {
1948
1911
ty:: ByValueExplicitSelfCategory
1949
1912
} else {
1950
1913
match explicit_type. sty {
1951
1914
ty:: TyRef ( r, mt) => ty:: ByReferenceExplicitSelfCategory ( * r, mt. mutbl ) ,
1952
1915
ty:: TyBox ( _) => ty:: ByBoxExplicitSelfCategory ,
1953
1916
_ => ty:: ByValueExplicitSelfCategory ,
1954
1917
}
1955
- }
1918
+ } ;
1919
+
1920
+ ( Some ( explicit_type) , Some ( category) )
1956
1921
}
1957
1922
} ;
1958
1923
0 commit comments