@@ -1413,25 +1413,6 @@ impl<'a> hir::lowering::Resolver for Resolver<'a> {
1413
1413
1414
1414
fn resolve_str_path ( & mut self , span : Span , crate_root : Option < & str > ,
1415
1415
components : & [ & str ] , is_value : bool ) -> hir:: Path {
1416
- self . resolve_str_path_cb ( span, crate_root, components, is_value,
1417
- |resolver, span, error| resolve_error ( resolver, span, error) )
1418
- }
1419
-
1420
- fn get_resolution ( & mut self , id : NodeId ) -> Option < PathResolution > {
1421
- self . def_map . get ( & id) . cloned ( )
1422
- }
1423
-
1424
- fn definitions ( & mut self ) -> & mut Definitions {
1425
- & mut self . definitions
1426
- }
1427
- }
1428
-
1429
- impl < ' a > Resolver < ' a > {
1430
- /// resolve_str_path, but takes a callback in case there was an error
1431
- fn resolve_str_path_cb < F > ( & mut self , span : Span , crate_root : Option < & str > ,
1432
- components : & [ & str ] , is_value : bool , error_callback : F ) -> hir:: Path
1433
- where F : for <' b , ' c > FnOnce ( & ' c mut Resolver , Span , ResolutionError < ' b > )
1434
- {
1435
1416
use std:: iter;
1436
1417
let mut path = hir:: Path {
1437
1418
span,
@@ -1441,19 +1422,45 @@ impl<'a> Resolver<'a> {
1441
1422
} ) . map ( hir:: PathSegment :: from_name) . collect ( ) ,
1442
1423
} ;
1443
1424
1444
- self . resolve_hir_path_cb ( & mut path, is_value, error_callback ) ;
1425
+ self . resolve_hir_path ( & mut path, is_value) ;
1445
1426
path
1446
1427
}
1447
1428
1429
+ fn get_resolution ( & mut self , id : NodeId ) -> Option < PathResolution > {
1430
+ self . def_map . get ( & id) . cloned ( )
1431
+ }
1432
+
1433
+ fn definitions ( & mut self ) -> & mut Definitions {
1434
+ & mut self . definitions
1435
+ }
1436
+ }
1437
+
1438
+ impl < ' a > Resolver < ' a > {
1448
1439
/// Rustdoc uses this to resolve things in a recoverable way. ResolutionError<'a>
1449
1440
/// isn't something that can be returned because it can't be made to live that long,
1450
1441
/// and also it's a private type. Fortunately rustdoc doesn't need to know the error,
1451
1442
/// just that an error occured.
1452
- pub fn resolve_str_path_error ( & mut self , span : Span , crate_root : Option < & str > ,
1453
- components : & [ & str ] , is_value : bool ) -> Result < hir :: Path , ( ) > {
1443
+ pub fn resolve_str_path_error ( & mut self , span : Span , path_str : & str , is_value : bool ) -> Result < hir :: Path , ( ) > {
1444
+ use std :: iter ;
1454
1445
let mut errored = false ;
1455
- let path = self . resolve_str_path_cb ( span, crate_root, components, is_value,
1456
- |_, _, _| errored = true ) ;
1446
+
1447
+ let mut path = if path_str. starts_with ( "::" ) {
1448
+ hir:: Path {
1449
+ span,
1450
+ def : Def :: Err ,
1451
+ segments : iter:: once ( keywords:: CrateRoot . name ( ) ) . chain ( {
1452
+ path_str. split ( "::" ) . skip ( 1 ) . map ( Symbol :: intern)
1453
+ } ) . map ( hir:: PathSegment :: from_name) . collect ( ) ,
1454
+ }
1455
+ } else {
1456
+ hir:: Path {
1457
+ span,
1458
+ def : Def :: Err ,
1459
+ segments : path_str. split ( "::" ) . map ( Symbol :: intern)
1460
+ . map ( hir:: PathSegment :: from_name) . collect ( ) ,
1461
+ }
1462
+ } ;
1463
+ self . resolve_hir_path_cb ( & mut path, is_value, |_, _, _| errored = true ) ;
1457
1464
if errored || path. def == Def :: Err {
1458
1465
Err ( ( ) )
1459
1466
} else {
@@ -1874,8 +1881,8 @@ impl<'a> Resolver<'a> {
1874
1881
// generate a fake "implementation scope" containing all the
1875
1882
// implementations thus found, for compatibility with old resolve pass.
1876
1883
1877
- fn with_scope < F > ( & mut self , id : NodeId , f : F )
1878
- where F : FnOnce ( & mut Resolver )
1884
+ pub fn with_scope < F , T > ( & mut self , id : NodeId , f : F ) -> T
1885
+ where F : FnOnce ( & mut Resolver ) -> T
1879
1886
{
1880
1887
let id = self . definitions . local_def_id ( id) ;
1881
1888
let module = self . module_map . get ( & id) . cloned ( ) ; // clones a reference
@@ -1886,13 +1893,14 @@ impl<'a> Resolver<'a> {
1886
1893
self . ribs [ TypeNS ] . push ( Rib :: new ( ModuleRibKind ( module) ) ) ;
1887
1894
1888
1895
self . finalize_current_module_macro_resolutions ( ) ;
1889
- f ( self ) ;
1896
+ let ret = f ( self ) ;
1890
1897
1891
1898
self . current_module = orig_module;
1892
1899
self . ribs [ ValueNS ] . pop ( ) ;
1893
1900
self . ribs [ TypeNS ] . pop ( ) ;
1901
+ ret
1894
1902
} else {
1895
- f ( self ) ;
1903
+ f ( self )
1896
1904
}
1897
1905
}
1898
1906
0 commit comments