@@ -1771,8 +1771,13 @@ impl<'a> hir::lowering::Resolver for Resolver<'a> {
1771
1771
path : & ast:: Path ,
1772
1772
is_value : bool ,
1773
1773
) -> Res {
1774
- self . resolve_ast_path_cb ( path, is_value,
1775
- |resolver, span, error| resolve_error ( resolver, span, error) )
1774
+ match self . resolve_ast_path_inner ( path, is_value) {
1775
+ Ok ( r) => r,
1776
+ Err ( ( span, error) ) => {
1777
+ resolve_error ( self , span, error) ;
1778
+ Res :: Err
1779
+ }
1780
+ }
1776
1781
}
1777
1782
1778
1783
fn resolve_str_path (
@@ -1833,8 +1838,6 @@ impl<'a> Resolver<'a> {
1833
1838
/// just that an error occurred.
1834
1839
pub fn resolve_str_path_error ( & mut self , span : Span , path_str : & str , is_value : bool )
1835
1840
-> Result < ( ast:: Path , Res ) , ( ) > {
1836
- let mut errored = false ;
1837
-
1838
1841
let path = if path_str. starts_with ( "::" ) {
1839
1842
ast:: Path {
1840
1843
span,
@@ -1855,48 +1858,38 @@ impl<'a> Resolver<'a> {
1855
1858
. collect ( ) ,
1856
1859
}
1857
1860
} ;
1858
- let res = self . resolve_ast_path_cb ( & path, is_value, |_, _, _| errored = true ) ;
1859
- if errored || res == def:: Res :: Err {
1860
- Err ( ( ) )
1861
- } else {
1862
- Ok ( ( path, res) )
1863
- }
1861
+ let res = self . resolve_ast_path_inner ( & path, is_value) . map_err ( |_| ( ) ) ?;
1862
+ Ok ( ( path, res) )
1864
1863
}
1865
1864
1866
1865
/// Like `resolve_ast_path`, but takes a callback in case there was an error.
1867
- // FIXME(eddyb) use `Result` or something instead of callbacks.
1868
- fn resolve_ast_path_cb < F > (
1866
+ fn resolve_ast_path_inner (
1869
1867
& mut self ,
1870
1868
path : & ast:: Path ,
1871
1869
is_value : bool ,
1872
- error_callback : F ,
1873
- ) -> Res
1874
- where F : for <' c , ' b > FnOnce ( & ' c mut Resolver < ' _ > , Span , ResolutionError < ' b > )
1875
- {
1870
+ ) -> Result < Res , ( Span , ResolutionError < ' a > ) > {
1876
1871
let namespace = if is_value { ValueNS } else { TypeNS } ;
1877
1872
let span = path. span ;
1878
1873
let path = Segment :: from_path ( & path) ;
1879
1874
// FIXME(Manishearth): intra-doc links won't get warned of epoch changes.
1880
1875
match self . resolve_path_without_parent_scope ( & path, Some ( namespace) , true ,
1881
1876
span, CrateLint :: No ) {
1882
1877
PathResult :: Module ( ModuleOrUniformRoot :: Module ( module) ) =>
1883
- module. res ( ) . unwrap ( ) ,
1878
+ Ok ( module. res ( ) . unwrap ( ) ) ,
1884
1879
PathResult :: NonModule ( path_res) if path_res. unresolved_segments ( ) == 0 =>
1885
- path_res. base_res ( ) ,
1880
+ Ok ( path_res. base_res ( ) ) ,
1886
1881
PathResult :: NonModule ( ..) => {
1887
- error_callback ( self , span, ResolutionError :: FailedToResolve {
1882
+ Err ( ( span, ResolutionError :: FailedToResolve {
1888
1883
label : String :: from ( "type-relative paths are not supported in this context" ) ,
1889
1884
suggestion : None ,
1890
- } ) ;
1891
- Res :: Err
1885
+ } ) )
1892
1886
}
1893
1887
PathResult :: Module ( ..) | PathResult :: Indeterminate => unreachable ! ( ) ,
1894
1888
PathResult :: Failed { span, label, suggestion, .. } => {
1895
- error_callback ( self , span, ResolutionError :: FailedToResolve {
1889
+ Err ( ( span, ResolutionError :: FailedToResolve {
1896
1890
label,
1897
1891
suggestion,
1898
- } ) ;
1899
- Res :: Err
1892
+ } ) )
1900
1893
}
1901
1894
}
1902
1895
}
0 commit comments