use rustc_session::Session;
use rustc_span::edition::Edition;
use rustc_span::source_map::FileName;
-use rustc_span::{symbol::sym, Symbol};
+use rustc_span::symbol::sym;
use super::cache::{build_index, ExternalLocation};
use super::print_item::{full_path, item_path, print_item};
use super::write_shared::write_shared;
use super::{print_sidebar, settings, AllTypes, NameDoc, StylePath, BASIC_KEYWORDS};
-use crate::clean::{self, AttributesExt};
+use crate::clean::{self, ExternalCrate};
use crate::config::RenderOptions;
use crate::docfs::{DocFS, PathError};
use crate::error::Error;
crate static_root_path: Option<String>,
/// The fs handle we are working with.
crate fs: DocFS,
- /// The default edition used to parse doctests.
- crate edition: Edition,
pub(super) codes: ErrorCodes,
pub(super) playground: Option<markdown::Playground>,
all: RefCell<AllTypes>,
crate fn maybe_collapsed_doc_value<'a>(&self, item: &'a clean::Item) -> Option<String> {
if self.collapsed { item.collapsed_doc_value() } else { item.doc_value() }
}
+
+ crate fn edition(&self) -> Edition {
+ self.tcx.sess.edition()
+ }
}
impl<'tcx> Context<'tcx> {
/// may happen, for example, with externally inlined items where the source
/// of their crate documentation isn't known.
pub(super) fn src_href(&self, item: &clean::Item) -> Option<String> {
- if item.span.is_dummy() {
+ if item.span(self.tcx()).is_dummy() {
return None;
}
let mut root = self.root_path();
let mut path = String::new();
- let cnum = item.span.cnum(self.sess());
+ let cnum = item.span(self.tcx()).cnum(self.sess());
// We can safely ignore synthetic `SourceFile`s.
- let file = match item.span.filename(self.sess()) {
- FileName::Real(ref path) => path.local_path().to_path_buf(),
+ let file = match item.span(self.tcx()).filename(self.sess()) {
+ FileName::Real(ref path) => path.local_path_if_available().to_path_buf(),
_ => return None,
};
let file = &file;
}
} else {
let (krate, src_root) = match *self.cache.extern_locations.get(&cnum)? {
- (name, ref src, ExternalLocation::Local) => (name, src),
- (name, ref src, ExternalLocation::Remote(ref s)) => {
+ ExternalLocation::Local => {
+ let e = ExternalCrate { crate_num: cnum };
+ (e.name(self.tcx()), e.src_root(self.tcx()))
+ }
+ ExternalLocation::Remote(ref s) => {
root = s.to_string();
- (name, src)
+ let e = ExternalCrate { crate_num: cnum };
+ (e.name(self.tcx()), e.src_root(self.tcx()))
}
- (_, _, ExternalLocation::Unknown) => return None,
+ ExternalLocation::Unknown => return None,
};
sources::clean_path(&src_root, file, false, |component| {
(&*symbol, &path)
};
- let loline = item.span.lo(self.sess()).line;
- let hiline = item.span.hi(self.sess()).line;
+ let loline = item.span(self.tcx()).lo(self.sess()).line;
+ let hiline = item.span(self.tcx()).hi(self.sess()).line;
let lines =
if loline == hiline { loline.to_string() } else { format!("{}-{}", loline, hiline) };
Some(format!(
fn init(
mut krate: clean::Crate,
options: RenderOptions,
- edition: Edition,
mut cache: Cache,
tcx: TyCtxt<'tcx>,
) -> Result<(Self, clean::Crate), Error> {
} = options;
let src_root = match krate.src {
- FileName::Real(ref p) => match p.local_path().parent() {
+ FileName::Real(ref p) => match p.local_path_if_available().parent() {
Some(p) => p.to_path_buf(),
None => PathBuf::new(),
},
resource_suffix,
static_root_path,
fs: DocFS::new(sender),
- edition,
codes: ErrorCodes::from(unstable_features.is_nightly_build()),
playground,
all: RefCell::new(AllTypes::new()),
}
}
- fn after_krate(
- &mut self,
- crate_name: Symbol,
- diag: &rustc_errors::Handler,
- ) -> Result<(), Error> {
+ fn after_krate(&mut self) -> Result<(), Error> {
+ let crate_name = self.tcx().crate_name(LOCAL_CRATE);
let final_file = self.dst.join(&*crate_name.as_str()).join("all.html");
let settings_file = self.dst.join("settings.html");
// Flush pending errors.
Rc::get_mut(&mut self.shared).unwrap().fs.close();
- let nb_errors = self.shared.errors.iter().map(|err| diag.struct_err(&err).emit()).count();
+ let nb_errors =
+ self.shared.errors.iter().map(|err| self.tcx().sess.struct_err(&err).emit()).count();
if nb_errors > 0 {
Err(Error::new(io::Error::new(io::ErrorKind::Other, "I/O error"), ""))
} else {
}
}
- fn mod_item_in(&mut self, item: &clean::Item, item_name: &str) -> Result<(), Error> {
+ fn mod_item_in(&mut self, item: &clean::Item) -> Result<(), Error> {
// Stripped modules survive the rustdoc passes (i.e., `strip-private`)
// if they contain impls for public types. These modules can also
// contain items such as publicly re-exported structures.
self.render_redirect_pages = item.is_stripped();
}
let scx = &self.shared;
- self.dst.push(item_name);
- self.current.push(item_name.to_owned());
+ let item_name = item.name.as_ref().unwrap().to_string();
+ self.dst.push(&item_name);
+ self.current.push(item_name);
info!("Recursing into {}", self.dst.display());
Ok(())
}
- fn mod_item_out(&mut self, _item_name: &str) -> Result<(), Error> {
+ fn mod_item_out(&mut self) -> Result<(), Error> {
info!("Recursed; leaving {}", self.dst.display());
// Go back to where we were at