@@ -37,7 +37,7 @@ use crate::hir::{self, ParamName};
37
37
use crate :: hir:: HirVec ;
38
38
use crate :: hir:: map:: { DefKey , DefPathData , Definitions } ;
39
39
use crate :: hir:: def_id:: { DefId , DefIndex , DefIndexAddressSpace , CRATE_DEF_INDEX } ;
40
- use crate :: hir:: def:: { Res , DefKind , PathResolution , PerNS } ;
40
+ use crate :: hir:: def:: { Res , DefKind , PartialRes , PerNS } ;
41
41
use crate :: hir:: { GenericArg , ConstArg } ;
42
42
use crate :: lint:: builtin:: { self , PARENTHESIZED_PARAMS_IN_TYPES_AND_MODULES ,
43
43
ELIDED_LIFETIMES_IN_PATHS } ;
@@ -145,11 +145,14 @@ pub trait Resolver {
145
145
is_value : bool ,
146
146
) -> hir:: Path ;
147
147
148
- /// Obtain the resolution for a `NodeId`.
149
- fn get_resolution ( & mut self , id : NodeId ) -> Option < PathResolution > ;
148
+ /// Obtain resolution for a `NodeId` with a single resolution .
149
+ fn get_partial_res ( & mut self , id : NodeId ) -> Option < PartialRes > ;
150
150
151
- /// Obtain the possible resolutions for the given `use` statement.
152
- fn get_import ( & mut self , id : NodeId ) -> PerNS < Option < PathResolution > > ;
151
+ /// Obtain per-namespace resolutions for `use` statement with the given `NoedId`.
152
+ fn get_import_res ( & mut self , id : NodeId ) -> PerNS < Option < Res < NodeId > > > ;
153
+
154
+ /// Obtain resolution for a label with the given `NodeId`.
155
+ fn get_label_res ( & mut self , id : NodeId ) -> Option < NodeId > ;
153
156
154
157
/// We must keep the set of definitions up to date as we add nodes that weren't in the AST.
155
158
/// This should only return `None` during testing.
@@ -821,7 +824,7 @@ impl<'a> LoweringContext<'a> {
821
824
}
822
825
823
826
fn expect_full_res ( & mut self , id : NodeId ) -> Res < NodeId > {
824
- self . resolver . get_resolution ( id) . map_or ( Res :: Err , |pr| {
827
+ self . resolver . get_partial_res ( id) . map_or ( Res :: Err , |pr| {
825
828
if pr. unresolved_segments ( ) != 0 {
826
829
bug ! ( "path not fully resolved: {:?}" , pr) ;
827
830
}
@@ -830,12 +833,7 @@ impl<'a> LoweringContext<'a> {
830
833
}
831
834
832
835
fn expect_full_res_from_use ( & mut self , id : NodeId ) -> impl Iterator < Item = Res < NodeId > > {
833
- self . resolver . get_import ( id) . present_items ( ) . map ( |pr| {
834
- if pr. unresolved_segments ( ) != 0 {
835
- bug ! ( "path not fully resolved: {:?}" , pr) ;
836
- }
837
- pr. base_res ( )
838
- } )
836
+ self . resolver . get_import_res ( id) . present_items ( )
839
837
}
840
838
841
839
fn diagnostic ( & self ) -> & errors:: Handler {
@@ -1251,7 +1249,7 @@ impl<'a> LoweringContext<'a> {
1251
1249
fn lower_loop_destination ( & mut self , destination : Option < ( NodeId , Label ) > ) -> hir:: Destination {
1252
1250
let target_id = match destination {
1253
1251
Some ( ( id, _) ) => {
1254
- if let Res :: Label ( loop_id) = self . expect_full_res ( id) {
1252
+ if let Some ( loop_id) = self . resolver . get_label_res ( id) {
1255
1253
Ok ( self . lower_node_id ( loop_id) )
1256
1254
} else {
1257
1255
Err ( hir:: LoopIdError :: UnresolvedLabel )
@@ -1842,13 +1840,13 @@ impl<'a> LoweringContext<'a> {
1842
1840
let qself_position = qself. as_ref ( ) . map ( |q| q. position ) ;
1843
1841
let qself = qself. as_ref ( ) . map ( |q| self . lower_ty ( & q. ty , itctx. reborrow ( ) ) ) ;
1844
1842
1845
- let resolution = self . resolver
1846
- . get_resolution ( id)
1847
- . unwrap_or_else ( || PathResolution :: new ( Res :: Err ) ) ;
1843
+ let partial_res = self . resolver
1844
+ . get_partial_res ( id)
1845
+ . unwrap_or_else ( || PartialRes :: new ( Res :: Err ) ) ;
1848
1846
1849
- let proj_start = p. segments . len ( ) - resolution . unresolved_segments ( ) ;
1847
+ let proj_start = p. segments . len ( ) - partial_res . unresolved_segments ( ) ;
1850
1848
let path = P ( hir:: Path {
1851
- res : self . lower_res ( resolution . base_res ( ) ) ,
1849
+ res : self . lower_res ( partial_res . base_res ( ) ) ,
1852
1850
segments : p. segments [ ..proj_start]
1853
1851
. iter ( )
1854
1852
. enumerate ( )
@@ -1869,7 +1867,7 @@ impl<'a> LoweringContext<'a> {
1869
1867
krate : def_id. krate ,
1870
1868
index : this. def_key ( def_id) . parent . expect ( "missing parent" ) ,
1871
1869
} ;
1872
- let type_def_id = match resolution . base_res ( ) {
1870
+ let type_def_id = match partial_res . base_res ( ) {
1873
1871
Res :: Def ( DefKind :: AssociatedTy , def_id) if i + 2 == proj_start => {
1874
1872
Some ( parent_def_id ( self , def_id) )
1875
1873
}
@@ -1886,7 +1884,7 @@ impl<'a> LoweringContext<'a> {
1886
1884
}
1887
1885
_ => None ,
1888
1886
} ;
1889
- let parenthesized_generic_args = match resolution . base_res ( ) {
1887
+ let parenthesized_generic_args = match partial_res . base_res ( ) {
1890
1888
// `a::b::Trait(Args)`
1891
1889
Res :: Def ( DefKind :: Trait , _)
1892
1890
if i + 1 == proj_start => ParenthesizedGenericArgs :: Ok ,
@@ -1940,7 +1938,7 @@ impl<'a> LoweringContext<'a> {
1940
1938
1941
1939
// Simple case, either no projections, or only fully-qualified.
1942
1940
// E.g., `std::mem::size_of` or `<I as Iterator>::Item`.
1943
- if resolution . unresolved_segments ( ) == 0 {
1941
+ if partial_res . unresolved_segments ( ) == 0 {
1944
1942
return hir:: QPath :: Resolved ( qself, path) ;
1945
1943
}
1946
1944
@@ -2792,7 +2790,7 @@ impl<'a> LoweringContext<'a> {
2792
2790
&& bound_pred. bound_generic_params . is_empty ( ) =>
2793
2791
{
2794
2792
if let Some ( Res :: Def ( DefKind :: TyParam , def_id) ) = self . resolver
2795
- . get_resolution ( bound_pred. bounded_ty . id )
2793
+ . get_partial_res ( bound_pred. bounded_ty . id )
2796
2794
. map ( |d| d. base_res ( ) )
2797
2795
{
2798
2796
if let Some ( node_id) =
@@ -3946,7 +3944,7 @@ impl<'a> LoweringContext<'a> {
3946
3944
let node = match p. node {
3947
3945
PatKind :: Wild => hir:: PatKind :: Wild ,
3948
3946
PatKind :: Ident ( ref binding_mode, ident, ref sub) => {
3949
- match self . resolver . get_resolution ( p. id ) . map ( |d| d. base_res ( ) ) {
3947
+ match self . resolver . get_partial_res ( p. id ) . map ( |d| d. base_res ( ) ) {
3950
3948
// `None` can occur in body-less function signatures
3951
3949
res @ None | res @ Some ( Res :: Local ( _) ) => {
3952
3950
let canonical_id = match res {
0 commit comments