-
Notifications
You must be signed in to change notification settings - Fork 13.5k
Refactor librustdoc html backend #73767
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 8 commits
c692ed4
5bc9794
6a4396b
a790952
65bf5d5
3d707a0
cee8023
7621a5b
29df050
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 |
---|---|---|
@@ -0,0 +1,56 @@ | ||
use std::error; | ||
use std::fmt::{self, Formatter}; | ||
use std::path::{Path, PathBuf}; | ||
|
||
use crate::docfs::PathError; | ||
|
||
#[derive(Debug)] | ||
pub struct Error { | ||
pub file: PathBuf, | ||
pub error: String, | ||
} | ||
|
||
impl error::Error for Error {} | ||
|
||
impl std::fmt::Display for Error { | ||
fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result { | ||
let file = self.file.display().to_string(); | ||
if file.is_empty() { | ||
write!(f, "{}", self.error) | ||
} else { | ||
write!(f, "\"{}\": {}", self.file.display(), self.error) | ||
} | ||
} | ||
} | ||
|
||
impl PathError for Error { | ||
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. Pre-existing, but do you know why rustdoc uses a separate error type and trait here? It has wrappers around both |
||
fn new<S, P: AsRef<Path>>(e: S, path: P) -> Error | ||
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. Pre-existing, but this would be better taking |
||
where | ||
S: ToString + Sized, | ||
{ | ||
Error { file: path.as_ref().to_path_buf(), error: e.to_string() } | ||
} | ||
} | ||
|
||
#[macro_export] | ||
macro_rules! try_none { | ||
($e:expr, $file:expr) => {{ | ||
use std::io; | ||
match $e { | ||
Some(e) => e, | ||
None => { | ||
return Err(Error::new(io::Error::new(io::ErrorKind::Other, "not found"), $file)); | ||
} | ||
} | ||
}}; | ||
} | ||
|
||
#[macro_export] | ||
macro_rules! try_err { | ||
($e:expr, $file:expr) => {{ | ||
match $e { | ||
Ok(e) => e, | ||
Err(e) => return Err(Error::new(e, $file)), | ||
} | ||
}}; | ||
} |
Uh oh!
There was an error while loading. Please reload this page.