@@ -37,7 +37,7 @@ use crate::hir::{self, ParamName};
3737use crate :: hir:: HirVec ;
3838use crate :: hir:: map:: { DefKey , DefPathData , Definitions } ;
3939use 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 } ;
4141use crate :: hir:: { GenericArg , ConstArg } ;
4242use crate :: lint:: builtin:: { self , PARENTHESIZED_PARAMS_IN_TYPES_AND_MODULES ,
4343 ELIDED_LIFETIMES_IN_PATHS } ;
@@ -145,11 +145,14 @@ pub trait Resolver {
145145 is_value : bool ,
146146 ) -> hir:: Path ;
147147
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 > ;
150150
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 > ;
153156
154157 /// We must keep the set of definitions up to date as we add nodes that weren't in the AST.
155158 /// This should only return `None` during testing.
@@ -821,7 +824,7 @@ impl<'a> LoweringContext<'a> {
821824 }
822825
823826 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| {
825828 if pr. unresolved_segments ( ) != 0 {
826829 bug ! ( "path not fully resolved: {:?}" , pr) ;
827830 }
@@ -830,12 +833,7 @@ impl<'a> LoweringContext<'a> {
830833 }
831834
832835 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 ( )
839837 }
840838
841839 fn diagnostic ( & self ) -> & errors:: Handler {
@@ -1251,7 +1249,7 @@ impl<'a> LoweringContext<'a> {
12511249 fn lower_loop_destination ( & mut self , destination : Option < ( NodeId , Label ) > ) -> hir:: Destination {
12521250 let target_id = match destination {
12531251 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) {
12551253 Ok ( self . lower_node_id ( loop_id) )
12561254 } else {
12571255 Err ( hir:: LoopIdError :: UnresolvedLabel )
@@ -1842,13 +1840,13 @@ impl<'a> LoweringContext<'a> {
18421840 let qself_position = qself. as_ref ( ) . map ( |q| q. position ) ;
18431841 let qself = qself. as_ref ( ) . map ( |q| self . lower_ty ( & q. ty , itctx. reborrow ( ) ) ) ;
18441842
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 ) ) ;
18481846
1849- let proj_start = p. segments . len ( ) - resolution . unresolved_segments ( ) ;
1847+ let proj_start = p. segments . len ( ) - partial_res . unresolved_segments ( ) ;
18501848 let path = P ( hir:: Path {
1851- res : self . lower_res ( resolution . base_res ( ) ) ,
1849+ res : self . lower_res ( partial_res . base_res ( ) ) ,
18521850 segments : p. segments [ ..proj_start]
18531851 . iter ( )
18541852 . enumerate ( )
@@ -1869,7 +1867,7 @@ impl<'a> LoweringContext<'a> {
18691867 krate : def_id. krate ,
18701868 index : this. def_key ( def_id) . parent . expect ( "missing parent" ) ,
18711869 } ;
1872- let type_def_id = match resolution . base_res ( ) {
1870+ let type_def_id = match partial_res . base_res ( ) {
18731871 Res :: Def ( DefKind :: AssociatedTy , def_id) if i + 2 == proj_start => {
18741872 Some ( parent_def_id ( self , def_id) )
18751873 }
@@ -1886,7 +1884,7 @@ impl<'a> LoweringContext<'a> {
18861884 }
18871885 _ => None ,
18881886 } ;
1889- let parenthesized_generic_args = match resolution . base_res ( ) {
1887+ let parenthesized_generic_args = match partial_res . base_res ( ) {
18901888 // `a::b::Trait(Args)`
18911889 Res :: Def ( DefKind :: Trait , _)
18921890 if i + 1 == proj_start => ParenthesizedGenericArgs :: Ok ,
@@ -1940,7 +1938,7 @@ impl<'a> LoweringContext<'a> {
19401938
19411939 // Simple case, either no projections, or only fully-qualified.
19421940 // E.g., `std::mem::size_of` or `<I as Iterator>::Item`.
1943- if resolution . unresolved_segments ( ) == 0 {
1941+ if partial_res . unresolved_segments ( ) == 0 {
19441942 return hir:: QPath :: Resolved ( qself, path) ;
19451943 }
19461944
@@ -2792,7 +2790,7 @@ impl<'a> LoweringContext<'a> {
27922790 && bound_pred. bound_generic_params . is_empty ( ) =>
27932791 {
27942792 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 )
27962794 . map ( |d| d. base_res ( ) )
27972795 {
27982796 if let Some ( node_id) =
@@ -3946,7 +3944,7 @@ impl<'a> LoweringContext<'a> {
39463944 let node = match p. node {
39473945 PatKind :: Wild => hir:: PatKind :: Wild ,
39483946 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 ( ) ) {
39503948 // `None` can occur in body-less function signatures
39513949 res @ None | res @ Some ( Res :: Local ( _) ) => {
39523950 let canonical_id = match res {
0 commit comments