-
Notifications
You must be signed in to change notification settings - Fork 13.4k
Replace error callback with Result #63286
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -1771,8 +1771,13 @@ impl<'a> hir::lowering::Resolver for Resolver<'a> { | |
path: &ast::Path, | ||
is_value: bool, | ||
) -> Res { | ||
self.resolve_ast_path_cb(path, is_value, | ||
|resolver, span, error| resolve_error(resolver, span, error)) | ||
match self.resolve_ast_path_inner(path, is_value) { | ||
Ok(r) => r, | ||
Err((span, error)) => { | ||
resolve_error(self, span, error); | ||
Res::Err | ||
} | ||
} | ||
} | ||
|
||
fn resolve_str_path( | ||
|
@@ -1833,8 +1838,6 @@ impl<'a> Resolver<'a> { | |
/// just that an error occurred. | ||
pub fn resolve_str_path_error(&mut self, span: Span, path_str: &str, is_value: bool) | ||
-> Result<(ast::Path, Res), ()> { | ||
let mut errored = false; | ||
|
||
let path = if path_str.starts_with("::") { | ||
ast::Path { | ||
span, | ||
|
@@ -1855,48 +1858,46 @@ impl<'a> Resolver<'a> { | |
.collect(), | ||
} | ||
}; | ||
let res = self.resolve_ast_path_cb(&path, is_value, |_, _, _| errored = true); | ||
if errored || res == def::Res::Err { | ||
Err(()) | ||
} else { | ||
Ok((path, res)) | ||
match self.resolve_ast_path_inner(&path, is_value) { | ||
Ok(res) => { | ||
if res == Res::Err { | ||
Err(()) | ||
} else { | ||
Ok((path, res)) | ||
} | ||
} | ||
Err(_) => Err(()), | ||
} | ||
} | ||
|
||
/// Like `resolve_ast_path`, but takes a callback in case there was an error. | ||
// FIXME(eddyb) use `Result` or something instead of callbacks. | ||
fn resolve_ast_path_cb<F>( | ||
fn resolve_ast_path_inner( | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The comment wasn't updated. But other than that I'm really happy the callback is gone! There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think it was lost in a rebase. I've added to my todo list to check if it's been removed after some of the resolver refactorings land so I don't cause merge conflicts and such. |
||
&mut self, | ||
path: &ast::Path, | ||
is_value: bool, | ||
error_callback: F, | ||
) -> Res | ||
where F: for<'c, 'b> FnOnce(&'c mut Resolver<'_>, Span, ResolutionError<'b>) | ||
{ | ||
) -> Result<Res, (Span, ResolutionError<'a>)> { | ||
let namespace = if is_value { ValueNS } else { TypeNS }; | ||
let span = path.span; | ||
let path = Segment::from_path(&path); | ||
// FIXME(Manishearth): intra-doc links won't get warned of epoch changes. | ||
match self.resolve_path_without_parent_scope(&path, Some(namespace), true, | ||
span, CrateLint::No) { | ||
PathResult::Module(ModuleOrUniformRoot::Module(module)) => | ||
module.res().unwrap(), | ||
Ok(module.res().unwrap()), | ||
PathResult::NonModule(path_res) if path_res.unresolved_segments() == 0 => | ||
path_res.base_res(), | ||
Ok(path_res.base_res()), | ||
PathResult::NonModule(..) => { | ||
error_callback(self, span, ResolutionError::FailedToResolve { | ||
Err((span, ResolutionError::FailedToResolve { | ||
label: String::from("type-relative paths are not supported in this context"), | ||
suggestion: None, | ||
}); | ||
Res::Err | ||
})) | ||
} | ||
PathResult::Module(..) | PathResult::Indeterminate => unreachable!(), | ||
PathResult::Failed { span, label, suggestion, .. } => { | ||
error_callback(self, span, ResolutionError::FailedToResolve { | ||
Err((span, ResolutionError::FailedToResolve { | ||
label, | ||
suggestion, | ||
}); | ||
Res::Err | ||
})) | ||
} | ||
} | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Although, I'd rather remove this condition (and then use
?
).If the function returns
Res
, then rustdoc should be ready to deal withRes::Err
as well.