Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Deny rustc::internal lints for rustdoc and clippy #80573

Merged
merged 2 commits into from
Jan 22, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions src/bootstrap/check.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
4 changes: 2 additions & 2 deletions src/librustdoc/config.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use std::collections::{BTreeMap, HashMap};
use std::collections::BTreeMap;
use std::convert::TryFrom;
use std::ffi::OsStr;
use std::fmt;
Expand Down Expand Up @@ -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
Expand Down
8 changes: 4 additions & 4 deletions src/librustdoc/doctest.rs
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -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 {
Expand All @@ -727,7 +727,7 @@ impl Collector {
position: DUMMY_SP,
source_map,
filename,
visited_tests: HashMap::new(),
visited_tests: FxHashMap::default(),
}
}

Expand Down Expand Up @@ -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),
)),
Expand Down
6 changes: 3 additions & 3 deletions src/librustdoc/formats/renderer.rs
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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.
Expand Down Expand Up @@ -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(),
Expand Down
5 changes: 3 additions & 2 deletions src/librustdoc/html/layout.rs
Original file line number Diff line number Diff line change
@@ -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};
Expand All @@ -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.
Expand Down
16 changes: 8 additions & 8 deletions src/librustdoc/html/markdown.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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 }
}

Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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() {
Expand Down
3 changes: 1 addition & 2 deletions src/librustdoc/html/render/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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();
Expand Down
6 changes: 3 additions & 3 deletions src/librustdoc/json/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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>>>,
Expand Down Expand Up @@ -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((
Expand Down
5 changes: 3 additions & 2 deletions src/librustdoc/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
#![feature(str_split_once)]
#![feature(iter_intersperse)]
#![recursion_limit = "256"]
#![deny(rustc::internal)]

#[macro_use]
extern crate lazy_static;
Expand Down Expand Up @@ -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};
Expand Down Expand Up @@ -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(()),
Expand Down
2 changes: 1 addition & 1 deletion src/librustdoc/passes/check_code_block_syntax.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
6 changes: 3 additions & 3 deletions src/librustdoc/passes/collect_intra_doc_links.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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::{
Expand Down Expand Up @@ -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(),
Expand Down Expand Up @@ -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,
};
Expand Down