Skip to content

Commit 4ff8fb9

Browse files
committed
Auto merge of #68831 - Dylan-DPC:rollup-j6x15y9, r=Dylan-DPC
Rollup of 7 pull requests Successful merges: - #68282 (Instrument C / C++ in MemorySanitizer example) - #68758 (Fix 59191 - ICE when macro replaces crate root with non-module item) - #68805 (bootstrap: fix clippy warnings) - #68810 (Remove Copy impl from OnceWith) - #68815 (remove redundant imports (clippy::single_component_path_imports)) - #68818 (fix couple of perf related clippy warnings) - #68819 (Suggest `split_at_mut` on multiple mutable index access) Failed merges: r? @ghost
2 parents 002287d + 793a5e6 commit 4ff8fb9

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

52 files changed

+156
-114
lines changed

src/bootstrap/bin/rustc.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ fn main() {
4747
};
4848
let stage = env::var("RUSTC_STAGE").expect("RUSTC_STAGE was not set");
4949
let sysroot = env::var_os("RUSTC_SYSROOT").expect("RUSTC_SYSROOT was not set");
50-
let on_fail = env::var_os("RUSTC_ON_FAIL").map(|of| Command::new(of));
50+
let on_fail = env::var_os("RUSTC_ON_FAIL").map(Command::new);
5151

