diff --git a/src/bootstrap/check.rs b/src/bootstrap/check.rs index c19bb536ce83c..6626fead774d6 100644 --- a/src/bootstrap/check.rs +++ b/src/bootstrap/check.rs @@ -320,6 +320,13 @@ macro_rules! tool_check_step { cargo.arg("--all-targets"); } + // Enable internal lints for clippy and rustdoc + // NOTE: this intentionally doesn't enable lints for any other tools, + // see https://github.com/rust-lang/rust/pull/80573#issuecomment-754010776 + if $path == "src/tools/rustdoc" || $path == "src/tools/clippy" { + cargo.rustflag("-Zunstable-options"); + } + builder.info(&format!( "Checking stage{} {} artifacts ({} -> {})", builder.top_stage, diff --git a/src/librustdoc/config.rs b/src/librustdoc/config.rs index e43ea965c0423..8006c3d277164 100644 --- a/src/librustdoc/config.rs +++ b/src/librustdoc/config.rs @@ -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, /// A map of the default settings (values are as for DOM storage API). Keys should lack the /// `rustdoc-` prefix. - crate default_settings: HashMap, + crate default_settings: FxHashMap, /// 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 diff --git a/src/librustdoc/doctest.rs b/src/librustdoc/doctest.rs index 3de97f2dd2e59..38969e7346826 100644 --- a/src/librustdoc/doctest.rs +++ b/src/librustdoc/doctest.rs @@ -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>, filename: Option, - 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), )), diff --git a/src/librustdoc/formats/renderer.rs b/src/librustdoc/formats/renderer.rs index c91d6decc0b67..5c0f5e50c9e2c 100644 --- a/src/librustdoc/formats/renderer.rs +++ b/src/librustdoc/formats/renderer.rs @@ -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(), diff --git a/src/librustdoc/html/layout.rs b/src/librustdoc/html/layout.rs index 4458eea95f3e1..c6ff4b57a6e59 100644 --- a/src/librustdoc/html/layout.rs +++ b/src/librustdoc/html/layout.rs @@ -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, + crate default_settings: FxHashMap, crate krate: String, /// The given user css file which allow to customize the generated /// documentation theme. diff --git a/src/librustdoc/html/markdown.rs b/src/librustdoc/html/markdown.rs index cfa6cd96595d6..7c8b76be374a8 100644 --- a/src/librustdoc/html/markdown.rs +++ b/src/librustdoc/html/markdown.rs @@ -620,7 +620,7 @@ crate fn find_testable_code( 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( } } -crate struct ExtraInfo<'a, 'b> { +crate struct ExtraInfo<'tcx> { hir_id: Option, item_did: Option, 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 { +crate fn rust_code_blocks(md: &str, extra_info: &ExtraInfo<'_>) -> Vec { let mut code_blocks = vec![]; if md.is_empty() { diff --git a/src/librustdoc/html/render/mod.rs b/src/librustdoc/html/render/mod.rs index 26afd705740b2..37a0f7f4d7c4b 100644 --- a/src/librustdoc/html/render/mod.rs +++ b/src/librustdoc/html/render/mod.rs @@ -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(); diff --git a/src/librustdoc/json/mod.rs b/src/librustdoc/json/mod.rs index 64500c1d91161..c93062c73a870 100644 --- a/src/librustdoc/json/mod.rs +++ b/src/librustdoc/json/mod.rs @@ -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>>, @@ -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(( diff --git a/src/librustdoc/lib.rs b/src/librustdoc/lib.rs index 719aca612f50d..d17189b416dd4 100644 --- a/src/librustdoc/lib.rs +++ b/src/librustdoc/lib.rs @@ -18,6 +18,7 @@ #![feature(str_split_once)] #![feature(iter_intersperse)] #![recursion_limit = "256"] +#![deny(rustc::internal)] #[macro_use] extern crate lazy_static; @@ -65,7 +66,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 +472,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::(krate, renderopts, render_info, &diag, edition, tcx) { Ok(_) => Ok(()), diff --git a/src/librustdoc/passes/check_code_block_syntax.rs b/src/librustdoc/passes/check_code_block_syntax.rs index 554392c213e24..9516130034b59 100644 --- a/src/librustdoc/passes/check_code_block_syntax.rs +++ b/src/librustdoc/passes/check_code_block_syntax.rs @@ -108,7 +108,7 @@ impl<'a, 'tcx> DocFolder for SyntaxChecker<'a, 'tcx> { fn fold_item(&mut self, item: clean::Item) -> Option { 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); } diff --git a/src/librustdoc/passes/collect_intra_doc_links.rs b/src/librustdoc/passes/collect_intra_doc_links.rs index 2694450a520c9..002d8938f694d 100644 --- a/src/librustdoc/passes/collect_intra_doc_links.rs +++ b/src/librustdoc/passes/collect_intra_doc_links.rs @@ -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, };