Skip to content

Commit c692ed4

Browse files
committed
Move Error and RenderInfo out of html module
1 parent efc02b0 commit c692ed4

File tree

7 files changed

+85
-71
lines changed

7 files changed

+85
-71
lines changed

src/librustdoc/config.rs

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,9 @@ use std::ffi::OsStr;
44
use std::fmt;
55
use std::path::PathBuf;
66

7+
use rustc_data_structures::fx::{FxHashMap, FxHashSet};
8+
use rustc_hir::def_id::DefId;
9+
use rustc_middle::middle::privacy::AccessLevels;
710
use rustc_session::config::{self, parse_crate_types_from_list, parse_externs, CrateType};
811
use rustc_session::config::{
912
build_codegen_options, build_debugging_options, get_cmd_lint_options, host_triple,
@@ -249,6 +252,20 @@ pub struct RenderOptions {
249252
pub document_hidden: bool,
250253
}
251254

255+
/// Temporary storage for data obtained during `RustdocVisitor::clean()`.
256+
/// Later on moved into `CACHE_KEY`.
257+
#[derive(Default)]
258+
pub struct RenderInfo {
259+
pub inlined: FxHashSet<DefId>,
260+
pub external_paths: crate::core::ExternalPaths,
261+
pub exact_paths: FxHashMap<DefId, Vec<String>>,
262+
pub access_levels: AccessLevels<DefId>,
263+
pub deref_trait_did: Option<DefId>,
264+
pub deref_mut_trait_did: Option<DefId>,
265+
pub owned_box_did: Option<DefId>,
266+
pub output_format: Option<OutputFormat>,
267+
}
268+
252269
impl Options {
253270
/// Parses the given command-line for options. If an error message or other early-return has
254271
/// been printed, returns `Err` with the exit code.

src/librustdoc/core.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,8 @@ use std::rc::Rc;
3232

3333
use crate::clean;
3434
use crate::clean::{AttributesExt, MAX_DEF_ID};
35+
use crate::config::RenderInfo;
3536
use crate::config::{Options as RustdocOptions, RenderOptions};
36-
use crate::html::render::RenderInfo;
3737
use crate::passes::{self, Condition::*, ConditionalPass};
3838

3939
pub use rustc_session::config::{CodegenOptions, DebuggingOptions, Input, Options};

src/librustdoc/error.rs

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
use std::error;
2+
use std::fmt::{self, Formatter};
3+
use std::path::{Path, PathBuf};
4+
5+
use crate::docfs::PathError;
6+
7+
#[derive(Debug)]
8+
pub struct Error {
9+
pub file: PathBuf,
10+
pub error: String,
11+
}
12+
13+
impl error::Error for Error {}
14+
15+
impl std::fmt::Display for Error {
16+
fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result {
17+
let file = self.file.display().to_string();
18+
if file.is_empty() {
19+
write!(f, "{}", self.error)
20+
} else {
21+
write!(f, "\"{}\": {}", self.file.display(), self.error)
22+
}
23+
}
24+
}
25+
26+
impl PathError for Error {
27+
fn new<S, P: AsRef<Path>>(e: S, path: P) -> Error
28+
where
29+
S: ToString + Sized,
30+
{
31+
Error { file: path.as_ref().to_path_buf(), error: e.to_string() }
32+
}
33+
}
34+
35+
#[macro_export]
36+
macro_rules! try_none {
37+
($e:expr, $file:expr) => {{
38+
use std::io;
39+
match $e {
40+
Some(e) => e,
41+
None => {
42+
return Err(Error::new(io::Error::new(io::ErrorKind::Other, "not found"), $file));
43+
}
44+
}
45+
}};
46+
}
47+
48+
#[macro_export]
49+
macro_rules! try_err {
50+
($e:expr, $file:expr) => {{
51+
match $e {
52+
Ok(e) => e,
53+
Err(e) => return Err(Error::new(e, $file)),
54+
}
55+
}};
56+
}

src/librustdoc/html/render.rs

Lines changed: 4 additions & 67 deletions
Original file line numberDiff line numberDiff line change
@@ -30,9 +30,8 @@ use std::cell::{Cell, RefCell};
3030
use std::cmp::Ordering;
3131
use std::collections::{BTreeMap, VecDeque};
3232
use std::default::Default;
33-
use std::error;
3433
use std::ffi::OsStr;
35-
use std::fmt::{self, Formatter, Write};
34+
use std::fmt::{self, Write};
3635
use std::fs::{self, File};
3736
use std::io::prelude::*;
3837
use std::io::{self, BufReader};
@@ -50,7 +49,6 @@ use rustc_feature::UnstableFeatures;
5049
use rustc_hir as hir;
5150
use rustc_hir::def_id::{DefId, LOCAL_CRATE};
5251
use rustc_hir::Mutability;
53-
use rustc_middle::middle::privacy::AccessLevels;
5452
use rustc_middle::middle::stability;
5553
use rustc_span::edition::Edition;
5654
use rustc_span::hygiene::MacroKind;
@@ -60,9 +58,11 @@ use serde::ser::SerializeSeq;
6058
use serde::{Serialize, Serializer};
6159

6260
use crate::clean::{self, AttributesExt, Deprecation, GetDefId, SelfTy, TypeKind};
63-
use crate::config::{OutputFormat, RenderOptions};
61+
use crate::config::RenderInfo;
62+
use crate::config::RenderOptions;
6463
use crate::docfs::{DocFS, ErrorStorage, PathError};
6564
use crate::doctree;
65+
use crate::error::Error;
6666
use crate::html::escape::Escape;
6767
use crate::html::format::fmt_impl_for_trait_page;
6868
use crate::html::format::Function;
@@ -90,55 +90,6 @@ crate fn ensure_trailing_slash(v: &str) -> impl fmt::Display + '_ {
9090
})
9191
}
9292