5252
let rustc = env::var_os(rustc).unwrap_or_else(|| panic!("{:?} was not set", rustc));
5353
let libdir = env::var_os(libdir).unwrap_or_else(|| panic!("{:?} was not set", libdir));
@@ -64,7 +64,7 @@ fn main() {
6464
if let Some(crate_name) = crate_name {
6565
if let Some(target) = env::var_os("RUSTC_TIME") {
6666
if target == "all"
67-
|| target.into_string().unwrap().split(",").any(|c| c.trim() == crate_name)
67+
|| target.into_string().unwrap().split(',').any(|c| c.trim() == crate_name)
6868
{
6969
cmd.arg("-Ztime");
7070
}
@@ -189,7 +189,7 @@ fn main() {
189189
crate_name,
190190
is_test,
191191
dur.as_secs(),
192-
dur.subsec_nanos() / 1_000_000
192+
dur.subsec_millis()
193193
);
194194

195195
match status.code() {

src/bootstrap/bin/rustdoc.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ fn main() {
6161
}
6262

6363
// Needed to be able to run all rustdoc tests.
64-
if let Some(_) = env::var_os("RUSTDOC_GENERATE_REDIRECT_PAGES") {
64+
if env::var_os("RUSTDOC_GENERATE_REDIRECT_PAGES").is_some() {
6565
// This "unstable-options" can be removed when `--generate-redirect-pages` is stabilized
6666
if !has_unstable {
6767
cmd.arg("-Z").arg("unstable-options");

src/bootstrap/builder.rs

+8-16
Original file line numberDiff line numberDiff line change
@@ -510,17 +510,15 @@ impl<'a> Builder<'a> {
510510
Subcommand::Format { .. } | Subcommand::Clean { .. } => panic!(),
511511
};
512512

513-
let builder = Builder {
513+
Builder {
514514
build,
515515
top_stage: build.config.stage.unwrap_or(2),
516516
kind,
517517
cache: Cache::new(),
518518
stack: RefCell::new(Vec::new()),
519519
time_spent_on_dependencies: Cell::new(Duration::new(0, 0)),
520520
paths: paths.to_owned(),
521-
};
522-
523-
builder
521+
}
524522
}
525523

526524
pub fn execute_cli(&self) {
@@ -753,13 +751,12 @@ impl<'a> Builder<'a> {
753751
cargo.env("RUST_CHECK", "1");
754752
}
755753

756-
let stage;
757-
if compiler.stage == 0 && self.local_rebuild {
754+
let stage = if compiler.stage == 0 && self.local_rebuild {
758755
// Assume the local-rebuild rustc already has stage1 features.
759-
stage = 1;
756+
1
760757
} else {
761-
stage = compiler.stage;
762-
}
758+
compiler.stage
759+
};
763760

764761
let mut rustflags = Rustflags::new(&target);
765762
if stage != 0 {
@@ -1252,12 +1249,7 @@ impl<'a> Builder<'a> {
12521249
};
12531250

12541251
if self.config.print_step_timings && dur > Duration::from_millis(100) {
1255-
println!(
1256-
"[TIMING] {:?} -- {}.{:03}",
1257-
step,
1258-
dur.as_secs(),
1259-
dur.subsec_nanos() / 1_000_000
1260-
);
1252+
println!("[TIMING] {:?} -- {}.{:03}", step, dur.as_secs(), dur.subsec_millis());
12611253
}
12621254

12631255
{
@@ -1302,7 +1294,7 @@ impl Rustflags {
13021294

13031295
fn arg(&mut self, arg: &str) -> &mut Self {
13041296
assert_eq!(arg.split_whitespace().count(), 1);
1305-
if self.0.len() > 0 {
1297+
if !self.0.is_empty() {
13061298
self.0.push_str(" ");
13071299
}
13081300
self.0.push_str(arg);

src/bootstrap/builder/tests.rs

-1
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ fn configure(host: &[&str], target: &[&str]) -> Config {
1919
config.out = dir;
2020
config.build = INTERNER.intern_str("A");
2121
config.hosts = vec![config.build]
22-
.clone()
2322
.into_iter()
2423
.chain(host.iter().map(|s| INTERNER.intern_str(s)))
2524
.collect::<Vec<_>>();

src/bootstrap/compile.rs

+10-10
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@ use std::str;
1818
use build_helper::{output, t, up_to_date};
1919
use filetime::FileTime;
2020
use serde::Deserialize;
21-
use serde_json;
2221

2322
use crate::builder::Cargo;
2423
use crate::dist;
@@ -149,7 +148,8 @@ fn copy_third_party_objects(
149148
// which is provided by std for this target.
150149
if target == "x86_64-fortanix-unknown-sgx" {
151150
let src_path_env = "X86_FORTANIX_SGX_LIBS";
152-
let src = env::var(src_path_env).expect(&format!("{} not found in env", src_path_env));
151+
let src =
152+
env::var(src_path_env).unwrap_or_else(|_| panic!("{} not found in env", src_path_env));
153153
copy_and_stamp(Path::new(&src), "libunwind.a");
154154
}
155155

@@ -361,7 +361,7 @@ impl Step for StartupObjects {
361361
);
362362
}
363363

364-
let target = sysroot_dir.join(file.to_string() + ".o");
364+
let target = sysroot_dir.join((*file).to_string() + ".o");
365365
builder.copy(dst_file, &target);
366366
target_deps.push(target);
367367
}
@@ -515,7 +515,7 @@ pub fn rustc_cargo_env(builder: &Builder<'_>, cargo: &mut Cargo, target: Interne
515515
.env("CFG_VERSION", builder.rust_version())
516516
.env("CFG_PREFIX", builder.config.prefix.clone().unwrap_or_default());
517517

518-
let libdir_relative = builder.config.libdir_relative().unwrap_or(Path::new("lib"));
518+
let libdir_relative = builder.config.libdir_relative().unwrap_or_else(|| Path::new("lib"));
519519
cargo.env("CFG_LIBDIR_RELATIVE", libdir_relative);
520520

521521
if let Some(ref ver_date) = builder.rust_info.commit_date() {
@@ -843,11 +843,11 @@ pub fn run_cargo(
843843
};
844844
for filename in filenames {
845845
// Skip files like executables
846-
if !filename.ends_with(".rlib")
847-
&& !filename.ends_with(".lib")
848-
&& !filename.ends_with(".a")
849-
&& !is_dylib(&filename)
850-
&& !(is_check && filename.ends_with(".rmeta"))
846+
if !(filename.ends_with(".rlib")
847+
|| filename.ends_with(".lib")
848+
|| filename.ends_with(".a")
849+
|| is_dylib(&filename)
850+
|| (is_check && filename.ends_with(".rmeta")))
851851
{
852852
continue;
853853
}
@@ -905,7 +905,7 @@ pub fn run_cargo(
905905
for (prefix, extension, expected_len) in toplevel {
906906
let candidates = contents.iter().filter(|&&(_, ref filename, ref meta)| {
907907
filename.starts_with(&prefix[..])
908-
&& filename[prefix.len()..].starts_with("-")
908+
&& filename[prefix.len()..].starts_with('-')
909909
&& filename.ends_with(&extension[..])
910910
&& meta.len() == expected_len
911911
});

src/bootstrap/config.rs

+3-4
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@ use crate::flags::Flags;
1616
pub use crate::flags::Subcommand;
1717
use build_helper::t;
1818
use serde::Deserialize;
19-
use toml;
2019

2120
/// Global configuration for the entire build and/or bootstrap.
2221
///
@@ -440,7 +439,7 @@ impl Config {
440439
}
441440
}
442441
})
443-
.unwrap_or_else(|| TomlConfig::default());
442+
.unwrap_or_else(TomlConfig::default);
444443

445444
let build = toml.build.clone().unwrap_or_default();
446445
// set by bootstrap.py
@@ -539,7 +538,7 @@ impl Config {
539538
config.llvm_ldflags = llvm.ldflags.clone();
540539
set(&mut config.llvm_use_libcxx, llvm.use_libcxx);
541540
config.llvm_use_linker = llvm.use_linker.clone();
542-
config.llvm_allow_old_toolchain = llvm.allow_old_toolchain.clone();
541+
config.llvm_allow_old_toolchain = llvm.allow_old_toolchain;
543542
}
544543

545544
if let Some(ref rust) = toml.rust {
@@ -606,7 +605,7 @@ impl Config {
606605
target.ar = cfg.ar.clone().map(PathBuf::from);
607606
target.ranlib = cfg.ranlib.clone().map(PathBuf::from);
608607
target.linker = cfg.linker.clone().map(PathBuf::from);
609-
target.crt_static = cfg.crt_static.clone();
608+
target.crt_static = cfg.crt_static;
610609
target.musl_root = cfg.musl_root.clone().map(PathBuf::from);
611610
target.wasi_root = cfg.wasi_root.clone().map(PathBuf::from);
612611
target.qemu_rootfs = cfg.qemu_rootfs.clone().map(PathBuf::from);

src/bootstrap/dist.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -828,7 +828,7 @@ impl Step for Analysis {
828828
assert!(builder.config.extended);
829829
let name = pkgname(builder, "rust-analysis");
830830

831-
if &compiler.host != builder.config.build {
831+
if compiler.host != builder.config.build {
832832
return distdir(builder).join(format!("{}-{}.tar.gz", name, target));
833833
}
834834

@@ -877,7 +877,7 @@ fn copy_src_dirs(builder: &Builder<'_>, src_dirs: &[&str], exclude_dirs: &[&str]
877877
Some(path) => path,
878878
None => return false,
879879
};
880-
if spath.ends_with("~") || spath.ends_with(".pyc") {
880+
if spath.ends_with('~') || spath.ends_with(".pyc") {
881881
return false;
882882
}
883883

src/bootstrap/doc.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -560,7 +560,7 @@ impl Step for Rustdoc {
560560
builder.ensure(Rustc { stage, target });
561561

562562
// Build rustdoc.
563-
builder.ensure(tool::Rustdoc { compiler: compiler });
563+
builder.ensure(tool::Rustdoc { compiler });
564564

565565
// Symlink compiler docs to the output directory of rustdoc documentation.
566566
let out_dir = builder.stage_out(compiler, Mode::ToolRustc).join(target).join("doc");

src/bootstrap/flags.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -571,7 +571,7 @@ fn split(s: &[String]) -> Vec<String> {
571571
}
572572

573573
fn parse_deny_warnings(matches: &getopts::Matches) -> Option<bool> {
574-
match matches.opt_str("warnings").as_ref().map(|v| v.as_str()) {
574+
match matches.opt_str("warnings").as_deref() {
575575
Some("deny") => Some(true),
576576
Some("warn") => Some(false),
577577
Some(value) => {

src/bootstrap/install.rs

+2-3
Original file line numberDiff line numberDiff line change
@@ -126,9 +126,8 @@ fn add_destdir(path: &Path, destdir: &Option<PathBuf>) -> PathBuf {
126126
None => return path.to_path_buf(),
127127
};
128128
for part in path.components() {
129-
match part {
130-
Component::Normal(s) => ret.push(s),
131-
_ => {}
129+
if let Component::Normal(s) = part {
130+
ret.push(s)
132131
}
133132
}
134133
ret

src/bootstrap/lib.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -444,7 +444,7 @@ impl Build {
444444
builder.execute_cli();
445445
} else {
446446
let builder = builder::Builder::new(&self);
447-
let _ = builder.execute_cli();
447+
builder.execute_cli();
448448
}
449449

450450
// Check for postponed failures from `test --no-fail-fast`.
@@ -839,7 +839,7 @@ impl Build {
839839
.target_config
840840
.get(&target)
841841
.and_then(|t| t.musl_root.as_ref())
842-
.or(self.config.musl_root.as_ref())
842+
.or_else(|| self.config.musl_root.as_ref())
843843
.map(|p| &**p)
844844
}
845845

src/bootstrap/metadata.rs

-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ use std::process::Command;
55

66
use build_helper::output;
77
use serde::Deserialize;
8-
use serde_json;
98

109
use crate::cache::INTERNER;
1110
use crate::{Build, Crate};

src/bootstrap/native.rs

+1-3
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,6 @@ use std::path::{Path, PathBuf};
1515
use std::process::Command;
1616

1717
use build_helper::{output, t};
18-
use cc;
19-
use cmake;
2018

2119
use crate::builder::{Builder, RunConfig, ShouldRun, Step};
2220
use crate::cache::Interned;
@@ -205,7 +203,7 @@ impl Step for Llvm {
205203
cfg.define("LLVM_ENABLE_LIBXML2", "OFF");
206204
}
207205

208-
if enabled_llvm_projects.len() > 0 {
206+
if !enabled_llvm_projects.is_empty() {
209207
enabled_llvm_projects.sort();
210208
enabled_llvm_projects.dedup();
211209
cfg.define("LLVM_ENABLE_PROJECTS", enabled_llvm_projects.join(";"));

src/bootstrap/test.rs

+3-6
Original file line numberDiff line numberDiff line change
@@ -1424,13 +1424,10 @@ impl Step for ErrorIndex {
14241424
}
14251425

14261426
fn markdown_test(builder: &Builder<'_>, compiler: Compiler, markdown: &Path) -> bool {
1427-
match fs::read_to_string(markdown) {
1428-
Ok(contents) => {
1429-
if !contents.contains("```") {
1430-
return true;
1431-
}
1427+
if let Ok(contents) = fs::read_to_string(markdown) {
1428+
if !contents.contains("```") {
1429+
return true;
14321430
}
1433-
Err(_) => {}
14341431
}
14351432

14361433
builder.info(&format!("doc tests for: {}", markdown.display()));

src/bootstrap/tool.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -234,7 +234,7 @@ pub fn prepare_tool_cargo(
234234
cargo.env("RUSTC_EXTERNAL_TOOL", "1");
235235
}
236236

237-
let mut features = extra_features.iter().cloned().collect::<Vec<_>>();
237+
let mut features = extra_features.to_vec();
238238
if builder.build.config.cargo_native_static {
239239
if path.ends_with("cargo")
240240
|| path.ends_with("rls")

src/bootstrap/toolstate.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@ fn check_changed_files(toolstates: &HashMap<Box<str>, ToolState>) {
124124
let output = t!(String::from_utf8(output.stdout));
125125

126126
for (tool, submodule) in STABLE_TOOLS.iter().chain(NIGHTLY_TOOLS.iter()) {
127-
let changed = output.lines().any(|l| l.starts_with("M") && l.ends_with(submodule));
127+
let changed = output.lines().any(|l| l.starts_with('M') && l.ends_with(submodule));
128128
eprintln!("Verifying status of {}...", tool);
129129
if !changed {
130130
continue;

src/bootstrap/util.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ impl Drop for TimeIt {
9898
fn drop(&mut self) {
9999
let time = self.1.elapsed();
100100
if !self.0 {
101-
println!("\tfinished in {}.{:03}", time.as_secs(), time.subsec_nanos() / 1_000_000);
101+
println!("\tfinished in {}.{:03}", time.as_secs(), time.subsec_millis());
102102
}
103103
}
104104
}

src/doc/unstable-book/src/compiler-flags/sanitizer.md

+10-2
Original file line numberDiff line numberDiff line change
@@ -170,7 +170,7 @@ Shadow byte legend (one shadow byte represents 8 application bytes):
170170
## MemorySanitizer
171171
172172
Use of uninitialized memory. Note that we are using `-Zbuild-std` to instrument
173-
standard library, and passing `-msan-track-origins=2` to the LLVM to track
173+
the standard library, and passing `-Zsanitizer-track-origins` to track the
174174
origins of uninitialized memory:
175175
176176
```shell
@@ -185,7 +185,15 @@ fn main() {
185185
}
186186
}
187187

188-
$ env RUSTFLAGS="-Zsanitizer=memory -Cllvm-args=-msan-track-origins=2" cargo -Zbuild-std run --target x86_64-unknown-linux-gnu
188+
$ export \
189+
CC=clang \
190+
CXX=clang++ \
191+
CFLAGS='-fsanitize=memory -fsanitize-memory-track-origins' \
192+
CXXFLAGS='-fsanitize=memory -fsanitize-memory-track-origins' \
193+
RUSTFLAGS='-Zsanitizer=memory -Zsanitizer-memory-track-origins' \
194+
RUSTDOCFLAGS='-Zsanitizer=memory -Zsanitizer-memory-track-origins'
195+
$ cargo clean
196+
$ cargo -Zbuild-std run --target x86_64-unknown-linux-gnu
189197
==9416==WARNING: MemorySanitizer: use-of-uninitialized-value
190198
#0 0x560c04f7488a in core::fmt::num::imp::fmt_u64::haa293b0b098501ca $RUST/build/x86_64-unknown-linux-gnu/stage1/lib/rustlib/src/rust/src/libcore/fmt/num.rs:202:16
191199
...

src/libcore/iter/sources.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -398,7 +398,7 @@ pub fn once<T>(value: T) -> Once<T> {
398398
/// See its documentation for more.
399399
///
400400
/// [`once_with`]: fn.once_with.html
401-
#[derive(Copy, Clone, Debug)]
401+
#[derive(Clone, Debug)]
402402
#[stable(feature = "iter_once_with", since = "1.43.0")]
403403
pub struct OnceWith<F> {
404404
gen: Option<F>,

src/librustc/traits/mod.rs

-1
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,6 @@ use crate::ty::fold::{TypeFoldable, TypeFolder, TypeVisitor};
3131
use crate::ty::subst::{InternalSubsts, SubstsRef};
3232
use crate::ty::{self, AdtKind, GenericParamDefKind, List, ToPredicate, Ty, TyCtxt, WithConstness};
3333
use crate::util::common::ErrorReported;
34-
use chalk_engine;
3534
use rustc_hir as hir;
3635
use rustc_hir::def_id::DefId;
3736
use rustc_macros::HashStable;

src/librustc/traits/structural_impls.rs

-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ use crate::traits;
22
use crate::traits::project::Normalized;
33
use crate::ty::fold::{TypeFoldable, TypeFolder, TypeVisitor};
44
use crate::ty::{self, Lift, Ty, TyCtxt};
5-
use chalk_engine;
65
use rustc_span::symbol::Symbol;
76
use smallvec::SmallVec;
87

0 commit comments

Comments
 (0)