Skip to content

Commit 30508fa

Browse files
committed
Auto merge of rust-lang#137796 - jieyouxu:rollup-qt9yr1g, r=jieyouxu
Rollup of 10 pull requests Successful merges: - rust-lang#134943 (Add FileCheck annotations to mir-opt/issues) - rust-lang#137017 (Don't error when adding a staticlib with bitcode files compiled by newer LLVM) - rust-lang#137197 (Update some comparison codegen tests now that they pass in LLVM20) - rust-lang#137540 (Fix (more) test directives that were accidentally ignored) - rust-lang#137551 (import `simd_` intrinsics) - rust-lang#137599 (tests: use minicore more) - rust-lang#137673 (Fix Windows `Command` search path bug) - rust-lang#137676 (linker: Fix escaping style for response files on Windows) - rust-lang#137693 (Re-enable `--generate-link-to-defintion` for tools internal rustdoc) - rust-lang#137770 (Fix sized constraint for unsafe binder) r? `@ghost` `@rustbot` modify labels: rollup
2 parents aa3c2d7 + 0cb9827 commit 30508fa

File tree

300 files changed

+1614
-2162
lines changed

Some content is hidden

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

300 files changed

+1614
-2162
lines changed

compiler/rustc_codegen_llvm/src/back/archive.rs

+22-3
Original file line numberDiff line numberDiff line change
@@ -132,14 +132,33 @@ fn get_llvm_object_symbols(
132132
if err.is_null() {
133133
return Ok(true);
134134
} else {
135-
return Err(unsafe { *Box::from_raw(err as *mut io::Error) });
135+
let error = unsafe { *Box::from_raw(err as *mut io::Error) };
136+
// These are the magic constants for LLVM bitcode files:
137+
// https://github.com/llvm/llvm-project/blob/7eadc1960d199676f04add402bb0aa6f65b7b234/llvm/lib/BinaryFormat/Magic.cpp#L90-L97
138+
if buf.starts_with(&[0xDE, 0xCE, 0x17, 0x0B]) || buf.starts_with(&[b'B', b'C', 0xC0, 0xDE])
139+
{
140+
// For LLVM bitcode, failure to read the symbols is not fatal. The bitcode may have been
141+
// produced by a newer LLVM version that the one linked to rustc. This is fine provided
142+
// that the linker does use said newer LLVM version. We skip writing the symbols for the
143+
// bitcode to the symbol table of the archive. Traditional linkers don't like this, but
144+
// newer linkers like lld, mold and wild ignore the symbol table anyway, so if they link
145+
// against a new enough LLVM it will work out in the end.
146+
// LLVM's archive writer also has this same behavior of only warning about invalid
147+
// bitcode since https://github.com/llvm/llvm-project/pull/96848
148+
149+
// We don't have access to the DiagCtxt here to produce a nice warning in the correct format.
150+
eprintln!("warning: Failed to read symbol table from LLVM bitcode: {}", error);
151+
return Ok(true);
152+
} else {
153+
return Err(error);
154+
}
136155
}
137156

138157
unsafe extern "C" fn callback(state: *mut c_void, symbol_name: *const c_char) -> *mut c_void {
139158
let f = unsafe { &mut *(state as *mut &mut dyn FnMut(&[u8]) -> io::Result<()>) };
140159
match f(unsafe { CStr::from_ptr(symbol_name) }.to_bytes()) {
141160
Ok(()) => std::ptr::null_mut(),
142-
Err(err) => Box::into_raw(Box::new(err)) as *mut c_void,
161+
Err(err) => Box::into_raw(Box::new(err) as Box<io::Error>) as *mut c_void,
143162
}
144163
}
145164

@@ -148,7 +167,7 @@ fn get_llvm_object_symbols(
148167
Box::into_raw(Box::new(io::Error::new(
149168
io::ErrorKind::Other,
150169
format!("LLVM error: {}", error.to_string_lossy()),
151-
))) as *mut c_void
170+
)) as Box<io::Error>) as *mut c_void
152171
}
153172
}
154173

compiler/rustc_codegen_ssa/src/back/link.rs

