Move Error
and RenderInfo
out of html
module
This commit is contained in:
parent
efc02b03d1
commit
c692ed468c
7 changed files with 85 additions and 71 deletions
|
@ -4,6 +4,9 @@ use std::ffi::OsStr;
|
||||||
use std::fmt;
|
use std::fmt;
|
||||||
use std::path::PathBuf;
|
use std::path::PathBuf;
|
||||||
|
|
||||||
|
use rustc_data_structures::fx::{FxHashMap, FxHashSet};
|
||||||
|
use rustc_hir::def_id::DefId;
|
||||||
|
use rustc_middle::middle::privacy::AccessLevels;
|
||||||
use rustc_session::config::{self, parse_crate_types_from_list, parse_externs, CrateType};
|
use rustc_session::config::{self, parse_crate_types_from_list, parse_externs, CrateType};
|
||||||
use rustc_session::config::{
|
use rustc_session::config::{
|
||||||
build_codegen_options, build_debugging_options, get_cmd_lint_options, host_triple,
|
build_codegen_options, build_debugging_options, get_cmd_lint_options, host_triple,
|
||||||
|
@ -249,6 +252,20 @@ pub struct RenderOptions {
|
||||||
pub document_hidden: bool,
|
pub document_hidden: bool,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// 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>,
|
||||||
|
}
|
||||||
|
|
||||||
impl Options {
|
impl Options {
|
||||||
/// Parses the given command-line for options. If an error message or other early-return has
|
/// Parses the given command-line for options. If an error message or other early-return has
|
||||||
/// been printed, returns `Err` with the exit code.
|
/// been printed, returns `Err` with the exit code.
|
||||||
|
|
|
@ -32,8 +32,8 @@ use std::rc::Rc;
|
||||||
|
|
||||||
use crate::clean;
|
use crate::clean;
|
||||||
use crate::clean::{AttributesExt, MAX_DEF_ID};
|
use crate::clean::{AttributesExt, MAX_DEF_ID};
|
||||||
|
use crate::config::RenderInfo;
|
||||||
use crate::config::{Options as RustdocOptions, RenderOptions};
|
use crate::config::{Options as RustdocOptions, RenderOptions};
|
||||||
use crate::html::render::RenderInfo;
|
|
||||||
use crate::passes::{self, Condition::*, ConditionalPass};
|
use crate::passes::{self, Condition::*, ConditionalPass};
|
||||||
|
|
||||||
pub use rustc_session::config::{CodegenOptions, DebuggingOptions, Input, Options};
|
pub use rustc_session::config::{CodegenOptions, DebuggingOptions, Input, Options};
|
||||||
|
|
56
src/librustdoc/error.rs
Normal file
56
src/librustdoc/error.rs
Normal file
|
@ -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 {
|
||||||
|
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_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)),
|
||||||
|
}
|
||||||
|
}};
|
||||||
|
}
|
|
@ -30,9 +30,8 @@ use std::cell::{Cell, RefCell};
|
||||||
use std::cmp::Ordering;
|
use std::cmp::Ordering;
|
||||||
use std::collections::{BTreeMap, VecDeque};
|
use std::collections::{BTreeMap, VecDeque};
|
||||||
use std::default::Default;
|
use std::default::Default;
|
||||||
use std::error;
|
|
||||||
use std::ffi::OsStr;
|
use std::ffi::OsStr;
|
||||||
use std::fmt::{self, Formatter, Write};
|
use std::fmt::{self, Write};
|
||||||
use std::fs::{self, File};
|
use std::fs::{self, File};
|
||||||
use std::io::prelude::*;
|
use std::io::prelude::*;
|
||||||
use std::io::{self, BufReader};
|
use std::io::{self, BufReader};
|
||||||
|
@ -50,7 +49,6 @@ use rustc_feature::UnstableFeatures;
|
||||||
use rustc_hir as hir;
|
use rustc_hir as hir;
|
||||||
use rustc_hir::def_id::{DefId, LOCAL_CRATE};
|
use rustc_hir::def_id::{DefId, LOCAL_CRATE};
|
||||||
use rustc_hir::Mutability;
|
use rustc_hir::Mutability;
|
||||||
use rustc_middle::middle::privacy::AccessLevels;
|
|
||||||
use rustc_middle::middle::stability;
|
use rustc_middle::middle::stability;
|
||||||
use rustc_span::edition::Edition;
|
use rustc_span::edition::Edition;
|
||||||
use rustc_span::hygiene::MacroKind;
|
use rustc_span::hygiene::MacroKind;
|
||||||
|
@ -60,9 +58,11 @@ use serde::ser::SerializeSeq;
|
||||||
use serde::{Serialize, Serializer};
|
use serde::{Serialize, Serializer};
|
||||||
|
|
||||||
use crate::clean::{self, AttributesExt, Deprecation, GetDefId, SelfTy, TypeKind};
|
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::docfs::{DocFS, ErrorStorage, PathError};
|
||||||
use crate::doctree;
|
use crate::doctree;
|
||||||
|
use crate::error::Error;
|
||||||
use crate::html::escape::Escape;
|
use crate::html::escape::Escape;
|
||||||
use crate::html::format::fmt_impl_for_trait_page;
|
use crate::html::format::fmt_impl_for_trait_page;
|
||||||
use crate::html::format::Function;
|
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
|
/// Major driving force in all rustdoc rendering. This contains information
|
||||||
/// about where in the tree-like hierarchy rendering is occurring and controls
|
/// about where in the tree-like hierarchy rendering is occurring and controls
|
||||||
/// how the current page is being rendered.
|
/// 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
|
// Helper structs for rendering items/sidebars and carrying along contextual
|
||||||
// information
|
// information
|
||||||
|
|
||||||
|
|
|
@ -12,7 +12,8 @@ use std::path::{Path, PathBuf};
|
||||||
use serde::Serialize;
|
use serde::Serialize;
|
||||||
|
|
||||||
use super::{plain_summary_line, shorten, Impl, IndexItem, IndexItemFunctionType, ItemType};
|
use super::{plain_summary_line, shorten, Impl, IndexItem, IndexItemFunctionType, ItemType};
|
||||||
use super::{Generic, RenderInfo, RenderType, TypeWithKind};
|
use super::{Generic, RenderType, TypeWithKind};
|
||||||
|
use crate::config::RenderInfo;
|
||||||
|
|
||||||
/// Indicates where an external crate can be found.
|
/// Indicates where an external crate can be found.
|
||||||
pub enum ExternalLocation {
|
pub enum ExternalLocation {
|
||||||
|
|
|
@ -1,10 +1,11 @@
|
||||||
use crate::clean;
|
use crate::clean;
|
||||||
use crate::docfs::PathError;
|
use crate::docfs::PathError;
|
||||||
|
use crate::error::Error;
|
||||||
use crate::fold::DocFolder;
|
use crate::fold::DocFolder;
|
||||||
use crate::html::format::Buffer;
|
use crate::html::format::Buffer;
|
||||||
use crate::html::highlight;
|
use crate::html::highlight;
|
||||||
use crate::html::layout;
|
use crate::html::layout;
|
||||||
use crate::html::render::{Error, SharedContext, BASIC_KEYWORDS};
|
use crate::html::render::{SharedContext, BASIC_KEYWORDS};
|
||||||
use rustc_hir::def_id::LOCAL_CRATE;
|
use rustc_hir::def_id::LOCAL_CRATE;
|
||||||
use rustc_span::source_map::FileName;
|
use rustc_span::source_map::FileName;
|
||||||
use std::ffi::OsStr;
|
use std::ffi::OsStr;
|
||||||
|
|
|
@ -63,6 +63,8 @@ mod config;
|
||||||
mod core;
|
mod core;
|
||||||
mod docfs;
|
mod docfs;
|
||||||
mod doctree;
|
mod doctree;
|
||||||
|
#[macro_use]
|
||||||
|
mod error;
|
||||||
mod fold;
|
mod fold;
|
||||||
pub mod html {
|
pub mod html {
|
||||||
crate mod escape;
|
crate mod escape;
|
||||||
|
@ -85,7 +87,7 @@ mod visit_lib;
|
||||||
|
|
||||||
struct Output {
|
struct Output {
|
||||||
krate: clean::Crate,
|
krate: clean::Crate,
|
||||||
renderinfo: html::render::RenderInfo,
|
renderinfo: config::RenderInfo,
|
||||||
renderopts: config::RenderOptions,
|
renderopts: config::RenderOptions,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue