@@ -149,12 +149,8 @@ pub trait Resolver {
149
149
/// Resolve a hir path generated by the lowerer when expanding `for`, `if let`, etc.
150
150
fn resolve_hir_path ( & mut self , path : & mut hir:: Path , is_value : bool ) ;
151
151
152
- /// Obtain the resolution for a node id. Prefers resolutions in Types, then Values, then
153
- /// Macros.
154
- fn get_resolution ( & mut self , id : NodeId ) -> Option < PathResolution > ;
155
-
156
152
/// Obtain resolutions for the given node id in all namespaces.
157
- fn get_all_resolutions ( & mut self , id : NodeId ) -> PerNS < Option < PathResolution > > ;
153
+ fn get_resolutions ( & mut self , id : NodeId ) -> PerNS < Option < PathResolution > > ;
158
154
159
155
/// We must keep the set of definitions up to date as we add nodes that weren't in the AST.
160
156
/// This should only return `None` during testing.
@@ -566,19 +562,8 @@ impl<'a> LoweringContext<'a> {
566
562
self . lower_node_id ( self . sess . next_node_id ( ) )
567
563
}
568
564
569
- fn expect_full_def ( & mut self , id : NodeId ) -> Def {
570
- //FIXME: this grabs the first valid resolution - should all users of this function ask for
571
- //a specific namespace?
572
- self . resolver . get_resolution ( id) . map_or ( Def :: Err , |pr| {
573
- if pr. unresolved_segments ( ) != 0 {
574
- bug ! ( "path not fully resolved: {:?}" , pr) ;
575
- }
576
- pr. base_def ( )
577
- } )
578
- }
579
-
580
- fn expect_full_def_per_ns ( & mut self , id : NodeId ) -> PerNS < Def > {
581
- self . resolver . get_all_resolutions ( id) . map ( |res| res. map_or ( Def :: Err , |pr| {
565
+ fn expect_full_defs ( & mut self , id : NodeId ) -> PerNS < Def > {
566
+ self . resolver . get_resolutions ( id) . map ( |res| res. map_or ( Def :: Err , |pr| {
582
567
if pr. unresolved_segments ( ) != 0 {
583
568
bug ! ( "path not fully resolved: {:?}" , pr) ;
584
569
}
@@ -935,11 +920,12 @@ impl<'a> LoweringContext<'a> {
935
920
fn lower_loop_destination ( & mut self , destination : Option < ( NodeId , Label ) > ) -> hir:: Destination {
936
921
match destination {
937
922
Some ( ( id, label) ) => {
938
- let target_id = if let Def :: Label ( loop_id) = self . expect_full_def ( id) {
939
- Ok ( self . lower_node_id ( loop_id) . node_id )
940
- } else {
941
- Err ( hir:: LoopIdError :: UnresolvedLabel )
942
- } ;
923
+ let target_id =
924
+ if let Def :: Label ( loop_id) = self . expect_full_defs ( id) . value_ns {
925
+ Ok ( self . lower_node_id ( loop_id) . node_id )
926
+ } else {
927
+ Err ( hir:: LoopIdError :: UnresolvedLabel )
928
+ } ;
943
929
hir:: Destination {
944
930
label : self . lower_label ( Some ( label) ) ,
945
931
target_id,
@@ -1085,7 +1071,7 @@ impl<'a> LoweringContext<'a> {
1085
1071
TyKind :: ImplicitSelf => hir:: TyPath ( hir:: QPath :: Resolved (
1086
1072
None ,
1087
1073
P ( hir:: Path {
1088
- defs : self . expect_full_def_per_ns ( t. id ) ,
1074
+ defs : self . expect_full_defs ( t. id ) ,
1089
1075
segments : hir_vec ! [ hir:: PathSegment :: from_name( keywords:: SelfType . name( ) ) ] ,
1090
1076
span : t. span ,
1091
1077
} ) ,
@@ -1395,12 +1381,15 @@ impl<'a> LoweringContext<'a> {
1395
1381
let qself = qself. as_ref ( ) . map ( |q| self . lower_ty ( & q. ty , itctx) ) ;
1396
1382
1397
1383
let resolutions = self . resolver
1398
- . get_all_resolutions ( id)
1384
+ . get_resolutions ( id)
1399
1385
. map ( |res| res. unwrap_or ( PathResolution :: new ( Def :: Err ) ) ) ;
1400
1386
1401
- //FIXME(misdreavus): when constructing the segments below, the code assumes only one
1402
- //resolution/def
1403
- let first_res = self . resolver . get_resolution ( id) . unwrap_or ( PathResolution :: new ( Def :: Err ) ) ;
1387
+ assert ! ( resolutions. into_iter( ) . filter( |pr| pr. base_def( ) != Def :: Err ) . count( ) <= 1 ,
1388
+ "attempting to lower a QPath resolving to more than one Def: {:?} {:?}" , id, p) ;
1389
+
1390
+ let first_res = resolutions. into_iter ( )
1391
+ . find ( |pr| pr. base_def ( ) != Def :: Err )
1392
+ . unwrap_or ( PathResolution :: new ( Def :: Err ) ) ;
1404
1393
1405
1394
let proj_start = p. segments . len ( ) - first_res. unresolved_segments ( ) ;
1406
1395
let path = P ( hir:: Path {
@@ -1557,7 +1546,7 @@ impl<'a> LoweringContext<'a> {
1557
1546
param_mode : ParamMode ,
1558
1547
) -> hir:: Path {
1559
1548
hir:: Path {
1560
- defs : self . expect_full_def_per_ns ( id) ,
1549
+ defs : self . expect_full_defs ( id) ,
1561
1550
segments : p. segments
1562
1551
. iter ( )
1563
1552
. map ( |segment| {
@@ -1950,7 +1939,8 @@ impl<'a> LoweringContext<'a> {
1950
1939
&& bound_pred. bound_generic_params . is_empty ( ) =>
1951
1940
{
1952
1941
if let Some ( Def :: TyParam ( def_id) ) = self . resolver
1953
- . get_resolution ( bound_pred. bounded_ty . id )
1942
+ . get_resolutions ( bound_pred. bounded_ty . id )
1943
+ . type_ns
1954
1944
. map ( |d| d. base_def ( ) )
1955
1945
{
1956
1946
if let Some ( node_id) =
@@ -2836,10 +2826,11 @@ impl<'a> LoweringContext<'a> {
2836
2826
let node = match p. node {
2837
2827
PatKind :: Wild => hir:: PatKind :: Wild ,
2838
2828
PatKind :: Ident ( ref binding_mode, ident, ref sub) => {
2839
- match self . resolver . get_resolution ( p. id ) . map ( |d| d. base_def ( ) ) {
2829
+ match self . resolver . get_resolutions ( p. id ) . map ( |d| d. map ( |d| d . base_def ( ) ) ) {
2840
2830
// `None` can occur in body-less function signatures
2841
- def @ None | def @ Some ( Def :: Local ( _) ) => {
2842
- let canonical_id = match def {
2831
+ defs @ PerNS { value_ns : None , .. } |
2832
+ defs @ PerNS { value_ns : Some ( Def :: Local ( _) ) , .. } => {
2833
+ let canonical_id = match defs. value_ns {
2843
2834
Some ( Def :: Local ( id) ) => id,
2844
2835
_ => p. id ,
2845
2836
} ;
@@ -2850,11 +2841,11 @@ impl<'a> LoweringContext<'a> {
2850
2841
sub. as_ref ( ) . map ( |x| self . lower_pat ( x) ) ,
2851
2842
)
2852
2843
}
2853
- Some ( def ) => hir:: PatKind :: Path ( hir:: QPath :: Resolved (
2844
+ defs => hir:: PatKind :: Path ( hir:: QPath :: Resolved (
2854
2845
None ,
2855
2846
P ( hir:: Path {
2856
2847
span : ident. span ,
2857
- defs : def . into ( ) ,
2848
+ defs : defs . map ( |d| d . unwrap_or ( Def :: Err ) ) ,
2858
2849
segments : hir_vec ! [ hir:: PathSegment :: from_name( ident. name) ] ,
2859
2850
} ) ,
2860
2851
) ) ,
0 commit comments