+6-2
Original file line numberDiff line numberDiff line change
@@ -1726,8 +1726,12 @@ fn exec_linker(
17261726
args.push_str(
17271727
&Escape {
17281728
arg: arg.to_str().unwrap(),
1729-
// LLD also uses MSVC-like parsing for @-files by default when running on windows hosts
1730-
is_like_msvc: sess.target.is_like_msvc || (cfg!(windows) && flavor.uses_lld()),
1729+
// Windows-style escaping for @-files is used by
1730+
// - all linkers targeting MSVC-like targets, including LLD
1731+
// - all LLD flavors running on Windows hosts
1732+
// С/С++ compilers use Posix-style escaping (except clang-cl, which we do not use).
1733+
is_like_msvc: sess.target.is_like_msvc
1734+
|| (cfg!(windows) && flavor.uses_lld() && !flavor.uses_cc()),
17311735
}
17321736
.to_string(),
17331737
);

compiler/rustc_ty_utils/src/ty.rs

+6-3
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,6 @@ fn sized_constraint_for_ty<'tcx>(tcx: TyCtxt<'tcx>, ty: Ty<'tcx>) -> Option<Ty<'
3737
| Never
3838
| Dynamic(_, _, ty::DynStar) => None,
3939

40-
UnsafeBinder(_) => todo!(),
41-
4240
// these are never sized
4341
Str | Slice(..) | Dynamic(_, _, ty::Dyn) | Foreign(..) => Some(ty),
4442

@@ -52,9 +50,14 @@ fn sized_constraint_for_ty<'tcx>(tcx: TyCtxt<'tcx>, ty: Ty<'tcx>) -> Option<Ty<'
5250
sized_constraint_for_ty(tcx, ty)
5351
}),
5452

55-
// these can be sized or unsized
53+
// these can be sized or unsized.
5654
Param(..) | Alias(..) | Error(_) => Some(ty),
5755

56+
// We cannot instantiate the binder, so just return the *original* type back,
57+
// but only if the inner type has a sized constraint. Thus we skip the binder,
58+
// but don't actually use the result from `sized_constraint_for_ty`.
59+
UnsafeBinder(inner_ty) => sized_constraint_for_ty(tcx, inner_ty.skip_binder()).map(|_| ty),
60+
5861
Placeholder(..) | Bound(..) | Infer(..) => {
5962
bug!("unexpected type `{ty:?}` in sized_constraint_for_ty")
6063
}

