Skip to content

Commit 949b49a

Browse files
authored
Rollup merge of #63286 - Mark-Simulacrum:resolve-no-cb, r=petrochenkov
Replace error callback with Result r? @petrochenkov
2 parents a389521 + 3cd7f08 commit 949b49a

File tree

2 files changed

+24
-24
lines changed

2 files changed

+24
-24
lines changed

Diff for: src/librustc_resolve/lib.rs

+17-24
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,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
}

Diff for: src/librustdoc/passes/collect_intra_doc_links.rs

+7
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,10 @@ impl<'a, 'tcx> LinkCollector<'a, 'tcx> {
7171
resolver.resolve_str_path_error(DUMMY_SP, &path_str, ns == ValueNS)
7272
})
7373
});
74+
let result = match result {
75+
Ok((_, Res::Err)) => Err(()),
76+
_ => result,
77+
};
7478

7579
if let Ok((_, res)) = result {
7680
let res = res.map_id(|_| panic!("unexpected node_id"));
@@ -134,6 +138,9 @@ impl<'a, 'tcx> LinkCollector<'a, 'tcx> {
134138
let (_, ty_res) = cx.enter_resolver(|resolver| resolver.with_scope(node_id, |resolver| {
135139
resolver.resolve_str_path_error(DUMMY_SP, &path, false)
136140
}))?;
141+
if let Res::Err = ty_res {
142+
return Err(());
143+
}
137144
let ty_res = ty_res.map_id(|_| panic!("unexpected node_id"));
138145
match ty_res {
139146
Res::Def(DefKind::Struct, did)

0 commit comments

Comments
 (0)