Skip to content

Commit 6732922

Browse files
committed
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
2 parents 993deaa + f05e6e6 commit 6732922

File tree

21 files changed

+140
-94
lines changed

21 files changed

+140
-94
lines changed

compiler/rustc_codegen_ssa/src/back/metadata.rs

+3-4
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ use object::{
1212

1313
use snap::write::FrameEncoder;
1414

15-
use object::elf::NT_GNU_PROPERTY_TYPE_0;
1615
use rustc_data_structures::memmap::Mmap;
1716
use rustc_data_structures::owned_slice::{try_slice_owned, OwnedSlice};
1817
use rustc_metadata::fs::METADATA_FILENAME;
@@ -124,7 +123,7 @@ fn add_gnu_property_note(
124123
let mut data: Vec<u8> = Vec::new();
125124
let n_namsz: u32 = 4; // Size of the n_name field
126125
let n_descsz: u32 = 16; // Size of the n_desc field
127-
let n_type: u32 = NT_GNU_PROPERTY_TYPE_0; // Type of note descriptor
126+
let n_type: u32 = object::elf::NT_GNU_PROPERTY_TYPE_0; // Type of note descriptor
128127
let header_values = [n_namsz, n_descsz, n_type];
129128
header_values.iter().for_each(|v| {
130129
data.extend_from_slice(&match endianness {
@@ -134,8 +133,8 @@ fn add_gnu_property_note(
134133
});
135134
data.extend_from_slice(b"GNU\0"); // Owner of the program property note
136135
let pr_type: u32 = match architecture {
137-
Architecture::X86_64 => 0xc0000002,
138-
Architecture::Aarch64 => 0xc0000000,
136+
Architecture::X86_64 => object::elf::GNU_PROPERTY_X86_FEATURE_1_AND,
137+
Architecture::Aarch64 => object::elf::GNU_PROPERTY_AARCH64_FEATURE_1_AND,
139138
_ => unreachable!(),
140139
};
141140
let pr_datasz: u32 = 4; //size of the pr_data field

compiler/rustc_infer/src/infer/error_reporting/suggest.rs

+39-38
Original file line numberDiff line numberDiff line change
@@ -464,52 +464,53 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> {
464464
span: Span,
465465
) -> Option<TypeErrorAdditionalDiags> {
466466
let hir = self.tcx.hir();
467-
if let Some(node) = self.tcx.hir().find_by_def_id(cause.body_id) &&
468-
let hir::Node::Item(hir::Item {
469-
kind: hir::ItemKind::Fn(_sig, _, body_id), ..
470-
}) = node {
471-
let body = hir.body(*body_id);
472-
473-
/// Find the if expression with given span
474-
struct IfVisitor {
475-
pub result: bool,
476-
pub found_if: bool,
477-
pub err_span: Span,
478-
}
467+
if let Some(body_id) = self.tcx.hir().maybe_body_owned_by(cause.body_id) {
468+
let body = hir.body(body_id);
469+
470+
/// Find the if expression with given span
471+
struct IfVisitor {
472+
pub result: bool,
473+
pub found_if: bool,
474+
pub err_span: Span,
475+
}
479476

480-
impl<'v> Visitor<'v> for IfVisitor {
481-
fn visit_expr(&mut self, ex: &'v hir::Expr<'v>) {
482-
if self.result { return; }
483-
match ex.kind {
484-
hir::ExprKind::If(cond, _, _) => {
485-
self.found_if = true;
486-
walk_expr(self, cond);
487-
self.found_if = false;
477+
impl<'v> Visitor<'v> for IfVisitor {
478+
fn visit_expr(&mut self, ex: &'v hir::Expr<'v>) {
479+
if self.result {
480+
return;
481+
}
482+
match ex.kind {
483+
hir::ExprKind::If(cond, _, _) => {
484+
self.found_if = true;
485+
walk_expr(self, cond);
486+
self.found_if = false;
487+
}
488+
_ => walk_expr(self, ex),
488489
}
489-
_ => walk_expr(self, ex),
490490
}
491-
}
492491

493-
fn visit_stmt(&mut self, ex: &'v hir::Stmt<'v>) {
494-
if let hir::StmtKind::Local(hir::Local {
495-
span, pat: hir::Pat{..}, ty: None, init: Some(_), ..
496-
}) = &ex.kind
497-
&& self.found_if
498-
&& span.eq(&self.err_span) {
499-
self.result = true;
492+
fn visit_stmt(&mut self, ex: &'v hir::Stmt<'v>) {
493+
if let hir::StmtKind::Local(hir::Local {
494+
span, pat: hir::Pat{..}, ty: None, init: Some(_), ..
495+
}) = &ex.kind
496+
&& self.found_if
497+
&& span.eq(&self.err_span) {
498+
self.result = true;
499+
}
500+
walk_stmt(self, ex);
500501
}
501-
walk_stmt(self, ex);
502-
}
503502

504-
fn visit_body(&mut self, body: &'v hir::Body<'v>) {
505-
hir::intravisit::walk_body(self, body);
503+
fn visit_body(&mut self, body: &'v hir::Body<'v>) {
504+
hir::intravisit::walk_body(self, body);
505+
}
506506
}
507-
}
508507

509-
let mut visitor = IfVisitor { err_span: span, found_if: false, result: false };
510-
visitor.visit_body(&body);
511-
if visitor.result {
512-
return Some(TypeErrorAdditionalDiags::AddLetForLetChains{span: span.shrink_to_lo()});
508+
let mut visitor = IfVisitor { err_span: span, found_if: false, result: false };
509+
visitor.visit_body(&body);
510+
if visitor.result {
511+
return Some(TypeErrorAdditionalDiags::AddLetForLetChains {
512+
span: span.shrink_to_lo(),
513+
});
513514
}
514515
}
515516
None

src/bootstrap/compile.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -688,8 +688,8 @@ fn cp_rustc_component_to_ci_sysroot(
688688
contents: Vec<String>,
689689
) {
690690
let sysroot = builder.ensure(Sysroot { compiler, force_recompile: false });
691+
let ci_rustc_dir = builder.config.ci_rustc_dir();
691692

692-
let ci_rustc_dir = builder.out.join(&*builder.build.build.triple).join("ci-rustc");
693693
for file in contents {
694694
let src = ci_rustc_dir.join(&file);
695695
let dst = sysroot.join(file);
@@ -1424,7 +1424,7 @@ impl Step for Sysroot {
14241424
// FIXME: this is wrong when compiler.host != build, but we don't support that today
14251425
OsStr::new(std::env::consts::DLL_EXTENSION),
14261426
];
1427-
let ci_rustc_dir = builder.ci_rustc_dir(builder.config.build);
1427+
let ci_rustc_dir = builder.config.ci_rustc_dir();
14281428
builder.cp_filtered(&ci_rustc_dir, &sysroot, &|path| {
14291429
if path.extension().map_or(true, |ext| !filtered_extensions.contains(&ext)) {
14301430
return true;

src/bootstrap/config.rs

+33-5
Original file line numberDiff line numberDiff line change
@@ -1375,6 +1375,25 @@ impl Config {
13751375
let mut omit_git_hash = None;
13761376

13771377
if let Some(rust) = toml.rust {
1378+
set(&mut config.channel, rust.channel);
1379+
1380+
config.download_rustc_commit = config.download_ci_rustc_commit(rust.download_rustc);
1381+
// This list is incomplete, please help by expanding it!
1382+
if config.download_rustc_commit.is_some() {
1383+
// We need the channel used by the downloaded compiler to match the one we set for rustdoc;
1384+
// otherwise rustdoc-ui tests break.
1385+
let ci_channel = t!(fs::read_to_string(config.src.join("src/ci/channel")));
1386+
let ci_channel = ci_channel.trim_end();
1387+
if config.channel != ci_channel
1388+
&& !(config.channel == "dev" && ci_channel == "nightly")
1389+
{
1390+
panic!(
1391+
"setting rust.channel={} is incompatible with download-rustc",
1392+
config.channel
1393+
);
1394+
}
1395+
}
1396+
13781397
debug = rust.debug;
13791398
debug_assertions = rust.debug_assertions;
13801399
debug_assertions_std = rust.debug_assertions_std;
@@ -1386,6 +1405,7 @@ impl Config {
13861405
debuginfo_level_std = rust.debuginfo_level_std;
13871406
debuginfo_level_tools = rust.debuginfo_level_tools;
13881407
debuginfo_level_tests = rust.debuginfo_level_tests;
1408+
13891409
config.rust_split_debuginfo = rust
13901410
.split_debuginfo
13911411
.as_deref()
@@ -1401,7 +1421,6 @@ impl Config {
14011421
set(&mut config.jemalloc, rust.jemalloc);
14021422
set(&mut config.test_compare_mode, rust.test_compare_mode);
14031423
set(&mut config.backtrace, rust.backtrace);
1404-
set(&mut config.channel, rust.channel);
14051424
config.description = rust.description;
14061425
set(&mut config.rust_dist_src, rust.dist_src);
14071426
set(&mut config.verbose_tests, rust.verbose_tests);
@@ -1442,8 +1461,6 @@ impl Config {
14421461
config.rust_codegen_units_std = rust.codegen_units_std.map(threads_from_config);
14431462
config.rust_profile_use = flags.rust_profile_use.or(rust.profile_use);
14441463
config.rust_profile_generate = flags.rust_profile_generate.or(rust.profile_generate);
1445-
config.download_rustc_commit = config.download_ci_rustc_commit(rust.download_rustc);
1446-
14471464
config.rust_lto = rust
14481465
.lto
14491466
.as_deref()
@@ -1555,6 +1572,11 @@ impl Config {
15551572
let mut target = Target::from_triple(&triple);
15561573

15571574
if let Some(ref s) = cfg.llvm_config {
1575+
if config.download_rustc_commit.is_some() && triple == &*config.build.triple {
1576+
panic!(
1577+
"setting llvm_config for the host is incompatible with download-rustc"
1578+
);
1579+
}
15581580
target.llvm_config = Some(config.src.join(s));
15591581
}
15601582
target.llvm_has_rust_patches = cfg.llvm_has_rust_patches;
@@ -1825,6 +1847,12 @@ impl Config {
18251847
self.out.join(&*self.build.triple).join("ci-llvm")
18261848
}
18271849

1850+
/// Directory where the extracted `rustc-dev` component is stored.
1851+
pub(crate) fn ci_rustc_dir(&self) -> PathBuf {
1852+
assert!(self.download_rustc());
1853+
self.out.join(self.build.triple).join("ci-rustc")
1854+
}
1855+
18281856
/// Determine whether llvm should be linked dynamically.
18291857
///
18301858
/// If `false`, llvm should be linked statically.
@@ -1860,11 +1888,11 @@ impl Config {
18601888
self.download_rustc_commit().is_some()
18611889
}
18621890

1863-
pub(crate) fn download_rustc_commit(&self) -> Option<&'static str> {
1891+
pub(crate) fn download_rustc_commit(&self) -> Option<&str> {
18641892
static DOWNLOAD_RUSTC: OnceCell<Option<String>> = OnceCell::new();
18651893
if self.dry_run() && DOWNLOAD_RUSTC.get().is_none() {
18661894
// avoid trying to actually download the commit
1867-
return None;
1895+
return self.download_rustc_commit.as_deref();
18681896
}
18691897

18701898
DOWNLOAD_RUSTC

src/bootstrap/dist.rs

+1-5
Original file line numberDiff line numberDiff line change
@@ -1074,11 +1074,7 @@ impl Step for Cargo {
10741074

10751075
tarball.add_file(&cargo, "bin", 0o755);
10761076
tarball.add_file(etc.join("_cargo"), "share/zsh/site-functions", 0o644);
1077-
tarball.add_renamed_file(
1078-
etc.join("cargo.bashcomp.sh"),
1079-
"src/etc/bash_completion.d",
1080-
"cargo",
1081-
);
1077+
tarball.add_renamed_file(etc.join("cargo.bashcomp.sh"), "etc/bash_completion.d", "cargo");
10821078
tarball.add_dir(etc.join("man"), "share/man/man1");
10831079
tarball.add_legal_and_readme_to("share/doc/cargo");
10841080

src/bootstrap/download.rs

+27-9
Original file line numberDiff line numberDiff line change
@@ -402,7 +402,11 @@ impl Config {
402402

403403
fn ci_component_contents(&self, stamp_file: &str) -> Vec<String> {
404404
assert!(self.download_rustc());
405-
let ci_rustc_dir = self.out.join(&*self.build.triple).join("ci-rustc");
405+
if self.dry_run() {
406+
return vec![];
407+
}
408+
409+
let ci_rustc_dir = self.ci_rustc_dir();
406410
let stamp_file = ci_rustc_dir.join(stamp_file);
407411
let contents_file = t!(File::open(&stamp_file), stamp_file.display().to_string());
408412
t!(BufReader::new(contents_file).lines().collect())
@@ -419,7 +423,7 @@ impl Config {
419423
self.download_toolchain(
420424
&version,
421425
"ci-rustc",
422-
commit,
426+
&format!("{commit}-{}", self.llvm_assertions),
423427
&extra_components,
424428
Self::download_ci_component,
425429
);
@@ -495,8 +499,15 @@ impl Config {
495499

496500
/// Download a single component of a CI-built toolchain (not necessarily a published nightly).
497501
// NOTE: intentionally takes an owned string to avoid downloading multiple times by accident
498-
fn download_ci_component(&self, filename: String, prefix: &str, commit: &str) {
499-
Self::download_component(self, DownloadSource::CI, filename, prefix, commit, "ci-rustc")
502+
fn download_ci_component(&self, filename: String, prefix: &str, commit_with_assertions: &str) {
503+
Self::download_component(
504+
self,
505+
DownloadSource::CI,
506+
filename,
507+
prefix,
508+
commit_with_assertions,
509+
"ci-rustc",
510+
)
500511
}
501512

502513
fn download_component(
@@ -516,11 +527,18 @@ impl Config {
516527
let bin_root = self.out.join(self.build.triple).join(destination);
517528
let tarball = cache_dir.join(&filename);
518529
let (base_url, url, should_verify) = match mode {
519-
DownloadSource::CI => (
520-
self.stage0_metadata.config.artifacts_server.clone(),
521-
format!("{key}/{filename}"),
522-
false,
523-
),
530+
DownloadSource::CI => {
531+
let dist_server = if self.llvm_assertions {
532+
self.stage0_metadata.config.artifacts_with_llvm_assertions_server.clone()
533+
} else {
534+
self.stage0_metadata.config.artifacts_server.clone()
535+
};
536+
let url = format!(
537+
"{}/{filename}",
538+
key.strip_suffix(&format!("-{}", self.llvm_assertions)).unwrap()
539+
);
540+
(dist_server, url, false)
541+
}
524542
DownloadSource::Dist => {
525543
let dist_server = env::var("RUSTUP_DIST_SERVER")
526544
.unwrap_or(self.stage0_metadata.config.dist_server.to_string());

src/bootstrap/lib.rs

-5
Original file line numberDiff line numberDiff line change
@@ -822,11 +822,6 @@ impl Build {
822822
self.stage_out(compiler, mode).join(&*target.triple).join(self.cargo_dir())
823823
}
824824

825-
/// Directory where the extracted `rustc-dev` component is stored.
826-
fn ci_rustc_dir(&self, target: TargetSelection) -> PathBuf {
827-
self.out.join(&*target.triple).join("ci-rustc")
828-
}
829-
830825
/// Root output directory for LLVM compiled for `target`
831826
///
832827
/// Note that if LLVM is configured externally then the directory returned

src/bootstrap/test.rs

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

src/doc/style-guide/src/expressions.md

+3-4
Original file line numberDiff line numberDiff line change
@@ -451,12 +451,11 @@ foo(
451451

452452
#### Multi-line elements
453453

454-
If any element in a chain is formatted across multiple lines, then that element
455-
and any later elements must be on their own line. Earlier elements may be kept
456-
on a single line. E.g.,
454+
If any element in a chain is formatted across multiple lines, put that element
455+
and any later elements on their own lines.
457456

458457
```rust
459-
a.b.c()?.d
458+
a.b.c()?
460459
.foo(
461460
an_expr,
462461
another_expr,

src/tools/lint-docs/src/groups.rs

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

src/tools/lint-docs/src/lib.rs

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

tests/ui-fulldeps/missing-rustc-driver-error.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
// Test that we get the following hint when trying to use a compiler crate without rustc_driver.
22
// error-pattern: try adding `extern crate rustc_driver;` at the top level of this crate
33
// compile-flags: --emit link
4-
// The exactly list of required crates depends on the target. as such only test Unix targets.
5-
// only-unix
4+
// normalize-stderr-test ".*crate .* required.*\n\n" -> ""
5+
// normalize-stderr-test: "aborting due to [0-9]+" -> "aborting due to NUMBER"
66

77
#![feature(rustc_private)]
88

tests/ui-fulldeps/missing-rustc-driver-error.stderr

+1-11
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,5 @@ error: crate `rustc_serialize` required to be available in rlib format, but was
22
|
33
= help: try adding `extern crate rustc_driver;` at the top level of this crate
44

5-
error: crate `smallvec` required to be available in rlib format, but was not found in this form
6-
7-
error: crate `thin_vec` required to be available in rlib format, but was not found in this form
8-
9-
error: crate `indexmap` required to be available in rlib format, but was not found in this form
10-
11-
error: crate `hashbrown` required to be available in rlib format, but was not found in this form
12-
13-
error: crate `equivalent` required to be available in rlib format, but was not found in this form
14-
15-
error: aborting due to 6 previous errors
5+
error: aborting due to NUMBER previous errors
166

tests/ui/inference/issue-113354.fixed

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
//run-rustfix
2+
fn main() {
3+
let _ = || { while let Some(_) = Some(1) { } }; //~ ERROR mismatched types
4+
}

0 commit comments

Comments
 (0)