Skip to content

Commit

Permalink
Clean-up compiler warnings in bookrunner (rust-lang#1030)
Browse files Browse the repository at this point in the history
  • Loading branch information
zhassan-aws authored and tedinski committed Apr 12, 2022
1 parent 6199966 commit 212c5da
Show file tree
Hide file tree
Showing 20 changed files with 36 additions and 202 deletions.
1 change: 0 additions & 1 deletion tools/bookrunner/librustdoc/clean/auto_trait.rs
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,6 @@ impl<'a, 'tcx> AutoTraitFinder<'a, 'tcx> {
visibility: Inherited,
def_id: ItemId::Auto { trait_: trait_def_id, for_: item_def_id },
kind: box ImplItem(Impl {
unsafety: hir::Unsafety::Normal,
generics: new_generics,
trait_: Some(trait_ref.clean(self.cx)),
for_: ty.clean(self.cx),
Expand Down
2 changes: 0 additions & 2 deletions tools/bookrunner/librustdoc/clean/blanket_impl.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
use crate::rustc_trait_selection::traits::query::evaluate_obligation::InferCtxtExt;
use rustc_hir as hir;
use rustc_infer::infer::{InferOk, TyCtxtInferExt};
use rustc_infer::traits;
use rustc_middle::ty::subst::Subst;
Expand Down Expand Up @@ -107,7 +106,6 @@ impl<'a, 'tcx> BlanketImplFinder<'a, 'tcx> {
visibility: Inherited,
def_id: ItemId::Blanket { impl_id: impl_def_id, for_: item_def_id },
kind: box ImplItem(Impl {
unsafety: hir::Unsafety::Normal,
generics: clean_ty_generics(
cx,
cx.tcx.generics_of(impl_def_id),
Expand Down
2 changes: 0 additions & 2 deletions tools/bookrunner/librustdoc/clean/inline.rs
Original file line number Diff line number Diff line change
Expand Up @@ -490,7 +490,6 @@ crate fn build_impl(
did,
None,
clean::ImplItem(clean::Impl {
unsafety: hir::Unsafety::Normal,
generics,
trait_,
for_,
Expand Down Expand Up @@ -579,7 +578,6 @@ fn build_static(cx: &mut DocContext<'_>, did: DefId, mutable: bool) -> clean::St
clean::Static {
type_: cx.tcx.type_of(did).clean(cx),
mutability: if mutable { Mutability::Mut } else { Mutability::Not },
expr: None,
}
}

Expand Down
7 changes: 3 additions & 4 deletions tools/bookrunner/librustdoc/clean/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1803,8 +1803,8 @@ fn clean_maybe_renamed_item(
let mut name = renamed.unwrap_or_else(|| cx.tcx.hir().name(item.hir_id()));
cx.with_param_env(def_id, |cx| {
let kind = match item.kind {
ItemKind::Static(ty, mutability, body_id) => {
StaticItem(Static { type_: ty.clean(cx), mutability, expr: Some(body_id) })
ItemKind::Static(ty, mutability, _) => {
StaticItem(Static { type_: ty.clean(cx), mutability })
}
ItemKind::Const(ty, body_id) => ConstantItem(Constant {
type_: ty.clean(cx),
Expand Down Expand Up @@ -1912,7 +1912,6 @@ fn clean_impl(impl_: &hir::Impl<'_>, hir_id: hir::HirId, cx: &mut DocContext<'_>
});
let mut make_item = |trait_: Option<Path>, for_: Type, items: Vec<Item>| {
let kind = ImplItem(Impl {
unsafety: impl_.unsafety,
generics: impl_.generics.clean(cx),
trait_,
for_,
Expand Down Expand Up @@ -2125,7 +2124,7 @@ fn clean_maybe_renamed_foreign_item(
})
}
hir::ForeignItemKind::Static(ref ty, mutability) => {
ForeignStaticItem(Static { type_: ty.clean(cx), mutability, expr: None })
ForeignStaticItem(Static { type_: ty.clean(cx), mutability })
}
hir::ForeignItemKind::Type => ForeignTypeItem,
};
Expand Down
17 changes: 1 addition & 16 deletions tools/bookrunner/librustdoc/clean/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -119,14 +119,13 @@ impl From<DefId> for ItemId {
#[derive(Clone, Debug)]
crate struct Crate {
crate module: Item,
crate primitives: ThinVec<(DefId, PrimitiveType)>,
/// Only here so that they can be filtered through the rustdoc passes.
crate external_traits: Rc<RefCell<FxHashMap<DefId, TraitWithExtraInfo>>>,
}

// `Crate` is frequently moved by-value. Make sure it doesn't unintentionally get bigger.
#[cfg(all(target_arch = "x86_64", target_pointer_width = "64"))]
rustc_data_structures::static_assert_size!(Crate, 72);
rustc_data_structures::static_assert_size!(Crate, 64);

impl Crate {
crate fn name(&self, tcx: TyCtxt<'_>) -> Symbol {
Expand Down Expand Up @@ -246,16 +245,6 @@ impl ExternalCrate {
}
}

/// Indicates where an external crate can be found.
crate enum ExternalLocation {
/// Remote URL root of the external crate
Remote(String),
/// This external crate can be found in the local doc/ folder
Local,
/// The external crate could not be found.
Unknown,
}

/// Anything with a source location and set of attributes and, optionally, a
/// name. That is, anything that can be documented. This doesn't correspond
/// directly to the AST's concept of an item; it's a strict superset.
Expand Down Expand Up @@ -582,7 +571,6 @@ crate enum ItemKind {
ForeignTypeItem,
MacroItem(Macro),
ProcMacroItem(ProcMacro),
PrimitiveItem(PrimitiveType),
AssocConstItem(Type, Option<ConstantKind>),
/// An associated item in a trait or trait impl.
///
Expand All @@ -591,7 +579,6 @@ crate enum ItemKind {
AssocTypeItem(Vec<GenericBound>, Option<Type>),
/// An item that has been stripped by a rustdoc pass
StrippedItem(Box<ItemKind>),
KeywordItem(Symbol),
}

impl ItemKind {}
Expand Down Expand Up @@ -1977,7 +1964,6 @@ crate struct BareFunctionDecl {
crate struct Static {
crate type_: Type,
crate mutability: Mutability,
crate expr: Option<BodyId>,
}

#[derive(Clone, PartialEq, Eq, Hash, Debug)]
Expand Down Expand Up @@ -2071,7 +2057,6 @@ impl ConstantKind {

#[derive(Clone, Debug)]
crate struct Impl {
crate unsafety: hir::Unsafety,
crate generics: Generics,
crate trait_: Option<Path>,
crate for_: Type,
Expand Down
7 changes: 1 addition & 6 deletions tools/bookrunner/librustdoc/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ use rustc_target::spec::TargetTriple;
use crate::externalfiles::ExternalHtml;
use crate::html::markdown::IdMap;
use crate::html::render::StylePath;
use crate::scrape_examples::{AllCallLocations, ScrapeExamplesOptions};
use crate::scrape_examples::AllCallLocations;

#[derive(Clone, Copy, PartialEq, Eq, Debug)]
crate enum OutputFormat {
Expand Down Expand Up @@ -123,10 +123,6 @@ crate struct Options {
crate json_unused_externs: bool,
/// Whether to skip capturing stdout and stderr of tests.
crate nocapture: bool,

/// Configuration for scraping examples from the current crate. If this option is Some(..) then
/// the compiler will scrape examples and not generate documentation.
crate scrape_examples_options: Option<ScrapeExamplesOptions>,
}

impl fmt::Debug for Options {
Expand Down Expand Up @@ -168,7 +164,6 @@ impl fmt::Debug for Options {
.field("run_check", &self.run_check)
.field("no_run", &self.no_run)
.field("nocapture", &self.nocapture)
.field("scrape_examples_options", &self.scrape_examples_options)
.finish()
}
}
Expand Down
2 changes: 1 addition & 1 deletion tools/bookrunner/librustdoc/doctest.rs
Original file line number Diff line number Diff line change
Expand Up @@ -408,7 +408,7 @@ pub fn make_test(
});
let (already_has_main, already_has_extern_crate, found_macro) = match result {
Ok(result) => result,
Err(ErrorGuaranteed) => {
Err(_) => {
// If the parser panicked due to a fatal error, pass the test code through unchanged.
// The error will be reported during compilation.
return (s.to_owned(), 0, false);
Expand Down
4 changes: 1 addition & 3 deletions tools/bookrunner/librustdoc/fold.rs
Original file line number Diff line number Diff line change
Expand Up @@ -84,10 +84,8 @@ crate trait DocFolder: Sized {
| ForeignTypeItem
| MacroItem(_)
| ProcMacroItem(_)
| PrimitiveItem(_)
| AssocConstItem(_, _)
| AssocTypeItem(_, _)
| KeywordItem(_) => kind,
| AssocTypeItem(_, _) => kind,
}
}

Expand Down
13 changes: 2 additions & 11 deletions tools/bookrunner/librustdoc/formats/cache.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use rustc_middle::middle::privacy::AccessLevels;
use rustc_middle::ty::TyCtxt;
use rustc_span::{sym, Symbol};

use crate::clean::{self, types::ExternalLocation, ItemId};
use crate::clean::{self, ItemId};
use crate::fold::DocFolder;
use crate::formats::item_type::ItemType;
use crate::formats::Impl;
Expand Down Expand Up @@ -68,9 +68,6 @@ crate struct Cache {
/// of trait ids to the list of known implementors of the trait
crate implementors: FxHashMap<DefId, Vec<Impl>>,

/// Cache of where external crate documentation can be found.
crate extern_locations: FxHashMap<CrateNum, ExternalLocation>,

/// Cache of where documentation for primitives can be found.
crate primitive_locations: FxHashMap<clean::PrimitiveType, DefId>,

Expand Down Expand Up @@ -307,11 +304,6 @@ impl<'a, 'tcx> DocFolder for CacheBuilder<'a, 'tcx> {
}
}
}
clean::PrimitiveItem(..) => {
self.cache
.paths
.insert(item.def_id.expect_def_id(), (self.cache.stack.clone(), item.type_()));
}

clean::ExternCrateItem { .. }
| clean::ImportItem(..)
Expand All @@ -322,8 +314,7 @@ impl<'a, 'tcx> DocFolder for CacheBuilder<'a, 'tcx> {
| clean::StructFieldItem(..)
| clean::AssocConstItem(..)
| clean::AssocTypeItem(..)
| clean::StrippedItem(..)
| clean::KeywordItem(..) => {
| clean::StrippedItem(..) => {
// FIXME: Do these need handling?
// The person writing this comment doesn't know.
// So would rather leave them to an expert,
Expand Down
2 changes: 0 additions & 2 deletions tools/bookrunner/librustdoc/formats/item_type.rs
Original file line number Diff line number Diff line change
Expand Up @@ -88,11 +88,9 @@ impl<'a> From<&'a clean::Item> for ItemType {
clean::ForeignFunctionItem(..) => ItemType::Function, // no ForeignFunction
clean::ForeignStaticItem(..) => ItemType::Static, // no ForeignStatic
clean::MacroItem(..) => ItemType::Macro,
clean::PrimitiveItem(..) => ItemType::Primitive,
clean::AssocConstItem(..) => ItemType::AssocConst,
clean::AssocTypeItem(..) => ItemType::AssocType,
clean::ForeignTypeItem => ItemType::ForeignType,
clean::KeywordItem(..) => ItemType::Keyword,
clean::TraitAliasItem(..) => ItemType::TraitAlias,
clean::ProcMacroItem(ref mac) => match mac.kind {
MacroKind::Bang => ItemType::Macro,
Expand Down
91 changes: 20 additions & 71 deletions tools/bookrunner/librustdoc/html/format.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,7 @@ use rustc_span::def_id::CRATE_DEF_INDEX;
use rustc_span::{sym, Symbol};
use rustc_target::spec::abi::Abi;

use crate::clean::{
self, types::ExternalLocation, utils::find_nearest_parent_module, ExternalCrate, ItemId,
PrimitiveType,
};
use crate::clean::{self, utils::find_nearest_parent_module, ItemId, PrimitiveType};
use crate::formats::item_type::ItemType;
use crate::html::escape::Escape;
use crate::html::render::Context;
Expand Down Expand Up @@ -496,8 +493,6 @@ impl clean::GenericArgs {
crate enum HrefError {
/// This item is known to rustdoc, but from a crate that does not have documentation generated.
///
/// This can only happen for non-local items.
DocumentationNotBuilt,
/// This can only happen for non-local items when `--document-private-items` is not passed.
Private,
// Not in external cache, href link should be in same page
Expand Down Expand Up @@ -543,43 +538,25 @@ crate fn href_with_root_path(
return Err(HrefError::Private);
}

let mut is_remote = false;
let (fqp, shortty, mut url_parts) = match cache.paths.get(&did) {
Some(&(ref fqp, shortty)) => (fqp, shortty, {
let module_fqp = to_module_fqp(shortty, fqp.as_slice());
debug!(?fqp, ?shortty, ?module_fqp);
href_relative_parts(module_fqp, relative_to).collect()
}),
None => {
if let Some(&(ref fqp, shortty)) = cache.external_paths.get(&did) {
let module_fqp = to_module_fqp(shortty, fqp);
(
fqp,
shortty,
match cache.extern_locations[&did.krate] {
ExternalLocation::Remote(ref s) => {
is_remote = true;
let s = s.trim_end_matches('/');
let mut builder = UrlPartsBuilder::singleton(s);
builder.extend(module_fqp.iter().copied());
builder
}
ExternalLocation::Local => {
href_relative_parts(module_fqp, relative_to).collect()
}
ExternalLocation::Unknown => return Err(HrefError::DocumentationNotBuilt),
},
)
} else {
return Err(HrefError::NotInExternalCache);
let (fqp, shortty, mut url_parts): (&Vec<Symbol>, ItemType, UrlPartsBuilder) =
match cache.paths.get(&did) {
Some(&(ref fqp, shortty)) => (fqp, shortty, {
let module_fqp = to_module_fqp(shortty, fqp.as_slice());
debug!(?fqp, ?shortty, ?module_fqp);
href_relative_parts(module_fqp, relative_to).collect()
}),
None => {
if let Some(&(ref fqp, shortty)) = cache.external_paths.get(&did) {
let module_fqp = to_module_fqp(shortty, fqp);
(fqp, shortty, href_relative_parts(module_fqp, relative_to).collect())
} else {
return Err(HrefError::NotInExternalCache);
}
}
}
};
if !is_remote {
if let Some(root_path) = root_path {
let root = root_path.trim_end_matches('/');
url_parts.push_front(root);
}
};
if let Some(root_path) = root_path {
let root = root_path.trim_end_matches('/');
url_parts.push_front(root);
}
debug!(?url_parts);
match shortty {
Expand Down Expand Up @@ -687,35 +664,7 @@ fn primitive_link(
)?;
needs_termination = true;
}
Some(&def_id) => {
let loc = match m.extern_locations[&def_id.krate] {
ExternalLocation::Remote(ref s) => {
let cname_sym = ExternalCrate { crate_num: def_id.krate }.name(cx.tcx());
let builder: UrlPartsBuilder =
[s.as_str().trim_end_matches('/'), cname_sym.as_str()]
.into_iter()
.collect();
Some(builder)
}
ExternalLocation::Local => {
let cname_sym = ExternalCrate { crate_num: def_id.krate }.name(cx.tcx());
Some(if cx.current.first() == Some(&cname_sym) {
iter::repeat(sym::dotdot).take(cx.current.len() - 1).collect()
} else {
iter::repeat(sym::dotdot)
.take(cx.current.len())
.chain(iter::once(cname_sym))
.collect()
})
}
ExternalLocation::Unknown => None,
};
if let Some(mut loc) = loc {
loc.push_fmt(format_args!("primitive.{}.html", prim.as_sym()));
write!(f, "<a class=\"primitive\" href=\"{}\">", loc.finish())?;
needs_termination = true;
}
}
Some(&_def_id) => {}
None => {}
}
}
Expand Down
1 change: 0 additions & 1 deletion tools/bookrunner/librustdoc/html/markdown.rs
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,6 @@ pub(crate) enum HeadingOffset {
H3,
H4,
H5,
H6,
}

/// When `to_string` is called, this struct will emit the HTML corresponding to
Expand Down
18 changes: 5 additions & 13 deletions tools/bookrunner/librustdoc/html/render/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ use super::{
BASIC_KEYWORDS,
};

use crate::clean::{self, types::ExternalLocation, ExternalCrate};
use crate::clean::{self, ExternalCrate};
use crate::config::RenderOptions;
use crate::docfs::{DocFS, PathError};
use crate::error::Error;
Expand Down Expand Up @@ -292,7 +292,7 @@ impl<'tcx> Context<'tcx> {
if span.is_dummy() {
return None;
}
let mut root = self.root_path();
let root = self.root_path();
let mut path = String::new();
let cnum = span.cnum(self.sess());

Expand All @@ -311,17 +311,9 @@ impl<'tcx> Context<'tcx> {
return None;
}
} else {
let (krate, src_root) = match *self.cache().extern_locations.get(&cnum)? {
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();
let e = ExternalCrate { crate_num: cnum };
(e.name(self.tcx()), e.src_root(self.tcx()))
}
ExternalLocation::Unknown => return None,
let (krate, src_root) = {
let e = ExternalCrate { crate_num: cnum };
(e.name(self.tcx()), e.src_root(self.tcx()))
};

sources::clean_path(&src_root, file, false, |component| {
Expand Down
Loading

0 comments on commit 212c5da

Please sign in to comment.