@@ -1771,8 +1771,13 @@ impl<'a> hir::lowering::Resolver for Resolver<'a> {
17711771 path : & ast:: Path ,
17721772 is_value : bool ,
17731773 ) -> 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+ }
17761781 }
17771782
17781783 fn resolve_str_path (
@@ -1833,8 +1838,6 @@ impl<'a> Resolver<'a> {
18331838 /// just that an error occurred.
18341839 pub fn resolve_str_path_error ( & mut self , span : Span , path_str : & str , is_value : bool )
18351840 -> Result < ( ast:: Path , Res ) , ( ) > {
1836- let mut errored = false ;
1837-
18381841 let path = if path_str. starts_with ( "::" ) {
18391842 ast:: Path {
18401843 span,
@@ -1855,48 +1858,38 @@ impl<'a> Resolver<'a> {
18551858 . collect ( ) ,
18561859 }
18571860 } ;
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) )
18641863 }
18651864
18661865 /// 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 (
18691867 & mut self ,
18701868 path : & ast:: Path ,
18711869 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 > ) > {
18761871 let namespace = if is_value { ValueNS } else { TypeNS } ;
18771872 let span = path. span ;
18781873 let path = Segment :: from_path ( & path) ;
18791874 // FIXME(Manishearth): intra-doc links won't get warned of epoch changes.
18801875 match self . resolve_path_without_parent_scope ( & path, Some ( namespace) , true ,
18811876 span, CrateLint :: No ) {
18821877 PathResult :: Module ( ModuleOrUniformRoot :: Module ( module) ) =>
1883- module. res ( ) . unwrap ( ) ,
1878+ Ok ( module. res ( ) . unwrap ( ) ) ,
18841879 PathResult :: NonModule ( path_res) if path_res. unresolved_segments ( ) == 0 =>
1885- path_res. base_res ( ) ,
1880+ Ok ( path_res. base_res ( ) ) ,
18861881 PathResult :: NonModule ( ..) => {
1887- error_callback ( self , span, ResolutionError :: FailedToResolve {
1882+ Err ( ( span, ResolutionError :: FailedToResolve {
18881883 label : String :: from ( "type-relative paths are not supported in this context" ) ,
18891884 suggestion : None ,
1890- } ) ;
1891- Res :: Err
1885+ } ) )
18921886 }
18931887 PathResult :: Module ( ..) | PathResult :: Indeterminate => unreachable ! ( ) ,
18941888 PathResult :: Failed { span, label, suggestion, .. } => {
1895- error_callback ( self , span, ResolutionError :: FailedToResolve {
1889+ Err ( ( span, ResolutionError :: FailedToResolve {
18961890 label,
18971891 suggestion,
1898- } ) ;
1899- Res :: Err
1892+ } ) )
19001893 }
19011894 }
19021895 }
0 commit comments