Skip to content

Commit 75983e1

Browse files
committed
Support configurable deny-warnings for all in-tree crates.
1 parent 9f3c96b commit 75983e1

File tree

22 files changed

+100
-82
lines changed

22 files changed

+100
-82
lines changed

Diff for: src/bootstrap/builder.rs

+3-2
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ use crate::install;
2323
use crate::native;
2424
use crate::run;
2525
use crate::test;
26-
use crate::tool;
26+
use crate::tool::{self, SourceType};
2727
use crate::util::{self, add_dylib_path, add_link_lib_path, exe, libdir};
2828
use crate::{Build, DocTests, GitRepo, Mode};
2929

@@ -759,6 +759,7 @@ impl<'a> Builder<'a> {
759759
&self,
760760
compiler: Compiler,
761761
mode: Mode,
762+
source_type: SourceType,
762763
target: Interned<String>,
763764
cmd: &str,
764765
) -> Cargo {
@@ -1125,7 +1126,7 @@ impl<'a> Builder<'a> {
11251126

11261127
cargo.env("RUSTC_VERBOSE", self.verbosity.to_string());
11271128

1128-
if !mode.is_tool() {
1129+
if source_type == SourceType::InTree {
11291130
// When extending this list, add the new lints to the RUSTFLAGS of the
11301131
// build_bootstrap function of src/bootstrap/bootstrap.py as well as
11311132
// some code doesn't go through this `rustc` wrapper.

Diff for: src/bootstrap/check.rs

+22-7
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,13 @@ impl Step for Std {
4444
let target = self.target;
4545
let compiler = builder.compiler(0, builder.config.build);
4646

47-
let mut cargo = builder.cargo(compiler, Mode::Std, target, cargo_subcommand(builder.kind));
47+
let mut cargo = builder.cargo(
48+
compiler,
49+
Mode::Std,
50+
SourceType::InTree,
51+
target,
52+
cargo_subcommand(builder.kind),
53+
);
4854
std_cargo(builder, target, compiler.stage, &mut cargo);
4955

5056
builder.info(&format!("Checking std artifacts ({} -> {})", &compiler.host, target));
@@ -92,8 +98,13 @@ impl Step for Rustc {
9298

9399
builder.ensure(Std { target });
94100

95-
let mut cargo =
96-
builder.cargo(compiler, Mode::Rustc, target, cargo_subcommand(builder.kind));
101+
let mut cargo = builder.cargo(
102+
compiler,
103+
Mode::Rustc,
104+
SourceType::InTree,
105+
target,
106+
cargo_subcommand(builder.kind),
107+
);
97108
rustc_cargo(builder, &mut cargo, target);
98109

99110
builder.info(&format!("Checking compiler artifacts ({} -> {})", &compiler.host, target));
@@ -113,7 +124,7 @@ impl Step for Rustc {
113124
}
114125

115126
macro_rules! tool_check_step {
116-
($name:ident, $path:expr) => {
127+
($name:ident, $path:expr, $source_type:expr) => {
117128
#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
118129
pub struct $name {
119130
pub target: Interned<String>,
@@ -145,7 +156,7 @@ macro_rules! tool_check_step {
145156
target,
146157
cargo_subcommand(builder.kind),
147158
$path,
148-
SourceType::InTree,
159+
$source_type,
149160
&[],
150161
);
151162

@@ -184,8 +195,12 @@ macro_rules! tool_check_step {
184195
};
185196
}
186197

187-
tool_check_step!(Rustdoc, "src/tools/rustdoc");
188-
tool_check_step!(Clippy, "src/tools/clippy");
198+
tool_check_step!(Rustdoc, "src/tools/rustdoc", SourceType::InTree);
199+
// Clippy is a hybrid. It is an external tool, but uses a git subtree instead
200+
// of a submodule. Since the SourceType only drives the deny-warnings
201+
// behavior, treat it as in-tree so that any new warnings in clippy will be
202+
// rejected.
203+
tool_check_step!(Clippy, "src/tools/clippy", SourceType::InTree);
189204

190205
/// Cargo's output path for the standard library in a given stage, compiled
191206
/// by a particular compiler for the specified target.

Diff for: src/bootstrap/compile.rs

+5-5
Original file line numberDiff line numberDiff line change
@@ -20,14 +20,14 @@ use filetime::FileTime;
2020
use serde::Deserialize;
2121

2222
use crate::builder::Cargo;
23+
use crate::builder::{Builder, Kind, RunConfig, ShouldRun, Step};
24+
use crate::cache::{Interned, INTERNER};
2325
use crate::dist;
2426
use crate::native;
27+
use crate::tool::SourceType;
2528
use crate::util::{exe, is_dylib, symlink_dir};
2629
use crate::{Compiler, DependencyType, GitRepo, Mode};
2730

28-
use crate::builder::{Builder, Kind, RunConfig, ShouldRun, Step};
29-
use crate::cache::{Interned, INTERNER};
30-
3131
#[derive(Debug, PartialOrd, Ord, Copy, Clone, PartialEq, Eq, Hash)]
3232
pub struct Std {
3333
pub target: Interned<String>,
@@ -87,7 +87,7 @@ impl Step for Std {
8787
target_deps.extend(copy_third_party_objects(builder, &compiler, target));
8888
target_deps.extend(copy_self_contained_objects(builder, &compiler, target));
8989

90-
let mut cargo = builder.cargo(compiler, Mode::Std, target, "build");
90+
let mut cargo = builder.cargo(compiler, Mode::Std, SourceType::InTree, target, "build");
9191
std_cargo(builder, target, compiler.stage, &mut cargo);
9292

9393
builder.info(&format!(
@@ -513,7 +513,7 @@ impl Step for Rustc {
513513
target: builder.config.build,
514514
});
515515

516-
let mut cargo = builder.cargo(compiler, Mode::Rustc, target, "build");
516+
let mut cargo = builder.cargo(compiler, Mode::Rustc, SourceType::InTree, target, "build");
517517
rustc_cargo(builder, &mut cargo, target);
518518

519519
builder.info(&format!(

Diff for: src/bootstrap/doc.rs

+3-2
Original file line numberDiff line numberDiff line change
@@ -435,7 +435,8 @@ impl Step for Std {
435435
t!(fs::copy(builder.src.join("src/doc/rust.css"), out.join("rust.css")));
436436

437437
let run_cargo_rustdoc_for = |package: &str| {
438-
let mut cargo = builder.cargo(compiler, Mode::Std, target, "rustdoc");
438+
let mut cargo =
439+
builder.cargo(compiler, Mode::Std, SourceType::InTree, target, "rustdoc");
439440
compile::std_cargo(builder, target, compiler.stage, &mut cargo);
440441

441442
// Keep a whitelist so we do not build internal stdlib crates, these will be
@@ -534,7 +535,7 @@ impl Step for Rustc {
534535
t!(symlink_dir_force(&builder.config, &out, &out_dir));
535536

536537
// Build cargo command.
537-
let mut cargo = builder.cargo(compiler, Mode::Rustc, target, "doc");
538+
let mut cargo = builder.cargo(compiler, Mode::Rustc, SourceType::InTree, target, "doc");
538539
cargo.env(
539540
"RUSTDOCFLAGS",
540541
"--document-private-items \

Diff for: src/bootstrap/lib.rs

+12-7
Original file line numberDiff line numberDiff line change
@@ -301,16 +301,21 @@ pub enum Mode {
301301
/// Build codegen libraries, placing output in the "stageN-codegen" directory
302302
Codegen,
303303

304-
/// Build some tools, placing output in the "stageN-tools" directory. The
305-
/// "other" here is for miscellaneous sets of tools that are built using the
306-
/// bootstrap compiler in its entirety (target libraries and all).
307-
/// Typically these tools compile with stable Rust.
304+
/// Build a tool, placing output in the "stage0-bootstrap-tools"
305+
/// directory. This is for miscellaneous sets of tools that are built
306+
/// using the bootstrap stage0 compiler in its entirety (target libraries
307+
/// and all). Typically these tools compile with stable Rust.
308308
ToolBootstrap,
309309

310-
/// Compile a tool which uses all libraries we compile (up to rustc).
311-
/// Doesn't use the stage0 compiler libraries like "other", and includes
312-
/// tools like rustdoc, cargo, rls, etc.
310+
/// Build a tool which uses the locally built std, placing output in the
311+
/// "stageN-tools" directory. Its usage is quite rare, mainly used by
312+
/// compiletest which needs libtest.
313313
ToolStd,
314+
315+
/// Build a tool which uses the locally built rustc and the target std,
316+
/// placing the output in the "stageN-tools" directory. This is used for
317+
/// anything that needs a fully functional rustc, such as rustdoc, clippy,
318+
/// cargo, rls, rustfmt, miri, etc.
314319
ToolRustc,
315320
}
316321

Diff for: src/bootstrap/test.rs

+4-2
Original file line numberDiff line numberDiff line change
@@ -367,7 +367,8 @@ impl Step for Miri {
367367
extra_features: Vec::new(),
368368
});
369369
if let (Some(miri), Some(_cargo_miri)) = (miri, cargo_miri) {
370-
let mut cargo = builder.cargo(compiler, Mode::ToolRustc, host, "install");
370+
let mut cargo =
371+
builder.cargo(compiler, Mode::ToolRustc, SourceType::Submodule, host, "install");
371372
cargo.arg("xargo");
372373
// Configure `cargo install` path. cargo adds a `bin/`.
373374
cargo.env("CARGO_INSTALL_ROOT", &builder.out);
@@ -1696,7 +1697,8 @@ impl Step for Crate {
16961697
// we're working with automatically.
16971698
let compiler = builder.compiler_for(compiler.stage, compiler.host, target);
16981699

1699-
let mut cargo = builder.cargo(compiler, mode, target, test_kind.subcommand());
1700+
let mut cargo =
1701+
builder.cargo(compiler, mode, SourceType::InTree, target, test_kind.subcommand());
17001702
match mode {
17011703
Mode::Std => {
17021704
compile::std_cargo(builder, target, compiler.stage, &mut cargo);

Diff for: src/bootstrap/tool.rs

+10-9
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ use crate::util::{add_dylib_path, exe, CiEnv};
1616
use crate::Compiler;
1717
use crate::Mode;
1818

19-
#[derive(Debug, Clone, Hash, PartialEq, Eq)]
19+
#[derive(Debug, Copy, Clone, Hash, PartialEq, Eq)]
2020
pub enum SourceType {
2121
InTree,
2222
Submodule,
@@ -226,14 +226,10 @@ pub fn prepare_tool_cargo(
226226
source_type: SourceType,
227227
extra_features: &[String],
228228
) -> CargoCommand {
229-
let mut cargo = builder.cargo(compiler, mode, target, command);
229+
let mut cargo = builder.cargo(compiler, mode, source_type, target, command);
230230
let dir = builder.src.join(path);
231231
cargo.arg("--manifest-path").arg(dir.join("Cargo.toml"));
232232

233-
if source_type == SourceType::Submodule {
234-
cargo.env("RUSTC_EXTERNAL_TOOL", "1");
235-
}
236-
237233
let mut features = extra_features.to_vec();
238234
if builder.build.config.cargo_native_static {
239235
if path.ends_with("cargo")
@@ -596,6 +592,7 @@ macro_rules! tool_extended {
596592
$path:expr,
597593
$tool_name:expr,
598594
stable = $stable:expr,
595+
$(in_tree = $in_tree:expr,)*
599596
$extra_deps:block;)+) => {
600597
$(
601598
#[derive(Debug, Clone, Hash, PartialEq, Eq)]
@@ -647,7 +644,11 @@ macro_rules! tool_extended {
647644
path: $path,
648645
extra_features: $sel.extra_features,
649646
is_optional_tool: true,
650-
source_type: SourceType::Submodule,
647+
source_type: if false $(|| $in_tree)* {
648+
SourceType::InTree
649+
} else {
650+
SourceType::Submodule
651+
},
651652
})
652653
}
653654
}
@@ -659,8 +660,8 @@ macro_rules! tool_extended {
659660
// to make `./x.py build <tool>` work.
660661
tool_extended!((self, builder),
661662
Cargofmt, rustfmt, "src/tools/rustfmt", "cargo-fmt", stable=true, {};
662-
CargoClippy, clippy, "src/tools/clippy", "cargo-clippy", stable=true, {};
663-
Clippy, clippy, "src/tools/clippy", "clippy-driver", stable=true, {};
663+
CargoClippy, clippy, "src/tools/clippy", "cargo-clippy", stable=true, in_tree=true, {};
664+
Clippy, clippy, "src/tools/clippy", "clippy-driver", stable=true, in_tree=true, {};
664665
Miri, miri, "src/tools/miri", "miri", stable=false, {};
665666
CargoMiri, miri, "src/tools/miri/cargo-miri", "cargo-miri", stable=false, {};
666667
Rls, rls, "src/tools/rls", "rls", stable=true, {

Diff for: src/librustdoc/clean/inline.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -278,7 +278,7 @@ fn build_type_alias_type(cx: &DocContext<'_>, did: DefId) -> Option<clean::Type>
278278
type_.def_id().and_then(|did| build_ty(cx, did))
279279
}
280280

281-
pub fn build_ty(cx: &DocContext, did: DefId) -> Option<clean::Type> {
281+
pub fn build_ty(cx: &DocContext<'_>, did: DefId) -> Option<clean::Type> {
282282
match cx.tcx.def_kind(did) {
283283
DefKind::Struct | DefKind::Union | DefKind::Enum | DefKind::Const | DefKind::Static => {
284284
Some(cx.tcx.type_of(did).clean(cx))

Diff for: src/librustdoc/clean/utils.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -328,7 +328,7 @@ pub fn strip_path(path: &Path) -> Path {
328328
Path { global: path.global, res: path.res, segments }
329329
}
330330

331-
pub fn qpath_to_string(p: &hir::QPath) -> String {
331+
pub fn qpath_to_string(p: &hir::QPath<'_>) -> String {
332332
let segments = match *p {
333333
hir::QPath::Resolved(_, ref path) => &path.segments,
334334
hir::QPath::TypeRelative(_, ref segment) => return segment.ident.to_string(),
@@ -417,7 +417,7 @@ impl ToSource for rustc_span::Span {
417417
}
418418
}
419419

420-
pub fn name_from_pat(p: &hir::Pat) -> String {
420+
pub fn name_from_pat(p: &hir::Pat<'_>) -> String {
421421
use rustc_hir::*;
422422
debug!("trying to get a name from pattern: {:?}", p);
423423

Diff for: src/librustdoc/doctree.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -262,7 +262,7 @@ pub struct ProcMacro<'hir> {
262262
pub whence: Span,
263263
}
264264

265-
pub fn struct_type_from_def(vdata: &hir::VariantData) -> StructType {
265+
pub fn struct_type_from_def(vdata: &hir::VariantData<'_>) -> StructType {
266266
match *vdata {
267267
hir::VariantData::Struct(..) => Plain,
268268
hir::VariantData::Tuple(..) => Tuple,

Diff for: src/librustdoc/test.rs

+9-9
Original file line numberDiff line numberDiff line change
@@ -166,7 +166,7 @@ pub fn run(options: Options) -> Result<(), String> {
166166
}
167167

168168
// Look for `#![doc(test(no_crate_inject))]`, used by crates in the std facade.
169-
fn scrape_test_config(krate: &::rustc_hir::Crate) -> TestOptions {
169+
fn scrape_test_config(krate: &::rustc_hir::Crate<'_>) -> TestOptions {
170170
use rustc_ast_pretty::pprust;
171171

172172
let mut opts =
@@ -973,7 +973,7 @@ impl<'a, 'hir, 'tcx> intravisit::Visitor<'hir> for HirCollector<'a, 'hir, 'tcx>
973973
intravisit::NestedVisitorMap::All(self.map)
974974
}
975975

976-
fn visit_item(&mut self, item: &'hir hir::Item) {
976+
fn visit_item(&mut self, item: &'hir hir::Item<'_>) {
977977
let name = if let hir::ItemKind::Impl { ref self_ty, .. } = item.kind {
978978
rustc_hir_pretty::id_to_string(&self.map, self_ty.hir_id)
979979
} else {
@@ -985,42 +985,42 @@ impl<'a, 'hir, 'tcx> intravisit::Visitor<'hir> for HirCollector<'a, 'hir, 'tcx>
985985
});
986986
}
987987

988-
fn visit_trait_item(&mut self, item: &'hir hir::TraitItem) {
988+
fn visit_trait_item(&mut self, item: &'hir hir::TraitItem<'_>) {
989989
self.visit_testable(item.ident.to_string(), &item.attrs, item.hir_id, item.span, |this| {
990990
intravisit::walk_trait_item(this, item);
991991
});
992992
}
993993

994-
fn visit_impl_item(&mut self, item: &'hir hir::ImplItem) {
994+
fn visit_impl_item(&mut self, item: &'hir hir::ImplItem<'_>) {
995995
self.visit_testable(item.ident.to_string(), &item.attrs, item.hir_id, item.span, |this| {
996996
intravisit::walk_impl_item(this, item);
997997
});
998998
}
999999

1000-
fn visit_foreign_item(&mut self, item: &'hir hir::ForeignItem) {
1000+
fn visit_foreign_item(&mut self, item: &'hir hir::ForeignItem<'_>) {
10011001
self.visit_testable(item.ident.to_string(), &item.attrs, item.hir_id, item.span, |this| {
10021002
intravisit::walk_foreign_item(this, item);
10031003
});
10041004
}
10051005

10061006
fn visit_variant(
10071007
&mut self,
1008-
v: &'hir hir::Variant,
1009-
g: &'hir hir::Generics,
1008+
v: &'hir hir::Variant<'_>,
1009+
g: &'hir hir::Generics<'_>,
10101010
item_id: hir::HirId,
10111011
) {
10121012
self.visit_testable(v.ident.to_string(), &v.attrs, v.id, v.span, |this| {
10131013
intravisit::walk_variant(this, v, g, item_id);
10141014
});
10151015
}
10161016

1017-
fn visit_struct_field(&mut self, f: &'hir hir::StructField) {
1017+
fn visit_struct_field(&mut self, f: &'hir hir::StructField<'_>) {
10181018
self.visit_testable(f.ident.to_string(), &f.attrs, f.hir_id, f.span, |this| {
10191019
intravisit::walk_struct_field(this, f);
10201020
});
10211021
}
10221022

1023-
fn visit_macro_def(&mut self, macro_def: &'hir hir::MacroDef) {
1023+
fn visit_macro_def(&mut self, macro_def: &'hir hir::MacroDef<'_>) {
10241024
self.visit_testable(
10251025
macro_def.ident.to_string(),
10261026
&macro_def.attrs,

0 commit comments

Comments
 (0)