Skip to content

Commit 18130ef

Browse files
Replace error callback with Result
1 parent 4be0675 commit 18130ef

File tree

1 file changed

+24
-23
lines changed

1 file changed

+24
-23
lines changed

Diff for: src/librustc_resolve/lib.rs

+24-23
Original file line numberDiff line numberDiff line change
@@ -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,46 @@ 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))
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(()),
18631870
}
18641871
}
18651872

18661873
/// 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(
18691875
&mut self,
18701876
path: &ast::Path,
18711877
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>)> {
18761879
let namespace = if is_value { ValueNS } else { TypeNS };
18771880
let span = path.span;
18781881
let path = Segment::from_path(&path);
18791882
// FIXME(Manishearth): intra-doc links won't get warned of epoch changes.
18801883
match self.resolve_path_without_parent_scope(&path, Some(namespace), true,
18811884
span, CrateLint::No) {
18821885
PathResult::Module(ModuleOrUniformRoot::Module(module)) =>
1883-
module.res().unwrap(),
1886+
Ok(module.res().unwrap()),
18841887
PathResult::NonModule(path_res) if path_res.unresolved_segments() == 0 =>
1885-
path_res.base_res(),
1888+
Ok(path_res.base_res()),
18861889
PathResult::NonModule(..) => {
1887-
error_callback(self, span, ResolutionError::FailedToResolve {
1890+
Err((span, ResolutionError::FailedToResolve {
18881891
label: String::from("type-relative paths are not supported in this context"),
18891892
suggestion: None,
1890-
});
1891-
Res::Err
1893+
}))
18921894
}
18931895
PathResult::Module(..) | PathResult::Indeterminate => unreachable!(),
18941896
PathResult::Failed { span, label, suggestion, .. } => {
1895-
error_callback(self, span, ResolutionError::FailedToResolve {
1897+
Err((span, ResolutionError::FailedToResolve {
18961898
label,
18971899
suggestion,
1898-
});
1899-
Res::Err
1900+
}))
19001901
}
19011902
}
19021903
}

0 commit comments

Comments
 (0)