@@ -987,26 +987,12 @@ impl<'a, 'b> ty::DefIdTree for &'a Resolver<'b> {
987
987
/// This interface is used through the AST→HIR step, to embed full paths into the HIR. After that
988
988
/// the resolver is no longer needed as all the relevant information is inline.
989
989
impl < ' a > hir:: lowering:: Resolver for Resolver < ' a > {
990
- fn resolve_ast_path (
991
- & mut self ,
992
- path : & ast:: Path ,
993
- is_value : bool ,
994
- ) -> Res {
995
- match self . resolve_ast_path_inner ( path, is_value) {
996
- Ok ( r) => r,
997
- Err ( ( span, error) ) => {
998
- self . report_error ( span, error) ;
999
- Res :: Err
1000
- }
1001
- }
1002
- }
1003
-
1004
990
fn resolve_str_path (
1005
991
& mut self ,
1006
992
span : Span ,
1007
993
crate_root : Option < Symbol > ,
1008
994
components : & [ Symbol ] ,
1009
- is_value : bool
995
+ ns : Namespace ,
1010
996
) -> ( ast:: Path , Res ) {
1011
997
let root = if crate_root. is_some ( ) {
1012
998
kw:: PathRoot
@@ -1025,7 +1011,14 @@ impl<'a> hir::lowering::Resolver for Resolver<'a> {
1025
1011
segments,
1026
1012
} ;
1027
1013
1028
- let res = self . resolve_ast_path ( & path, is_value) ;
1014
+ let parent_scope = & self . dummy_parent_scope ( ) ;
1015
+ let res = match self . resolve_ast_path ( & path, ns, parent_scope) {
1016
+ Ok ( res) => res,
1017
+ Err ( ( span, error) ) => {
1018
+ self . report_error ( span, error) ;
1019
+ Res :: Err
1020
+ }
1021
+ } ;
1029
1022
( path, res)
1030
1023
}
1031
1024
@@ -1738,7 +1731,7 @@ impl<'a> Resolver<'a> {
1738
1731
crate_lint : CrateLint ,
1739
1732
) -> PathResult < ' a > {
1740
1733
self . resolve_path_with_ribs (
1741
- path, opt_ns, parent_scope, record_used, path_span, crate_lint, & Default :: default ( )
1734
+ path, opt_ns, parent_scope, record_used, path_span, crate_lint, None
1742
1735
)
1743
1736
}
1744
1737
@@ -1750,7 +1743,7 @@ impl<'a> Resolver<'a> {
1750
1743
record_used : bool ,
1751
1744
path_span : Span ,
1752
1745
crate_lint : CrateLint ,
1753
- ribs : & PerNS < Vec < Rib < ' a > > > ,
1746
+ ribs : Option < & PerNS < Vec < Rib < ' a > > > > ,
1754
1747
) -> PathResult < ' a > {
1755
1748
let mut module = None ;
1756
1749
let mut allow_super = true ;
@@ -1864,16 +1857,17 @@ impl<'a> Resolver<'a> {
1864
1857
self . resolve_ident_in_module (
1865
1858
module, ident, ns, parent_scope, record_used, path_span
1866
1859
)
1867
- } else if opt_ns. is_none ( ) || opt_ns == Some ( MacroNS ) {
1868
- assert ! ( ns == TypeNS ) ;
1869
- let scopes = if opt_ns. is_none ( ) { ScopeSet :: Import ( ns) } else { ScopeSet :: Module } ;
1860
+ } else if ribs. is_none ( ) || opt_ns. is_none ( ) || opt_ns == Some ( MacroNS ) {
1861
+ // FIXME: Decouple the import property from `ScopeSet`.
1862
+ let is_import = opt_ns. is_none ( ) || ns != TypeNS ;
1863
+ let scopes = if is_import { ScopeSet :: Import ( ns) } else { ScopeSet :: Module } ;
1870
1864
self . early_resolve_ident_in_lexical_scope ( ident, scopes, parent_scope, record_used,
1871
1865
record_used, path_span)
1872
1866
} else {
1873
1867
let record_used_id =
1874
1868
if record_used { crate_lint. node_id ( ) . or ( Some ( CRATE_NODE_ID ) ) } else { None } ;
1875
1869
match self . resolve_ident_in_lexical_scope (
1876
- ident, ns, parent_scope, record_used_id, path_span, & ribs[ ns]
1870
+ ident, ns, parent_scope, record_used_id, path_span, & ribs. unwrap ( ) [ ns]
1877
1871
) {
1878
1872
// we found a locally-imported or available item/module
1879
1873
Some ( LexicalScopeBinding :: Item ( binding) ) => Ok ( binding) ,
@@ -2639,8 +2633,10 @@ impl<'a> Resolver<'a> {
2639
2633
/// isn't something that can be returned because it can't be made to live that long,
2640
2634
/// and also it's a private type. Fortunately rustdoc doesn't need to know the error,
2641
2635
/// just that an error occurred.
2642
- pub fn resolve_str_path_error ( & mut self , span : Span , path_str : & str , is_value : bool )
2643
- -> Result < ( ast:: Path , Res ) , ( ) > {
2636
+ // FIXME(Manishearth): intra-doc links won't get warned of epoch changes.
2637
+ pub fn resolve_str_path_error (
2638
+ & mut self , span : Span , path_str : & str , ns : Namespace , module_id : NodeId
2639
+ ) -> Result < ( ast:: Path , Res ) , ( ) > {
2644
2640
let path = if path_str. starts_with ( "::" ) {
2645
2641
ast:: Path {
2646
2642
span,
@@ -2661,28 +2657,31 @@ impl<'a> Resolver<'a> {
2661
2657
. collect ( ) ,
2662
2658
}
2663
2659
} ;
2664
- let res = self . resolve_ast_path_inner ( & path, is_value) . map_err ( |_| ( ) ) ?;
2660
+ let module = self . block_map . get ( & module_id) . copied ( ) . unwrap_or_else ( || {
2661
+ let def_id = self . definitions . local_def_id ( module_id) ;
2662
+ self . module_map . get ( & def_id) . copied ( ) . unwrap_or ( self . graph_root )
2663
+ } ) ;
2664
+ let parent_scope = & ParentScope { module, ..self . dummy_parent_scope ( ) } ;
2665
+ let res = self . resolve_ast_path ( & path, ns, parent_scope) . map_err ( |_| ( ) ) ?;
2665
2666
Ok ( ( path, res) )
2666
2667
}
2667
2668
2668
- /// Like `resolve_ast_path`, but takes a callback in case there was an error .
2669
- fn resolve_ast_path_inner (
2669
+ // Resolve a path passed from rustdoc or HIR lowering .
2670
+ fn resolve_ast_path (
2670
2671
& mut self ,
2671
2672
path : & ast:: Path ,
2672
- is_value : bool ,
2673
+ ns : Namespace ,
2674
+ parent_scope : & ParentScope < ' a > ,
2673
2675
) -> Result < Res , ( Span , ResolutionError < ' a > ) > {
2674
- let namespace = if is_value { ValueNS } else { TypeNS } ;
2675
- let span = path. span ;
2676
- let path = Segment :: from_path ( & path) ;
2677
- // FIXME(Manishearth): intra-doc links won't get warned of epoch changes.
2678
- let parent_scope = & self . dummy_parent_scope ( ) ;
2679
- match self . resolve_path ( & path, Some ( namespace) , parent_scope, true , span, CrateLint :: No ) {
2676
+ match self . resolve_path (
2677
+ & Segment :: from_path ( path) , Some ( ns) , parent_scope, true , path. span , CrateLint :: No
2678
+ ) {
2680
2679
PathResult :: Module ( ModuleOrUniformRoot :: Module ( module) ) =>
2681
2680
Ok ( module. res ( ) . unwrap ( ) ) ,
2682
2681
PathResult :: NonModule ( path_res) if path_res. unresolved_segments ( ) == 0 =>
2683
2682
Ok ( path_res. base_res ( ) ) ,
2684
2683
PathResult :: NonModule ( ..) => {
2685
- Err ( ( span, ResolutionError :: FailedToResolve {
2684
+ Err ( ( path . span , ResolutionError :: FailedToResolve {
2686
2685
label : String :: from ( "type-relative paths are not supported in this context" ) ,
2687
2686
suggestion : None ,
2688
2687
} ) )
0 commit comments