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)
This commit is contained in:
Mara Bos
2021-01-22 14:30:03 +00:00
committed by GitHub
11 changed files with 38 additions and 30 deletions
+7
View File
@@ -320,6 +320,13 @@ fn run(self, builder: &Builder<'_>) {
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,
+2 -2
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 @@ fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
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
+4 -4
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_target::spec::TargetTriple;
use tempfile::Builder as TempFileBuilder;
use std::collections::HashMap;
use std::env;
use std::io::{self, Write};
use std::panic;
@@ -704,7 +704,7 @@ fn register_header(&mut self, _name: &str, _level: u32) {}
position: Span,
source_map: Option<Lrc<SourceMap>>,
filename: Option<PathBuf>,
visited_tests: HashMap<(String, usize), usize>,
visited_tests: FxHashMap<(String, usize), usize>,
}
impl Collector {
@@ -728,7 +728,7 @@ impl Collector {
position: DUMMY_SP,
source_map,
filename,
visited_tests: HashMap::new(),
visited_tests: FxHashMap::default(),
}
}
@@ -1010,7 +1010,7 @@ fn visit_testable<F: FnOnce(&mut Self)>(
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),
)),
+3 -3
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 @@ fn init(
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 @@ fn after_krate(
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(),
+3 -2
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 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.
+8 -8
View File
@@ -620,7 +620,7 @@ fn next(&mut self) -> Option<Self::Item> {
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 @@ fn next(&mut self) -> Option<Self::Item> {
}
}
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 @@ fn parse(
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 @@ fn push(s: &mut String, text_length: &mut usize, text: &str) {
/// 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() {
+1 -2
View File
@@ -55,7 +55,6 @@
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 @@ fn init(
_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();
+3 -3
View File
@@ -13,7 +13,7 @@
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 @@
#[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 @@ fn init(
_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((
+3 -2
View File
@@ -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 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::<T>(krate, renderopts, render_info, &diag, edition, tcx) {
Ok(_) => Ok(()),
@@ -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);
}
@@ -13,6 +13,7 @@
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 @@ fn article(self) -> &'static str {
}
}
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 @@ fn fold_item(&mut self, mut item: Item) -> Option<Item> {
// 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,
};