1
Fork 0

Move Error and RenderInfo out of html module

This commit is contained in:
Joseph Ryan 2020-06-15 13:42:29 -05:00
parent efc02b03d1
commit c692ed468c
No known key found for this signature in database
GPG key ID: 1A89B54043BBCCBD
7 changed files with 85 additions and 71 deletions

View file

@ -30,9 +30,8 @@ use std::cell::{Cell, RefCell};
use std::cmp::Ordering;
use std::collections::{BTreeMap, VecDeque};
use std::default::Default;
use std::error;
use std::ffi::OsStr;
use std::fmt::{self, Formatter, Write};
use std::fmt::{self, Write};
use std::fs::{self, File};
use std::io::prelude::*;
use std::io::{self, BufReader};
@ -50,7 +49,6 @@ use rustc_feature::UnstableFeatures;
use rustc_hir as hir;
use rustc_hir::def_id::{DefId, LOCAL_CRATE};
use rustc_hir::Mutability;
use rustc_middle::middle::privacy::AccessLevels;
use rustc_middle::middle::stability;
use rustc_span::edition::Edition;
use rustc_span::hygiene::MacroKind;
@ -60,9 +58,11 @@ use serde::ser::SerializeSeq;
use serde::{Serialize, Serializer};
use crate::clean::{self, AttributesExt, Deprecation, GetDefId, SelfTy, TypeKind};
use crate::config::{OutputFormat, RenderOptions};
use crate::config::RenderInfo;
use crate::config::RenderOptions;
use crate::docfs::{DocFS, ErrorStorage, PathError};
use crate::doctree;
use crate::error::Error;
use crate::html::escape::Escape;
use crate::html::format::fmt_impl_for_trait_page;
use crate::html::format::Function;
@ -90,55 +90,6 @@ crate fn ensure_trailing_slash(v: &str) -> impl fmt::Display + '_ {
})
}
#[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 {
fn new<S, P: AsRef<Path>>(e: S, path: P) -> Error
where
S: ToString + Sized,
{
Error { file: path.as_ref().to_path_buf(), error: e.to_string() }
}
}
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_rules! try_err {
($e:expr, $file:expr) => {{
match $e {
Ok(e) => e,
Err(e) => return Err(Error::new(e, $file)),
}
}};
}
/// Major driving force in all rustdoc rendering. This contains information
/// about where in the tree-like hierarchy rendering is occurring and controls
/// how the current page is being rendered.
@ -260,20 +211,6 @@ impl Impl {
}
}
/// Temporary storage for data obtained during `RustdocVisitor::clean()`.
/// Later on moved into `CACHE_KEY`.
#[derive(Default)]
pub struct RenderInfo {
pub inlined: FxHashSet<DefId>,
pub external_paths: crate::core::ExternalPaths,
pub exact_paths: FxHashMap<DefId, Vec<String>>,
pub access_levels: AccessLevels<DefId>,
pub deref_trait_did: Option<DefId>,
pub deref_mut_trait_did: Option<DefId>,
pub owned_box_did: Option<DefId>,
pub output_format: Option<OutputFormat>,
}
// Helper structs for rendering items/sidebars and carrying along contextual
// information