@@ -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,46 @@ 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) )
1861
+ match self . resolve_ast_path_inner ( & path, is_value) {
1862
+ Ok ( res) => {
1863
+ if res == Res :: Err {
1864
+ Err ( ( ) )
1865
+ } else {
1866
+ Ok ( ( path, res) )
1867
+ }
1868
+ }
1869
+ Err ( _) => Err ( ( ) ) ,
1863
1870
}
1864
1871
}
1865
1872
1866
1873
/// 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 > (
1874
+ fn resolve_ast_path_inner (
1869
1875
& mut self ,
1870
1876
path : & ast:: Path ,
1871
1877
is_value : bool ,
1872
- error_callback : F ,
1873
- ) -> Res
1874
- where F : for <' c , ' b > FnOnce ( & ' c mut Resolver < ' _ > , Span , ResolutionError < ' b > )
1875
- {
1878
+ ) -> Result < Res , ( Span , ResolutionError < ' a > ) > {
1876
1879
let namespace = if is_value { ValueNS } else { TypeNS } ;
1877
1880
let span = path. span ;
1878
1881
let path = Segment :: from_path ( & path) ;
1879
1882
// FIXME(Manishearth): intra-doc links won't get warned of epoch changes.
1880
1883
match self . resolve_path_without_parent_scope ( & path, Some ( namespace) , true ,
1881
1884
span, CrateLint :: No ) {
1882
1885
PathResult :: Module ( ModuleOrUniformRoot :: Module ( module) ) =>
1883
- module. res ( ) . unwrap ( ) ,
1886
+ Ok ( module. res ( ) . unwrap ( ) ) ,
1884
1887
PathResult :: NonModule ( path_res) if path_res. unresolved_segments ( ) == 0 =>
1885
- path_res. base_res ( ) ,
1888
+ Ok ( path_res. base_res ( ) ) ,
1886
1889
PathResult :: NonModule ( ..) => {
1887
- error_callback ( self , span, ResolutionError :: FailedToResolve {
1890
+ Err ( ( span, ResolutionError :: FailedToResolve {
1888
1891
label : String :: from ( "type-relative paths are not supported in this context" ) ,
1889
1892
suggestion : None ,
1890
- } ) ;
1891
- Res :: Err
1893
+ } ) )
1892
1894
}
1893
1895
PathResult :: Module ( ..) | PathResult :: Indeterminate => unreachable ! ( ) ,
1894
1896
PathResult :: Failed { span, label, suggestion, .. } => {
1895
- error_callback ( self , span, ResolutionError :: FailedToResolve {
1897
+ Err ( ( span, ResolutionError :: FailedToResolve {
1896
1898
label,
1897
1899
suggestion,
1898
- } ) ;
1899
- Res :: Err
1900
+ } ) )
1900
1901
}
1901
1902
}
1902
1903
}
0 commit comments