1
Fork 0

Fix rustc::internal lints on rustdoc

This commit is contained in:
Joshua Nelson 2020-12-31 23:25:30 -05:00
parent 65767e5653
commit a194881991
10 changed files with 30 additions and 30 deletions

View file

@ -1,4 +1,4 @@
use std::collections::{BTreeMap, HashMap};
use std::collections::BTreeMap;
use std::convert::TryFrom;
use std::ffi::OsStr;
use std::fmt;
@ -219,7 +219,7 @@ crate struct RenderOptions {
crate extern_html_root_urls: BTreeMap<String, String>,
/// A map of the default settings (values are as for DOM storage API). Keys should lack the
/// `rustdoc-` prefix.
crate default_settings: HashMap<String, String>,
crate default_settings: FxHashMap<String, String>,
/// If present, suffix added to CSS/JavaScript files when referencing them in generated pages.
crate resource_suffix: String,
/// Whether to run the static CSS/JavaScript through a minifier when outputting them. `true` by

View file

@ -1,4 +1,5 @@
use rustc_ast as ast;
use rustc_data_structures::fx::FxHashMap;
use rustc_data_structures::sync::Lrc;
use rustc_errors::{ColorConfig, ErrorReported};
use rustc_hir as hir;
@ -16,7 +17,6 @@ use rustc_span::{BytePos, FileName, Pos, Span, DUMMY_SP};
use rustc_target::spec::TargetTriple;
use tempfile::Builder as TempFileBuilder;
use std::collections::HashMap;
use std::env;
use std::io::{self, Write};
use std::panic;
@ -703,7 +703,7 @@ crate struct Collector {
position: Span,
source_map: Option<Lrc<SourceMap>>,
filename: Option<PathBuf>,
visited_tests: HashMap<(String, usize), usize>,
visited_tests: FxHashMap<(String, usize), usize>,
}
impl Collector {
@ -727,7 +727,7 @@ impl Collector {
position: DUMMY_SP,
source_map,
filename,
visited_tests: HashMap::new(),
visited_tests: FxHashMap::default(),
}
}
@ -1009,7 +1009,7 @@ impl<'a, 'hir, 'tcx> HirCollector<'a, 'hir, 'tcx> {
self.codes,
self.collector.enable_per_target_ignores,
Some(&crate::html::markdown::ExtraInfo::new(
&self.tcx,
self.tcx,
hir_id,
span_of_attrs(&attrs).unwrap_or(sp),
)),

View file

@ -1,6 +1,6 @@
use std::sync::Arc;
use rustc_middle::ty;
use rustc_middle::ty::TyCtxt;
use rustc_span::edition::Edition;
use crate::clean;
@ -20,7 +20,7 @@ crate trait FormatRenderer<'tcx>: Clone {
render_info: RenderInfo,
edition: Edition,
cache: &mut Cache,
tcx: ty::TyCtxt<'tcx>,
tcx: TyCtxt<'tcx>,
) -> Result<(Self, clean::Crate), Error>;
/// Renders a single non-module item. This means no recursive sub-item rendering is required.
@ -55,7 +55,7 @@ crate fn run_format<'tcx, T: FormatRenderer<'tcx>>(
render_info: RenderInfo,
diag: &rustc_errors::Handler,
edition: Edition,
tcx: ty::TyCtxt<'tcx>,
tcx: TyCtxt<'tcx>,
) -> Result<(), Error> {
let (krate, mut cache) = Cache::from_krate(
render_info.clone(),

View file

@ -1,6 +1,7 @@
use std::collections::HashMap;
use std::path::PathBuf;
use rustc_data_structures::fx::FxHashMap;
use crate::externalfiles::ExternalHtml;
use crate::html::escape::Escape;
use crate::html::format::{Buffer, Print};
@ -11,7 +12,7 @@ crate struct Layout {
crate logo: String,
crate favicon: String,
crate external_html: ExternalHtml,
crate default_settings: HashMap<String, String>,
crate default_settings: FxHashMap<String, String>,
crate krate: String,
/// The given user css file which allow to customize the generated
/// documentation theme.

View file

@ -620,7 +620,7 @@ crate fn find_testable_code<T: doctest::Tester>(
tests: &mut T,
error_codes: ErrorCodes,
enable_per_target_ignores: bool,
extra_info: Option<&ExtraInfo<'_, '_>>,
extra_info: Option<&ExtraInfo<'_>>,
) {
let mut parser = Parser::new(doc).into_offset_iter();
let mut prev_offset = 0;
@ -681,19 +681,19 @@ crate fn find_testable_code<T: doctest::Tester>(
}
}
crate struct ExtraInfo<'a, 'b> {
crate struct ExtraInfo<'tcx> {
hir_id: Option<HirId>,
item_did: Option<DefId>,
sp: Span,
tcx: &'a TyCtxt<'b>,
tcx: TyCtxt<'tcx>,
}
impl<'a, 'b> ExtraInfo<'a, 'b> {
crate fn new(tcx: &'a TyCtxt<'b>, hir_id: HirId, sp: Span) -> ExtraInfo<'a, 'b> {
impl<'tcx> ExtraInfo<'tcx> {
crate fn new(tcx: TyCtxt<'tcx>, hir_id: HirId, sp: Span) -> ExtraInfo<'tcx> {
ExtraInfo { hir_id: Some(hir_id), item_did: None, sp, tcx }
}
crate fn new_did(tcx: &'a TyCtxt<'b>, did: DefId, sp: Span) -> ExtraInfo<'a, 'b> {
crate fn new_did(tcx: TyCtxt<'tcx>, did: DefId, sp: Span) -> ExtraInfo<'tcx> {
ExtraInfo { hir_id: None, item_did: Some(did), sp, tcx }
}
@ -775,7 +775,7 @@ impl LangString {
string: &str,
allow_error_code_check: ErrorCodes,
enable_per_target_ignores: bool,
extra: Option<&ExtraInfo<'_, '_>>,
extra: Option<&ExtraInfo<'_>>,
) -> LangString {
let allow_error_code_check = allow_error_code_check.as_bool();
let mut seen_rust_tags = false;
@ -1208,7 +1208,7 @@ crate struct RustCodeBlock {
/// Returns a range of bytes for each code block in the markdown that is tagged as `rust` or
/// untagged (and assumed to be rust).
crate fn rust_code_blocks(md: &str, extra_info: &ExtraInfo<'_, '_>) -> Vec<RustCodeBlock> {
crate fn rust_code_blocks(md: &str, extra_info: &ExtraInfo<'_>) -> Vec<RustCodeBlock> {
let mut code_blocks = vec![];
if md.is_empty() {

View file

@ -55,7 +55,6 @@ use rustc_hir as hir;
use rustc_hir::def_id::{DefId, LOCAL_CRATE};
use rustc_hir::Mutability;
use rustc_middle::middle::stability;
use rustc_middle::ty;
use rustc_middle::ty::TyCtxt;
use rustc_session::Session;
use rustc_span::edition::Edition;
@ -390,7 +389,7 @@ impl<'tcx> FormatRenderer<'tcx> for Context<'tcx> {
_render_info: RenderInfo,
edition: Edition,
cache: &mut Cache,
tcx: ty::TyCtxt<'tcx>,
tcx: TyCtxt<'tcx>,
) -> Result<(Self, clean::Crate), Error> {
// need to save a copy of the options for rendering the index page
let md_opts = options.clone();

View file

@ -13,7 +13,7 @@ use std::path::PathBuf;
use std::rc::Rc;
use rustc_data_structures::fx::FxHashMap;
use rustc_middle::ty;
use rustc_middle::ty::TyCtxt;
use rustc_session::Session;
use rustc_span::edition::Edition;
@ -26,7 +26,7 @@ use crate::html::render::cache::ExternalLocation;
#[derive(Clone)]
crate struct JsonRenderer<'tcx> {
tcx: ty::TyCtxt<'tcx>,
tcx: TyCtxt<'tcx>,
/// A mapping of IDs that contains all local items for this crate which gets output as a top
/// level field of the JSON blob.
index: Rc<RefCell<FxHashMap<types::Id, types::Item>>>,
@ -131,7 +131,7 @@ impl<'tcx> FormatRenderer<'tcx> for JsonRenderer<'tcx> {
_render_info: RenderInfo,
_edition: Edition,
_cache: &mut Cache,
tcx: ty::TyCtxt<'tcx>,
tcx: TyCtxt<'tcx>,
) -> Result<(Self, clean::Crate), Error> {
debug!("Initializing json renderer");
Ok((

View file

@ -65,7 +65,7 @@ use std::process;
use rustc_driver::abort_on_err;
use rustc_errors::ErrorReported;
use rustc_interface::interface;
use rustc_middle::ty;
use rustc_middle::ty::TyCtxt;
use rustc_session::config::{make_crate_type_option, ErrorOutputType, RustcOptGroup};
use rustc_session::getopts;
use rustc_session::{early_error, early_warn};
@ -471,7 +471,7 @@ fn run_renderer<'tcx, T: formats::FormatRenderer<'tcx>>(
render_info: config::RenderInfo,
diag: &rustc_errors::Handler,
edition: rustc_span::edition::Edition,
tcx: ty::TyCtxt<'tcx>,
tcx: TyCtxt<'tcx>,
) -> MainResult {
match formats::run_format::<T>(krate, renderopts, render_info, &diag, edition, tcx) {
Ok(_) => Ok(()),

View file

@ -108,7 +108,7 @@ impl<'a, 'tcx> DocFolder for SyntaxChecker<'a, 'tcx> {
fn fold_item(&mut self, item: clean::Item) -> Option<clean::Item> {
if let Some(dox) = &item.attrs.collapsed_doc_value() {
let sp = span_of_attrs(&item.attrs).unwrap_or(item.source.span());
let extra = crate::html::markdown::ExtraInfo::new_did(&self.cx.tcx, item.def_id, sp);
let extra = crate::html::markdown::ExtraInfo::new_did(self.cx.tcx, item.def_id, sp);
for code_block in markdown::rust_code_blocks(&dox, &extra) {
self.check_rust_syntax(&item, &dox, code_block);
}

View file

@ -13,6 +13,7 @@ use rustc_hir::def::{
PerNS,
};
use rustc_hir::def_id::{CrateNum, DefId};
use rustc_middle::ty::TyCtxt;
use rustc_middle::{bug, ty};
use rustc_resolve::ParentScope;
use rustc_session::lint::{
@ -85,7 +86,7 @@ impl Res {
}
}
fn name(self, tcx: ty::TyCtxt<'_>) -> String {
fn name(self, tcx: TyCtxt<'_>) -> String {
match self {
Res::Def(_, id) => tcx.item_name(id).to_string(),
Res::Primitive(prim) => prim.as_str().to_string(),
@ -865,12 +866,11 @@ impl<'a, 'tcx> DocFolder for LinkCollector<'a, 'tcx> {
// FIXME(jynelson): this shouldn't go through stringification, rustdoc should just use the DefId directly
let self_name = self_id.and_then(|self_id| {
use ty::TyKind;
if matches!(self.cx.tcx.def_kind(self_id), DefKind::Impl) {
// using `ty.to_string()` (or any variant) has issues with raw idents
let ty = self.cx.tcx.type_of(self_id);
let name = match ty.kind() {
TyKind::Adt(def, _) => Some(self.cx.tcx.item_name(def.did).to_string()),
ty::Adt(def, _) => Some(self.cx.tcx.item_name(def.did).to_string()),
other if other.is_primitive() => Some(ty.to_string()),
_ => None,
};