library/core/src/cmp.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -1369,7 +1369,7 @@ pub trait PartialOrd<Rhs: ?Sized = Self>: PartialEq<Rhs> {
13691369
#[stable(feature = "rust1", since = "1.0.0")]
13701370
#[rustc_diagnostic_item = "cmp_partialord_lt"]
13711371
fn lt(&self, other: &Rhs) -> bool {
1372-
matches!(self.partial_cmp(other), Some(Less))
1372+
self.partial_cmp(other).is_some_and(Ordering::is_lt)
13731373
}
13741374

13751375
/// Tests less than or equal to (for `self` and `other`) and is used by the
@@ -1387,7 +1387,7 @@ pub trait PartialOrd<Rhs: ?Sized = Self>: PartialEq<Rhs> {
13871387
#[stable(feature = "rust1", since = "1.0.0")]
13881388
#[rustc_diagnostic_item = "cmp_partialord_le"]
13891389
fn le(&self, other: &Rhs) -> bool {
1390-
matches!(self.partial_cmp(other), Some(Less | Equal))
1390+
self.partial_cmp(other).is_some_and(Ordering::is_le)
13911391
}
13921392

13931393
/// Tests greater than (for `self` and `other`) and is used by the `>`
@@ -1405,7 +1405,7 @@ pub trait PartialOrd<Rhs: ?Sized = Self>: PartialEq<Rhs> {
14051405
#[stable(feature = "rust1", since = "1.0.0")]
14061406
#[rustc_diagnostic_item = "cmp_partialord_gt"]
14071407
fn gt(&self, other: &Rhs) -> bool {
1408-
matches!(self.partial_cmp(other), Some(Greater))
1408+
self.partial_cmp(other).is_some_and(Ordering::is_gt)
14091409
}
14101410

14111411
/// Tests greater than or equal to (for `self` and `other`) and is used by
@@ -1423,7 +1423,7 @@ pub trait PartialOrd<Rhs: ?Sized = Self>: PartialEq<Rhs> {
14231423
#[stable(feature = "rust1", since = "1.0.0")]
14241424
#[rustc_diagnostic_item = "cmp_partialord_ge"]
14251425
fn ge(&self, other: &Rhs) -> bool {
1426-
matches!(self.partial_cmp(other), Some(Greater | Equal))
1426+
self.partial_cmp(other).is_some_and(Ordering::is_ge)
14271427
}
14281428
}
14291429

library/core/src/intrinsics/simd.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
/// `idx` must be in-bounds of the vector.
1212
#[rustc_intrinsic]
1313
#[rustc_nounwind]
14-
pub unsafe fn simd_insert<T, U>(_x: T, _idx: u32, _val: U) -> T;
14+
pub const unsafe fn simd_insert<T, U>(_x: T, _idx: u32, _val: U) -> T;
1515

1616
/// Extracts an element from a vector.
1717
///
@@ -22,7 +22,7 @@ pub unsafe fn simd_insert<T, U>(_x: T, _idx: u32, _val: U) -> T;
2222
/// `idx` must be in-bounds of the vector.
2323
#[rustc_intrinsic]
2424
#[rustc_nounwind]
25-
pub unsafe fn simd_extract<T, U>(_x: T, _idx: u32) -> U;
25+
pub const unsafe fn simd_extract<T, U>(_x: T, _idx: u32) -> U;
2626

2727
/// Adds two simd vectors elementwise.
2828
///

library/std/src/sys/pal/windows/process.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -260,9 +260,10 @@ impl Command {
260260
needs_stdin: bool,
261261
proc_thread_attribute_list: Option<&ProcThreadAttributeList<'_>>,
262262
) -> io::Result<(Process, StdioPipes)> {
263+
let env_saw_path = self.env.have_changed_path();
263264
let maybe_env = self.env.capture_if_changed();
264265

265-
let child_paths = if let Some(env) = maybe_env.as_ref() {
266+
let child_paths = if env_saw_path && let Some(env) = maybe_env.as_ref() {
266267
env.get(&EnvKey::new("PATH")).map(|s| s.as_os_str())
267268
} else {
268269
None

src/bootstrap/src/core/build_steps/doc.rs

+1-3
Original file line numberDiff line numberDiff line change
@@ -987,9 +987,7 @@ macro_rules! tool_doc {
987987
cargo.rustdocflag("-Arustdoc::private-intra-doc-links");
988988
cargo.rustdocflag("--enable-index-page");
989989
cargo.rustdocflag("--show-type-layout");
990-
// FIXME: `--generate-link-to-definition` tries to resolve cfged out code
991-
// see https://github.com/rust-lang/rust/pull/122066#issuecomment-1983049222
992-
// cargo.rustdocflag("--generate-link-to-definition");
990+
cargo.rustdocflag("--generate-link-to-definition");
993991

994992
let out_dir = builder.stage_out(compiler, Mode::ToolRustc).join(target).join("doc");
995993
$(for krate in $crates {

src/bootstrap/src/core/build_steps/test.rs

+16-4
Original file line numberDiff line numberDiff line change
@@ -269,7 +269,13 @@ impl Step for Cargotest {
269269
.args(builder.config.test_args())
270270
.env("RUSTC", builder.rustc(compiler))
271271
.env("RUSTDOC", builder.rustdoc(compiler));
272-
add_rustdoc_cargo_linker_args(&mut cmd, builder, compiler.host, LldThreads::No);
272+
add_rustdoc_cargo_linker_args(
273+
&mut cmd,
274+
builder,
275+
compiler.host,
276+
LldThreads::No,
277+
compiler.stage,
278+
);
273279
cmd.delay_failure().run(builder);
274280
}
275281
}
@@ -847,7 +853,7 @@ impl Step for RustdocTheme {
847853
.env("CFG_RELEASE_CHANNEL", &builder.config.channel)
848854
.env("RUSTDOC_REAL", builder.rustdoc(self.compiler))
849855
.env("RUSTC_BOOTSTRAP", "1");
850-
cmd.args(linker_args(builder, self.compiler.host, LldThreads::No));
856+
cmd.args(linker_args(builder, self.compiler.host, LldThreads::No, self.compiler.stage));
851857

852858
cmd.delay_failure().run(builder);
853859
}
@@ -1023,7 +1029,13 @@ impl Step for RustdocGUI {
10231029
cmd.env("RUSTDOC", builder.rustdoc(self.compiler))
10241030
.env("RUSTC", builder.rustc(self.compiler));
10251031

1026-
add_rustdoc_cargo_linker_args(&mut cmd, builder, self.compiler.host, LldThreads::No);
1032+
add_rustdoc_cargo_linker_args(
1033+
&mut cmd,
1034+
builder,
1035+
self.compiler.host,
1036+
LldThreads::No,
1037+
self.compiler.stage,
1038+
);
10271039

10281040
for path in &builder.paths {
10291041
if let Some(p) = helpers::is_valid_test_suite_arg(path, "tests/rustdoc-gui", builder) {
@@ -1887,7 +1899,7 @@ NOTE: if you're sure you want to do this, please open an issue as to why. In the
18871899

18881900
let mut hostflags = flags.clone();
18891901
hostflags.push(format!("-Lnative={}", builder.test_helpers_out(compiler.host).display()));
1890-
hostflags.extend(linker_flags(builder, compiler.host, LldThreads::No));
1902+
hostflags.extend(linker_flags(builder, compiler.host, LldThreads::No, compiler.stage));
18911903

18921904
let mut targetflags = flags;
18931905
targetflags.push(format!("-Lnative={}", builder.test_helpers_out(target).display()));

src/bootstrap/src/core/builder/cargo.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -260,7 +260,7 @@ impl Cargo {
260260
}
261261
}
262262

263-
for arg in linker_args(builder, compiler.host, LldThreads::Yes) {
263+
for arg in linker_args(builder, compiler.host, LldThreads::Yes, 0) {
264264
self.hostflags.arg(&arg);
265265
}
266266

@@ -270,10 +270,10 @@ impl Cargo {
270270
}
271271
// We want to set -Clinker using Cargo, therefore we only call `linker_flags` and not
272272
// `linker_args` here.
273-
for flag in linker_flags(builder, target, LldThreads::Yes) {
273+
for flag in linker_flags(builder, target, LldThreads::Yes, compiler.stage) {
274274
self.rustflags.arg(&flag);
275275
}
276-
for arg in linker_args(builder, target, LldThreads::Yes) {
276+
for arg in linker_args(builder, target, LldThreads::Yes, compiler.stage) {
277277
self.rustdocflags.arg(&arg);
278278
}
279279

src/bootstrap/src/core/builder/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1462,7 +1462,7 @@ impl<'a> Builder<'a> {
14621462
cmd.arg("-Dwarnings");
14631463
}
14641464
cmd.arg("-Znormalize-docs");
1465-
cmd.args(linker_args(self, compiler.host, LldThreads::Yes));
1465+
cmd.args(linker_args(self, compiler.host, LldThreads::Yes, compiler.stage));
14661466
cmd
14671467
}
14681468

src/bootstrap/src/utils/helpers.rs

+11-3
Original file line numberDiff line numberDiff line change
@@ -430,8 +430,9 @@ pub fn linker_args(
430430
builder: &Builder<'_>,
431431
target: TargetSelection,
432432
lld_threads: LldThreads,
433+
stage: u32,
433434
) -> Vec<String> {
434-
let mut args = linker_flags(builder, target, lld_threads);
435+
let mut args = linker_flags(builder, target, lld_threads, stage);
435436

436437
if let Some(linker) = builder.linker(target) {
437438
args.push(format!("-Clinker={}", linker.display()));
@@ -446,12 +447,18 @@ pub fn linker_flags(
446447
builder: &Builder<'_>,
447448
target: TargetSelection,
448449
lld_threads: LldThreads,
450+
stage: u32,
449451
) -> Vec<String> {
450452
let mut args = vec![];
451453
if !builder.is_lld_direct_linker(target) && builder.config.lld_mode.is_used() {
452454
match builder.config.lld_mode {
453455
LldMode::External => {
454-
args.push("-Clinker-flavor=gnu-lld-cc".to_string());
456+
// cfg(bootstrap) - remove after updating bootstrap compiler (#137498)
457+
if stage == 0 && target.is_windows() {
458+
args.push("-Clink-arg=-fuse-ld=lld".to_string());
459+
} else {
460+
args.push("-Clinker-flavor=gnu-lld-cc".to_string());
461+
}
455462
// FIXME(kobzol): remove this flag once MCP510 gets stabilized
456463
args.push("-Zunstable-options".to_string());
457464
}
@@ -479,8 +486,9 @@ pub fn add_rustdoc_cargo_linker_args(
479486
builder: &Builder<'_>,
480487
target: TargetSelection,
481488
lld_threads: LldThreads,
489+
stage: u32,
482490
) {
483-
let args = linker_args(builder, target, lld_threads);
491+
let args = linker_args(builder, target, lld_threads, stage);
484492
let mut flags = cmd
485493
.get_envs()
486494
.find_map(|(k, v)| if k == OsStr::new("RUSTDOCFLAGS") { v } else { None })

tests/assembly/aarch64-pointer-auth.rs

+3-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
// Test that PAC instructions are emitted when branch-protection is specified.
22

3+
//@ add-core-stubs
34
//@ revisions: PACRET PAUTHLR_NOP PAUTHLR
45
//@ assembly-output: emit-asm
56
//@ needs-llvm-components: aarch64
@@ -14,8 +15,8 @@
1415
#![no_core]
1516
#![crate_type = "lib"]
1617

17-
#[lang = "sized"]
18-
trait Sized {}
18+
extern crate minicore;
19+
use minicore::*;
1920

2021
// PACRET: hint #25
2122
// PACRET: hint #29

tests/assembly/cmse.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
//@ add-core-stubs
12
//@ revisions: hard soft
23
//@ assembly-output: emit-asm
34
//@ [hard] compile-flags: --target thumbv8m.main-none-eabihf --crate-type lib -Copt-level=1
@@ -7,10 +8,9 @@
78
#![crate_type = "lib"]
89
#![feature(abi_c_cmse_nonsecure_call, cmse_nonsecure_entry, no_core, lang_items)]
910
#![no_core]
10-
#[lang = "sized"]
11-
pub trait Sized {}
12-
#[lang = "copy"]
13-
pub trait Copy {}
11+
12+
extern crate minicore;
13+
use minicore::*;
1414

1515
// CHECK-LABEL: __acle_se_entry_point:
1616
// CHECK-NEXT: entry_point:

tests/assembly/dwarf4.rs

+3-4
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,15 @@
11
// Makes sure that `-Z dwarf-version=4` causes `rustc` to emit DWARF version 4.
22
//@ assembly-output: emit-asm
3+
//@ add-core-stubs
34
//@ compile-flags: -g --target x86_64-unknown-linux-gnu -Z dwarf-version=4 -Copt-level=0
45
//@ needs-llvm-components: x86
56

67
#![feature(no_core, lang_items)]
78
#![crate_type = "rlib"]
89
#![no_core]
910

10-
#[lang = "sized"]
11-
trait Sized {}
12-
#[lang = "copy"]
13-
trait Copy {}
11+
extern crate minicore;
12+
use minicore::*;
1413

1514
pub fn wibble() {}
1615

tests/assembly/dwarf5.rs

+3-4
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
// Makes sure that `-Z dwarf-version=5` causes `rustc` to emit DWARF version 5.
2+
//@ add-core-stubs
23
//@ assembly-output: emit-asm
34
//@ compile-flags: -g --target x86_64-unknown-linux-gnu -Z dwarf-version=5 -Copt-level=0
45
//@ needs-llvm-components: x86
@@ -7,10 +8,8 @@
78
#![crate_type = "rlib"]
89
#![no_core]
910

10-
#[lang = "sized"]
11-
trait Sized {}
12-
#[lang = "copy"]
13-
trait Copy {}
11+
extern crate minicore;
12+
use minicore::*;
1413

1514
pub fn wibble() {}
1615

tests/assembly/pic-relocation-model.rs

+3-4
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
//@ add-core-stubs
12
//@ revisions: x64
23
//@ assembly-output: emit-asm
34
//@ [x64] compile-flags: --target x86_64-unknown-linux-gnu -Crelocation-model=pic
@@ -7,10 +8,8 @@
78
#![no_core]
89
#![crate_type = "rlib"]
910

10-
#[lang = "sized"]
11-
trait Sized {}
12-
#[lang = "copy"]
13-
trait Copy {}
11+
extern crate minicore;
12+
use minicore::*;
1413

1514
// CHECK-LABEL: call_other_fn:
1615
// CHECK: {{(jmpq|callq)}} *other_fn@GOTPCREL(%rip)

tests/assembly/pie-relocation-model.rs

+3-4
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
//@ add-core-stubs
12
//@ revisions: x64
23
//@ assembly-output: emit-asm
34
//@ [x64] compile-flags: --target x86_64-unknown-linux-gnu -Crelocation-model=pie
@@ -7,10 +8,8 @@
78
#![no_core]
89
#![crate_type = "rlib"]
910

10-
#[lang = "sized"]
11-
trait Sized {}
12-
#[lang = "copy"]
13-
trait Copy {}
11+
extern crate minicore;
12+
use minicore::*;
1413

1514
// CHECK-LABEL: call_other_fn:
1615
// With PIE local functions are called "directly".

0 commit comments

Comments
 (0)