93-
#[derive(Debug)]
94-
pub struct Error {
95-
pub file: PathBuf,
96-
pub error: String,
97-
}
98-
99-
impl error::Error for Error {}
100-
101-
impl std::fmt::Display for Error {
102-
fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result {
103-
let file = self.file.display().to_string();
104-
if file.is_empty() {
105-
write!(f, "{}", self.error)
106-
} else {
107-
write!(f, "\"{}\": {}", self.file.display(), self.error)
108-
}
109-
}
110-
}
111-
112-
impl PathError for Error {
113-
fn new<S, P: AsRef<Path>>(e: S, path: P) -> Error
114-
where
115-
S: ToString + Sized,
116-
{
117-
Error { file: path.as_ref().to_path_buf(), error: e.to_string() }
118-
}
119-
}
120-
121-
macro_rules! try_none {
122-
($e:expr, $file:expr) => {{
123-
use std::io;
124-
match $e {
125-
Some(e) => e,
126-
None => {
127-
return Err(Error::new(io::Error::new(io::ErrorKind::Other, "not found"), $file));
128-
}
129-
}
130-
}};
131-
}
132-
133-
macro_rules! try_err {
134-
($e:expr, $file:expr) => {{
135-
match $e {
136-
Ok(e) => e,
137-
Err(e) => return Err(Error::new(e, $file)),
138-
}
139-
}};
140-
}
141-
14293
/// Major driving force in all rustdoc rendering. This contains information
14394
/// about where in the tree-like hierarchy rendering is occurring and controls
14495
/// how the current page is being rendered.
@@ -260,20 +211,6 @@ impl Impl {
260211
}
261212
}
262213

263-
/// Temporary storage for data obtained during `RustdocVisitor::clean()`.
264-
/// Later on moved into `CACHE_KEY`.
265-
#[derive(Default)]
266-
pub struct RenderInfo {
267-
pub inlined: FxHashSet<DefId>,
268-
pub external_paths: crate::core::ExternalPaths,
269-
pub exact_paths: FxHashMap<DefId, Vec<String>>,
270-
pub access_levels: AccessLevels<DefId>,
271-
pub deref_trait_did: Option<DefId>,
272-
pub deref_mut_trait_did: Option<DefId>,
273-
pub owned_box_did: Option<DefId>,
274-
pub output_format: Option<OutputFormat>,
275-
}
276-
277214
// Helper structs for rendering items/sidebars and carrying along contextual
278215
// information
279216

src/librustdoc/html/render/cache.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,8 @@ use std::path::{Path, PathBuf};
1212
use serde::Serialize;
1313

1414
use super::{plain_summary_line, shorten, Impl, IndexItem, IndexItemFunctionType, ItemType};
15-
use super::{Generic, RenderInfo, RenderType, TypeWithKind};
15+
use super::{Generic, RenderType, TypeWithKind};
16+
use crate::config::RenderInfo;
1617

1718
/// Indicates where an external crate can be found.
1819
pub enum ExternalLocation {

src/librustdoc/html/sources.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
use crate::clean;
22
use crate::docfs::PathError;
3+
use crate::error::Error;
34
use crate::fold::DocFolder;
45
use crate::html::format::Buffer;
56
use crate::html::highlight;
67
use crate::html::layout;
7-
use crate::html::render::{Error, SharedContext, BASIC_KEYWORDS};
8+
use crate::html::render::{SharedContext, BASIC_KEYWORDS};
89
use rustc_hir::def_id::LOCAL_CRATE;
910
use rustc_span::source_map::FileName;
1011
use std::ffi::OsStr;

src/librustdoc/lib.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,8 @@ mod config;
6363
mod core;
6464
mod docfs;
6565
mod doctree;
66+
#[macro_use]
67+
mod error;
6668
mod fold;
6769
pub mod html {
6870
crate mod escape;
@@ -85,7 +87,7 @@ mod visit_lib;
8587

8688
struct Output {
8789
krate: clean::Crate,
88-
renderinfo: html::render::RenderInfo,
90+
renderinfo: config::RenderInfo,
8991
renderopts: config::RenderOptions,
9092
}
9193

0 commit comments

Comments
 (0)