Skip to content

Commit 98c0364

Browse files
authored
Rollup merge of #80573 - jyn514:tool-lints, r=GuillaumeGomez
Deny rustc::internal lints for rustdoc and clippy - Fix rustc::internal lints for rustdoc - Deny internal lints only for rustdoc and clippy (previously the lints were ignored for clippy because -Zunstable-options didn't get passed)
2 parents bbc01bb + 0797ffe commit 98c0364

File tree

11 files changed

+38
-30
lines changed

11 files changed

+38
-30
lines changed

src/bootstrap/check.rs

+7
Original file line numberDiff line numberDiff line change
@@ -320,6 +320,13 @@ macro_rules! tool_check_step {
320320
cargo.arg("--all-targets");
321321
}
322322

323+
// Enable internal lints for clippy and rustdoc
324+
// NOTE: this intentionally doesn't enable lints for any other tools,
325+
// see https://github.com/rust-lang/rust/pull/80573#issuecomment-754010776
326+
if $path == "src/tools/rustdoc" || $path == "src/tools/clippy" {
327+
cargo.rustflag("-Zunstable-options");
328+
}
329+
323330
builder.info(&format!(
324331
"Checking stage{} {} artifacts ({} -> {})",
325332
builder.top_stage,

src/librustdoc/config.rs

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

src/librustdoc/doctest.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
use rustc_ast as ast;
2+
use rustc_data_structures::fx::FxHashMap;
23
use rustc_data_structures::sync::Lrc;
34
use rustc_errors::{ColorConfig, ErrorReported};
45
use rustc_hir as hir;
@@ -16,7 +17,6 @@ use rustc_span::{BytePos, FileName, Pos, Span, DUMMY_SP};
1617
use rustc_target::spec::TargetTriple;
1718
use tempfile::Builder as TempFileBuilder;
1819

19-
use std::collections::HashMap;
2020
use std::env;
2121
use std::io::{self, Write};
2222
use std::panic;
@@ -704,7 +704,7 @@ crate struct Collector {
704704
position: Span,
705705
source_map: Option<Lrc<SourceMap>>,
706706
filename: Option<PathBuf>,
707-
visited_tests: HashMap<(String, usize), usize>,
707+
visited_tests: FxHashMap<(String, usize), usize>,
708708
}
709709

710710
impl Collector {
@@ -728,7 +728,7 @@ impl Collector {
728728
position: DUMMY_SP,
729729
source_map,
730730
filename,
731-
visited_tests: HashMap::new(),
731+
visited_tests: FxHashMap::default(),
732732
}
733733
}
734734

@@ -1010,7 +1010,7 @@ impl<'a, 'hir, 'tcx> HirCollector<'a, 'hir, 'tcx> {
10101010
self.codes,
10111011
self.collector.enable_per_target_ignores,
10121012
Some(&crate::html::markdown::ExtraInfo::new(
1013-
&self.tcx,
1013+
self.tcx,
10141014
hir_id,
10151015
span_of_attrs(&attrs).unwrap_or(sp),
10161016
)),

src/librustdoc/formats/renderer.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
use std::sync::Arc;
22

3-
use rustc_middle::ty;
3+
use rustc_middle::ty::TyCtxt;
44
use rustc_span::edition::Edition;
55

66
use crate::clean;
@@ -20,7 +20,7 @@ crate trait FormatRenderer<'tcx>: Clone {
2020
render_info: RenderInfo,
2121
edition: Edition,
2222
cache: &mut Cache,
23-
tcx: ty::TyCtxt<'tcx>,
23+
tcx: TyCtxt<'tcx>,
2424
) -> Result<(Self, clean::Crate), Error>;
2525

2626
/// 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>>(
5555
render_info: RenderInfo,
5656
diag: &rustc_errors::Handler,
5757
edition: Edition,
58-
tcx: ty::TyCtxt<'tcx>,
58+
tcx: TyCtxt<'tcx>,
5959
) -> Result<(), Error> {
6060
let (krate, mut cache) = Cache::from_krate(
6161
render_info.clone(),

src/librustdoc/html/layout.rs

+3-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
1-
use std::collections::HashMap;
21
use std::path::PathBuf;
32

3+
use rustc_data_structures::fx::FxHashMap;
4+
45
use crate::externalfiles::ExternalHtml;
56
use crate::html::escape::Escape;
67
use crate::html::format::{Buffer, Print};
@@ -11,7 +12,7 @@ crate struct Layout {
1112
crate logo: String,
1213
crate favicon: String,
1314
crate external_html: ExternalHtml,
14-
crate default_settings: HashMap<String, String>,
15+
crate default_settings: FxHashMap<String, String>,
1516
crate krate: String,
1617
/// The given user css file which allow to customize the generated
1718
/// documentation theme.

src/librustdoc/html/markdown.rs

+8-8
Original file line numberDiff line numberDiff line change
@@ -620,7 +620,7 @@ crate fn find_testable_code<T: doctest::Tester>(
620620
tests: &mut T,
621621
error_codes: ErrorCodes,
622622
enable_per_target_ignores: bool,
623-
extra_info: Option<&ExtraInfo<'_, '_>>,
623+
extra_info: Option<&ExtraInfo<'_>>,
624624
) {
625625
let mut parser = Parser::new(doc).into_offset_iter();
626626
let mut prev_offset = 0;
@@ -681,19 +681,19 @@ crate fn find_testable_code<T: doctest::Tester>(
681681
}
682682
}
683683

684-
crate struct ExtraInfo<'a, 'b> {
684+
crate struct ExtraInfo<'tcx> {
685685
hir_id: Option<HirId>,
686686
item_did: Option<DefId>,
687687
sp: Span,
688-
tcx: &'a TyCtxt<'b>,
688+
tcx: TyCtxt<'tcx>,
689689
}
690690

691-
impl<'a, 'b> ExtraInfo<'a, 'b> {
692-
crate fn new(tcx: &'a TyCtxt<'b>, hir_id: HirId, sp: Span) -> ExtraInfo<'a, 'b> {
691+
impl<'tcx> ExtraInfo<'tcx> {
692+
crate fn new(tcx: TyCtxt<'tcx>, hir_id: HirId, sp: Span) -> ExtraInfo<'tcx> {
693693
ExtraInfo { hir_id: Some(hir_id), item_did: None, sp, tcx }
694694
}
695695

696-
crate fn new_did(tcx: &'a TyCtxt<'b>, did: DefId, sp: Span) -> ExtraInfo<'a, 'b> {
696+
crate fn new_did(tcx: TyCtxt<'tcx>, did: DefId, sp: Span) -> ExtraInfo<'tcx> {
697697
ExtraInfo { hir_id: None, item_did: Some(did), sp, tcx }
698698
}
699699

@@ -775,7 +775,7 @@ impl LangString {
775775
string: &str,
776776
allow_error_code_check: ErrorCodes,
777777
enable_per_target_ignores: bool,
778-
extra: Option<&ExtraInfo<'_, '_>>,
778+
extra: Option<&ExtraInfo<'_>>,
779779
) -> LangString {
780780
let allow_error_code_check = allow_error_code_check.as_bool();
781781
let mut seen_rust_tags = false;
@@ -1208,7 +1208,7 @@ crate struct RustCodeBlock {
12081208

12091209
/// Returns a range of bytes for each code block in the markdown that is tagged as `rust` or
12101210
/// untagged (and assumed to be rust).
1211-
crate fn rust_code_blocks(md: &str, extra_info: &ExtraInfo<'_, '_>) -> Vec<RustCodeBlock> {
1211+
crate fn rust_code_blocks(md: &str, extra_info: &ExtraInfo<'_>) -> Vec<RustCodeBlock> {
12121212
let mut code_blocks = vec![];
12131213

12141214
if md.is_empty() {

src/librustdoc/html/render/mod.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,6 @@ use rustc_hir as hir;
5555
use rustc_hir::def_id::{DefId, LOCAL_CRATE};
5656
use rustc_hir::Mutability;
5757
use rustc_middle::middle::stability;
58-
use rustc_middle::ty;
5958
use rustc_middle::ty::TyCtxt;
6059
use rustc_session::Session;
6160
use rustc_span::edition::Edition;
@@ -390,7 +389,7 @@ impl<'tcx> FormatRenderer<'tcx> for Context<'tcx> {
390389
_render_info: RenderInfo,
391390
edition: Edition,
392391
cache: &mut Cache,
393-
tcx: ty::TyCtxt<'tcx>,
392+
tcx: TyCtxt<'tcx>,
394393
) -> Result<(Self, clean::Crate), Error> {
395394
// need to save a copy of the options for rendering the index page
396395
let md_opts = options.clone();

src/librustdoc/json/mod.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ use std::path::PathBuf;
1313
use std::rc::Rc;
1414

1515
use rustc_data_structures::fx::FxHashMap;
16-
use rustc_middle::ty;
16+
use rustc_middle::ty::TyCtxt;
1717
use rustc_session::Session;
1818
use rustc_span::edition::Edition;
1919

@@ -26,7 +26,7 @@ use crate::html::render::cache::ExternalLocation;
2626

2727
#[derive(Clone)]
2828
crate struct JsonRenderer<'tcx> {
29-
tcx: ty::TyCtxt<'tcx>,
29+
tcx: TyCtxt<'tcx>,
3030
/// A mapping of IDs that contains all local items for this crate which gets output as a top
3131
/// level field of the JSON blob.
3232
index: Rc<RefCell<FxHashMap<types::Id, types::Item>>>,
@@ -131,7 +131,7 @@ impl<'tcx> FormatRenderer<'tcx> for JsonRenderer<'tcx> {
131131
_render_info: RenderInfo,
132132
_edition: Edition,
133133
_cache: &mut Cache,
134-
tcx: ty::TyCtxt<'tcx>,
134+
tcx: TyCtxt<'tcx>,
135135
) -> Result<(Self, clean::Crate), Error> {
136136
debug!("Initializing json renderer");
137137
Ok((

src/librustdoc/lib.rs

+3-2
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
#![feature(str_split_once)]
1919
#![feature(iter_intersperse)]
2020
#![recursion_limit = "256"]
21+
#![deny(rustc::internal)]
2122

2223
#[macro_use]
2324
extern crate lazy_static;
@@ -65,7 +66,7 @@ use std::process;
6566
use rustc_driver::abort_on_err;
6667
use rustc_errors::ErrorReported;
6768
use rustc_interface::interface;
68-
use rustc_middle::ty;
69+
use rustc_middle::ty::TyCtxt;
6970
use rustc_session::config::{make_crate_type_option, ErrorOutputType, RustcOptGroup};
7071
use rustc_session::getopts;
7172
use rustc_session::{early_error, early_warn};
@@ -471,7 +472,7 @@ fn run_renderer<'tcx, T: formats::FormatRenderer<'tcx>>(
471472
render_info: config::RenderInfo,
472473
diag: &rustc_errors::Handler,
473474
edition: rustc_span::edition::Edition,
474-
tcx: ty::TyCtxt<'tcx>,
475+
tcx: TyCtxt<'tcx>,
475476
) -> MainResult {
476477
match formats::run_format::<T>(krate, renderopts, render_info, &diag, edition, tcx) {
477478
Ok(_) => Ok(()),

src/librustdoc/passes/check_code_block_syntax.rs

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

src/librustdoc/passes/collect_intra_doc_links.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ use rustc_hir::def::{
1313
PerNS,
1414
};
1515
use rustc_hir::def_id::{CrateNum, DefId};
16+
use rustc_middle::ty::TyCtxt;
1617
use rustc_middle::{bug, ty};
1718
use rustc_resolve::ParentScope;
1819
use rustc_session::lint::{
@@ -85,7 +86,7 @@ impl Res {
8586
}
8687
}
8788

88-
fn name(self, tcx: ty::TyCtxt<'_>) -> String {
89+
fn name(self, tcx: TyCtxt<'_>) -> String {
8990
match self {
9091
Res::Def(_, id) => tcx.item_name(id).to_string(),
9192
Res::Primitive(prim) => prim.as_str().to_string(),
@@ -865,12 +866,11 @@ impl<'a, 'tcx> DocFolder for LinkCollector<'a, 'tcx> {
865866

866867
// FIXME(jynelson): this shouldn't go through stringification, rustdoc should just use the DefId directly
867868
let self_name = self_id.and_then(|self_id| {
868-
use ty::TyKind;
869869
if matches!(self.cx.tcx.def_kind(self_id), DefKind::Impl) {
870870
// using `ty.to_string()` (or any variant) has issues with raw idents
871871
let ty = self.cx.tcx.type_of(self_id);
872872
let name = match ty.kind() {
873-
TyKind::Adt(def, _) => Some(self.cx.tcx.item_name(def.did).to_string()),
873+
ty::Adt(def, _) => Some(self.cx.tcx.item_name(def.did).to_string()),
874874
other if other.is_primitive() => Some(ty.to_string()),
875875
_ => None,
876876
};

0 commit comments

Comments
 (0)