Auto merge of #113608 - workingjubilee:rollup-8763ius, r=workingjubilee

Rollup of 5 pull requests

Successful merges:

 - #113373 (various download-rustc fixes)
 - #113385 (style-guide: Fix chain example to match rustfmt behavior)
 - #113567 (While let suggestion will work for closure body)
 - #113579 (Revert "fix: 🐛 etc/bash_complettion -> src/etc/... to avoid copy …)
 - #113595 (Use constants from object crate)

r? `@ghost`
`@rustbot` modify labels: rollup
This commit is contained in:
bors 2023-07-12 06:03:53 +00:00
commit 6732922ea6
21 changed files with 142 additions and 96 deletions

View File

@ -12,7 +12,6 @@ use object::{
use snap::write::FrameEncoder; use snap::write::FrameEncoder;
use object::elf::NT_GNU_PROPERTY_TYPE_0;
use rustc_data_structures::memmap::Mmap; use rustc_data_structures::memmap::Mmap;
use rustc_data_structures::owned_slice::{try_slice_owned, OwnedSlice}; use rustc_data_structures::owned_slice::{try_slice_owned, OwnedSlice};
use rustc_metadata::fs::METADATA_FILENAME; use rustc_metadata::fs::METADATA_FILENAME;
@ -124,7 +123,7 @@ fn add_gnu_property_note(
let mut data: Vec<u8> = Vec::new(); let mut data: Vec<u8> = Vec::new();
let n_namsz: u32 = 4; // Size of the n_name field let n_namsz: u32 = 4; // Size of the n_name field
let n_descsz: u32 = 16; // Size of the n_desc field let n_descsz: u32 = 16; // Size of the n_desc field
let n_type: u32 = NT_GNU_PROPERTY_TYPE_0; // Type of note descriptor let n_type: u32 = object::elf::NT_GNU_PROPERTY_TYPE_0; // Type of note descriptor
let header_values = [n_namsz, n_descsz, n_type]; let header_values = [n_namsz, n_descsz, n_type];
header_values.iter().for_each(|v| { header_values.iter().for_each(|v| {
data.extend_from_slice(&match endianness { data.extend_from_slice(&match endianness {
@ -134,8 +133,8 @@ fn add_gnu_property_note(
}); });
data.extend_from_slice(b"GNU\0"); // Owner of the program property note data.extend_from_slice(b"GNU\0"); // Owner of the program property note
let pr_type: u32 = match architecture { let pr_type: u32 = match architecture {
Architecture::X86_64 => 0xc0000002, Architecture::X86_64 => object::elf::GNU_PROPERTY_X86_FEATURE_1_AND,
Architecture::Aarch64 => 0xc0000000, Architecture::Aarch64 => object::elf::GNU_PROPERTY_AARCH64_FEATURE_1_AND,
_ => unreachable!(), _ => unreachable!(),
}; };
let pr_datasz: u32 = 4; //size of the pr_data field let pr_datasz: u32 = 4; //size of the pr_data field

View File

@ -464,11 +464,8 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> {
span: Span, span: Span,
) -> Option<TypeErrorAdditionalDiags> { ) -> Option<TypeErrorAdditionalDiags> {
let hir = self.tcx.hir(); let hir = self.tcx.hir();
if let Some(node) = self.tcx.hir().find_by_def_id(cause.body_id) && if let Some(body_id) = self.tcx.hir().maybe_body_owned_by(cause.body_id) {
let hir::Node::Item(hir::Item { let body = hir.body(body_id);
kind: hir::ItemKind::Fn(_sig, _, body_id), ..
}) = node {
let body = hir.body(*body_id);
/// Find the if expression with given span /// Find the if expression with given span
struct IfVisitor { struct IfVisitor {
@ -479,7 +476,9 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> {
impl<'v> Visitor<'v> for IfVisitor { impl<'v> Visitor<'v> for IfVisitor {
fn visit_expr(&mut self, ex: &'v hir::Expr<'v>) { fn visit_expr(&mut self, ex: &'v hir::Expr<'v>) {
if self.result { return; } if self.result {
return;
}
match ex.kind { match ex.kind {
hir::ExprKind::If(cond, _, _) => { hir::ExprKind::If(cond, _, _) => {
self.found_if = true; self.found_if = true;
@ -509,7 +508,9 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> {
let mut visitor = IfVisitor { err_span: span, found_if: false, result: false }; let mut visitor = IfVisitor { err_span: span, found_if: false, result: false };
visitor.visit_body(&body); visitor.visit_body(&body);
if visitor.result { if visitor.result {
return Some(TypeErrorAdditionalDiags::AddLetForLetChains{span: span.shrink_to_lo()}); return Some(TypeErrorAdditionalDiags::AddLetForLetChains {
span: span.shrink_to_lo(),
});
} }
} }
None None

View File

@ -688,8 +688,8 @@ fn cp_rustc_component_to_ci_sysroot(
contents: Vec<String>, contents: Vec<String>,
) { ) {
let sysroot = builder.ensure(Sysroot { compiler, force_recompile: false }); let sysroot = builder.ensure(Sysroot { compiler, force_recompile: false });
let ci_rustc_dir = builder.config.ci_rustc_dir();
let ci_rustc_dir = builder.out.join(&*builder.build.build.triple).join("ci-rustc");
for file in contents { for file in contents {
let src = ci_rustc_dir.join(&file); let src = ci_rustc_dir.join(&file);
let dst = sysroot.join(file); let dst = sysroot.join(file);
@ -1424,7 +1424,7 @@ impl Step for Sysroot {
// FIXME: this is wrong when compiler.host != build, but we don't support that today // FIXME: this is wrong when compiler.host != build, but we don't support that today
OsStr::new(std::env::consts::DLL_EXTENSION), OsStr::new(std::env::consts::DLL_EXTENSION),
]; ];
let ci_rustc_dir = builder.ci_rustc_dir(builder.config.build); let ci_rustc_dir = builder.config.ci_rustc_dir();
builder.cp_filtered(&ci_rustc_dir, &sysroot, &|path| { builder.cp_filtered(&ci_rustc_dir, &sysroot, &|path| {
if path.extension().map_or(true, |ext| !filtered_extensions.contains(&ext)) { if path.extension().map_or(true, |ext| !filtered_extensions.contains(&ext)) {
return true; return true;

View File

@ -1375,6 +1375,25 @@ impl Config {
let mut omit_git_hash = None; let mut omit_git_hash = None;
if let Some(rust) = toml.rust { if let Some(rust) = toml.rust {
set(&mut config.channel, rust.channel);
config.download_rustc_commit = config.download_ci_rustc_commit(rust.download_rustc);
// This list is incomplete, please help by expanding it!
if config.download_rustc_commit.is_some() {
// We need the channel used by the downloaded compiler to match the one we set for rustdoc;
// otherwise rustdoc-ui tests break.
let ci_channel = t!(fs::read_to_string(config.src.join("src/ci/channel")));
let ci_channel = ci_channel.trim_end();
if config.channel != ci_channel
&& !(config.channel == "dev" && ci_channel == "nightly")
{
panic!(
"setting rust.channel={} is incompatible with download-rustc",
config.channel
);
}
}
debug = rust.debug; debug = rust.debug;
debug_assertions = rust.debug_assertions; debug_assertions = rust.debug_assertions;
debug_assertions_std = rust.debug_assertions_std; debug_assertions_std = rust.debug_assertions_std;
@ -1386,6 +1405,7 @@ impl Config {
debuginfo_level_std = rust.debuginfo_level_std; debuginfo_level_std = rust.debuginfo_level_std;
debuginfo_level_tools = rust.debuginfo_level_tools; debuginfo_level_tools = rust.debuginfo_level_tools;
debuginfo_level_tests = rust.debuginfo_level_tests; debuginfo_level_tests = rust.debuginfo_level_tests;
config.rust_split_debuginfo = rust config.rust_split_debuginfo = rust
.split_debuginfo .split_debuginfo
.as_deref() .as_deref()
@ -1401,7 +1421,6 @@ impl Config {
set(&mut config.jemalloc, rust.jemalloc); set(&mut config.jemalloc, rust.jemalloc);
set(&mut config.test_compare_mode, rust.test_compare_mode); set(&mut config.test_compare_mode, rust.test_compare_mode);
set(&mut config.backtrace, rust.backtrace); set(&mut config.backtrace, rust.backtrace);
set(&mut config.channel, rust.channel);
config.description = rust.description; config.description = rust.description;
set(&mut config.rust_dist_src, rust.dist_src); set(&mut config.rust_dist_src, rust.dist_src);
set(&mut config.verbose_tests, rust.verbose_tests); set(&mut config.verbose_tests, rust.verbose_tests);
@ -1442,8 +1461,6 @@ impl Config {
config.rust_codegen_units_std = rust.codegen_units_std.map(threads_from_config); config.rust_codegen_units_std = rust.codegen_units_std.map(threads_from_config);
config.rust_profile_use = flags.rust_profile_use.or(rust.profile_use); config.rust_profile_use = flags.rust_profile_use.or(rust.profile_use);
config.rust_profile_generate = flags.rust_profile_generate.or(rust.profile_generate); config.rust_profile_generate = flags.rust_profile_generate.or(rust.profile_generate);
config.download_rustc_commit = config.download_ci_rustc_commit(rust.download_rustc);
config.rust_lto = rust config.rust_lto = rust
.lto .lto
.as_deref() .as_deref()
@ -1555,6 +1572,11 @@ impl Config {
let mut target = Target::from_triple(&triple); let mut target = Target::from_triple(&triple);
if let Some(ref s) = cfg.llvm_config { if let Some(ref s) = cfg.llvm_config {
if config.download_rustc_commit.is_some() && triple == &*config.build.triple {
panic!(
"setting llvm_config for the host is incompatible with download-rustc"
);
}
target.llvm_config = Some(config.src.join(s)); target.llvm_config = Some(config.src.join(s));
} }
target.llvm_has_rust_patches = cfg.llvm_has_rust_patches; target.llvm_has_rust_patches = cfg.llvm_has_rust_patches;
@ -1825,6 +1847,12 @@ impl Config {
self.out.join(&*self.build.triple).join("ci-llvm") self.out.join(&*self.build.triple).join("ci-llvm")
} }
/// Directory where the extracted `rustc-dev` component is stored.
pub(crate) fn ci_rustc_dir(&self) -> PathBuf {
assert!(self.download_rustc());
self.out.join(self.build.triple).join("ci-rustc")
}
/// Determine whether llvm should be linked dynamically. /// Determine whether llvm should be linked dynamically.
/// ///
/// If `false`, llvm should be linked statically. /// If `false`, llvm should be linked statically.
@ -1860,11 +1888,11 @@ impl Config {
self.download_rustc_commit().is_some() self.download_rustc_commit().is_some()
} }
pub(crate) fn download_rustc_commit(&self) -> Option<&'static str> { pub(crate) fn download_rustc_commit(&self) -> Option<&str> {
static DOWNLOAD_RUSTC: OnceCell<Option<String>> = OnceCell::new(); static DOWNLOAD_RUSTC: OnceCell<Option<String>> = OnceCell::new();
if self.dry_run() && DOWNLOAD_RUSTC.get().is_none() { if self.dry_run() && DOWNLOAD_RUSTC.get().is_none() {
// avoid trying to actually download the commit // avoid trying to actually download the commit
return None; return self.download_rustc_commit.as_deref();
} }
DOWNLOAD_RUSTC DOWNLOAD_RUSTC

View File

@ -1074,11 +1074,7 @@ impl Step for Cargo {
tarball.add_file(&cargo, "bin", 0o755); tarball.add_file(&cargo, "bin", 0o755);
tarball.add_file(etc.join("_cargo"), "share/zsh/site-functions", 0o644); tarball.add_file(etc.join("_cargo"), "share/zsh/site-functions", 0o644);
tarball.add_renamed_file( tarball.add_renamed_file(etc.join("cargo.bashcomp.sh"), "etc/bash_completion.d", "cargo");
etc.join("cargo.bashcomp.sh"),
"src/etc/bash_completion.d",
"cargo",
);
tarball.add_dir(etc.join("man"), "share/man/man1"); tarball.add_dir(etc.join("man"), "share/man/man1");
tarball.add_legal_and_readme_to("share/doc/cargo"); tarball.add_legal_and_readme_to("share/doc/cargo");

View File

@ -402,7 +402,11 @@ impl Config {
fn ci_component_contents(&self, stamp_file: &str) -> Vec<String> { fn ci_component_contents(&self, stamp_file: &str) -> Vec<String> {
assert!(self.download_rustc()); assert!(self.download_rustc());
let ci_rustc_dir = self.out.join(&*self.build.triple).join("ci-rustc"); if self.dry_run() {
return vec![];
}
let ci_rustc_dir = self.ci_rustc_dir();
let stamp_file = ci_rustc_dir.join(stamp_file); let stamp_file = ci_rustc_dir.join(stamp_file);
let contents_file = t!(File::open(&stamp_file), stamp_file.display().to_string()); let contents_file = t!(File::open(&stamp_file), stamp_file.display().to_string());
t!(BufReader::new(contents_file).lines().collect()) t!(BufReader::new(contents_file).lines().collect())
@ -419,7 +423,7 @@ impl Config {
self.download_toolchain( self.download_toolchain(
&version, &version,
"ci-rustc", "ci-rustc",
commit, &format!("{commit}-{}", self.llvm_assertions),
&extra_components, &extra_components,
Self::download_ci_component, Self::download_ci_component,
); );
@ -495,8 +499,15 @@ impl Config {
/// Download a single component of a CI-built toolchain (not necessarily a published nightly). /// Download a single component of a CI-built toolchain (not necessarily a published nightly).
// NOTE: intentionally takes an owned string to avoid downloading multiple times by accident // NOTE: intentionally takes an owned string to avoid downloading multiple times by accident
fn download_ci_component(&self, filename: String, prefix: &str, commit: &str) { fn download_ci_component(&self, filename: String, prefix: &str, commit_with_assertions: &str) {
Self::download_component(self, DownloadSource::CI, filename, prefix, commit, "ci-rustc") Self::download_component(
self,
DownloadSource::CI,
filename,
prefix,
commit_with_assertions,
"ci-rustc",
)
} }
fn download_component( fn download_component(
@ -516,11 +527,18 @@ impl Config {
let bin_root = self.out.join(self.build.triple).join(destination); let bin_root = self.out.join(self.build.triple).join(destination);
let tarball = cache_dir.join(&filename); let tarball = cache_dir.join(&filename);
let (base_url, url, should_verify) = match mode { let (base_url, url, should_verify) = match mode {
DownloadSource::CI => ( DownloadSource::CI => {
self.stage0_metadata.config.artifacts_server.clone(), let dist_server = if self.llvm_assertions {
format!("{key}/{filename}"), self.stage0_metadata.config.artifacts_with_llvm_assertions_server.clone()
false, } else {
), self.stage0_metadata.config.artifacts_server.clone()
};
let url = format!(
"{}/{filename}",
key.strip_suffix(&format!("-{}", self.llvm_assertions)).unwrap()
);
(dist_server, url, false)
}
DownloadSource::Dist => { DownloadSource::Dist => {
let dist_server = env::var("RUSTUP_DIST_SERVER") let dist_server = env::var("RUSTUP_DIST_SERVER")
.unwrap_or(self.stage0_metadata.config.dist_server.to_string()); .unwrap_or(self.stage0_metadata.config.dist_server.to_string());

View File

@ -822,11 +822,6 @@ impl Build {
self.stage_out(compiler, mode).join(&*target.triple).join(self.cargo_dir()) self.stage_out(compiler, mode).join(&*target.triple).join(self.cargo_dir())
} }
/// Directory where the extracted `rustc-dev` component is stored.
fn ci_rustc_dir(&self, target: TargetSelection) -> PathBuf {
self.out.join(&*target.triple).join("ci-rustc")
}
/// Root output directory for LLVM compiled for `target` /// Root output directory for LLVM compiled for `target`
/// ///
/// Note that if LLVM is configured externally then the directory returned /// Note that if LLVM is configured externally then the directory returned

View File

@ -2348,7 +2348,7 @@ impl Step for Crate {
// `std_cargo` actually does the wrong thing: it passes `--sysroot build/host/stage2`, // `std_cargo` actually does the wrong thing: it passes `--sysroot build/host/stage2`,
// but we want to use the force-recompile std we just built in `build/host/stage2-test-sysroot`. // but we want to use the force-recompile std we just built in `build/host/stage2-test-sysroot`.
// Override it. // Override it.
if builder.download_rustc() { if builder.download_rustc() && compiler.stage > 0 {
let sysroot = builder let sysroot = builder
.out .out
.join(compiler.host.triple) .join(compiler.host.triple)

View File

@ -451,12 +451,11 @@ foo(
#### Multi-line elements #### Multi-line elements
If any element in a chain is formatted across multiple lines, then that element If any element in a chain is formatted across multiple lines, put that element
and any later elements must be on their own line. Earlier elements may be kept and any later elements on their own lines.
on a single line. E.g.,
```rust ```rust
a.b.c()?.d a.b.c()?
.foo( .foo(
an_expr, an_expr,
another_expr, another_expr,

View File

@ -39,7 +39,6 @@ impl<'a> LintExtractor<'a> {
fn collect_groups(&self) -> Result<LintGroups, Box<dyn Error>> { fn collect_groups(&self) -> Result<LintGroups, Box<dyn Error>> {
let mut result = BTreeMap::new(); let mut result = BTreeMap::new();
let mut cmd = Command::new(self.rustc_path); let mut cmd = Command::new(self.rustc_path);
cmd.env_remove("LD_LIBRARY_PATH");
cmd.arg("-Whelp"); cmd.arg("-Whelp");
let output = cmd.output().map_err(|e| format!("failed to run command {:?}\n{}", cmd, e))?; let output = cmd.output().map_err(|e| format!("failed to run command {:?}\n{}", cmd, e))?;
if !output.status.success() { if !output.status.success() {

View File

@ -403,12 +403,6 @@ impl<'a> LintExtractor<'a> {
fs::write(&tempfile, source) fs::write(&tempfile, source)
.map_err(|e| format!("failed to write {}: {}", tempfile.display(), e))?; .map_err(|e| format!("failed to write {}: {}", tempfile.display(), e))?;
let mut cmd = Command::new(self.rustc_path); let mut cmd = Command::new(self.rustc_path);
// NOTE: bootstrap sets `LD_LIBRARY_PATH` for building lint-docs itself.
// Unfortunately, lint-docs is a bootstrap tool while rustc is built from source,
// and sometimes the paths conflict. In particular, when using `download-rustc`,
// the LLVM versions can differ between `ci-llvm` and `ci-rustc-sysroot`.
// Unset LD_LIBRARY_PATH here so it doesn't interfere with running the compiler.
cmd.env_remove("LD_LIBRARY_PATH");
if options.contains(&"edition2015") { if options.contains(&"edition2015") {
cmd.arg("--edition=2015"); cmd.arg("--edition=2015");
} else { } else {

View File

@ -1,8 +1,8 @@
// Test that we get the following hint when trying to use a compiler crate without rustc_driver. // Test that we get the following hint when trying to use a compiler crate without rustc_driver.
// error-pattern: try adding `extern crate rustc_driver;` at the top level of this crate // error-pattern: try adding `extern crate rustc_driver;` at the top level of this crate
// compile-flags: --emit link // compile-flags: --emit link
// The exactly list of required crates depends on the target. as such only test Unix targets. // normalize-stderr-test ".*crate .* required.*\n\n" -> ""
// only-unix // normalize-stderr-test: "aborting due to [0-9]+" -> "aborting due to NUMBER"
#![feature(rustc_private)] #![feature(rustc_private)]

View File

@ -2,15 +2,5 @@ error: crate `rustc_serialize` required to be available in rlib format, but was
| |
= help: try adding `extern crate rustc_driver;` at the top level of this crate = help: try adding `extern crate rustc_driver;` at the top level of this crate
error: crate `smallvec` required to be available in rlib format, but was not found in this form error: aborting due to NUMBER previous errors
error: crate `thin_vec` required to be available in rlib format, but was not found in this form
error: crate `indexmap` required to be available in rlib format, but was not found in this form
error: crate `hashbrown` required to be available in rlib format, but was not found in this form
error: crate `equivalent` required to be available in rlib format, but was not found in this form
error: aborting due to 6 previous errors

View File

@ -0,0 +1,4 @@
//run-rustfix
fn main() {
let _ = || { while let Some(_) = Some(1) { } }; //~ ERROR mismatched types
}

View File

@ -0,0 +1,4 @@
//run-rustfix
fn main() {
let _ = || { while Some(_) = Some(1) { } }; //~ ERROR mismatched types
}

View File

@ -0,0 +1,14 @@
error[E0308]: mismatched types
--> $DIR/issue-113354.rs:3:24
|
LL | let _ = || { while Some(_) = Some(1) { } };
| ^^^^^^^^^^^^^^^^^ expected `bool`, found `()`
|
help: consider adding `let`
|
LL | let _ = || { while let Some(_) = Some(1) { } };
| +++
error: aborting due to previous error
For more information about this error, try `rustc --explain E0308`.

View File

@ -1,11 +1,12 @@
// needs-sanitizer-support // needs-sanitizer-support
// needs-sanitizer-address // needs-sanitizer-address
// ignore-cross-compile
// //
// compile-flags: -Z sanitizer=address -O -g // compile-flags: -Z sanitizer=address -O -g
// //
// run-fail // run-fail
// error-pattern: AddressSanitizer: stack-buffer-overflow // error-pattern: AddressSanitizer: stack-buffer-overflow
// error-pattern: 'xs' (line 13) <== Memory access at offset // error-pattern: 'xs' (line 14) <== Memory access at offset
use std::hint::black_box; use std::hint::black_box;

View File

@ -1,5 +1,6 @@
// needs-sanitizer-support // needs-sanitizer-support
// needs-sanitizer-address // needs-sanitizer-address
// ignore-cross-compile
// //
// compile-flags: -Z sanitizer=address -O // compile-flags: -Z sanitizer=address -O
// //

View File

@ -5,6 +5,7 @@
// //
// needs-sanitizer-support // needs-sanitizer-support
// needs-sanitizer-address // needs-sanitizer-address
// ignore-cross-compile
// //
// compile-flags: -Copt-level=0 -Zsanitizer=address // compile-flags: -Copt-level=0 -Zsanitizer=address
// run-pass // run-pass

View File

@ -4,6 +4,7 @@
// //
// needs-sanitizer-support // needs-sanitizer-support
// needs-sanitizer-address // needs-sanitizer-address
// ignore-cross-compile
// //
// no-prefer-dynamic // no-prefer-dynamic
// revisions: opt0 opt1 // revisions: opt0 opt1

View File

@ -1,5 +1,6 @@
// needs-sanitizer-support // needs-sanitizer-support
// needs-sanitizer-address // needs-sanitizer-address
// ignore-cross-compile
// //
// compile-flags: -Zsanitizer=address // compile-flags: -Zsanitizer=address
// run-fail // run-fail