From ac87434362f2db51dc6ca29805daef99c606cba4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Joel=20Wejdenst=C3=A5l?= Date: Mon, 21 Jul 2025 01:09:58 +0200 Subject: [PATCH 01/16] Implement support for explicit tail calls in the MIR block builders and the LLVM codegen bckend. --- compiler/rustc_codegen_gcc/src/builder.rs | 15 +++++ compiler/rustc_codegen_llvm/src/builder.rs | 26 +++++++- compiler/rustc_codegen_llvm/src/llvm/ffi.rs | 11 ++++ compiler/rustc_codegen_ssa/src/mir/block.rs | 60 +++++++++++++++---- .../rustc_codegen_ssa/src/traits/builder.rs | 12 ++++ .../rustc_llvm/llvm-wrapper/RustWrapper.cpp | 27 +++++++++ 6 files changed, 139 insertions(+), 12 deletions(-) diff --git a/compiler/rustc_codegen_gcc/src/builder.rs b/compiler/rustc_codegen_gcc/src/builder.rs index a4ec4bf8deac4..48e11c755a4f0 100644 --- a/compiler/rustc_codegen_gcc/src/builder.rs +++ b/compiler/rustc_codegen_gcc/src/builder.rs @@ -1742,6 +1742,21 @@ impl<'a, 'gcc, 'tcx> BuilderMethods<'a, 'tcx> for Builder<'a, 'gcc, 'tcx> { call } + fn tail_call( + &mut self, + _llty: Self::Type, + _fn_attrs: Option<&CodegenFnAttrs>, + _fn_abi: &FnAbi<'tcx, Ty<'tcx>>, + _llfn: Self::Value, + _args: &[Self::Value], + _funclet: Option<&Self::Funclet>, + _instance: Option>, + ) { + bug!( + "Guaranteed tail calls with the 'become' keyword are not implemented in the GCC backend" + ); + } + fn zext(&mut self, value: RValue<'gcc>, dest_typ: Type<'gcc>) -> RValue<'gcc> { // FIXME(antoyo): this does not zero-extend. self.gcc_int_cast(value, dest_typ) diff --git a/compiler/rustc_codegen_llvm/src/builder.rs b/compiler/rustc_codegen_llvm/src/builder.rs index 514923ad6f37f..c1beba767cf8c 100644 --- a/compiler/rustc_codegen_llvm/src/builder.rs +++ b/compiler/rustc_codegen_llvm/src/builder.rs @@ -14,6 +14,7 @@ use rustc_codegen_ssa::mir::place::PlaceRef; use rustc_codegen_ssa::traits::*; use rustc_data_structures::small_c_str::SmallCStr; use rustc_hir::def_id::DefId; +use rustc_middle::bug; use rustc_middle::middle::codegen_fn_attrs::CodegenFnAttrs; use rustc_middle::ty::layout::{ FnAbiError, FnAbiOfHelpers, FnAbiRequest, HasTypingEnv, LayoutError, LayoutOfHelpers, @@ -23,7 +24,7 @@ use rustc_middle::ty::{self, Instance, Ty, TyCtxt}; use rustc_sanitizers::{cfi, kcfi}; use rustc_session::config::OptLevel; use rustc_span::Span; -use rustc_target::callconv::FnAbi; +use rustc_target::callconv::{FnAbi, PassMode}; use rustc_target::spec::{HasTargetSpec, SanitizerSet, Target}; use smallvec::SmallVec; use tracing::{debug, instrument}; @@ -1362,6 +1363,29 @@ impl<'a, 'll, 'tcx> BuilderMethods<'a, 'tcx> for Builder<'a, 'll, 'tcx> { call } + fn tail_call( + &mut self, + llty: Self::Type, + fn_attrs: Option<&CodegenFnAttrs>, + fn_abi: &FnAbi<'tcx, Ty<'tcx>>, + llfn: Self::Value, + args: &[Self::Value], + funclet: Option<&Self::Funclet>, + instance: Option>, + ) { + let call = self.call(llty, fn_attrs, Some(fn_abi), llfn, args, funclet, instance); + + match &fn_abi.ret.mode { + PassMode::Ignore | PassMode::Indirect { .. } => self.ret_void(), + PassMode::Direct(_) | PassMode::Pair { .. } => self.ret(call), + mode @ PassMode::Cast { .. } => { + bug!("Encountered `PassMode::{mode:?}` during codegen") + } + } + + llvm::LLVMSetTailCallKind(call, llvm::TailCallKind::MustTail); + } + fn zext(&mut self, val: &'ll Value, dest_ty: &'ll Type) -> &'ll Value { unsafe { llvm::LLVMBuildZExt(self.llbuilder, val, dest_ty, UNNAMED) } } diff --git a/compiler/rustc_codegen_llvm/src/llvm/ffi.rs b/compiler/rustc_codegen_llvm/src/llvm/ffi.rs index 80a0e5c5accc2..f6e4b649b515f 100644 --- a/compiler/rustc_codegen_llvm/src/llvm/ffi.rs +++ b/compiler/rustc_codegen_llvm/src/llvm/ffi.rs @@ -97,6 +97,16 @@ pub(crate) enum ModuleFlagMergeBehavior { // Consts for the LLVM CallConv type, pre-cast to usize. +#[derive(Copy, Clone, PartialEq, Debug)] +#[repr(C)] +#[allow(dead_code)] +pub(crate) enum TailCallKind { + None = 0, + Tail = 1, + MustTail = 2, + NoTail = 3, +} + /// LLVM CallingConv::ID. Should we wrap this? /// /// See @@ -1181,6 +1191,7 @@ unsafe extern "C" { pub(crate) safe fn LLVMIsGlobalConstant(GlobalVar: &Value) -> Bool; pub(crate) safe fn LLVMSetGlobalConstant(GlobalVar: &Value, IsConstant: Bool); pub(crate) safe fn LLVMSetTailCall(CallInst: &Value, IsTailCall: Bool); + pub(crate) safe fn LLVMSetTailCallKind(CallInst: &Value, Kind: TailCallKind); // Operations on attributes pub(crate) fn LLVMCreateStringAttribute( diff --git a/compiler/rustc_codegen_ssa/src/mir/block.rs b/compiler/rustc_codegen_ssa/src/mir/block.rs index bde63fd501aa2..e97a4e98a257a 100644 --- a/compiler/rustc_codegen_ssa/src/mir/block.rs +++ b/compiler/rustc_codegen_ssa/src/mir/block.rs @@ -160,6 +160,7 @@ impl<'a, 'tcx> TerminatorCodegenHelper<'tcx> { mut unwind: mir::UnwindAction, lifetime_ends_after_call: &[(Bx::Value, Size)], instance: Option>, + tail: bool, mergeable_succ: bool, ) -> MergingSucc { let tcx = bx.tcx(); @@ -221,6 +222,15 @@ impl<'a, 'tcx> TerminatorCodegenHelper<'tcx> { } }; + if tail { + bx.tail_call(fn_ty, fn_attrs, fn_abi, fn_ptr, llargs, self.funclet(fx), instance); + for &(tmp, size) in lifetime_ends_after_call { + bx.lifetime_end(tmp, size); + } + + return MergingSucc::False; + } + if let Some(unwind_block) = unwind_block { let ret_llbb = if let Some((_, target)) = destination { fx.llbb(target) @@ -659,6 +669,7 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> { unwind, &[], Some(drop_instance), + false, !maybe_null && mergeable_succ, ) } @@ -747,8 +758,19 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> { let (fn_abi, llfn, instance) = common::build_langcall(bx, span, lang_item); // Codegen the actual panic invoke/call. - let merging_succ = - helper.do_call(self, bx, fn_abi, llfn, &args, None, unwind, &[], Some(instance), false); + let merging_succ = helper.do_call( + self, + bx, + fn_abi, + llfn, + &args, + None, + unwind, + &[], + Some(instance), + false, + false, + ); assert_eq!(merging_succ, MergingSucc::False); MergingSucc::False } @@ -778,6 +800,7 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> { &[], Some(instance), false, + false, ); assert_eq!(merging_succ, MergingSucc::False); } @@ -845,6 +868,7 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> { unwind, &[], Some(instance), + false, mergeable_succ, )) } @@ -860,6 +884,7 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> { target: Option, unwind: mir::UnwindAction, fn_span: Span, + tail: bool, mergeable_succ: bool, ) -> MergingSucc { let source_info = mir::SourceInfo { span: fn_span, ..terminator.source_info }; @@ -1003,8 +1028,12 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> { // We still need to call `make_return_dest` even if there's no `target`, since // `fn_abi.ret` could be `PassMode::Indirect`, even if it is uninhabited, // and `make_return_dest` adds the return-place indirect pointer to `llargs`. - let return_dest = self.make_return_dest(bx, destination, &fn_abi.ret, &mut llargs); - let destination = target.map(|target| (return_dest, target)); + let destination = if !tail { + let return_dest = self.make_return_dest(bx, destination, &fn_abi.ret, &mut llargs); + target.map(|target| (return_dest, target)) + } else { + None + }; // Split the rust-call tupled arguments off. let (first_args, untuple) = if sig.abi() == ExternAbi::RustCall @@ -1147,6 +1176,7 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> { unwind, &lifetime_ends_after_call, instance, + tail, mergeable_succ, ) } @@ -1388,15 +1418,23 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> { target, unwind, fn_span, + false, mergeable_succ(), ), - mir::TerminatorKind::TailCall { .. } => { - // FIXME(explicit_tail_calls): implement tail calls in ssa backend - span_bug!( - terminator.source_info.span, - "`TailCall` terminator is not yet supported by `rustc_codegen_ssa`" - ) - } + mir::TerminatorKind::TailCall { ref func, ref args, fn_span } => self + .codegen_call_terminator( + helper, + bx, + terminator, + func, + args, + mir::Place::from(mir::RETURN_PLACE), + None, + mir::UnwindAction::Unreachable, + fn_span, + true, + mergeable_succ(), + ), mir::TerminatorKind::CoroutineDrop | mir::TerminatorKind::Yield { .. } => { bug!("coroutine ops in codegen") } diff --git a/compiler/rustc_codegen_ssa/src/traits/builder.rs b/compiler/rustc_codegen_ssa/src/traits/builder.rs index 979456a6ba70f..4b18146863bf4 100644 --- a/compiler/rustc_codegen_ssa/src/traits/builder.rs +++ b/compiler/rustc_codegen_ssa/src/traits/builder.rs @@ -595,6 +595,18 @@ pub trait BuilderMethods<'a, 'tcx>: funclet: Option<&Self::Funclet>, instance: Option>, ) -> Self::Value; + + fn tail_call( + &mut self, + llty: Self::Type, + fn_attrs: Option<&CodegenFnAttrs>, + fn_abi: &FnAbi<'tcx, Ty<'tcx>>, + llfn: Self::Value, + args: &[Self::Value], + funclet: Option<&Self::Funclet>, + instance: Option>, + ); + fn zext(&mut self, val: Self::Value, dest_ty: Self::Type) -> Self::Value; fn apply_attrs_to_cleanup_callsite(&mut self, llret: Self::Value); diff --git a/compiler/rustc_llvm/llvm-wrapper/RustWrapper.cpp b/compiler/rustc_llvm/llvm-wrapper/RustWrapper.cpp index 90aa9188c8300..83d44f76e511d 100644 --- a/compiler/rustc_llvm/llvm-wrapper/RustWrapper.cpp +++ b/compiler/rustc_llvm/llvm-wrapper/RustWrapper.cpp @@ -51,6 +51,14 @@ // //===----------------------------------------------------------------------=== +// Define TailCallKind enum values to match LLVM's +enum LLVMRustTailCallKind { + LLVMRustTailCallKindNone = 0, + LLVMRustTailCallKindTail = 1, + LLVMRustTailCallKindMustTail = 2, + LLVMRustTailCallKindNoTail = 3 +}; + using namespace llvm; using namespace llvm::sys; using namespace llvm::object; @@ -1949,3 +1957,22 @@ extern "C" void LLVMRustSetNoSanitizeHWAddress(LLVMValueRef Global) { MD.NoHWAddress = true; GV.setSanitizerMetadata(MD); } + +extern "C" void LLVMSetTailCallKind(LLVMValueRef Call, + LLVMRustTailCallKind Kind) { + CallInst *CI = unwrap(Call); + switch (Kind) { + case LLVMRustTailCallKindNone: + CI->setTailCallKind(CallInst::TCK_None); + break; + case LLVMRustTailCallKindTail: + CI->setTailCallKind(CallInst::TCK_Tail); + break; + case LLVMRustTailCallKindMustTail: + CI->setTailCallKind(CallInst::TCK_MustTail); + break; + case LLVMRustTailCallKindNoTail: + CI->setTailCallKind(CallInst::TCK_NoTail); + break; + } +} From a96bd57ebcc38707d1d6121758c2ab32367060a9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Joel=20Wejdenst=C3=A5l?= Date: Mon, 21 Jul 2025 01:17:00 +0200 Subject: [PATCH 02/16] chore: clang-format --- compiler/rustc_codegen_llvm/src/builder.rs | 2 +- compiler/rustc_codegen_llvm/src/llvm/ffi.rs | 2 +- .../rustc_llvm/llvm-wrapper/RustWrapper.cpp | 17 ++++++++--------- 3 files changed, 10 insertions(+), 11 deletions(-) diff --git a/compiler/rustc_codegen_llvm/src/builder.rs b/compiler/rustc_codegen_llvm/src/builder.rs index c1beba767cf8c..0bb5de1b834fa 100644 --- a/compiler/rustc_codegen_llvm/src/builder.rs +++ b/compiler/rustc_codegen_llvm/src/builder.rs @@ -1383,7 +1383,7 @@ impl<'a, 'll, 'tcx> BuilderMethods<'a, 'tcx> for Builder<'a, 'll, 'tcx> { } } - llvm::LLVMSetTailCallKind(call, llvm::TailCallKind::MustTail); + llvm::LLVMRustSetTailCallKind(call, llvm::TailCallKind::MustTail); } fn zext(&mut self, val: &'ll Value, dest_ty: &'ll Type) -> &'ll Value { diff --git a/compiler/rustc_codegen_llvm/src/llvm/ffi.rs b/compiler/rustc_codegen_llvm/src/llvm/ffi.rs index f6e4b649b515f..ee5575370ed25 100644 --- a/compiler/rustc_codegen_llvm/src/llvm/ffi.rs +++ b/compiler/rustc_codegen_llvm/src/llvm/ffi.rs @@ -1191,7 +1191,7 @@ unsafe extern "C" { pub(crate) safe fn LLVMIsGlobalConstant(GlobalVar: &Value) -> Bool; pub(crate) safe fn LLVMSetGlobalConstant(GlobalVar: &Value, IsConstant: Bool); pub(crate) safe fn LLVMSetTailCall(CallInst: &Value, IsTailCall: Bool); - pub(crate) safe fn LLVMSetTailCallKind(CallInst: &Value, Kind: TailCallKind); + pub(crate) safe fn LLVMRustSetTailCallKind(CallInst: &Value, Kind: TailCallKind); // Operations on attributes pub(crate) fn LLVMCreateStringAttribute( diff --git a/compiler/rustc_llvm/llvm-wrapper/RustWrapper.cpp b/compiler/rustc_llvm/llvm-wrapper/RustWrapper.cpp index 83d44f76e511d..50128500e09fa 100644 --- a/compiler/rustc_llvm/llvm-wrapper/RustWrapper.cpp +++ b/compiler/rustc_llvm/llvm-wrapper/RustWrapper.cpp @@ -51,14 +51,6 @@ // //===----------------------------------------------------------------------=== -// Define TailCallKind enum values to match LLVM's -enum LLVMRustTailCallKind { - LLVMRustTailCallKindNone = 0, - LLVMRustTailCallKindTail = 1, - LLVMRustTailCallKindMustTail = 2, - LLVMRustTailCallKindNoTail = 3 -}; - using namespace llvm; using namespace llvm::sys; using namespace llvm::object; @@ -1958,7 +1950,14 @@ extern "C" void LLVMRustSetNoSanitizeHWAddress(LLVMValueRef Global) { GV.setSanitizerMetadata(MD); } -extern "C" void LLVMSetTailCallKind(LLVMValueRef Call, +enum LLVMRustTailCallKind { + LLVMRustTailCallKindNone = 0, + LLVMRustTailCallKindTail = 1, + LLVMRustTailCallKindMustTail = 2, + LLVMRustTailCallKindNoTail = 3 +}; + +extern "C" void LLVMRustSetTailCallKind(LLVMValueRef Call, LLVMRustTailCallKind Kind) { CallInst *CI = unwrap(Call); switch (Kind) { From 205f4ca8b99efa2b17705942b4f70d13c01e60ca Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Joel=20Wejdenst=C3=A5l?= Date: Mon, 21 Jul 2025 02:12:24 +0200 Subject: [PATCH 03/16] tests: add ui fail/pass tests and llvm ir tail codegen tests --- tests/codegen/become-musttail.rs | 18 ++++++++++++++++++ .../ui/explicit-tail-calls/recursion-no-tce.rs | 16 ++++++++++++++++ tests/ui/explicit-tail-calls/recursion-tce.rs | 17 +++++++++++++++++ 3 files changed, 51 insertions(+) create mode 100644 tests/codegen/become-musttail.rs create mode 100644 tests/ui/explicit-tail-calls/recursion-no-tce.rs create mode 100644 tests/ui/explicit-tail-calls/recursion-tce.rs diff --git a/tests/codegen/become-musttail.rs b/tests/codegen/become-musttail.rs new file mode 100644 index 0000000000000..779ee3efc21ce --- /dev/null +++ b/tests/codegen/become-musttail.rs @@ -0,0 +1,18 @@ +//@ compile-flags: -C opt-level=0 -Cpanic=abort -C no-prepopulate-passes +//@ needs-unwind + +#![crate_type = "lib"] +#![feature(explicit_tail_calls)] + +// CHECK-LABEL: define {{.*}}@fibonacci( +#[no_mangle] +#[inline(never)] +pub fn fibonacci(n: u64, a: u64, b: u64) -> u64 { + // CHECK: musttail call {{.*}}@fibonacci( + // CHECK-NEXT: ret u64 + match n { + 0 => a, + 1 => b, + _ => become fibonacci(n - 1, b, a + b), + } +} diff --git a/tests/ui/explicit-tail-calls/recursion-no-tce.rs b/tests/ui/explicit-tail-calls/recursion-no-tce.rs new file mode 100644 index 0000000000000..93e4cb655dc2f --- /dev/null +++ b/tests/ui/explicit-tail-calls/recursion-no-tce.rs @@ -0,0 +1,16 @@ +//@ run-fail + +use std::hint::black_box; + +pub fn count(curr: u64, top: u64) -> u64 { + if black_box(curr) >= top { + curr + } else { + count(curr + 1, top) + } +} + +fn main() { + println!("{}", + count(0, black_box(1000000))); +} diff --git a/tests/ui/explicit-tail-calls/recursion-tce.rs b/tests/ui/explicit-tail-calls/recursion-tce.rs new file mode 100644 index 0000000000000..8c89ceb7869aa --- /dev/null +++ b/tests/ui/explicit-tail-calls/recursion-tce.rs @@ -0,0 +1,17 @@ +//@ run-pass +#![expect(incomplete_features)] +#![feature(explicit_tail_calls)] + +use std::hint::black_box; + +pub fn count(curr: u64, top: u64) -> u64 { + if black_box(curr) >= top { + curr + } else { + become count(curr + 1, top) + } +} + +fn main() { + println!("{}", count(0, black_box(1000000))); +} From 3fac2797c5e07f2c4780c4bedefb5e846df032b2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Joel=20Wejdenst=C3=A5l?= Date: Mon, 21 Jul 2025 02:13:43 +0200 Subject: [PATCH 04/16] chore: fix typo --- tests/ui/explicit-tail-calls/recursion-no-tce.rs | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/tests/ui/explicit-tail-calls/recursion-no-tce.rs b/tests/ui/explicit-tail-calls/recursion-no-tce.rs index 93e4cb655dc2f..ada1a69509fa9 100644 --- a/tests/ui/explicit-tail-calls/recursion-no-tce.rs +++ b/tests/ui/explicit-tail-calls/recursion-no-tce.rs @@ -11,6 +11,5 @@ pub fn count(curr: u64, top: u64) -> u64 { } fn main() { - println!("{}", - count(0, black_box(1000000))); + println!("{}", count(0, black_box(1000000))); } From bcaa79529d351416a2ab1c07931a0ba05b99c9c3 Mon Sep 17 00:00:00 2001 From: Kivooeo Date: Sat, 19 Jul 2025 15:18:21 +0500 Subject: [PATCH 05/16] removed tidy check on issues files --- src/tools/tidy/src/issues.txt | 1224 -------------------------------- src/tools/tidy/src/ui_tests.rs | 55 +- triagebot.toml | 6 + 3 files changed, 10 insertions(+), 1275 deletions(-) diff --git a/src/tools/tidy/src/issues.txt b/src/tools/tidy/src/issues.txt index 77414bec82d35..ee06707415f59 100644 --- a/src/tools/tidy/src/issues.txt +++ b/src/tools/tidy/src/issues.txt @@ -1364,1230 +1364,6 @@ ui/infinite/issue-41731-infinite-macro-println.rs ui/intrinsics/issue-28575.rs ui/intrinsics/issue-84297-reifying-copy.rs ui/invalid/issue-114435-layout-type-err.rs -ui/issues/auxiliary/issue-11224.rs -ui/issues/auxiliary/issue-11508.rs -ui/issues/auxiliary/issue-11529.rs -ui/issues/auxiliary/issue-11680.rs -ui/issues/auxiliary/issue-12612-1.rs -ui/issues/auxiliary/issue-12612-2.rs -ui/issues/auxiliary/issue-12660-aux.rs -ui/issues/auxiliary/issue-13507.rs -ui/issues/auxiliary/issue-13620-1.rs -ui/issues/auxiliary/issue-13620-2.rs -ui/issues/auxiliary/issue-14344-1.rs -ui/issues/auxiliary/issue-14344-2.rs -ui/issues/auxiliary/issue-14422.rs -ui/issues/auxiliary/issue-15562.rs -ui/issues/auxiliary/issue-16643.rs -ui/issues/auxiliary/issue-16725.rs -ui/issues/auxiliary/issue-17662.rs -ui/issues/auxiliary/issue-18501.rs -ui/issues/auxiliary/issue-18514.rs -ui/issues/auxiliary/issue-18711.rs -ui/issues/auxiliary/issue-18913-1.rs -ui/issues/auxiliary/issue-18913-2.rs -ui/issues/auxiliary/issue-19293.rs -ui/issues/auxiliary/issue-20389.rs -ui/issues/auxiliary/issue-21202.rs -ui/issues/auxiliary/issue-2170-lib.rs -ui/issues/auxiliary/issue-2316-a.rs -ui/issues/auxiliary/issue-2316-b.rs -ui/issues/auxiliary/issue-2380.rs -ui/issues/auxiliary/issue-2414-a.rs -ui/issues/auxiliary/issue-2414-b.rs -ui/issues/auxiliary/issue-2472-b.rs -ui/issues/auxiliary/issue-25185-1.rs -ui/issues/auxiliary/issue-25185-2.rs -ui/issues/auxiliary/issue-2526.rs -ui/issues/auxiliary/issue-25467.rs -ui/issues/auxiliary/issue-2631-a.rs -ui/issues/auxiliary/issue-2723-a.rs -ui/issues/auxiliary/issue-29265.rs -ui/issues/auxiliary/issue-29485.rs -ui/issues/auxiliary/issue-3012-1.rs -ui/issues/auxiliary/issue-30123-aux.rs -ui/issues/auxiliary/issue-3136-a.rs -ui/issues/auxiliary/issue-31702-1.rs -ui/issues/auxiliary/issue-31702-2.rs -ui/issues/auxiliary/issue-34796-aux.rs -ui/issues/auxiliary/issue-36954.rs -ui/issues/auxiliary/issue-38190.rs -ui/issues/auxiliary/issue-38226-aux.rs -ui/issues/auxiliary/issue-3979-traits.rs -ui/issues/auxiliary/issue-41053.rs -ui/issues/auxiliary/issue-41549.rs -ui/issues/auxiliary/issue-42007-s.rs -ui/issues/auxiliary/issue-4208-cc.rs -ui/issues/auxiliary/issue-4545.rs -ui/issues/auxiliary/issue-48984-aux.rs -ui/issues/auxiliary/issue-49544.rs -ui/issues/auxiliary/issue-51798.rs -ui/issues/auxiliary/issue-52489.rs -ui/issues/auxiliary/issue-5518.rs -ui/issues/auxiliary/issue-5521.rs -ui/issues/auxiliary/issue-56943.rs -ui/issues/auxiliary/issue-57271-lib.rs -ui/issues/auxiliary/issue-5844-aux.rs -ui/issues/auxiliary/issue-7178.rs -ui/issues/auxiliary/issue-73112.rs -ui/issues/auxiliary/issue-7899.rs -ui/issues/auxiliary/issue-8044.rs -ui/issues/auxiliary/issue-8259.rs -ui/issues/auxiliary/issue-8401.rs -ui/issues/auxiliary/issue-9123.rs -ui/issues/auxiliary/issue-9155.rs -ui/issues/auxiliary/issue-9188.rs -ui/issues/auxiliary/issue-9906.rs -ui/issues/auxiliary/issue-9968.rs -ui/issues/issue-10228.rs -ui/issues/issue-10291.rs -ui/issues/issue-102964.rs -ui/issues/issue-10396.rs -ui/issues/issue-10412.rs -ui/issues/issue-10436.rs -ui/issues/issue-10456.rs -ui/issues/issue-10465.rs -ui/issues/issue-10545.rs -ui/issues/issue-10638.rs -ui/issues/issue-10656.rs -ui/issues/issue-106755.rs -ui/issues/issue-10683.rs -ui/issues/issue-10718.rs -ui/issues/issue-10734.rs -ui/issues/issue-10764.rs -ui/issues/issue-10767.rs -ui/issues/issue-10802.rs -ui/issues/issue-10806.rs -ui/issues/issue-10853.rs -ui/issues/issue-10877.rs -ui/issues/issue-10902.rs -ui/issues/issue-11004.rs -ui/issues/issue-11047.rs -ui/issues/issue-11085.rs -ui/issues/issue-11192.rs -ui/issues/issue-11205.rs -ui/issues/issue-11224.rs -ui/issues/issue-11267.rs -ui/issues/issue-11374.rs -ui/issues/issue-11382.rs -ui/issues/issue-11384.rs -ui/issues/issue-11508.rs -ui/issues/issue-11529.rs -ui/issues/issue-11552.rs -ui/issues/issue-11592.rs -ui/issues/issue-11677.rs -ui/issues/issue-11680.rs -ui/issues/issue-11681.rs -ui/issues/issue-11709.rs -ui/issues/issue-11740.rs -ui/issues/issue-11771.rs -ui/issues/issue-11820.rs -ui/issues/issue-11844.rs -ui/issues/issue-11869.rs -ui/issues/issue-11958.rs -ui/issues/issue-12033.rs -ui/issues/issue-12041.rs -ui/issues/issue-12127.rs -ui/issues/issue-12285.rs -ui/issues/issue-12567.rs -ui/issues/issue-12612.rs -ui/issues/issue-12660.rs -ui/issues/issue-12677.rs -ui/issues/issue-12729.rs -ui/issues/issue-12744.rs -ui/issues/issue-12860.rs -ui/issues/issue-12863.rs -ui/issues/issue-12909.rs -ui/issues/issue-12920.rs -ui/issues/issue-13027.rs -ui/issues/issue-13058.rs -ui/issues/issue-13105.rs -ui/issues/issue-13167.rs -ui/issues/issue-13202.rs -ui/issues/issue-13204.rs -ui/issues/issue-13214.rs -ui/issues/issue-13259-windows-tcb-trash.rs -ui/issues/issue-13264.rs -ui/issues/issue-13323.rs -ui/issues/issue-13359.rs -ui/issues/issue-13405.rs -ui/issues/issue-13407.rs -ui/issues/issue-13434.rs -ui/issues/issue-13446.rs -ui/issues/issue-13466.rs -ui/issues/issue-13482-2.rs -ui/issues/issue-13482.rs -ui/issues/issue-13497-2.rs -ui/issues/issue-13497.rs -ui/issues/issue-13507-2.rs -ui/issues/issue-13620.rs -ui/issues/issue-13665.rs -ui/issues/issue-13703.rs -ui/issues/issue-13763.rs -ui/issues/issue-13775.rs -ui/issues/issue-13808.rs -ui/issues/issue-13847.rs -ui/issues/issue-13867.rs -ui/issues/issue-14082.rs -ui/issues/issue-14091-2.rs -ui/issues/issue-14091.rs -ui/issues/issue-14092.rs -ui/issues/issue-14229.rs -ui/issues/issue-14254.rs -ui/issues/issue-14285.rs -ui/issues/issue-14308.rs -ui/issues/issue-14330.rs -ui/issues/issue-14344.rs -ui/issues/issue-14366.rs -ui/issues/issue-14382.rs -ui/issues/issue-14393.rs -ui/issues/issue-14399.rs -ui/issues/issue-14422.rs -ui/issues/issue-14541.rs -ui/issues/issue-14721.rs -ui/issues/issue-14821.rs -ui/issues/issue-14845.rs -ui/issues/issue-14853.rs -ui/issues/issue-14865.rs -ui/issues/issue-14875.rs -ui/issues/issue-14901.rs -ui/issues/issue-14915.rs -ui/issues/issue-14919.rs -ui/issues/issue-14959.rs -ui/issues/issue-15034.rs -ui/issues/issue-15043.rs -ui/issues/issue-15063.rs -ui/issues/issue-15094.rs -ui/issues/issue-15104.rs -ui/issues/issue-15129-rpass.rs -ui/issues/issue-15167.rs -ui/issues/issue-15189.rs -ui/issues/issue-15207.rs -ui/issues/issue-15260.rs -ui/issues/issue-15381.rs -ui/issues/issue-15444.rs -ui/issues/issue-15523-big.rs -ui/issues/issue-15523.rs -ui/issues/issue-15562.rs -ui/issues/issue-15571.rs -ui/issues/issue-15673.rs -ui/issues/issue-15734.rs -ui/issues/issue-15735.rs -ui/issues/issue-15756.rs -ui/issues/issue-15763.rs -ui/issues/issue-15774.rs -ui/issues/issue-15783.rs -ui/issues/issue-15793.rs -ui/issues/issue-15858.rs -ui/issues/issue-15896.rs -ui/issues/issue-15965.rs -ui/issues/issue-16048.rs -ui/issues/issue-16149.rs -ui/issues/issue-16151.rs -ui/issues/issue-16256.rs -ui/issues/issue-16278.rs -ui/issues/issue-16401.rs -ui/issues/issue-16441.rs -ui/issues/issue-16452.rs -ui/issues/issue-16492.rs -ui/issues/issue-16530.rs -ui/issues/issue-16560.rs -ui/issues/issue-16562.rs -ui/issues/issue-16596.rs -ui/issues/issue-16643.rs -ui/issues/issue-16648.rs -ui/issues/issue-16668.rs -ui/issues/issue-16671.rs -ui/issues/issue-16683.rs -ui/issues/issue-16725.rs -ui/issues/issue-16739.rs -ui/issues/issue-16745.rs -ui/issues/issue-16774.rs -ui/issues/issue-16783.rs -ui/issues/issue-16819.rs -ui/issues/issue-16922-rpass.rs -ui/issues/issue-16966.rs -ui/issues/issue-16994.rs -ui/issues/issue-17001.rs -ui/issues/issue-17033.rs -ui/issues/issue-17068.rs -ui/issues/issue-17121.rs -ui/issues/issue-17216.rs -ui/issues/issue-17252.rs -ui/issues/issue-17322.rs -ui/issues/issue-17336.rs -ui/issues/issue-17337.rs -ui/issues/issue-17351.rs -ui/issues/issue-17361.rs -ui/issues/issue-17373.rs -ui/issues/issue-17385.rs -ui/issues/issue-17405.rs -ui/issues/issue-17441.rs -ui/issues/issue-17450.rs -ui/issues/issue-17503.rs -ui/issues/issue-17546.rs -ui/issues/issue-17551.rs -ui/issues/issue-17651.rs -ui/issues/issue-17662.rs -ui/issues/issue-17732.rs -ui/issues/issue-17734.rs -ui/issues/issue-17740.rs -ui/issues/issue-17746.rs -ui/issues/issue-17758.rs -ui/issues/issue-17771.rs -ui/issues/issue-17800.rs -ui/issues/issue-17816.rs -ui/issues/issue-17877.rs -ui/issues/issue-17897.rs -ui/issues/issue-17904-2.rs -ui/issues/issue-17904.rs -ui/issues/issue-17905-2.rs -ui/issues/issue-17905.rs -ui/issues/issue-17933.rs -ui/issues/issue-17954.rs -ui/issues/issue-17959.rs -ui/issues/issue-17994.rs -ui/issues/issue-17999.rs -ui/issues/issue-18058.rs -ui/issues/issue-18088.rs -ui/issues/issue-18107.rs -ui/issues/issue-18110.rs -ui/issues/issue-18119.rs -ui/issues/issue-18159.rs -ui/issues/issue-18173.rs -ui/issues/issue-18183.rs -ui/issues/issue-18188.rs -ui/issues/issue-18232.rs -ui/issues/issue-18352.rs -ui/issues/issue-18353.rs -ui/issues/issue-18389.rs -ui/issues/issue-18423.rs -ui/issues/issue-18446-2.rs -ui/issues/issue-18446.rs -ui/issues/issue-18464.rs -ui/issues/issue-18501.rs -ui/issues/issue-18514.rs -ui/issues/issue-18532.rs -ui/issues/issue-18539.rs -ui/issues/issue-18566.rs -ui/issues/issue-18611.rs -ui/issues/issue-18685.rs -ui/issues/issue-18711.rs -ui/issues/issue-18767.rs -ui/issues/issue-18783.rs -ui/issues/issue-18809.rs -ui/issues/issue-18845.rs -ui/issues/issue-18859.rs -ui/issues/issue-18906.rs -ui/issues/issue-18913.rs -ui/issues/issue-18919.rs -ui/issues/issue-18952.rs -ui/issues/issue-18959.rs -ui/issues/issue-18988.rs -ui/issues/issue-19001.rs -ui/issues/issue-19037.rs -ui/issues/issue-19086.rs -ui/issues/issue-19097.rs -ui/issues/issue-19098.rs -ui/issues/issue-19100.rs -ui/issues/issue-19127.rs -ui/issues/issue-19135.rs -ui/issues/issue-19293.rs -ui/issues/issue-19367.rs -ui/issues/issue-19380.rs -ui/issues/issue-19398.rs -ui/issues/issue-19404.rs -ui/issues/issue-19479.rs -ui/issues/issue-19482.rs -ui/issues/issue-19499.rs -ui/issues/issue-19601.rs -ui/issues/issue-19631.rs -ui/issues/issue-19632.rs -ui/issues/issue-19692.rs -ui/issues/issue-19734.rs -ui/issues/issue-19811-escape-unicode.rs -ui/issues/issue-19850.rs -ui/issues/issue-19922.rs -ui/issues/issue-19982.rs -ui/issues/issue-19991.rs -ui/issues/issue-20009.rs -ui/issues/issue-20055-box-trait.rs -ui/issues/issue-20055-box-unsized-array.rs -ui/issues/issue-20162.rs -ui/issues/issue-20174.rs -ui/issues/issue-20186.rs -ui/issues/issue-20225.rs -ui/issues/issue-20261.rs -ui/issues/issue-20313-rpass.rs -ui/issues/issue-20313.rs -ui/issues/issue-20389.rs -ui/issues/issue-20396.rs -ui/issues/issue-20413.rs -ui/issues/issue-20414.rs -ui/issues/issue-20427.rs -ui/issues/issue-20433.rs -ui/issues/issue-20454.rs -ui/issues/issue-20544.rs -ui/issues/issue-20575.rs -ui/issues/issue-20644.rs -ui/issues/issue-20676.rs -ui/issues/issue-20714.rs -ui/issues/issue-2074.rs -ui/issues/issue-20772.rs -ui/issues/issue-20797.rs -ui/issues/issue-20803.rs -ui/issues/issue-20831-debruijn.rs -ui/issues/issue-20847.rs -ui/issues/issue-20939.rs -ui/issues/issue-20953.rs -ui/issues/issue-20971.rs -ui/issues/issue-21033.rs -ui/issues/issue-21140.rs -ui/issues/issue-21160.rs -ui/issues/issue-21174-2.rs -ui/issues/issue-21174.rs -ui/issues/issue-21177.rs -ui/issues/issue-21202.rs -ui/issues/issue-21245.rs -ui/issues/issue-21291.rs -ui/issues/issue-21306.rs -ui/issues/issue-21332.rs -ui/issues/issue-21361.rs -ui/issues/issue-21384.rs -ui/issues/issue-21400.rs -ui/issues/issue-21402.rs -ui/issues/issue-21449.rs -ui/issues/issue-2150.rs -ui/issues/issue-2151.rs -ui/issues/issue-21546.rs -ui/issues/issue-21554.rs -ui/issues/issue-21600.rs -ui/issues/issue-21622.rs -ui/issues/issue-21634.rs -ui/issues/issue-21655.rs -ui/issues/issue-2170-exe.rs -ui/issues/issue-21701.rs -ui/issues/issue-21763.rs -ui/issues/issue-21891.rs -ui/issues/issue-2190-1.rs -ui/issues/issue-21909.rs -ui/issues/issue-21922.rs -ui/issues/issue-21946.rs -ui/issues/issue-21950.rs -ui/issues/issue-21974.rs -ui/issues/issue-22008.rs -ui/issues/issue-22034.rs -ui/issues/issue-22036.rs -ui/issues/issue-2214.rs -ui/issues/issue-22258.rs -ui/issues/issue-22289.rs -ui/issues/issue-22312.rs -ui/issues/issue-22346.rs -ui/issues/issue-22356.rs -ui/issues/issue-22370.rs -ui/issues/issue-22403.rs -ui/issues/issue-22426.rs -ui/issues/issue-22434.rs -ui/issues/issue-22468.rs -ui/issues/issue-22471.rs -ui/issues/issue-22577.rs -ui/issues/issue-22599.rs -ui/issues/issue-22603.rs -ui/issues/issue-22629.rs -ui/issues/issue-22638.rs -ui/issues/issue-22644.rs -ui/issues/issue-22673.rs -ui/issues/issue-22684.rs -ui/issues/issue-22706.rs -ui/issues/issue-22777.rs -ui/issues/issue-22781.rs -ui/issues/issue-22789.rs -ui/issues/issue-2281-part1.rs -ui/issues/issue-22814.rs -ui/issues/issue-2284.rs -ui/issues/issue-22872.rs -ui/issues/issue-22874.rs -ui/issues/issue-2288.rs -ui/issues/issue-22886.rs -ui/issues/issue-22894.rs -ui/issues/issue-22992-2.rs -ui/issues/issue-22992.rs -ui/issues/issue-23024.rs -ui/issues/issue-23036.rs -ui/issues/issue-23041.rs -ui/issues/issue-23046.rs -ui/issues/issue-23073.rs -ui/issues/issue-2311-2.rs -ui/issues/issue-2311.rs -ui/issues/issue-2312.rs -ui/issues/issue-2316-c.rs -ui/issues/issue-23173.rs -ui/issues/issue-23189.rs -ui/issues/issue-23217.rs -ui/issues/issue-23253.rs -ui/issues/issue-23261.rs -ui/issues/issue-23281.rs -ui/issues/issue-23311.rs -ui/issues/issue-23336.rs -ui/issues/issue-23354-2.rs -ui/issues/issue-23354.rs -ui/issues/issue-23406.rs -ui/issues/issue-23433.rs -ui/issues/issue-23442.rs -ui/issues/issue-23477.rs -ui/issues/issue-23485.rs -ui/issues/issue-23491.rs -ui/issues/issue-23543.rs -ui/issues/issue-23544.rs -ui/issues/issue-23550.rs -ui/issues/issue-23589.rs -ui/issues/issue-23699.rs -ui/issues/issue-2380-b.rs -ui/issues/issue-2383.rs -ui/issues/issue-23891.rs -ui/issues/issue-23898.rs -ui/issues/issue-23958.rs -ui/issues/issue-23966.rs -ui/issues/issue-23992.rs -ui/issues/issue-24013.rs -ui/issues/issue-24036.rs -ui/issues/issue-24086.rs -ui/issues/issue-2414-c.rs -ui/issues/issue-24161.rs -ui/issues/issue-24227.rs -ui/issues/issue-2428.rs -ui/issues/issue-24308.rs -ui/issues/issue-24322.rs -ui/issues/issue-24352.rs -ui/issues/issue-24353.rs -ui/issues/issue-24357.rs -ui/issues/issue-24363.rs -ui/issues/issue-24365.rs -ui/issues/issue-24389.rs -ui/issues/issue-24424.rs -ui/issues/issue-24434.rs -ui/issues/issue-2445-b.rs -ui/issues/issue-2445.rs -ui/issues/issue-24533.rs -ui/issues/issue-24589.rs -ui/issues/issue-2463.rs -ui/issues/issue-24682.rs -ui/issues/issue-24687-embed-debuginfo/auxiliary/issue-24687-lib.rs -ui/issues/issue-24687-embed-debuginfo/auxiliary/issue-24687-mbcs-in-comments.rs -ui/issues/issue-2470-bounds-check-overflow.rs -ui/issues/issue-2472.rs -ui/issues/issue-24779.rs -ui/issues/issue-24819.rs -ui/issues/issue-2487-a.rs -ui/issues/issue-24945-repeat-dash-opts.rs -ui/issues/issue-24947.rs -ui/issues/issue-24954.rs -ui/issues/issue-2502.rs -ui/issues/issue-25076.rs -ui/issues/issue-25089.rs -ui/issues/issue-25145.rs -ui/issues/issue-25180.rs -ui/issues/issue-25185.rs -ui/issues/issue-2526-a.rs -ui/issues/issue-25279.rs -ui/issues/issue-25343.rs -ui/issues/issue-25368.rs -ui/issues/issue-25386.rs -ui/issues/issue-25394.rs -ui/issues/issue-25467.rs -ui/issues/issue-25497.rs -ui/issues/issue-2550.rs -ui/issues/issue-25515.rs -ui/issues/issue-25549-multiple-drop.rs -ui/issues/issue-25579.rs -ui/issues/issue-25679.rs -ui/issues/issue-25693.rs -ui/issues/issue-25746-bool-transmute.rs -ui/issues/issue-25757.rs -ui/issues/issue-25810.rs -ui/issues/issue-2590.rs -ui/issues/issue-25901.rs -ui/issues/issue-26056.rs -ui/issues/issue-26093.rs -ui/issues/issue-26095.rs -ui/issues/issue-26127.rs -ui/issues/issue-26186.rs -ui/issues/issue-26205.rs -ui/issues/issue-26217.rs -ui/issues/issue-26237.rs -ui/issues/issue-2631-b.rs -ui/issues/issue-2642.rs -ui/issues/issue-26468.rs -ui/issues/issue-26472.rs -ui/issues/issue-26484.rs -ui/issues/issue-26614.rs -ui/issues/issue-26619.rs -ui/issues/issue-26641.rs -ui/issues/issue-26646.rs -ui/issues/issue-26655.rs -ui/issues/issue-26709.rs -ui/issues/issue-26802.rs -ui/issues/issue-26805.rs -ui/issues/issue-26812.rs -ui/issues/issue-26948.rs -ui/issues/issue-26997.rs -ui/issues/issue-27008.rs -ui/issues/issue-27033.rs -ui/issues/issue-27042.rs -ui/issues/issue-27054-primitive-binary-ops.rs -ui/issues/issue-27078.rs -ui/issues/issue-2708.rs -ui/issues/issue-27105.rs -ui/issues/issue-2723-b.rs -ui/issues/issue-27240.rs -ui/issues/issue-27268.rs -ui/issues/issue-27281.rs -ui/issues/issue-27340.rs -ui/issues/issue-27401-dropflag-reinit.rs -ui/issues/issue-27433.rs -ui/issues/issue-27592.rs -ui/issues/issue-2761.rs -ui/issues/issue-27639.rs -ui/issues/issue-27697.rs -ui/issues/issue-27815.rs -ui/issues/issue-27842.rs -ui/issues/issue-27889.rs -ui/issues/issue-27942.rs -ui/issues/issue-27949.rs -ui/issues/issue-27997.rs -ui/issues/issue-28105.rs -ui/issues/issue-28109.rs -ui/issues/issue-28181.rs -ui/issues/issue-28279.rs -ui/issues/issue-28344.rs -ui/issues/issue-28433.rs -ui/issues/issue-28472.rs -ui/issues/issue-2848.rs -ui/issues/issue-2849.rs -ui/issues/issue-28498-must-work-ex1.rs -ui/issues/issue-28498-must-work-ex2.rs -ui/issues/issue-28498-ugeh-ex1.rs -ui/issues/issue-28550.rs -ui/issues/issue-28561.rs -ui/issues/issue-28568.rs -ui/issues/issue-28586.rs -ui/issues/issue-28600.rs -ui/issues/issue-28625.rs -ui/issues/issue-28776.rs -ui/issues/issue-28828.rs -ui/issues/issue-28839.rs -ui/issues/issue-28936.rs -ui/issues/issue-2895.rs -ui/issues/issue-28971.rs -ui/issues/issue-28983.rs -ui/issues/issue-28999.rs -ui/issues/issue-29030.rs -ui/issues/issue-29037.rs -ui/issues/issue-2904.rs -ui/issues/issue-29048.rs -ui/issues/issue-29053.rs -ui/issues/issue-29071-2.rs -ui/issues/issue-29071.rs -ui/issues/issue-29092.rs -ui/issues/issue-29147-rpass.rs -ui/issues/issue-29147.rs -ui/issues/issue-29265.rs -ui/issues/issue-29276.rs -ui/issues/issue-2935.rs -ui/issues/issue-29466.rs -ui/issues/issue-29485.rs -ui/issues/issue-2951.rs -ui/issues/issue-29516.rs -ui/issues/issue-29522.rs -ui/issues/issue-29540.rs -ui/issues/issue-29663.rs -ui/issues/issue-29668.rs -ui/issues/issue-29710.rs -ui/issues/issue-29723.rs -ui/issues/issue-29740.rs -ui/issues/issue-29743.rs -ui/issues/issue-29821.rs -ui/issues/issue-29857.rs -ui/issues/issue-29861.rs -ui/issues/issue-2989.rs -ui/issues/issue-29948.rs -ui/issues/issue-2995.rs -ui/issues/issue-30018-panic.rs -ui/issues/issue-30081.rs -ui/issues/issue-3012-2.rs -ui/issues/issue-30123.rs -ui/issues/issue-3021-b.rs -ui/issues/issue-3021-d.rs -ui/issues/issue-30236.rs -ui/issues/issue-30255.rs -ui/issues/issue-3026.rs -ui/issues/issue-3029.rs -ui/issues/issue-3037.rs -ui/issues/issue-30371.rs -ui/issues/issue-3038.rs -ui/issues/issue-30380.rs -ui/issues/issue-3052.rs -ui/issues/issue-30530.rs -ui/issues/issue-30589.rs -ui/issues/issue-30615.rs -ui/issues/issue-30756.rs -ui/issues/issue-30891.rs -ui/issues/issue-3091.rs -ui/issues/issue-31011.rs -ui/issues/issue-3109.rs -ui/issues/issue-3121.rs -ui/issues/issue-31267-additional.rs -ui/issues/issue-31267.rs -ui/issues/issue-31299.rs -ui/issues/issue-3136-b.rs -ui/issues/issue-3149.rs -ui/issues/issue-31511.rs -ui/issues/issue-3154.rs -ui/issues/issue-31702.rs -ui/issues/issue-31769.rs -ui/issues/issue-31776.rs -ui/issues/issue-31910.rs -ui/issues/issue-32004.rs -ui/issues/issue-32008.rs -ui/issues/issue-32086.rs -ui/issues/issue-3220.rs -ui/issues/issue-32292.rs -ui/issues/issue-32324.rs -ui/issues/issue-32326.rs -ui/issues/issue-32377.rs -ui/issues/issue-32389.rs -ui/issues/issue-32518.rs -ui/issues/issue-32655.rs -ui/issues/issue-32782.rs -ui/issues/issue-32797.rs -ui/issues/issue-32805.rs -ui/issues/issue-3290.rs -ui/issues/issue-32995-2.rs -ui/issues/issue-32995.rs -ui/issues/issue-33202.rs -ui/issues/issue-33241.rs -ui/issues/issue-33287.rs -ui/issues/issue-33293.rs -ui/issues/issue-33387.rs -ui/issues/issue-3344.rs -ui/issues/issue-33461.rs -ui/issues/issue-33504.rs -ui/issues/issue-33525.rs -ui/issues/issue-33571.rs -ui/issues/issue-33687.rs -ui/issues/issue-33770.rs -ui/issues/issue-3389.rs -ui/issues/issue-33941.rs -ui/issues/issue-34047.rs -ui/issues/issue-34074.rs -ui/issues/issue-34209.rs -ui/issues/issue-34229.rs -ui/issues/issue-3424.rs -ui/issues/issue-3429.rs -ui/issues/issue-34334.rs -ui/issues/issue-34349.rs -ui/issues/issue-34373.rs -ui/issues/issue-34418.rs -ui/issues/issue-34427.rs -ui/issues/issue-3447.rs -ui/issues/issue-34503.rs -ui/issues/issue-34569.rs -ui/issues/issue-34571.rs -ui/issues/issue-34751.rs -ui/issues/issue-3477.rs -ui/issues/issue-34780.rs -ui/issues/issue-34796.rs -ui/issues/issue-34839.rs -ui/issues/issue-3500.rs -ui/issues/issue-35139.rs -ui/issues/issue-3521-2.rs -ui/issues/issue-35241.rs -ui/issues/issue-35423.rs -ui/issues/issue-3556.rs -ui/issues/issue-35570.rs -ui/issues/issue-3559.rs -ui/issues/issue-35600.rs -ui/issues/issue-3574.rs -ui/issues/issue-35815.rs -ui/issues/issue-35976.rs -ui/issues/issue-35988.rs -ui/issues/issue-36023.rs -ui/issues/issue-36036-associated-type-layout.rs -ui/issues/issue-36075.rs -ui/issues/issue-3609.rs -ui/issues/issue-36116.rs -ui/issues/issue-36260.rs -ui/issues/issue-36278-prefix-nesting.rs -ui/issues/issue-36299.rs -ui/issues/issue-36379.rs -ui/issues/issue-36400.rs -ui/issues/issue-36474.rs -ui/issues/issue-3656.rs -ui/issues/issue-3668-non-constant-value-in-constant/issue-3668-2.rs -ui/issues/issue-3668-non-constant-value-in-constant/issue-3668.rs -ui/issues/issue-36744-bitcast-args-if-needed.rs -ui/issues/issue-36786-resolve-call.rs -ui/issues/issue-3680.rs -ui/issues/issue-36816.rs -ui/issues/issue-36836.rs -ui/issues/issue-36839.rs -ui/issues/issue-36856.rs -ui/issues/issue-36936.rs -ui/issues/issue-36954.rs -ui/issues/issue-3702-2.rs -ui/issues/issue-3702.rs -ui/issues/issue-37051.rs -ui/issues/issue-37109.rs -ui/issues/issue-37131.rs -ui/issues/issue-37311-type-length-limit/issue-37311.rs -ui/issues/issue-37510.rs -ui/issues/issue-3753.rs -ui/issues/issue-37534.rs -ui/issues/issue-37576.rs -ui/issues/issue-3763.rs -ui/issues/issue-37665.rs -ui/issues/issue-37686.rs -ui/issues/issue-37725.rs -ui/issues/issue-37733.rs -ui/issues/issue-3779.rs -ui/issues/issue-37884.rs -ui/issues/issue-38160.rs -ui/issues/issue-38190.rs -ui/issues/issue-38226.rs -ui/issues/issue-38381.rs -ui/issues/issue-38412.rs -ui/issues/issue-38437.rs -ui/issues/issue-38458.rs -ui/issues/issue-3847.rs -ui/issues/issue-38556.rs -ui/issues/issue-38727.rs -ui/issues/issue-3874.rs -ui/issues/issue-38763.rs -ui/issues/issue-38857.rs -ui/issues/issue-38875/auxiliary/issue-38875-b.rs -ui/issues/issue-38875/issue-38875.rs -ui/issues/issue-3888-2.rs -ui/issues/issue-38919.rs -ui/issues/issue-38942.rs -ui/issues/issue-3895.rs -ui/issues/issue-38954.rs -ui/issues/issue-38987.rs -ui/issues/issue-39089.rs -ui/issues/issue-39211.rs -ui/issues/issue-39367.rs -ui/issues/issue-39548.rs -ui/issues/issue-39687.rs -ui/issues/issue-39709.rs -ui/issues/issue-3979-2.rs -ui/issues/issue-3979-xcrate.rs -ui/issues/issue-3979.rs -ui/issues/issue-39808.rs -ui/issues/issue-39827.rs -ui/issues/issue-39848.rs -ui/issues/issue-3991.rs -ui/issues/issue-3993.rs -ui/issues/issue-39970.rs -ui/issues/issue-39984.rs -ui/issues/issue-40000.rs -ui/issues/issue-4025.rs -ui/issues/issue-40288-2.rs -ui/issues/issue-40288.rs -ui/issues/issue-40951.rs -ui/issues/issue-41053.rs -ui/issues/issue-41229-ref-str.rs -ui/issues/issue-41298.rs -ui/issues/issue-41479.rs -ui/issues/issue-41498.rs -ui/issues/issue-41549.rs -ui/issues/issue-41604.rs -ui/issues/issue-41652/auxiliary/issue-41652-b.rs -ui/issues/issue-41652/issue-41652.rs -ui/issues/issue-41677.rs -ui/issues/issue-41696.rs -ui/issues/issue-41726.rs -ui/issues/issue-41742.rs -ui/issues/issue-41744.rs -ui/issues/issue-41849-variance-req.rs -ui/issues/issue-41880.rs -ui/issues/issue-41888.rs -ui/issues/issue-41936-variance-coerce-unsized-cycle.rs -ui/issues/issue-41974.rs -ui/issues/issue-41998.rs -ui/issues/issue-42007.rs -ui/issues/issue-4208.rs -ui/issues/issue-42106.rs -ui/issues/issue-42148.rs -ui/issues/issue-42210.rs -ui/issues/issue-4228.rs -ui/issues/issue-42312.rs -ui/issues/issue-42453.rs -ui/issues/issue-42467.rs -ui/issues/issue-4252.rs -ui/issues/issue-42552.rs -ui/issues/issue-4265.rs -ui/issues/issue-42755.rs -ui/issues/issue-42796.rs -ui/issues/issue-42880.rs -ui/issues/issue-42956.rs -ui/issues/issue-43057.rs -ui/issues/issue-43205.rs -ui/issues/issue-43250.rs -ui/issues/issue-43291.rs -ui/issues/issue-4333.rs -ui/issues/issue-4335.rs -ui/issues/issue-43355.rs -ui/issues/issue-43357.rs -ui/issues/issue-43420-no-over-suggest.rs -ui/issues/issue-43424.rs -ui/issues/issue-43431.rs -ui/issues/issue-43483.rs -ui/issues/issue-43692.rs -ui/issues/issue-43806.rs -ui/issues/issue-43853.rs -ui/issues/issue-4387.rs -ui/issues/issue-43910.rs -ui/issues/issue-43923.rs -ui/issues/issue-43988.rs -ui/issues/issue-44023.rs -ui/issues/issue-44056.rs -ui/issues/issue-44078.rs -ui/issues/issue-44216-add-instant.rs -ui/issues/issue-44216-add-system-time.rs -ui/issues/issue-44216-sub-instant.rs -ui/issues/issue-44216-sub-system-time.rs -ui/issues/issue-44239.rs -ui/issues/issue-44247.rs -ui/issues/issue-44405.rs -ui/issues/issue-4464.rs -ui/issues/issue-44730.rs -ui/issues/issue-44851.rs -ui/issues/issue-4517.rs -ui/issues/issue-4541.rs -ui/issues/issue-4542.rs -ui/issues/issue-45425.rs -ui/issues/issue-4545.rs -ui/issues/issue-45510.rs -ui/issues/issue-45562.rs -ui/issues/issue-45697-1.rs -ui/issues/issue-45697.rs -ui/issues/issue-45730.rs -ui/issues/issue-45731.rs -ui/issues/issue-45801.rs -ui/issues/issue-45965.rs -ui/issues/issue-46069.rs -ui/issues/issue-46101.rs -ui/issues/issue-46302.rs -ui/issues/issue-46311.rs -ui/issues/issue-46332.rs -ui/issues/issue-46471-1.rs -ui/issues/issue-46472.rs -ui/issues/issue-46604.rs -ui/issues/issue-46756-consider-borrowing-cast-or-binexpr.rs -ui/issues/issue-46771.rs -ui/issues/issue-46855.rs -ui/issues/issue-46964.rs -ui/issues/issue-46983.rs -ui/issues/issue-47073-zero-padded-tuple-struct-indices.rs -ui/issues/issue-47094.rs -ui/issues/issue-47184.rs -ui/issues/issue-47309.rs -ui/issues/issue-4734.rs -ui/issues/issue-4735.rs -ui/issues/issue-4736.rs -ui/issues/issue-47364.rs -ui/issues/issue-47377.rs -ui/issues/issue-47380.rs -ui/issues/issue-47486.rs -ui/issues/issue-4759-1.rs -ui/issues/issue-4759.rs -ui/issues/issue-47638.rs -ui/issues/issue-47673.rs -ui/issues/issue-47703-1.rs -ui/issues/issue-47703-tuple.rs -ui/issues/issue-47703.rs -ui/issues/issue-47715.rs -ui/issues/issue-47722.rs -ui/issues/issue-48006.rs -ui/issues/issue-48131.rs -ui/issues/issue-48132.rs -ui/issues/issue-48159.rs -ui/issues/issue-48276.rs -ui/issues/issue-4830.rs -ui/issues/issue-48364.rs -ui/issues/issue-48728.rs -ui/issues/issue-4875.rs -ui/issues/issue-48984.rs -ui/issues/issue-49298.rs -ui/issues/issue-4935.rs -ui/issues/issue-49544.rs -ui/issues/issue-49632.rs -ui/issues/issue-4968.rs -ui/issues/issue-4972.rs -ui/issues/issue-49824.rs -ui/issues/issue-49854.rs -ui/issues/issue-49919.rs -ui/issues/issue-49934-errors.rs -ui/issues/issue-49934.rs -ui/issues/issue-49955.rs -ui/issues/issue-49973.rs -ui/issues/issue-50187.rs -ui/issues/issue-50411.rs -ui/issues/issue-50415.rs -ui/issues/issue-50442.rs -ui/issues/issue-50471.rs -ui/issues/issue-50518.rs -ui/issues/issue-50581.rs -ui/issues/issue-50582.rs -ui/issues/issue-50585.rs -ui/issues/issue-50600.rs -ui/issues/issue-50618.rs -ui/issues/issue-5062.rs -ui/issues/issue-5067.rs -ui/issues/issue-50688.rs -ui/issues/issue-50714.rs -ui/issues/issue-50761.rs -ui/issues/issue-50781.rs -ui/issues/issue-50802.rs -ui/issues/issue-50811.rs -ui/issues/issue-5100.rs -ui/issues/issue-51022.rs -ui/issues/issue-51044.rs -ui/issues/issue-51102.rs -ui/issues/issue-51116.rs -ui/issues/issue-51154.rs -ui/issues/issue-51515.rs -ui/issues/issue-51632-try-desugar-incompatible-types.rs -ui/issues/issue-51655.rs -ui/issues/issue-51714.rs -ui/issues/issue-51798.rs -ui/issues/issue-51874.rs -ui/issues/issue-51907.rs -ui/issues/issue-5192.rs -ui/issues/issue-51947.rs -ui/issues/issue-52049.rs -ui/issues/issue-52126-assign-op-invariance.rs -ui/issues/issue-52262.rs -ui/issues/issue-52489.rs -ui/issues/issue-52533.rs -ui/issues/issue-52717.rs -ui/issues/issue-5280.rs -ui/issues/issue-5315.rs -ui/issues/issue-5321-immediates-with-bare-self.rs -ui/issues/issue-53251.rs -ui/issues/issue-53275.rs -ui/issues/issue-53300.rs -ui/issues/issue-53333.rs -ui/issues/issue-53348.rs -ui/issues/issue-53419.rs -ui/issues/issue-53568.rs -ui/issues/issue-5358-1.rs -ui/issues/issue-53728.rs -ui/issues/issue-53843.rs -ui/issues/issue-54044.rs -ui/issues/issue-54062.rs -ui/issues/issue-54094.rs -ui/issues/issue-5439.rs -ui/issues/issue-54410.rs -ui/issues/issue-54462-mutable-noalias-correctness.rs -ui/issues/issue-54477-reduced-2.rs -ui/issues/issue-54696.rs -ui/issues/issue-5518.rs -ui/issues/issue-5521.rs -ui/issues/issue-55376.rs -ui/issues/issue-55380.rs -ui/issues/issue-5550.rs -ui/issues/issue-5554.rs -ui/issues/issue-55587.rs -ui/issues/issue-5572.rs -ui/issues/issue-55731.rs -ui/issues/issue-56128.rs -ui/issues/issue-56175.rs -ui/issues/issue-56199.rs -ui/issues/issue-56229.rs -ui/issues/issue-56237.rs -ui/issues/issue-5666.rs -ui/issues/issue-56806.rs -ui/issues/issue-56835.rs -ui/issues/issue-56870.rs -ui/issues/issue-5688.rs -ui/issues/issue-56943.rs -ui/issues/issue-5708.rs -ui/issues/issue-57156.rs -ui/issues/issue-57162.rs -ui/issues/issue-5718.rs -ui/issues/issue-57198-pass.rs -ui/issues/issue-57271.rs -ui/issues/issue-57399-self-return-impl-trait.rs -ui/issues/issue-5741.rs -ui/issues/issue-5754.rs -ui/issues/issue-57741-dereference-boxed-value/issue-57741-1.rs -ui/issues/issue-57741-dereference-boxed-value/issue-57741.rs -ui/issues/issue-57781.rs -ui/issues/issue-57924.rs -ui/issues/issue-58212.rs -ui/issues/issue-58375-monomorphize-default-impls.rs -ui/issues/issue-5844.rs -ui/issues/issue-58463.rs -ui/issues/issue-58712.rs -ui/issues/issue-58734.rs -ui/issues/issue-5883.rs -ui/issues/issue-5884.rs -ui/issues/issue-58857.rs -ui/issues/issue-5900.rs -ui/issues/issue-59020.rs -ui/issues/issue-5917.rs -ui/issues/issue-59326.rs -ui/issues/issue-59488.rs -ui/issues/issue-59494.rs -ui/issues/issue-5950.rs -ui/issues/issue-59756.rs -ui/issues/issue-5988.rs -ui/issues/issue-5997-outer-generic-parameter/issue-5997-enum.rs -ui/issues/issue-5997-outer-generic-parameter/issue-5997-struct.rs -ui/issues/issue-5997-outer-generic-parameter/issue-5997.rs -ui/issues/issue-60218.rs -ui/issues/issue-60622.rs -ui/issues/issue-60989.rs -ui/issues/issue-61106.rs -ui/issues/issue-61108.rs -ui/issues/issue-6117.rs -ui/issues/issue-6130.rs -ui/issues/issue-61475.rs -ui/issues/issue-6153.rs -ui/issues/issue-61623.rs -ui/issues/issue-61894.rs -ui/issues/issue-62480.rs -ui/issues/issue-6318.rs -ui/issues/issue-6344-let.rs -ui/issues/issue-6344-match.rs -ui/issues/issue-63983.rs -ui/issues/issue-64430.rs -ui/issues/issue-64559.rs -ui/issues/issue-64593.rs -ui/issues/issue-64792-bad-unicode-ctor.rs -ui/issues/issue-65131.rs -ui/issues/issue-65230.rs -ui/issues/issue-65462.rs -ui/issues/issue-6557.rs -ui/issues/issue-66308.rs -ui/issues/issue-66353.rs -ui/issues/issue-66667-function-cmp-cycle.rs -ui/issues/issue-66702-break-outside-loop-val.rs -ui/issues/issue-66706.rs -ui/issues/issue-66923-show-error-for-correct-call.rs -ui/issues/issue-67039-unsound-pin-partialeq.rs -ui/issues/issue-6738.rs -ui/issues/issue-67535.rs -ui/issues/issue-67552.rs -ui/issues/issue-68010-large-zst-consts.rs -ui/issues/issue-68696-catch-during-unwind.rs -ui/issues/issue-6892.rs -ui/issues/issue-68951.rs -ui/issues/issue-6898.rs -ui/issues/issue-69130.rs -ui/issues/issue-6919.rs -ui/issues/issue-69306.rs -ui/issues/issue-6936.rs -ui/issues/issue-69455.rs -ui/issues/issue-69602-type-err-during-codegen-ice.rs -ui/issues/issue-69683.rs -ui/issues/issue-7012.rs -ui/issues/issue-70381.rs -ui/issues/issue-7044.rs -ui/issues/issue-7061.rs -ui/issues/issue-70673.rs -ui/issues/issue-70724-add_type_neq_err_label-unwrap.rs -ui/issues/issue-70746.rs -ui/issues/issue-7092.rs -ui/issues/issue-71406.rs -ui/issues/issue-7178.rs -ui/issues/issue-72002.rs -ui/issues/issue-72076.rs -ui/issues/issue-72278.rs -ui/issues/issue-7246.rs -ui/issues/issue-7268.rs -ui/issues/issue-72839-error-overflow.rs -ui/issues/issue-72933-match-stack-overflow.rs -ui/issues/issue-73112.rs -ui/issues/issue-73229.rs -ui/issues/issue-7344.rs -ui/issues/issue-7364.rs -ui/issues/issue-74082.rs -ui/issues/issue-74564-if-expr-stack-overflow.rs -ui/issues/issue-7519-match-unit-in-arg.rs -ui/issues/issue-75283.rs -ui/issues/issue-7563.rs -ui/issues/issue-75704.rs -ui/issues/issue-7575.rs -ui/issues/issue-76042.rs -ui/issues/issue-76077-inaccesible-private-fields/issue-76077-1.rs -ui/issues/issue-76077-inaccesible-private-fields/issue-76077.rs -ui/issues/issue-76191.rs -ui/issues/issue-7660.rs -ui/issues/issue-7663.rs -ui/issues/issue-7673-cast-generically-implemented-trait.rs -ui/issues/issue-77218/issue-77218-2.rs -ui/issues/issue-77218/issue-77218.rs -ui/issues/issue-7784.rs -ui/issues/issue-77919.rs -ui/issues/issue-78192.rs -ui/issues/issue-78622.rs -ui/issues/issue-7867.rs -ui/issues/issue-78957.rs -ui/issues/issue-7899.rs -ui/issues/issue-7911.rs -ui/issues/issue-7970a.rs -ui/issues/issue-8044.rs -ui/issues/issue-80607.rs -ui/issues/issue-81584.rs -ui/issues/issue-8171-default-method-self-inherit-builtin-trait.rs -ui/issues/issue-81918.rs -ui/issues/issue-8248.rs -ui/issues/issue-8249.rs -ui/issues/issue-8259.rs -ui/issues/issue-83048.rs -ui/issues/issue-8391.rs -ui/issues/issue-8398.rs -ui/issues/issue-8401.rs -ui/issues/issue-8498.rs -ui/issues/issue-8506.rs -ui/issues/issue-8521.rs -ui/issues/issue-85461.rs -ui/issues/issue-8578.rs -ui/issues/issue-86756.rs -ui/issues/issue-87199.rs -ui/issues/issue-8727.rs -ui/issues/issue-87490.rs -ui/issues/issue-8761.rs -ui/issues/issue-8767.rs -ui/issues/issue-87707.rs -ui/issues/issue-8783.rs -ui/issues/issue-88150.rs -ui/issues/issue-8860.rs -ui/issues/issue-8898.rs -ui/issues/issue-9047.rs -ui/issues/issue-9110.rs -ui/issues/issue-9123.rs -ui/issues/issue-9129.rs -ui/issues/issue-91489.rs -ui/issues/issue-9155.rs -ui/issues/issue-9188.rs -ui/issues/issue-9243.rs -ui/issues/issue-9249.rs -ui/issues/issue-9259.rs -ui/issues/issue-92741.rs -ui/issues/issue-9446.rs -ui/issues/issue-9725.rs -ui/issues/issue-9737.rs -ui/issues/issue-9814.rs -ui/issues/issue-98299.rs -ui/issues/issue-9837.rs -ui/issues/issue-9906.rs -ui/issues/issue-9918.rs -ui/issues/issue-9942.rs -ui/issues/issue-9951.rs -ui/issues/issue-9968.rs -ui/issues/issue-99838.rs ui/iterators/issue-28098.rs ui/iterators/issue-58952-filter-type-length.rs ui/lang-items/issue-83471.rs diff --git a/src/tools/tidy/src/ui_tests.rs b/src/tools/tidy/src/ui_tests.rs index b9d22ece59752..4d195b3952e27 100644 --- a/src/tools/tidy/src/ui_tests.rs +++ b/src/tools/tidy/src/ui_tests.rs @@ -1,24 +1,12 @@ //! Tidy check to ensure below in UI test directories: -//! - the number of entries in each directory must be less than `ENTRY_LIMIT` //! - there are no stray `.stderr` files -use std::collections::{BTreeSet, HashMap}; +use std::collections::BTreeSet; use std::ffi::OsStr; use std::fs; use std::io::Write; use std::path::{Path, PathBuf}; -use ignore::Walk; - -// FIXME: GitHub's UI truncates file lists that exceed 1000 entries, so these -// should all be 1000 or lower. Limits significantly smaller than 1000 are also -// desirable, because large numbers of files are unwieldy in general. See issue -// #73494. -const ENTRY_LIMIT: u32 = 901; -// FIXME: The following limits should be reduced eventually. - -const ISSUES_ENTRY_LIMIT: u32 = 1616; - const EXPECTED_TEST_FILE_EXTENSIONS: &[&str] = &[ "rs", // test source files "stderr", // expected stderr file, corresponds to a rs file @@ -54,42 +42,6 @@ const EXTENSION_EXCEPTION_PATHS: &[&str] = &[ "tests/ui/std/windows-bat-args3.bat", // tests escaping arguments through batch files ]; -fn check_entries(tests_path: &Path, bad: &mut bool) { - let mut directories: HashMap = HashMap::new(); - - for entry in Walk::new(tests_path.join("ui")).flatten() { - let parent = entry.path().parent().unwrap().to_path_buf(); - *directories.entry(parent).or_default() += 1; - } - - let (mut max, mut max_issues) = (0, 0); - for (dir_path, count) in directories { - let is_issues_dir = tests_path.join("ui/issues") == dir_path; - let (limit, maxcnt) = if is_issues_dir { - (ISSUES_ENTRY_LIMIT, &mut max_issues) - } else { - (ENTRY_LIMIT, &mut max) - }; - *maxcnt = (*maxcnt).max(count); - if count > limit { - tidy_error!( - bad, - "following path contains more than {} entries, \ - you should move the test to some relevant subdirectory (current: {}): {}", - limit, - count, - dir_path.display() - ); - } - } - if ISSUES_ENTRY_LIMIT > max_issues { - tidy_error!( - bad, - "`ISSUES_ENTRY_LIMIT` is too high (is {ISSUES_ENTRY_LIMIT}, should be {max_issues})" - ); - } -} - pub fn check(root_path: &Path, bless: bool, bad: &mut bool) { let issues_txt_header = r#"============================================================ ⚠️⚠️⚠️NOTHING SHOULD EVER BE ADDED TO THIS LIST⚠️⚠️⚠️ @@ -97,7 +49,6 @@ pub fn check(root_path: &Path, bless: bool, bad: &mut bool) { "#; let path = &root_path.join("tests"); - check_entries(path, bad); // the list of files in ui tests that are allowed to start with `issue-XXXX` // BTreeSet because we would like a stable ordering so --bless works @@ -179,7 +130,9 @@ pub fn check(root_path: &Path, bless: bool, bad: &mut bool) { .unwrap() .replace(std::path::MAIN_SEPARATOR_STR, "/"); - if !remaining_issue_names.remove(stripped_path.as_str()) { + if !remaining_issue_names.remove(stripped_path.as_str()) + && !stripped_path.starts_with("ui/issues/") + { tidy_error!( bad, "file `tests/{stripped_path}` must begin with a descriptive name, consider `{{reason}}-issue-{issue_n}.rs`", diff --git a/triagebot.toml b/triagebot.toml index 61d8a814c89ee..4aec1251c7e7c 100644 --- a/triagebot.toml +++ b/triagebot.toml @@ -1147,6 +1147,12 @@ cc = ["@nnethercote"] message = "Changes to the size of AST and/or HIR nodes." cc = ["@nnethercote"] +[mentions."tests/ui/issues"] +message = """ +This PR modifies `tests/ui/issues/`. If this PR is adding new tests to `tests/ui/issues/`, +please refrain from doing so, and instead add it to more descriptive subdirectories. +""" + [mentions."compiler/rustc_sanitizers"] cc = ["@rcvalle"] From 58537fb869a8e08d5146e8feab982f17b3fd990a Mon Sep 17 00:00:00 2001 From: roblabla Date: Mon, 21 Jul 2025 01:32:26 +0200 Subject: [PATCH 06/16] Fix broken TLS destructors on 32-bit win7 On the 32-bit win7 target, we use OS TLS instead of native TLS, due to issues with how the OS handles alignment. Unfortunately, this caused issues due to the TLS destructors not running, causing memory leaks among other problems. On Windows, to support OS TLS, the TlsAlloc family of function is used by Rust. This function does not support TLS destructors at all. However, rust has some code to emulate those destructors, by leveraging the TLS support functionality found in the MSVC CRT (specifically, in tlssup.c of the CRT). Specifically, the CRT provides the ability to register callbacks that are called (among other things) on thread destruction. By registering our own callback, we can run through a list of registered destructors functions to execute. To use this functionality, the user must do two things: 1. They must put the address to their callback in a section between `.CRT$XLB` and `.CRT$XLY`. 2. They must add a reference to `_tls_used` (or `__tls_used` on x86) to make sure the TLS support code in tlssup.c isn't garbage collected by the linker. Prior to this commit, this second bit wasn't being done properly by the Rust TLS support code. Instead of adding a reference to _tls_used, it instead had a reference to its own callback to prevent it from getting GC'd by the linker. While this is _also_ necessary, not having a reference on _tls_used made the entire support non-functional. This commit reworks the code to: 1. Add an unconditional `#[used]` attribute on the CALLBACK, which should be enough to prevent it from getting GC'd by the linker. 2. Add a reference to `_tls_used`, which should pull the TLS support code into the Rust programs and not let it be GC'd by the linker. --- .../std/src/sys/thread_local/guard/windows.rs | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/library/std/src/sys/thread_local/guard/windows.rs b/library/std/src/sys/thread_local/guard/windows.rs index b15a0d7c0bdfb..f747129465d6d 100644 --- a/library/std/src/sys/thread_local/guard/windows.rs +++ b/library/std/src/sys/thread_local/guard/windows.rs @@ -58,7 +58,7 @@ //! We don't actually use the `/INCLUDE` linker flag here like the article //! mentions because the Rust compiler doesn't propagate linker flags, but //! instead we use a shim function which performs a volatile 1-byte load from -//! the address of the symbol to ensure it sticks around. +//! the address of the _tls_used symbol to ensure it sticks around. //! //! [1]: https://www.codeproject.com/Articles/8113/Thread-Local-Storage-The-C-Way //! [2]: https://github.com/ChromiumWebApps/chromium/blob/master/base/threading/thread_local_storage_win.cc#L42 @@ -68,9 +68,20 @@ use core::ffi::c_void; use crate::ptr; use crate::sys::c; +unsafe extern "C" { + #[link_name = "_tls_used"] + static TLS_USED: u8; +} pub fn enable() { - // When destructors are used, we don't want LLVM eliminating CALLBACK for any - // reason. Once the symbol makes it to the linker, it will do the rest. + // When destructors are used, we need to add a reference to the _tls_used + // symbol provided by the CRT, otherwise the TLS support code will get + // GC'd by the linker and our callback won't be called. + unsafe { ptr::from_ref(&TLS_USED).read_volatile() }; + // We also need to reference CALLBACK to make sure it does not get GC'd + // by the compiler/LLVM. The callback will end up inside the TLS + // callback array pointed to by _TLS_USED through linker shenanigans, + // but as far as the compiler is concerned, it looks like the data is + // unused, so we need this hack to prevent it from disappearing. unsafe { ptr::from_ref(&CALLBACK).read_volatile() }; } From b2f8b406335310f885a0d2d21ff8472b6a5f9ce5 Mon Sep 17 00:00:00 2001 From: Oli Scherer Date: Mon, 21 Jul 2025 13:16:10 +0000 Subject: [PATCH 07/16] Don't ICE on non-TypeId metadata within TypeId --- .../rustc_const_eval/src/interpret/memory.rs | 2 +- tests/ui/consts/const_transmute_type_id6.rs | 16 ++++++++++++++++ tests/ui/consts/const_transmute_type_id6.stderr | 15 +++++++++++++++ 3 files changed, 32 insertions(+), 1 deletion(-) create mode 100644 tests/ui/consts/const_transmute_type_id6.rs create mode 100644 tests/ui/consts/const_transmute_type_id6.stderr diff --git a/compiler/rustc_const_eval/src/interpret/memory.rs b/compiler/rustc_const_eval/src/interpret/memory.rs index 20c8e983ceaef..20825d2ad9b5e 100644 --- a/compiler/rustc_const_eval/src/interpret/memory.rs +++ b/compiler/rustc_const_eval/src/interpret/memory.rs @@ -997,7 +997,7 @@ impl<'tcx, M: Machine<'tcx>> InterpCx<'tcx, M> { ptr: Pointer>, ) -> InterpResult<'tcx, (Ty<'tcx>, u64)> { let (alloc_id, offset, _meta) = self.ptr_get_alloc_id(ptr, 0)?; - let GlobalAlloc::TypeId { ty } = self.tcx.global_alloc(alloc_id) else { + let Some(GlobalAlloc::TypeId { ty }) = self.tcx.try_get_global_alloc(alloc_id) else { throw_ub_format!("invalid `TypeId` value: not all bytes carry type id metadata") }; interp_ok((ty, offset.bytes())) diff --git a/tests/ui/consts/const_transmute_type_id6.rs b/tests/ui/consts/const_transmute_type_id6.rs new file mode 100644 index 0000000000000..668eb0bb2b0fd --- /dev/null +++ b/tests/ui/consts/const_transmute_type_id6.rs @@ -0,0 +1,16 @@ +//! Test that we do not ICE and that we do report an error +//! when placing non-TypeId provenance into a TypeId. + +#![feature(const_trait_impl, const_cmp)] + +use std::any::TypeId; +use std::mem::transmute; + +const X: bool = { + let a = (); + let id: TypeId = unsafe { transmute([&raw const a; 16 / size_of::<*const ()>()]) }; + id == id + //~^ ERROR: invalid `TypeId` value: not all bytes carry type id metadata +}; + +fn main() {} diff --git a/tests/ui/consts/const_transmute_type_id6.stderr b/tests/ui/consts/const_transmute_type_id6.stderr new file mode 100644 index 0000000000000..f5d90256e7c6a --- /dev/null +++ b/tests/ui/consts/const_transmute_type_id6.stderr @@ -0,0 +1,15 @@ +error[E0080]: invalid `TypeId` value: not all bytes carry type id metadata + --> $DIR/const_transmute_type_id6.rs:12:5 + | +LL | id == id + | ^^^^^^^^ evaluation of `X` failed inside this call + | +note: inside `::eq` + --> $SRC_DIR/core/src/any.rs:LL:COL +note: inside `::eq::compiletime` + --> $SRC_DIR/core/src/any.rs:LL:COL + = note: this error originates in the macro `$crate::intrinsics::const_eval_select` which comes from the expansion of the macro `crate::intrinsics::const_eval_select` (in Nightly builds, run with -Z macro-backtrace for more info) + +error: aborting due to 1 previous error + +For more information about this error, try `rustc --explain E0080`. From 55b5612b326c724d137ba1b7f138933d87eb57f2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Joel=20Wejdenst=C3=A5l?= Date: Mon, 21 Jul 2025 17:51:23 +0200 Subject: [PATCH 08/16] don't end lifetimes after call --- compiler/rustc_codegen_ssa/src/mir/block.rs | 4 ---- 1 file changed, 4 deletions(-) diff --git a/compiler/rustc_codegen_ssa/src/mir/block.rs b/compiler/rustc_codegen_ssa/src/mir/block.rs index e97a4e98a257a..42ff6fff90001 100644 --- a/compiler/rustc_codegen_ssa/src/mir/block.rs +++ b/compiler/rustc_codegen_ssa/src/mir/block.rs @@ -224,10 +224,6 @@ impl<'a, 'tcx> TerminatorCodegenHelper<'tcx> { if tail { bx.tail_call(fn_ty, fn_attrs, fn_abi, fn_ptr, llargs, self.funclet(fx), instance); - for &(tmp, size) in lifetime_ends_after_call { - bx.lifetime_end(tmp, size); - } - return MergingSucc::False; } From 2cd84dc29c99795bb25e9daf1587378ef2d7fe23 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Joel=20Wejdenst=C3=A5l?= Date: Mon, 21 Jul 2025 17:54:57 +0200 Subject: [PATCH 09/16] recursion-no-tce.rs should be run-crash --- tests/ui/explicit-tail-calls/recursion-no-tce.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/ui/explicit-tail-calls/recursion-no-tce.rs b/tests/ui/explicit-tail-calls/recursion-no-tce.rs index ada1a69509fa9..c1f297804d3ad 100644 --- a/tests/ui/explicit-tail-calls/recursion-no-tce.rs +++ b/tests/ui/explicit-tail-calls/recursion-no-tce.rs @@ -1,4 +1,4 @@ -//@ run-fail +//@ run-crash use std::hint::black_box; From d424207be03627a946dc74ef2fb2c08e2d0dc19b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Joel=20Wejdenst=C3=A5l?= Date: Mon, 21 Jul 2025 18:26:39 +0200 Subject: [PATCH 10/16] fix typo in codegen test --- tests/codegen/become-musttail.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/codegen/become-musttail.rs b/tests/codegen/become-musttail.rs index 779ee3efc21ce..07f3357191042 100644 --- a/tests/codegen/become-musttail.rs +++ b/tests/codegen/become-musttail.rs @@ -9,7 +9,7 @@ #[inline(never)] pub fn fibonacci(n: u64, a: u64, b: u64) -> u64 { // CHECK: musttail call {{.*}}@fibonacci( - // CHECK-NEXT: ret u64 + // CHECK-NEXT: ret i64 match n { 0 => a, 1 => b, From dad96b107c0dd35ce2eecfaecc0e6af4988b3bb4 Mon Sep 17 00:00:00 2001 From: Noratrieb <48135649+Noratrieb@users.noreply.github.com> Date: Sun, 20 Jul 2025 14:35:43 +0200 Subject: [PATCH 11/16] Use serde for target spec json deserialize The previous manual parsing of `serde_json::Value` was a lot of complicated code and extremely error-prone. It was full of janky behavior like sometimes ignoring type errors, sometimes erroring for type errors, sometimes warning for type errors, and sometimes just ICEing for type errors (the icing on the top). Additionally, many of the error messages about allowed values were out of date because they were in a completely different place than the FromStr impls. Overall, the system caused confusion for users. I also found the old deserialization code annoying to read. Whenever a `key!` invocation was found, one had to first look for the right macro arm, and no go to definition could help. This PR replaces all this manual parsing with a 2-step process involving serde. First, the string is parsed into a `TargetSpecJson` struct. This struct is a 1:1 representation of the spec JSON. It already parses all the enums and is very simple to read and write. Then, the fields from this struct are copied into the actual `Target`. The reason for this two-step process instead of just serializing into a `Target` is because of a few reasons 1. There are a few transformations performed between the two formats 2. The default logic is implemented this way. Otherwise all the default field values would have to be spelled out again, which is suboptimal. With this logic, they fall out naturally, because everything in the json struct is an `Option`. Overall, the mapping is pretty simple, with the vast majority of fields just doing a 1:1 mapping that is captured by two macros. I have deliberately avoided making the macros generic to keep them simple. All the `FromStr` impls now have the error message right inside them, which increases the chance of it being up to date. Some "`from_str`" impls were turned into proper `FromStr` impls to support this. The new code is much less involved, delegating all the JSON parsing logic to serde, without any manual type matching. This change introduces a few breaking changes for consumers. While it is possible to use this format on stable, it is very much subject to change, so breaking changes are expected. The hope is also that because of the way stricter behavior, breaking changes are easier to deal with, as they come with clearer error messages. 1. Invalid types now always error, everywhere. Previously, they would sometimes error, and sometimes just be ignored (which meant the users JSON was still broken, just silently!) 2. This now makes use of `deny_unknown_fields` instead of just warning on unused fields, which was done previously. Serde doesn't make it easy to get such warning behavior, which was the primary reason that this now changed. But I think error behavior is very reasonable too. If someone has random stale fields in their JSON, it is likely because these fields did something at some point but no longer do, and the user likely wants to be informed of this so they can figure out what to do. This is also relevant for the future. If we remove a field but someone has it set, it probably makes sense for them to take a look whether they need this and should look for alternatives, or whether they can just delete it. Overall, the JSON is made more explicit. This is the only expected breakage, but there could also be small breakage from small mistakes. All targets roundtrip though, so it can't be anything too major. --- Cargo.lock | 13 + compiler/rustc_session/src/config.rs | 4 +- compiler/rustc_session/src/options.rs | 2 +- compiler/rustc_target/Cargo.toml | 3 + compiler/rustc_target/src/json.rs | 15 + compiler/rustc_target/src/spec/json.rs | 1025 ++++++----------- compiler/rustc_target/src/spec/mod.rs | 388 ++++--- compiler/rustc_target/src/tests.rs | 50 +- src/librustdoc/doctest.rs | 2 +- src/tools/tidy/src/deps.rs | 1 + .../rustdoc-target-spec-json-path/target.json | 1 - .../target-specs/endianness-mismatch.json | 1 - .../target-specs/my-awesome-platform.json | 4 +- .../target-specs/my-incomplete-platform.json | 4 +- .../my-x86_64-unknown-linux-gnu-platform.json | 4 +- .../target-specs/require-explicit-cpu.json | 1 - tests/run-make/target-specs/rmake.rs | 4 +- tests/ui/check-cfg/my-awesome-platform.json | 1 - tests/ui/codegen/mismatched-data-layout.json | 1 - tests/ui/codegen/mismatched-data-layouts.rs | 1 + .../ui/codegen/mismatched-data-layouts.stderr | 2 +- 21 files changed, 678 insertions(+), 849 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 7d2fca8bb3f48..1537a60718623 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -4499,7 +4499,10 @@ dependencies = [ "rustc_macros", "rustc_serialize", "rustc_span", + "serde", + "serde_derive", "serde_json", + "serde_path_to_error", "tracing", ] @@ -4870,6 +4873,16 @@ dependencies = [ "serde", ] +[[package]] +name = "serde_path_to_error" +version = "0.1.17" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "59fab13f937fa393d08645bf3a84bdfe86e296747b506ada67bb15f10f218b2a" +dependencies = [ + "itoa", + "serde", +] + [[package]] name = "serde_spanned" version = "0.6.9" diff --git a/compiler/rustc_session/src/config.rs b/compiler/rustc_session/src/config.rs index d6215e1de043a..190cb6c5e0388 100644 --- a/compiler/rustc_session/src/config.rs +++ b/compiler/rustc_session/src/config.rs @@ -336,12 +336,12 @@ impl LinkSelfContained { if let Some(component_to_enable) = component.strip_prefix('+') { self.explicitly_set = None; self.enabled_components - .insert(LinkSelfContainedComponents::from_str(component_to_enable)?); + .insert(LinkSelfContainedComponents::from_str(component_to_enable).ok()?); Some(()) } else if let Some(component_to_disable) = component.strip_prefix('-') { self.explicitly_set = None; self.disabled_components - .insert(LinkSelfContainedComponents::from_str(component_to_disable)?); + .insert(LinkSelfContainedComponents::from_str(component_to_disable).ok()?); Some(()) } else { None diff --git a/compiler/rustc_session/src/options.rs b/compiler/rustc_session/src/options.rs index 2bdde2f887a30..313eec6268d3c 100644 --- a/compiler/rustc_session/src/options.rs +++ b/compiler/rustc_session/src/options.rs @@ -1295,7 +1295,7 @@ pub mod parse { } pub(crate) fn parse_linker_flavor(slot: &mut Option, v: Option<&str>) -> bool { - match v.and_then(LinkerFlavorCli::from_str) { + match v.and_then(|v| LinkerFlavorCli::from_str(v).ok()) { Some(lf) => *slot = Some(lf), _ => return false, } diff --git a/compiler/rustc_target/Cargo.toml b/compiler/rustc_target/Cargo.toml index 0121c752dbdde..56932c24922e5 100644 --- a/compiler/rustc_target/Cargo.toml +++ b/compiler/rustc_target/Cargo.toml @@ -12,7 +12,10 @@ rustc_fs_util = { path = "../rustc_fs_util" } rustc_macros = { path = "../rustc_macros" } rustc_serialize = { path = "../rustc_serialize" } rustc_span = { path = "../rustc_span" } +serde = "1.0.219" +serde_derive = "1.0.219" serde_json = "1.0.59" +serde_path_to_error = "0.1.17" tracing = "0.1" # tidy-alphabetical-end diff --git a/compiler/rustc_target/src/json.rs b/compiler/rustc_target/src/json.rs index 4fcc477921ba2..896609bdbe3a7 100644 --- a/compiler/rustc_target/src/json.rs +++ b/compiler/rustc_target/src/json.rs @@ -114,3 +114,18 @@ impl ToJson for rustc_abi::CanonAbi { self.to_string().to_json() } } + +macro_rules! serde_deserialize_from_str { + ($ty:ty) => { + impl<'de> serde::Deserialize<'de> for $ty { + fn deserialize(deserializer: D) -> Result + where + D: serde::Deserializer<'de>, + { + let s = String::deserialize(deserializer)?; + FromStr::from_str(&s).map_err(serde::de::Error::custom) + } + } + }; +} +pub(crate) use serde_deserialize_from_str; diff --git a/compiler/rustc_target/src/spec/json.rs b/compiler/rustc_target/src/spec/json.rs index 6c716f8712530..d27c1929aef74 100644 --- a/compiler/rustc_target/src/spec/json.rs +++ b/compiler/rustc_target/src/spec/json.rs @@ -1,60 +1,47 @@ -use std::borrow::Cow; use std::collections::BTreeMap; use std::str::FromStr; -use rustc_abi::{Align, AlignFromBytesError, ExternAbi}; -use serde_json::Value; +use rustc_abi::{Align, AlignFromBytesError}; -use super::{Target, TargetKind, TargetOptions, TargetWarnings}; +use super::crt_objects::CrtObjects; +use super::{ + BinaryFormat, CodeModel, DebuginfoKind, FloatAbi, FramePointer, LinkArgsCli, + LinkSelfContainedComponents, LinkSelfContainedDefault, LinkerFlavorCli, LldFlavor, + MergeFunctions, PanicStrategy, RelocModel, RelroLevel, RustcAbi, SanitizerSet, + SmallDataThresholdSupport, SplitDebuginfo, StackProbeType, StaticCow, SymbolVisibility, Target, + TargetKind, TargetOptions, TargetWarnings, TlsModel, +}; use crate::json::{Json, ToJson}; use crate::spec::AbiMap; impl Target { /// Loads a target descriptor from a JSON object. - pub fn from_json(obj: Json) -> Result<(Target, TargetWarnings), String> { - // While ugly, this code must remain this way to retain - // compatibility with existing JSON fields and the internal - // expected naming of the Target and TargetOptions structs. - // To ensure compatibility is retained, the built-in targets - // are round-tripped through this code to catch cases where - // the JSON parser is not updated to match the structs. - - let mut obj = match obj { - Value::Object(obj) => obj, - _ => return Err("Expected JSON object for target")?, - }; + pub fn from_json(json: &str) -> Result<(Target, TargetWarnings), String> { + let json_deserializer = &mut serde_json::Deserializer::from_str(json); - let mut get_req_field = |name: &str| { - obj.remove(name) - .and_then(|j| j.as_str().map(str::to_string)) - .ok_or_else(|| format!("Field {name} in target specification is required")) - }; + let json: TargetSpecJson = + serde_path_to_error::deserialize(json_deserializer).map_err(|err| err.to_string())?; let mut base = Target { - llvm_target: get_req_field("llvm-target")?.into(), + llvm_target: json.llvm_target, metadata: Default::default(), - pointer_width: get_req_field("target-pointer-width")? - .parse::() - .map_err(|_| "target-pointer-width must be an integer".to_string())?, - data_layout: get_req_field("data-layout")?.into(), - arch: get_req_field("arch")?.into(), + pointer_width: json + .target_pointer_width + .parse() + .map_err(|err| format!("invalid target-pointer-width: {err}"))?, + data_layout: json.data_layout, + arch: json.arch, options: Default::default(), }; // FIXME: This doesn't properly validate anything and just ignores the data if it's invalid. // That's okay for now, the only use of this is when generating docs, which we don't do for // custom targets. - if let Some(Json::Object(mut metadata)) = obj.remove("metadata") { - base.metadata.description = metadata - .remove("description") - .and_then(|desc| desc.as_str().map(|desc| desc.to_owned().into())); - base.metadata.tier = metadata - .remove("tier") - .and_then(|tier| tier.as_u64()) - .filter(|tier| (1..=3).contains(tier)); - base.metadata.host_tools = - metadata.remove("host_tools").and_then(|host| host.as_bool()); - base.metadata.std = metadata.remove("std").and_then(|host| host.as_bool()); + if let Some(metadata) = json.metadata { + base.metadata.description = metadata.description; + base.metadata.tier = metadata.tier.filter(|tier| (1..=3).contains(tier)); + base.metadata.host_tools = metadata.host_tools; + base.metadata.std = metadata.std; } let alignment_error = |field_name: &str, error: AlignFromBytesError| -> String { @@ -65,640 +52,188 @@ impl Target { format!("`{}` bits is not a valid value for {field_name}: {msg}", error.align() * 8) }; - let mut incorrect_type = vec![]; - - macro_rules! key { - ($key_name:ident) => ( { - let name = (stringify!($key_name)).replace("_", "-"); - if let Some(s) = obj.remove(&name).and_then(|s| s.as_str().map(str::to_string).map(Cow::from)) { - base.$key_name = s; - } - } ); - ($key_name:ident = $json_name:expr) => ( { - let name = $json_name; - if let Some(s) = obj.remove(name).and_then(|s| s.as_str().map(str::to_string).map(Cow::from)) { - base.$key_name = s; - } - } ); - ($key_name:ident = $json_name:expr, u64 as $int_ty:ty) => ( { - let name = $json_name; - if let Some(s) = obj.remove(name).and_then(|b| b.as_u64()) { - base.$key_name = s as $int_ty; - } - } ); - ($key_name:ident, bool) => ( { - let name = (stringify!($key_name)).replace("_", "-"); - if let Some(s) = obj.remove(&name).and_then(|b| b.as_bool()) { - base.$key_name = s; - } - } ); - ($key_name:ident = $json_name:expr, bool) => ( { - let name = $json_name; - if let Some(s) = obj.remove(name).and_then(|b| b.as_bool()) { - base.$key_name = s; - } - } ); - ($key_name:ident, u32) => ( { - let name = (stringify!($key_name)).replace("_", "-"); - if let Some(s) = obj.remove(&name).and_then(|b| b.as_u64()) { - if s < 1 || s > 5 { - return Err("Not a valid DWARF version number".into()); - } - base.$key_name = s as u32; - } - } ); - ($key_name:ident, Option) => ( { - let name = (stringify!($key_name)).replace("_", "-"); - if let Some(s) = obj.remove(&name).and_then(|b| b.as_bool()) { - base.$key_name = Some(s); - } - } ); - ($key_name:ident, Option) => ( { - let name = (stringify!($key_name)).replace("_", "-"); - if let Some(s) = obj.remove(&name).and_then(|b| b.as_u64()) { - base.$key_name = Some(s); - } - } ); - ($key_name:ident, Option>) => ( { - let name = (stringify!($key_name)).replace("_", "-"); - if let Some(s) = obj.remove(&name).and_then(|b| Some(b.as_str()?.to_string())) { - base.$key_name = Some(s.into()); - } - } ); - ($key_name:ident, Option) => ( { - let name = (stringify!($key_name)).replace("_", "-"); - if let Some(b) = obj.remove(&name).and_then(|b| b.as_u64()) { - match Align::from_bits(b) { - Ok(align) => base.$key_name = Some(align), - Err(e) => return Err(alignment_error(&name, e)), - } - } - } ); - ($key_name:ident, BinaryFormat) => ( { - let name = (stringify!($key_name)).replace("_", "-"); - obj.remove(&name).and_then(|f| f.as_str().and_then(|s| { - match s.parse::() { - Ok(binary_format) => base.$key_name = binary_format, - _ => return Some(Err(format!( - "'{s}' is not a valid value for binary_format. \ - Use 'coff', 'elf', 'mach-o', 'wasm' or 'xcoff' " - ))), - } - Some(Ok(())) - })).unwrap_or(Ok(())) - } ); - ($key_name:ident, MergeFunctions) => ( { - let name = (stringify!($key_name)).replace("_", "-"); - obj.remove(&name).and_then(|o| o.as_str().and_then(|s| { - match s.parse::() { - Ok(mergefunc) => base.$key_name = mergefunc, - _ => return Some(Err(format!("'{}' is not a valid value for \ - merge-functions. Use 'disabled', \ - 'trampolines', or 'aliases'.", - s))), - } - Some(Ok(())) - })).unwrap_or(Ok(())) - } ); - ($key_name:ident, FloatAbi) => ( { - let name = (stringify!($key_name)).replace("_", "-"); - obj.remove(&name).and_then(|o| o.as_str().and_then(|s| { - match s.parse::() { - Ok(float_abi) => base.$key_name = Some(float_abi), - _ => return Some(Err(format!("'{}' is not a valid value for \ - llvm-floatabi. Use 'soft' or 'hard'.", - s))), - } - Some(Ok(())) - })).unwrap_or(Ok(())) - } ); - ($key_name:ident, RustcAbi) => ( { - let name = (stringify!($key_name)).replace("_", "-"); - obj.remove(&name).and_then(|o| o.as_str().and_then(|s| { - match s.parse::() { - Ok(rustc_abi) => base.$key_name = Some(rustc_abi), - _ => return Some(Err(format!( - "'{s}' is not a valid value for rustc-abi. \ - Use 'x86-softfloat' or leave the field unset." - ))), - } - Some(Ok(())) - })).unwrap_or(Ok(())) - } ); - ($key_name:ident, RelocModel) => ( { - let name = (stringify!($key_name)).replace("_", "-"); - obj.remove(&name).and_then(|o| o.as_str().and_then(|s| { - match s.parse::() { - Ok(relocation_model) => base.$key_name = relocation_model, - _ => return Some(Err(format!("'{}' is not a valid relocation model. \ - Run `rustc --print relocation-models` to \ - see the list of supported values.", s))), - } - Some(Ok(())) - })).unwrap_or(Ok(())) - } ); - ($key_name:ident, CodeModel) => ( { - let name = (stringify!($key_name)).replace("_", "-"); - obj.remove(&name).and_then(|o| o.as_str().and_then(|s| { - match s.parse::() { - Ok(code_model) => base.$key_name = Some(code_model), - _ => return Some(Err(format!("'{}' is not a valid code model. \ - Run `rustc --print code-models` to \ - see the list of supported values.", s))), - } - Some(Ok(())) - })).unwrap_or(Ok(())) - } ); - ($key_name:ident, TlsModel) => ( { - let name = (stringify!($key_name)).replace("_", "-"); - obj.remove(&name).and_then(|o| o.as_str().and_then(|s| { - match s.parse::() { - Ok(tls_model) => base.$key_name = tls_model, - _ => return Some(Err(format!("'{}' is not a valid TLS model. \ - Run `rustc --print tls-models` to \ - see the list of supported values.", s))), - } - Some(Ok(())) - })).unwrap_or(Ok(())) - } ); - ($key_name:ident, SmallDataThresholdSupport) => ( { - obj.remove("small-data-threshold-support").and_then(|o| o.as_str().and_then(|s| { - match s.parse::() { - Ok(support) => base.small_data_threshold_support = support, - _ => return Some(Err(format!("'{s}' is not a valid value for small-data-threshold-support."))), - } - Some(Ok(())) - })).unwrap_or(Ok(())) - } ); - ($key_name:ident, PanicStrategy) => ( { - let name = (stringify!($key_name)).replace("_", "-"); - obj.remove(&name).and_then(|o| o.as_str().and_then(|s| { - match s { - "unwind" => base.$key_name = super::PanicStrategy::Unwind, - "abort" => base.$key_name = super::PanicStrategy::Abort, - _ => return Some(Err(format!("'{}' is not a valid value for \ - panic-strategy. Use 'unwind' or 'abort'.", - s))), - } - Some(Ok(())) - })).unwrap_or(Ok(())) - } ); - ($key_name:ident, RelroLevel) => ( { - let name = (stringify!($key_name)).replace("_", "-"); - obj.remove(&name).and_then(|o| o.as_str().and_then(|s| { - match s.parse::() { - Ok(level) => base.$key_name = level, - _ => return Some(Err(format!("'{}' is not a valid value for \ - relro-level. Use 'full', 'partial, or 'off'.", - s))), - } - Some(Ok(())) - })).unwrap_or(Ok(())) - } ); - ($key_name:ident, Option) => ( { - let name = (stringify!($key_name)).replace("_", "-"); - obj.remove(&name).and_then(|o| o.as_str().and_then(|s| { - match s.parse::() { - Ok(level) => base.$key_name = Some(level), - _ => return Some(Err(format!("'{}' is not a valid value for \ - symbol-visibility. Use 'hidden', 'protected, or 'interposable'.", - s))), - } - Some(Ok(())) - })).unwrap_or(Ok(())) - } ); - ($key_name:ident, DebuginfoKind) => ( { - let name = (stringify!($key_name)).replace("_", "-"); - obj.remove(&name).and_then(|o| o.as_str().and_then(|s| { - match s.parse::() { - Ok(level) => base.$key_name = level, - _ => return Some(Err( - format!("'{s}' is not a valid value for debuginfo-kind. Use 'dwarf', \ - 'dwarf-dsym' or 'pdb'.") - )), - } - Some(Ok(())) - })).unwrap_or(Ok(())) - } ); - ($key_name:ident, SplitDebuginfo) => ( { - let name = (stringify!($key_name)).replace("_", "-"); - obj.remove(&name).and_then(|o| o.as_str().and_then(|s| { - match s.parse::() { - Ok(level) => base.$key_name = level, - _ => return Some(Err(format!("'{}' is not a valid value for \ - split-debuginfo. Use 'off' or 'dsymutil'.", - s))), - } - Some(Ok(())) - })).unwrap_or(Ok(())) - } ); - ($key_name:ident, list) => ( { - let name = (stringify!($key_name)).replace("_", "-"); - if let Some(j) = obj.remove(&name) { - if let Some(v) = j.as_array() { - base.$key_name = v.iter() - .map(|a| a.as_str().unwrap().to_string().into()) - .collect(); - } else { - incorrect_type.push(name) - } - } - } ); - ($key_name:ident, opt_list) => ( { - let name = (stringify!($key_name)).replace("_", "-"); - if let Some(j) = obj.remove(&name) { - if let Some(v) = j.as_array() { - base.$key_name = Some(v.iter() - .map(|a| a.as_str().unwrap().to_string().into()) - .collect()); - } else { - incorrect_type.push(name) - } + macro_rules! forward { + ($name:ident) => { + if let Some($name) = json.$name { + base.$name = $name; } - } ); - ($key_name:ident, fallible_list) => ( { - let name = (stringify!($key_name)).replace("_", "-"); - obj.remove(&name).and_then(|j| { - if let Some(v) = j.as_array() { - match v.iter().map(|a| FromStr::from_str(a.as_str().unwrap())).collect() { - Ok(l) => { base.$key_name = l }, - // FIXME: `fallible_list` can't re-use the `key!` macro for list - // elements and the error messages from that macro, so it has a bad - // generic message instead - Err(_) => return Some(Err( - format!("`{:?}` is not a valid value for `{}`", j, name) - )), - } - } else { - incorrect_type.push(name) - } - Some(Ok(())) - }).unwrap_or(Ok(())) - } ); - ($key_name:ident, optional) => ( { - let name = (stringify!($key_name)).replace("_", "-"); - if let Some(o) = obj.remove(&name) { - base.$key_name = o - .as_str() - .map(|s| s.to_string().into()); - } - } ); - ($key_name:ident = $json_name:expr, LldFlavor) => ( { - let name = $json_name; - obj.remove(name).and_then(|o| o.as_str().and_then(|s| { - if let Some(flavor) = super::LldFlavor::from_str(&s) { - base.$key_name = flavor; - } else { - return Some(Err(format!( - "'{}' is not a valid value for lld-flavor. \ - Use 'darwin', 'gnu', 'link' or 'wasm'.", - s))) - } - Some(Ok(())) - })).unwrap_or(Ok(())) - } ); - ($key_name:ident = $json_name:expr, LinkerFlavorCli) => ( { - let name = $json_name; - obj.remove(name).and_then(|o| o.as_str().and_then(|s| { - match super::LinkerFlavorCli::from_str(s) { - Some(linker_flavor) => base.$key_name = linker_flavor, - _ => return Some(Err(format!("'{}' is not a valid value for linker-flavor. \ - Use {}", s, super::LinkerFlavorCli::one_of()))), - } - Some(Ok(())) - })).unwrap_or(Ok(())) - } ); - ($key_name:ident, StackProbeType) => ( { - let name = (stringify!($key_name)).replace("_", "-"); - obj.remove(&name).and_then(|o| match super::StackProbeType::from_json(&o) { - Ok(v) => { - base.$key_name = v; - Some(Ok(())) - }, - Err(s) => Some(Err( - format!("`{:?}` is not a valid value for `{}`: {}", o, name, s) - )), - }).unwrap_or(Ok(())) - } ); - ($key_name:ident, SanitizerSet) => ( { - let name = (stringify!($key_name)).replace("_", "-"); - if let Some(o) = obj.remove(&name) { - if let Some(a) = o.as_array() { - for s in a { - use super::SanitizerSet; - base.$key_name |= match s.as_str() { - Some("address") => SanitizerSet::ADDRESS, - Some("cfi") => SanitizerSet::CFI, - Some("dataflow") => SanitizerSet::DATAFLOW, - Some("kcfi") => SanitizerSet::KCFI, - Some("kernel-address") => SanitizerSet::KERNELADDRESS, - Some("leak") => SanitizerSet::LEAK, - Some("memory") => SanitizerSet::MEMORY, - Some("memtag") => SanitizerSet::MEMTAG, - Some("safestack") => SanitizerSet::SAFESTACK, - Some("shadow-call-stack") => SanitizerSet::SHADOWCALLSTACK, - Some("thread") => SanitizerSet::THREAD, - Some("hwaddress") => SanitizerSet::HWADDRESS, - Some(s) => return Err(format!("unknown sanitizer {}", s)), - _ => return Err(format!("not a string: {:?}", s)), - }; - } - } else { - incorrect_type.push(name) - } - } - Ok::<(), String>(()) - } ); - ($key_name:ident, link_self_contained_components) => ( { - // Skeleton of what needs to be parsed: - // - // ``` - // $name: { - // "components": [ - // - // ] - // } - // ``` - let name = (stringify!($key_name)).replace("_", "-"); - if let Some(o) = obj.remove(&name) { - if let Some(o) = o.as_object() { - let component_array = o.get("components") - .ok_or_else(|| format!("{name}: expected a \ - JSON object with a `components` field."))?; - let component_array = component_array.as_array() - .ok_or_else(|| format!("{name}.components: expected a JSON array"))?; - let mut components = super::LinkSelfContainedComponents::empty(); - for s in component_array { - components |= match s.as_str() { - Some(s) => { - super::LinkSelfContainedComponents::from_str(s) - .ok_or_else(|| format!("unknown \ - `-Clink-self-contained` component: {s}"))? - }, - _ => return Err(format!("not a string: {:?}", s)), - }; - } - base.$key_name = super::LinkSelfContainedDefault::WithComponents(components); - } else { - incorrect_type.push(name) - } - } - Ok::<(), String>(()) - } ); - ($key_name:ident = $json_name:expr, link_self_contained_backwards_compatible) => ( { - let name = $json_name; - obj.remove(name).and_then(|o| o.as_str().and_then(|s| { - match s.parse::() { - Ok(lsc_default) => base.$key_name = lsc_default, - _ => return Some(Err(format!("'{}' is not a valid `-Clink-self-contained` default. \ - Use 'false', 'true', 'musl' or 'mingw'", s))), - } - Some(Ok(())) - })).unwrap_or(Ok(())) - } ); - ($key_name:ident = $json_name:expr, link_objects) => ( { - let name = $json_name; - if let Some(val) = obj.remove(name) { - let obj = val.as_object().ok_or_else(|| format!("{}: expected a \ - JSON object with fields per CRT object kind.", name))?; - let mut args = super::CrtObjects::new(); - for (k, v) in obj { - let kind = super::LinkOutputKind::from_str(&k).ok_or_else(|| { - format!("{}: '{}' is not a valid value for CRT object kind. \ - Use '(dynamic,static)-(nopic,pic)-exe' or \ - '(dynamic,static)-dylib' or 'wasi-reactor-exe'", name, k) - })?; - - let v = v.as_array().ok_or_else(|| - format!("{}.{}: expected a JSON array", name, k) - )?.iter().enumerate() - .map(|(i,s)| { - let s = s.as_str().ok_or_else(|| - format!("{}.{}[{}]: expected a JSON string", name, k, i))?; - Ok(s.to_string().into()) - }) - .collect::, String>>()?; - - args.insert(kind, v); - } - base.$key_name = args; - } - } ); - ($key_name:ident = $json_name:expr, link_args) => ( { - let name = $json_name; - if let Some(val) = obj.remove(name) { - let obj = val.as_object().ok_or_else(|| format!("{}: expected a \ - JSON object with fields per linker-flavor.", name))?; - let mut args = super::LinkArgsCli::new(); - for (k, v) in obj { - let flavor = super::LinkerFlavorCli::from_str(&k).ok_or_else(|| { - format!("{}: '{}' is not a valid value for linker-flavor. \ - Use 'em', 'gcc', 'ld' or 'msvc'", name, k) - })?; - - let v = v.as_array().ok_or_else(|| - format!("{}.{}: expected a JSON array", name, k) - )?.iter().enumerate() - .map(|(i,s)| { - let s = s.as_str().ok_or_else(|| - format!("{}.{}[{}]: expected a JSON string", name, k, i))?; - Ok(s.to_string().into()) - }) - .collect::, String>>()?; - - args.insert(flavor, v); - } - base.$key_name = args; - } - } ); - ($key_name:ident, env) => ( { - let name = (stringify!($key_name)).replace("_", "-"); - if let Some(o) = obj.remove(&name) { - if let Some(a) = o.as_array() { - for o in a { - if let Some(s) = o.as_str() { - if let [k, v] = *s.split('=').collect::>() { - base.$key_name - .to_mut() - .push((k.to_string().into(), v.to_string().into())) - } - } - } - } else { - incorrect_type.push(name) - } + }; + } + macro_rules! forward_opt { + ($name:ident) => { + if let Some($name) = json.$name { + base.$name = Some($name); } - } ); - ($key_name:ident, target_families) => ( { - if let Some(value) = obj.remove("target-family") { - if let Some(v) = value.as_array() { - base.$key_name = v.iter() - .map(|a| a.as_str().unwrap().to_string().into()) - .collect(); - } else if let Some(v) = value.as_str() { - base.$key_name = vec![v.to_string().into()].into(); - } + }; + } + + if let Some(target_endian) = json.target_endian { + base.endian = target_endian.0; + } + + forward!(frame_pointer); + forward!(c_int_width); + forward_opt!(c_enum_min_bits); // if None, matches c_int_width + forward!(os); + forward!(env); + forward!(abi); + forward!(vendor); + forward_opt!(linker); + forward!(linker_flavor_json); + forward!(lld_flavor_json); + forward!(linker_is_gnu_json); + forward!(pre_link_objects); + forward!(post_link_objects); + forward!(pre_link_objects_self_contained); + forward!(post_link_objects_self_contained); + + // Deserializes the backwards-compatible variants of `-Clink-self-contained` + if let Some(link_self_contained) = json.link_self_contained_backwards_compatible { + base.link_self_contained = link_self_contained; + } + // Deserializes the components variant of `-Clink-self-contained` + if let Some(link_self_contained) = json.link_self_contained { + let components = link_self_contained + .components + .into_iter() + .fold(LinkSelfContainedComponents::empty(), |a, b| a | b); + base.link_self_contained = LinkSelfContainedDefault::WithComponents(components); + } + + forward!(pre_link_args_json); + forward!(late_link_args_json); + forward!(late_link_args_dynamic_json); + forward!(late_link_args_static_json); + forward!(post_link_args_json); + forward_opt!(link_script); + + if let Some(link_env) = json.link_env { + for s in link_env { + if let [k, v] = *s.split('=').collect::>() { + base.link_env.to_mut().push((k.to_string().into(), v.to_string().into())) + } else { + return Err(format!("link-env value '{s}' must be of the pattern 'KEY=VALUE'")); } - } ); + } } - if let Some(j) = obj.remove("target-endian") { - if let Some(s) = j.as_str() { - base.endian = s.parse()?; - } else { - incorrect_type.push("target-endian".into()) + forward!(link_env_remove); + forward!(asm_args); + forward!(cpu); + forward!(need_explicit_cpu); + forward!(features); + forward!(dynamic_linking); + forward_opt!(direct_access_external_data); + forward!(dll_tls_export); + forward!(only_cdylib); + forward!(executables); + forward!(relocation_model); + forward_opt!(code_model); + forward!(tls_model); + forward!(disable_redzone); + forward!(function_sections); + forward!(dll_prefix); + forward!(dll_suffix); + forward!(exe_suffix); + forward!(staticlib_prefix); + forward!(staticlib_suffix); + + if let Some(target_family) = json.target_family { + match target_family { + TargetFamiliesJson::Array(families) => base.families = families, + TargetFamiliesJson::String(family) => base.families = vec![family].into(), } } - if let Some(fp) = obj.remove("frame-pointer") { - if let Some(s) = fp.as_str() { - base.frame_pointer = s - .parse() - .map_err(|()| format!("'{s}' is not a valid value for frame-pointer"))?; - } else { - incorrect_type.push("frame-pointer".into()) + forward!(abi_return_struct_as_int); + forward!(is_like_aix); + forward!(is_like_darwin); + forward!(is_like_solaris); + forward!(is_like_windows); + forward!(is_like_msvc); + forward!(is_like_wasm); + forward!(is_like_android); + forward!(binary_format); + forward!(default_dwarf_version); + forward!(allows_weak_linkage); + forward!(has_rpath); + forward!(no_default_libraries); + forward!(position_independent_executables); + forward!(static_position_independent_executables); + forward!(plt_by_default); + forward!(relro_level); + forward!(archive_format); + forward!(allow_asm); + forward!(main_needs_argc_argv); + forward!(has_thread_local); + forward!(obj_is_bitcode); + forward!(bitcode_llvm_cmdline); + forward_opt!(max_atomic_width); + forward_opt!(min_atomic_width); + forward!(atomic_cas); + forward!(panic_strategy); + forward!(crt_static_allows_dylibs); + forward!(crt_static_default); + forward!(crt_static_respected); + forward!(stack_probes); + + if let Some(min_global_align) = json.min_global_align { + match Align::from_bits(min_global_align) { + Ok(align) => base.min_global_align = Some(align), + Err(e) => return Err(alignment_error("min-global-align", e)), } } - key!(c_int_width = "target-c-int-width", u64 as u16); - key!(c_enum_min_bits, Option); // if None, matches c_int_width - key!(os); - key!(env); - key!(abi); - key!(vendor); - key!(linker, optional); - key!(linker_flavor_json = "linker-flavor", LinkerFlavorCli)?; - key!(lld_flavor_json = "lld-flavor", LldFlavor)?; - key!(linker_is_gnu_json = "linker-is-gnu", bool); - key!(pre_link_objects = "pre-link-objects", link_objects); - key!(post_link_objects = "post-link-objects", link_objects); - key!(pre_link_objects_self_contained = "pre-link-objects-fallback", link_objects); - key!(post_link_objects_self_contained = "post-link-objects-fallback", link_objects); - // Deserializes the backwards-compatible variants of `-Clink-self-contained` - key!( - link_self_contained = "crt-objects-fallback", - link_self_contained_backwards_compatible - )?; - // Deserializes the components variant of `-Clink-self-contained` - key!(link_self_contained, link_self_contained_components)?; - key!(pre_link_args_json = "pre-link-args", link_args); - key!(late_link_args_json = "late-link-args", link_args); - key!(late_link_args_dynamic_json = "late-link-args-dynamic", link_args); - key!(late_link_args_static_json = "late-link-args-static", link_args); - key!(post_link_args_json = "post-link-args", link_args); - key!(link_script, optional); - key!(link_env, env); - key!(link_env_remove, list); - key!(asm_args, list); - key!(cpu); - key!(need_explicit_cpu, bool); - key!(features); - key!(dynamic_linking, bool); - key!(direct_access_external_data, Option); - key!(dll_tls_export, bool); - key!(only_cdylib, bool); - key!(executables, bool); - key!(relocation_model, RelocModel)?; - key!(code_model, CodeModel)?; - key!(tls_model, TlsModel)?; - key!(disable_redzone, bool); - key!(function_sections, bool); - key!(dll_prefix); - key!(dll_suffix); - key!(exe_suffix); - key!(staticlib_prefix); - key!(staticlib_suffix); - key!(families, target_families); - key!(abi_return_struct_as_int, bool); - key!(is_like_aix, bool); - key!(is_like_darwin, bool); - key!(is_like_solaris, bool); - key!(is_like_windows, bool); - key!(is_like_msvc, bool); - key!(is_like_wasm, bool); - key!(is_like_android, bool); - key!(binary_format, BinaryFormat)?; - key!(default_dwarf_version, u32); - key!(allows_weak_linkage, bool); - key!(has_rpath, bool); - key!(no_default_libraries, bool); - key!(position_independent_executables, bool); - key!(static_position_independent_executables, bool); - key!(plt_by_default, bool); - key!(relro_level, RelroLevel)?; - key!(archive_format); - key!(allow_asm, bool); - key!(main_needs_argc_argv, bool); - key!(has_thread_local, bool); - key!(obj_is_bitcode, bool); - key!(bitcode_llvm_cmdline); - key!(max_atomic_width, Option); - key!(min_atomic_width, Option); - key!(atomic_cas, bool); - key!(panic_strategy, PanicStrategy)?; - key!(crt_static_allows_dylibs, bool); - key!(crt_static_default, bool); - key!(crt_static_respected, bool); - key!(stack_probes, StackProbeType)?; - key!(min_global_align, Option); - key!(default_codegen_units, Option); - key!(default_codegen_backend, Option>); - key!(trap_unreachable, bool); - key!(requires_lto, bool); - key!(singlethread, bool); - key!(no_builtins, bool); - key!(default_visibility, Option)?; - key!(emit_debug_gdb_scripts, bool); - key!(requires_uwtable, bool); - key!(default_uwtable, bool); - key!(simd_types_indirect, bool); - key!(limit_rdylib_exports, bool); - key!(override_export_symbols, opt_list); - key!(merge_functions, MergeFunctions)?; - key!(mcount = "target-mcount"); - key!(llvm_mcount_intrinsic, optional); - key!(llvm_abiname); - key!(llvm_floatabi, FloatAbi)?; - key!(rustc_abi, RustcAbi)?; - key!(relax_elf_relocations, bool); - key!(llvm_args, list); - key!(use_ctors_section, bool); - key!(eh_frame_header, bool); - key!(has_thumb_interworking, bool); - key!(debuginfo_kind, DebuginfoKind)?; - key!(split_debuginfo, SplitDebuginfo)?; - key!(supported_split_debuginfo, fallible_list)?; - key!(supported_sanitizers, SanitizerSet)?; - key!(generate_arange_section, bool); - key!(supports_stack_protector, bool); - key!(small_data_threshold_support, SmallDataThresholdSupport)?; - key!(entry_name); - key!(supports_xray, bool); + forward_opt!(default_codegen_units); + forward_opt!(default_codegen_backend); + forward!(trap_unreachable); + forward!(requires_lto); + forward!(singlethread); + forward!(no_builtins); + forward_opt!(default_visibility); + forward!(emit_debug_gdb_scripts); + forward!(requires_uwtable); + forward!(default_uwtable); + forward!(simd_types_indirect); + forward!(limit_rdylib_exports); + forward_opt!(override_export_symbols); + forward!(merge_functions); + forward!(mcount); + forward_opt!(llvm_mcount_intrinsic); + forward!(llvm_abiname); + forward_opt!(llvm_floatabi); + forward_opt!(rustc_abi); + forward!(relax_elf_relocations); + forward!(llvm_args); + forward!(use_ctors_section); + forward!(eh_frame_header); + forward!(has_thumb_interworking); + forward!(debuginfo_kind); + forward!(split_debuginfo); + forward!(supported_split_debuginfo); + + if let Some(supported_sanitizers) = json.supported_sanitizers { + base.supported_sanitizers = + supported_sanitizers.into_iter().fold(SanitizerSet::empty(), |a, b| a | b); + } + + forward!(generate_arange_section); + forward!(supports_stack_protector); + forward!(small_data_threshold_support); + forward!(entry_name); + forward!(supports_xray); // we're going to run `update_from_cli`, but that won't change the target's AbiMap // FIXME: better factor the Target definition so we enforce this on a type level let abi_map = AbiMap::from_target(&base); - - if let Some(abi_str) = obj.remove("entry-abi") { - if let Json::String(abi_str) = abi_str { - match abi_str.parse::() { - Ok(abi) => base.options.entry_abi = abi_map.canonize_abi(abi, false).unwrap(), - Err(_) => return Err(format!("{abi_str} is not a valid ExternAbi")), - } - } else { - incorrect_type.push("entry-abi".to_owned()) - } + if let Some(entry_abi) = json.entry_abi { + base.options.entry_abi = abi_map.canonize_abi(entry_abi.0, false).unwrap(); } base.update_from_cli(); base.check_consistency(TargetKind::Json)?; - // Each field should have been read using `Json::remove` so any keys remaining are unused. - let remaining_keys = obj.keys(); - Ok(( - base, - TargetWarnings { unused_fields: remaining_keys.cloned().collect(), incorrect_type }, - )) + Ok((base, TargetWarnings { unused_fields: vec![] })) } } @@ -877,3 +412,189 @@ impl ToJson for Target { Json::Object(d) } } + +#[derive(serde_derive::Deserialize)] +struct LinkSelfContainedComponentsWrapper { + components: Vec, +} + +#[derive(serde_derive::Deserialize)] +#[serde(untagged)] +enum TargetFamiliesJson { + Array(StaticCow<[StaticCow]>), + String(StaticCow), +} + +/// `Endian` is in `rustc_abi`, which doesn't have access to the macro and serde. +struct EndianWrapper(rustc_abi::Endian); +impl FromStr for EndianWrapper { + type Err = String; + fn from_str(s: &str) -> Result { + rustc_abi::Endian::from_str(s).map(Self) + } +} +crate::json::serde_deserialize_from_str!(EndianWrapper); + +/// `ExternAbi` is in `rustc_abi`, which doesn't have access to the macro and serde. +struct ExternAbiWrapper(rustc_abi::ExternAbi); +impl FromStr for ExternAbiWrapper { + type Err = String; + fn from_str(s: &str) -> Result { + rustc_abi::ExternAbi::from_str(s) + .map(Self) + .map_err(|_| format!("{s} is not a valid extern ABI")) + } +} +crate::json::serde_deserialize_from_str!(ExternAbiWrapper); + +#[derive(serde_derive::Deserialize)] +struct TargetSpecJsonMetadata { + description: Option>, + tier: Option, + host_tools: Option, + std: Option, +} + +#[derive(serde_derive::Deserialize)] +#[serde(rename_all = "kebab-case")] +// Ensure that all unexpected fields get turned into errors. +// This helps users stay up to date when the schema changes instead of silently +// ignoring their old values. +#[serde(deny_unknown_fields)] +struct TargetSpecJson { + llvm_target: StaticCow, + target_pointer_width: String, + data_layout: StaticCow, + arch: StaticCow, + + metadata: Option, + + // options: + target_endian: Option, + frame_pointer: Option, + #[serde(rename = "target-c-int-width")] + c_int_width: Option, + c_enum_min_bits: Option, + os: Option>, + env: Option>, + abi: Option>, + vendor: Option>, + linker: Option>, + #[serde(rename = "linker-flavor")] + linker_flavor_json: Option, + #[serde(rename = "lld-flavor")] + lld_flavor_json: Option, + #[serde(rename = "linker-is-gnu")] + linker_is_gnu_json: Option, + #[serde(rename = "pre-link-objects")] + pre_link_objects: Option, + #[serde(rename = "post-link-objects")] + post_link_objects: Option, + #[serde(rename = "pre-link-objects-fallback")] + pre_link_objects_self_contained: Option, + #[serde(rename = "post-link-objects-fallback")] + post_link_objects_self_contained: Option, + #[serde(rename = "crt-objects-fallback")] + link_self_contained_backwards_compatible: Option, + link_self_contained: Option, + #[serde(rename = "pre-link-args")] + pre_link_args_json: Option, + #[serde(rename = "late-link-args")] + late_link_args_json: Option, + #[serde(rename = "late-link-args-dynamic")] + late_link_args_dynamic_json: Option, + #[serde(rename = "late-link-args-static")] + late_link_args_static_json: Option, + #[serde(rename = "post-link-args")] + post_link_args_json: Option, + link_script: Option>, + link_env: Option>>, + link_env_remove: Option]>>, + asm_args: Option]>>, + cpu: Option>, + need_explicit_cpu: Option, + features: Option>, + dynamic_linking: Option, + direct_access_external_data: Option, + dll_tls_export: Option, + only_cdylib: Option, + executables: Option, + relocation_model: Option, + code_model: Option, + tls_model: Option, + disable_redzone: Option, + function_sections: Option, + dll_prefix: Option>, + dll_suffix: Option>, + exe_suffix: Option>, + staticlib_prefix: Option>, + staticlib_suffix: Option>, + target_family: Option, + abi_return_struct_as_int: Option, + is_like_aix: Option, + is_like_darwin: Option, + is_like_solaris: Option, + is_like_windows: Option, + is_like_msvc: Option, + is_like_wasm: Option, + is_like_android: Option, + binary_format: Option, + default_dwarf_version: Option, + allows_weak_linkage: Option, + has_rpath: Option, + no_default_libraries: Option, + position_independent_executables: Option, + static_position_independent_executables: Option, + plt_by_default: Option, + relro_level: Option, + archive_format: Option>, + allow_asm: Option, + main_needs_argc_argv: Option, + has_thread_local: Option, + obj_is_bitcode: Option, + bitcode_llvm_cmdline: Option>, + max_atomic_width: Option, + min_atomic_width: Option, + atomic_cas: Option, + panic_strategy: Option, + crt_static_allows_dylibs: Option, + crt_static_default: Option, + crt_static_respected: Option, + stack_probes: Option, + min_global_align: Option, + default_codegen_units: Option, + default_codegen_backend: Option>, + trap_unreachable: Option, + requires_lto: Option, + singlethread: Option, + no_builtins: Option, + default_visibility: Option, + emit_debug_gdb_scripts: Option, + requires_uwtable: Option, + default_uwtable: Option, + simd_types_indirect: Option, + limit_rdylib_exports: Option, + override_export_symbols: Option]>>, + merge_functions: Option, + #[serde(rename = "target-mcount")] + mcount: Option>, + llvm_mcount_intrinsic: Option>, + llvm_abiname: Option>, + llvm_floatabi: Option, + rustc_abi: Option, + relax_elf_relocations: Option, + llvm_args: Option]>>, + use_ctors_section: Option, + eh_frame_header: Option, + has_thumb_interworking: Option, + debuginfo_kind: Option, + split_debuginfo: Option, + supported_split_debuginfo: Option>, + supported_sanitizers: Option>, + generate_arange_section: Option, + supports_stack_protector: Option, + small_data_threshold_support: Option, + entry_name: Option>, + supports_xray: Option, + entry_abi: Option, +} diff --git a/compiler/rustc_target/src/spec/mod.rs b/compiler/rustc_target/src/spec/mod.rs index 4bc0d88a910cb..c64cd9a51b7d2 100644 --- a/compiler/rustc_target/src/spec/mod.rs +++ b/compiler/rustc_target/src/spec/mod.rs @@ -37,6 +37,7 @@ //! //! [JSON]: https://json.org +use core::result::Result; use std::borrow::Cow; use std::collections::BTreeMap; use std::hash::{Hash, Hasher}; @@ -198,18 +199,29 @@ impl LldFlavor { LldFlavor::Link => "link", } } +} - fn from_str(s: &str) -> Option { - Some(match s { +impl FromStr for LldFlavor { + type Err = String; + + fn from_str(s: &str) -> Result { + Ok(match s { "darwin" => LldFlavor::Ld64, "gnu" => LldFlavor::Ld, "link" => LldFlavor::Link, "wasm" => LldFlavor::Wasm, - _ => return None, + _ => { + return Err( + "invalid value for lld flavor: '{s}', expected one of 'darwin', 'gnu', 'link', 'wasm'" + .into(), + ); + } }) } } +crate::json::serde_deserialize_from_str!(LldFlavor); + impl ToJson for LldFlavor { fn to_json(&self) -> Json { self.as_str().to_json() @@ -494,19 +506,23 @@ macro_rules! linker_flavor_cli_impls { concat!("one of: ", $($string, " ",)*) } - pub fn from_str(s: &str) -> Option { - Some(match s { - $($string => $($flavor)*,)* - _ => return None, - }) - } - pub fn desc(self) -> &'static str { match self { $($($flavor)* => $string,)* } } } + + impl FromStr for LinkerFlavorCli { + type Err = String; + + fn from_str(s: &str) -> Result { + Ok(match s { + $($string => $($flavor)*,)* + _ => return Err(format!("invalid linker flavor, allowed values: {}", Self::one_of())), + }) + } + } ) } @@ -540,6 +556,8 @@ linker_flavor_cli_impls! { (LinkerFlavorCli::Em) "em" } +crate::json::serde_deserialize_from_str!(LinkerFlavorCli); + impl ToJson for LinkerFlavorCli { fn to_json(&self) -> Json { self.desc().to_json() @@ -573,19 +591,26 @@ pub enum LinkSelfContainedDefault { /// Parses a backwards-compatible `-Clink-self-contained` option string, without components. impl FromStr for LinkSelfContainedDefault { - type Err = (); + type Err = String; - fn from_str(s: &str) -> Result { + fn from_str(s: &str) -> Result { Ok(match s { "false" => LinkSelfContainedDefault::False, "true" | "wasm" => LinkSelfContainedDefault::True, "musl" => LinkSelfContainedDefault::InferredForMusl, "mingw" => LinkSelfContainedDefault::InferredForMingw, - _ => return Err(()), + _ => { + return Err(format!( + "'{s}' is not a valid `-Clink-self-contained` default. \ + Use 'false', 'true', 'wasm', 'musl' or 'mingw'", + )); + } }) } } +crate::json::serde_deserialize_from_str!(LinkSelfContainedDefault); + impl ToJson for LinkSelfContainedDefault { fn to_json(&self) -> Json { match *self { @@ -652,19 +677,6 @@ bitflags::bitflags! { rustc_data_structures::external_bitflags_debug! { LinkSelfContainedComponents } impl LinkSelfContainedComponents { - /// Parses a single `-Clink-self-contained` well-known component, not a set of flags. - pub fn from_str(s: &str) -> Option { - Some(match s { - "crto" => LinkSelfContainedComponents::CRT_OBJECTS, - "libc" => LinkSelfContainedComponents::LIBC, - "unwind" => LinkSelfContainedComponents::UNWIND, - "linker" => LinkSelfContainedComponents::LINKER, - "sanitizers" => LinkSelfContainedComponents::SANITIZERS, - "mingw" => LinkSelfContainedComponents::MINGW, - _ => return None, - }) - } - /// Return the component's name. /// /// Returns `None` if the bitflags aren't a singular component (but a mix of multiple flags). @@ -708,6 +720,29 @@ impl LinkSelfContainedComponents { } } +impl FromStr for LinkSelfContainedComponents { + type Err = String; + + /// Parses a single `-Clink-self-contained` well-known component, not a set of flags. + fn from_str(s: &str) -> Result { + Ok(match s { + "crto" => LinkSelfContainedComponents::CRT_OBJECTS, + "libc" => LinkSelfContainedComponents::LIBC, + "unwind" => LinkSelfContainedComponents::UNWIND, + "linker" => LinkSelfContainedComponents::LINKER, + "sanitizers" => LinkSelfContainedComponents::SANITIZERS, + "mingw" => LinkSelfContainedComponents::MINGW, + _ => { + return Err(format!( + "'{s}' is not a valid link-self-contained component, expected 'crto', 'libc', 'unwind', 'linker', 'sanitizers', 'mingw'" + )); + } + }) + } +} + +crate::json::serde_deserialize_from_str!(LinkSelfContainedComponents); + impl ToJson for LinkSelfContainedComponents { fn to_json(&self) -> Json { let components: Vec<_> = Self::all_components() @@ -821,6 +856,25 @@ impl PanicStrategy { } } +impl FromStr for PanicStrategy { + type Err = String; + fn from_str(s: &str) -> Result { + Ok(match s { + "unwind" => PanicStrategy::Unwind, + "abort" => PanicStrategy::Abort, + _ => { + return Err(format!( + "'{}' is not a valid value for \ + panic-strategy. Use 'unwind' or 'abort'.", + s + )); + } + }) + } +} + +crate::json::serde_deserialize_from_str!(PanicStrategy); + impl ToJson for PanicStrategy { fn to_json(&self) -> Json { match *self { @@ -867,18 +921,24 @@ impl SymbolVisibility { } impl FromStr for SymbolVisibility { - type Err = (); + type Err = String; - fn from_str(s: &str) -> Result { + fn from_str(s: &str) -> Result { match s { "hidden" => Ok(SymbolVisibility::Hidden), "protected" => Ok(SymbolVisibility::Protected), "interposable" => Ok(SymbolVisibility::Interposable), - _ => Err(()), + _ => Err(format!( + "'{}' is not a valid value for \ + symbol-visibility. Use 'hidden', 'protected, or 'interposable'.", + s + )), } } } +crate::json::serde_deserialize_from_str!(SymbolVisibility); + impl ToJson for SymbolVisibility { fn to_json(&self) -> Json { match *self { @@ -890,19 +950,25 @@ impl ToJson for SymbolVisibility { } impl FromStr for RelroLevel { - type Err = (); + type Err = String; - fn from_str(s: &str) -> Result { + fn from_str(s: &str) -> Result { match s { "full" => Ok(RelroLevel::Full), "partial" => Ok(RelroLevel::Partial), "off" => Ok(RelroLevel::Off), "none" => Ok(RelroLevel::None), - _ => Err(()), + _ => Err(format!( + "'{}' is not a valid value for \ + relro-level. Use 'full', 'partial, 'off', or 'none'.", + s + )), } } } +crate::json::serde_deserialize_from_str!(RelroLevel); + impl ToJson for RelroLevel { fn to_json(&self) -> Json { match *self { @@ -923,7 +989,7 @@ pub enum SmallDataThresholdSupport { } impl FromStr for SmallDataThresholdSupport { - type Err = (); + type Err = String; fn from_str(s: &str) -> Result { if s == "none" { @@ -935,11 +1001,13 @@ impl FromStr for SmallDataThresholdSupport { } else if let Some(arg) = s.strip_prefix("llvm-arg=") { Ok(Self::LlvmArg(arg.to_string().into())) } else { - Err(()) + Err(format!("'{s}' is not a valid value for small-data-threshold-support.")) } } } +crate::json::serde_deserialize_from_str!(SmallDataThresholdSupport); + impl ToJson for SmallDataThresholdSupport { fn to_json(&self) -> Value { match self { @@ -969,18 +1037,25 @@ impl MergeFunctions { } impl FromStr for MergeFunctions { - type Err = (); + type Err = String; - fn from_str(s: &str) -> Result { + fn from_str(s: &str) -> Result { match s { "disabled" => Ok(MergeFunctions::Disabled), "trampolines" => Ok(MergeFunctions::Trampolines), "aliases" => Ok(MergeFunctions::Aliases), - _ => Err(()), + _ => Err(format!( + "'{}' is not a valid value for \ + merge-functions. Use 'disabled', \ + 'trampolines', or 'aliases'.", + s + )), } } } +crate::json::serde_deserialize_from_str!(MergeFunctions); + impl ToJson for MergeFunctions { fn to_json(&self) -> Json { match *self { @@ -1040,9 +1115,9 @@ impl RelocModel { } impl FromStr for RelocModel { - type Err = (); + type Err = String; - fn from_str(s: &str) -> Result { + fn from_str(s: &str) -> Result { Ok(match s { "static" => RelocModel::Static, "pic" => RelocModel::Pic, @@ -1051,11 +1126,19 @@ impl FromStr for RelocModel { "ropi" => RelocModel::Ropi, "rwpi" => RelocModel::Rwpi, "ropi-rwpi" => RelocModel::RopiRwpi, - _ => return Err(()), + _ => { + return Err(format!( + "invalid relocation model '{s}'. + Run `rustc --print relocation-models` to \ + see the list of supported values.'" + )); + } }) } } +crate::json::serde_deserialize_from_str!(RelocModel); + impl ToJson for RelocModel { fn to_json(&self) -> Json { self.desc().to_json() @@ -1072,20 +1155,28 @@ pub enum CodeModel { } impl FromStr for CodeModel { - type Err = (); + type Err = String; - fn from_str(s: &str) -> Result { + fn from_str(s: &str) -> Result { Ok(match s { "tiny" => CodeModel::Tiny, "small" => CodeModel::Small, "kernel" => CodeModel::Kernel, "medium" => CodeModel::Medium, "large" => CodeModel::Large, - _ => return Err(()), + _ => { + return Err(format!( + "'{s}' is not a valid code model. \ + Run `rustc --print code-models` to \ + see the list of supported values." + )); + } }) } } +crate::json::serde_deserialize_from_str!(CodeModel); + impl ToJson for CodeModel { fn to_json(&self) -> Json { match *self { @@ -1107,17 +1198,25 @@ pub enum FloatAbi { } impl FromStr for FloatAbi { - type Err = (); + type Err = String; - fn from_str(s: &str) -> Result { + fn from_str(s: &str) -> Result { Ok(match s { "soft" => FloatAbi::Soft, "hard" => FloatAbi::Hard, - _ => return Err(()), + _ => { + return Err(format!( + "'{}' is not a valid value for \ + llvm-floatabi. Use 'soft' or 'hard'.", + s + )); + } }) } } +crate::json::serde_deserialize_from_str!(FloatAbi); + impl ToJson for FloatAbi { fn to_json(&self) -> Json { match *self { @@ -1138,17 +1237,24 @@ pub enum RustcAbi { } impl FromStr for RustcAbi { - type Err = (); + type Err = String; - fn from_str(s: &str) -> Result { + fn from_str(s: &str) -> Result { Ok(match s { "x86-sse2" => RustcAbi::X86Sse2, "x86-softfloat" => RustcAbi::X86Softfloat, - _ => return Err(()), + _ => { + return Err(format!( + "'{s}' is not a valid value for rustc-abi. \ + Use 'x86-softfloat' or leave the field unset." + )); + } }) } } +crate::json::serde_deserialize_from_str!(RustcAbi); + impl ToJson for RustcAbi { fn to_json(&self) -> Json { match *self { @@ -1169,9 +1275,9 @@ pub enum TlsModel { } impl FromStr for TlsModel { - type Err = (); + type Err = String; - fn from_str(s: &str) -> Result { + fn from_str(s: &str) -> Result { Ok(match s { // Note the difference "general" vs "global" difference. The model name is "general", // but the user-facing option name is "global" for consistency with other compilers. @@ -1180,11 +1286,19 @@ impl FromStr for TlsModel { "initial-exec" => TlsModel::InitialExec, "local-exec" => TlsModel::LocalExec, "emulated" => TlsModel::Emulated, - _ => return Err(()), + _ => { + return Err(format!( + "'{s}' is not a valid TLS model. \ + Run `rustc --print tls-models` to \ + see the list of supported values." + )); + } }) } } +crate::json::serde_deserialize_from_str!(TlsModel); + impl ToJson for TlsModel { fn to_json(&self) -> Json { match *self { @@ -1230,19 +1344,6 @@ impl LinkOutputKind { } } - pub(super) fn from_str(s: &str) -> Option { - Some(match s { - "dynamic-nopic-exe" => LinkOutputKind::DynamicNoPicExe, - "dynamic-pic-exe" => LinkOutputKind::DynamicPicExe, - "static-nopic-exe" => LinkOutputKind::StaticNoPicExe, - "static-pic-exe" => LinkOutputKind::StaticPicExe, - "dynamic-dylib" => LinkOutputKind::DynamicDylib, - "static-dylib" => LinkOutputKind::StaticDylib, - "wasi-reactor-exe" => LinkOutputKind::WasiReactorExe, - _ => return None, - }) - } - pub fn can_link_dylib(self) -> bool { match self { LinkOutputKind::StaticNoPicExe | LinkOutputKind::StaticPicExe => false, @@ -1255,6 +1356,31 @@ impl LinkOutputKind { } } +impl FromStr for LinkOutputKind { + type Err = String; + + fn from_str(s: &str) -> Result { + Ok(match s { + "dynamic-nopic-exe" => LinkOutputKind::DynamicNoPicExe, + "dynamic-pic-exe" => LinkOutputKind::DynamicPicExe, + "static-nopic-exe" => LinkOutputKind::StaticNoPicExe, + "static-pic-exe" => LinkOutputKind::StaticPicExe, + "dynamic-dylib" => LinkOutputKind::DynamicDylib, + "static-dylib" => LinkOutputKind::StaticDylib, + "wasi-reactor-exe" => LinkOutputKind::WasiReactorExe, + _ => { + return Err(format!( + "invalid value for CRT object kind. \ + Use '(dynamic,static)-(nopic,pic)-exe' or \ + '(dynamic,static)-dylib' or 'wasi-reactor-exe'" + )); + } + }) + } +} + +crate::json::serde_deserialize_from_str!(LinkOutputKind); + impl fmt::Display for LinkOutputKind { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { f.write_str(self.as_str()) @@ -1290,18 +1416,25 @@ impl DebuginfoKind { } impl FromStr for DebuginfoKind { - type Err = (); + type Err = String; - fn from_str(s: &str) -> Result { + fn from_str(s: &str) -> Result { Ok(match s { "dwarf" => DebuginfoKind::Dwarf, "dwarf-dsym" => DebuginfoKind::DwarfDsym, "pdb" => DebuginfoKind::Pdb, - _ => return Err(()), + _ => { + return Err(format!( + "'{s}' is not a valid value for debuginfo-kind. Use 'dwarf', \ + 'dwarf-dsym' or 'pdb'." + )); + } }) } } +crate::json::serde_deserialize_from_str!(DebuginfoKind); + impl ToJson for DebuginfoKind { fn to_json(&self) -> Json { self.as_str().to_json() @@ -1354,18 +1487,25 @@ impl SplitDebuginfo { } impl FromStr for SplitDebuginfo { - type Err = (); + type Err = String; - fn from_str(s: &str) -> Result { + fn from_str(s: &str) -> Result { Ok(match s { "off" => SplitDebuginfo::Off, "unpacked" => SplitDebuginfo::Unpacked, "packed" => SplitDebuginfo::Packed, - _ => return Err(()), + _ => { + return Err(format!( + "'{s}' is not a valid value for \ + split-debuginfo. Use 'off', 'unpacked', or 'packed'.", + )); + } }) } } +crate::json::serde_deserialize_from_str!(SplitDebuginfo); + impl ToJson for SplitDebuginfo { fn to_json(&self) -> Json { self.as_str().to_json() @@ -1378,7 +1518,9 @@ impl fmt::Display for SplitDebuginfo { } } -#[derive(Clone, Debug, PartialEq, Eq)] +#[derive(Clone, Debug, PartialEq, Eq, serde_derive::Deserialize)] +#[serde(tag = "kind")] +#[serde(rename_all = "kebab-case")] pub enum StackProbeType { /// Don't emit any stack probes. None, @@ -1390,44 +1532,10 @@ pub enum StackProbeType { Call, /// Use inline option for LLVM versions later than specified in `min_llvm_version_for_inline` /// and call `__rust_probestack` otherwise. - InlineOrCall { min_llvm_version_for_inline: (u32, u32, u32) }, -} - -impl StackProbeType { - fn from_json(json: &Json) -> Result { - let object = json.as_object().ok_or_else(|| "expected a JSON object")?; - let kind = object - .get("kind") - .and_then(|o| o.as_str()) - .ok_or_else(|| "expected `kind` to be a string")?; - match kind { - "none" => Ok(StackProbeType::None), - "inline" => Ok(StackProbeType::Inline), - "call" => Ok(StackProbeType::Call), - "inline-or-call" => { - let min_version = object - .get("min-llvm-version-for-inline") - .and_then(|o| o.as_array()) - .ok_or_else(|| "expected `min-llvm-version-for-inline` to be an array")?; - let mut iter = min_version.into_iter().map(|v| { - let int = v.as_u64().ok_or_else( - || "expected `min-llvm-version-for-inline` values to be integers", - )?; - u32::try_from(int) - .map_err(|_| "`min-llvm-version-for-inline` values don't convert to u32") - }); - let min_llvm_version_for_inline = ( - iter.next().unwrap_or(Ok(11))?, - iter.next().unwrap_or(Ok(0))?, - iter.next().unwrap_or(Ok(0))?, - ); - Ok(StackProbeType::InlineOrCall { min_llvm_version_for_inline }) - } - _ => Err(String::from( - "`kind` expected to be one of `none`, `inline`, `call` or `inline-or-call`", - )), - } - } + InlineOrCall { + #[serde(rename = "min-llvm-version-for-inline")] + min_llvm_version_for_inline: (u32, u32, u32), + }, } impl ToJson for StackProbeType { @@ -1549,6 +1657,29 @@ impl fmt::Display for SanitizerSet { } } +impl FromStr for SanitizerSet { + type Err = String; + fn from_str(s: &str) -> Result { + Ok(match s { + "address" => SanitizerSet::ADDRESS, + "cfi" => SanitizerSet::CFI, + "dataflow" => SanitizerSet::DATAFLOW, + "kcfi" => SanitizerSet::KCFI, + "kernel-address" => SanitizerSet::KERNELADDRESS, + "leak" => SanitizerSet::LEAK, + "memory" => SanitizerSet::MEMORY, + "memtag" => SanitizerSet::MEMTAG, + "safestack" => SanitizerSet::SAFESTACK, + "shadow-call-stack" => SanitizerSet::SHADOWCALLSTACK, + "thread" => SanitizerSet::THREAD, + "hwaddress" => SanitizerSet::HWADDRESS, + s => return Err(format!("unknown sanitizer {s}")), + }) + } +} + +crate::json::serde_deserialize_from_str!(SanitizerSet); + impl ToJson for SanitizerSet { fn to_json(&self) -> Json { self.into_iter() @@ -1587,17 +1718,19 @@ impl FramePointer { } impl FromStr for FramePointer { - type Err = (); - fn from_str(s: &str) -> Result { + type Err = String; + fn from_str(s: &str) -> Result { Ok(match s { "always" => Self::Always, "non-leaf" => Self::NonLeaf, "may-omit" => Self::MayOmit, - _ => return Err(()), + _ => return Err(format!("'{s}' is not a valid value for frame-pointer")), }) } } +crate::json::serde_deserialize_from_str!(FramePointer); + impl ToJson for FramePointer { fn to_json(&self) -> Json { match *self { @@ -1685,7 +1818,7 @@ impl BinaryFormat { } impl FromStr for BinaryFormat { - type Err = (); + type Err = String; fn from_str(s: &str) -> Result { match s { "coff" => Ok(Self::Coff), @@ -1693,11 +1826,16 @@ impl FromStr for BinaryFormat { "mach-o" => Ok(Self::MachO), "wasm" => Ok(Self::Wasm), "xcoff" => Ok(Self::Xcoff), - _ => Err(()), + _ => Err(format!( + "'{s}' is not a valid value for binary_format. \ + Use 'coff', 'elf', 'mach-o', 'wasm' or 'xcoff' " + )), } } } +crate::json::serde_deserialize_from_str!(BinaryFormat); + impl ToJson for BinaryFormat { fn to_json(&self) -> Json { match self { @@ -2130,12 +2268,11 @@ pub(crate) use cvs; #[derive(Debug, PartialEq)] pub struct TargetWarnings { unused_fields: Vec, - incorrect_type: Vec, } impl TargetWarnings { pub fn empty() -> Self { - Self { unused_fields: Vec::new(), incorrect_type: Vec::new() } + Self { unused_fields: Vec::new() } } pub fn warning_messages(&self) -> Vec { @@ -2146,12 +2283,6 @@ impl TargetWarnings { self.unused_fields.join(", ") )); } - if !self.incorrect_type.is_empty() { - warnings.push(format!( - "target json file contains fields whose value doesn't have the correct json type: {}", - self.incorrect_type.join(", ") - )); - } warnings } } @@ -3325,7 +3456,8 @@ impl Target { /// Test target self-consistency and JSON encoding/decoding roundtrip. #[cfg(test)] fn test_target(mut self) { - let recycled_target = Target::from_json(self.to_json()).map(|(j, _)| j); + let recycled_target = + Target::from_json(&serde_json::to_string(&self.to_json()).unwrap()).map(|(j, _)| j); self.update_to_cli(); self.check_consistency(TargetKind::Builtin).unwrap(); assert_eq!(recycled_target, Ok(self)); @@ -3373,8 +3505,7 @@ impl Target { fn load_file(path: &Path) -> Result<(Target, TargetWarnings), String> { let contents = fs::read_to_string(path).map_err(|e| e.to_string())?; - let obj = serde_json::from_str(&contents).map_err(|e| e.to_string())?; - Target::from_json(obj) + Target::from_json(&contents) } match *target_tuple { @@ -3422,10 +3553,7 @@ impl Target { Err(format!("could not find specification for target {target_tuple:?}")) } } - TargetTuple::TargetJson { ref contents, .. } => { - let obj = serde_json::from_str(contents).map_err(|e| e.to_string())?; - Target::from_json(obj) - } + TargetTuple::TargetJson { ref contents, .. } => Target::from_json(contents), } } diff --git a/compiler/rustc_target/src/tests.rs b/compiler/rustc_target/src/tests.rs index 76375170db63d..ee847a84007f0 100644 --- a/compiler/rustc_target/src/tests.rs +++ b/compiler/rustc_target/src/tests.rs @@ -2,8 +2,7 @@ use crate::spec::Target; #[test] fn report_unused_fields() { - let json = serde_json::from_str( - r#" + let json = r#" { "arch": "powerpc64", "data-layout": "e-m:e-i64:64-n32:64", @@ -11,47 +10,8 @@ fn report_unused_fields() { "target-pointer-width": "64", "code-mode": "foo" } - "#, - ) - .unwrap(); - let warnings = Target::from_json(json).unwrap().1; - assert_eq!(warnings.warning_messages().len(), 1); - assert!(warnings.warning_messages().join("\n").contains("code-mode")); -} - -#[test] -fn report_incorrect_json_type() { - let json = serde_json::from_str( - r#" - { - "arch": "powerpc64", - "data-layout": "e-m:e-i64:64-n32:64", - "llvm-target": "powerpc64le-elf", - "target-pointer-width": "64", - "link-env-remove": "foo" - } - "#, - ) - .unwrap(); - let warnings = Target::from_json(json).unwrap().1; - assert_eq!(warnings.warning_messages().len(), 1); - assert!(warnings.warning_messages().join("\n").contains("link-env-remove")); -} - -#[test] -fn no_warnings_for_valid_target() { - let json = serde_json::from_str( - r#" - { - "arch": "powerpc64", - "data-layout": "e-m:e-i64:64-n32:64", - "llvm-target": "powerpc64le-elf", - "target-pointer-width": "64", - "link-env-remove": ["foo"] - } - "#, - ) - .unwrap(); - let warnings = Target::from_json(json).unwrap().1; - assert_eq!(warnings.warning_messages().len(), 0); + "#; + let result = Target::from_json(json); + eprintln!("{result:#?}"); + assert!(result.is_err()); } diff --git a/src/librustdoc/doctest.rs b/src/librustdoc/doctest.rs index 38ba6b4503dc1..a32c2f7fb18c5 100644 --- a/src/librustdoc/doctest.rs +++ b/src/librustdoc/doctest.rs @@ -444,7 +444,7 @@ fn add_exe_suffix(input: String, target: &TargetTuple) -> String { let exe_suffix = match target { TargetTuple::TargetTuple(_) => Target::expect_builtin(target).options.exe_suffix, TargetTuple::TargetJson { contents, .. } => { - Target::from_json(contents.parse().unwrap()).unwrap().0.options.exe_suffix + Target::from_json(contents).unwrap().0.options.exe_suffix } }; input + &exe_suffix diff --git a/src/tools/tidy/src/deps.rs b/src/tools/tidy/src/deps.rs index f43f5eae9a560..d17ae162ab235 100644 --- a/src/tools/tidy/src/deps.rs +++ b/src/tools/tidy/src/deps.rs @@ -378,6 +378,7 @@ const PERMITTED_RUSTC_DEPENDENCIES: &[&str] = &[ "serde", "serde_derive", "serde_json", + "serde_path_to_error", "sha1", "sha2", "sharded-slab", diff --git a/tests/run-make/rustdoc-target-spec-json-path/target.json b/tests/run-make/rustdoc-target-spec-json-path/target.json index c478f1196fae0..d7e4cac57ae75 100644 --- a/tests/run-make/rustdoc-target-spec-json-path/target.json +++ b/tests/run-make/rustdoc-target-spec-json-path/target.json @@ -6,7 +6,6 @@ "dynamic-linking": true, "env": "gnu", "executables": true, - "has-elf-tls": true, "has-rpath": true, "linker-is-gnu": true, "llvm-target": "x86_64-unknown-linux-gnu", diff --git a/tests/run-make/target-specs/endianness-mismatch.json b/tests/run-make/target-specs/endianness-mismatch.json index 431053ea99b60..cc03becc59af6 100644 --- a/tests/run-make/target-specs/endianness-mismatch.json +++ b/tests/run-make/target-specs/endianness-mismatch.json @@ -5,7 +5,6 @@ "llvm-target": "x86_64-unknown-linux-gnu", "target-endian": "big", "target-pointer-width": "64", - "target-c-int-width": "32", "arch": "x86_64", "os": "linux" } diff --git a/tests/run-make/target-specs/my-awesome-platform.json b/tests/run-make/target-specs/my-awesome-platform.json index 1673ef7bd54d1..d41038b84a865 100644 --- a/tests/run-make/target-specs/my-awesome-platform.json +++ b/tests/run-make/target-specs/my-awesome-platform.json @@ -4,8 +4,6 @@ "llvm-target": "i686-unknown-linux-gnu", "target-endian": "little", "target-pointer-width": "32", - "target-c-int-width": "32", "arch": "x86", - "os": "linux", - "morestack": false + "os": "linux" } diff --git a/tests/run-make/target-specs/my-incomplete-platform.json b/tests/run-make/target-specs/my-incomplete-platform.json index ceaa25cdf2fef..8bdc4108f494a 100644 --- a/tests/run-make/target-specs/my-incomplete-platform.json +++ b/tests/run-make/target-specs/my-incomplete-platform.json @@ -3,8 +3,6 @@ "linker-flavor": "gcc", "target-endian": "little", "target-pointer-width": "32", - "target-c-int-width": "32", "arch": "x86", - "os": "foo", - "morestack": false + "os": "foo" } diff --git a/tests/run-make/target-specs/my-x86_64-unknown-linux-gnu-platform.json b/tests/run-make/target-specs/my-x86_64-unknown-linux-gnu-platform.json index 0cafce15a9fef..27833f1abdd9e 100644 --- a/tests/run-make/target-specs/my-x86_64-unknown-linux-gnu-platform.json +++ b/tests/run-make/target-specs/my-x86_64-unknown-linux-gnu-platform.json @@ -5,8 +5,6 @@ "llvm-target": "x86_64-unknown-linux-gnu", "target-endian": "little", "target-pointer-width": "64", - "target-c-int-width": "32", "arch": "x86_64", - "os": "linux", - "morestack": false + "os": "linux" } diff --git a/tests/run-make/target-specs/require-explicit-cpu.json b/tests/run-make/target-specs/require-explicit-cpu.json index 5cbb9573b3f12..9744bca168e2d 100644 --- a/tests/run-make/target-specs/require-explicit-cpu.json +++ b/tests/run-make/target-specs/require-explicit-cpu.json @@ -4,7 +4,6 @@ "llvm-target": "i686-unknown-linux-gnu", "target-endian": "little", "target-pointer-width": "32", - "target-c-int-width": "32", "arch": "x86", "os": "linux", "need-explicit-cpu": true diff --git a/tests/run-make/target-specs/rmake.rs b/tests/run-make/target-specs/rmake.rs index 9184e5f772f78..7e565588ed6bc 100644 --- a/tests/run-make/target-specs/rmake.rs +++ b/tests/run-make/target-specs/rmake.rs @@ -8,8 +8,6 @@ use run_make_support::{diff, rfs, rustc}; fn main() { - rustc().input("foo.rs").target("my-awesome-platform.json").crate_type("lib").emit("asm").run(); - assert!(!rfs::read_to_string("foo.s").contains("morestack")); rustc() .input("foo.rs") .target("my-invalid-platform.json") @@ -19,7 +17,7 @@ fn main() { .input("foo.rs") .target("my-incomplete-platform.json") .run_fail() - .assert_stderr_contains("Field llvm-target"); + .assert_stderr_contains("missing field `llvm-target`"); rustc() .env("RUST_TARGET_PATH", ".") .input("foo.rs") diff --git a/tests/ui/check-cfg/my-awesome-platform.json b/tests/ui/check-cfg/my-awesome-platform.json index 03b08b727bd3a..4c16d06c7b7d6 100644 --- a/tests/ui/check-cfg/my-awesome-platform.json +++ b/tests/ui/check-cfg/my-awesome-platform.json @@ -4,7 +4,6 @@ "arch": "x86_64", "target-endian": "little", "target-pointer-width": "64", - "target-c-int-width": "32", "os": "ericos", "linker-flavor": "ld.lld", "linker": "rust-lld", diff --git a/tests/ui/codegen/mismatched-data-layout.json b/tests/ui/codegen/mismatched-data-layout.json index 7adc883252474..f8c510c186362 100644 --- a/tests/ui/codegen/mismatched-data-layout.json +++ b/tests/ui/codegen/mismatched-data-layout.json @@ -4,7 +4,6 @@ "arch": "x86_64", "target-endian": "little", "target-pointer-width": "64", - "target-c-int-width": "32", "os": "none", "linker-flavor": "ld.lld", "linker": "rust-lld", diff --git a/tests/ui/codegen/mismatched-data-layouts.rs b/tests/ui/codegen/mismatched-data-layouts.rs index 6428b8c5247b7..ea1457148a52c 100644 --- a/tests/ui/codegen/mismatched-data-layouts.rs +++ b/tests/ui/codegen/mismatched-data-layouts.rs @@ -5,6 +5,7 @@ //@ compile-flags: --crate-type=lib --target={{src-base}}/codegen/mismatched-data-layout.json -Z unstable-options //@ normalize-stderr: "`, `[A-Za-z0-9-:]*`" -> "`, `normalized data layout`" //@ normalize-stderr: "layout, `[A-Za-z0-9-:]*`" -> "layout, `normalized data layout`" +//@ normalize-stderr: "`mismatched-data-layout-\d+`" -> "`mismatched-data-layout-`" #![feature(lang_items, no_core, auto_traits)] #![no_core] diff --git a/tests/ui/codegen/mismatched-data-layouts.stderr b/tests/ui/codegen/mismatched-data-layouts.stderr index b7d5d82bee08c..d1117564d5b73 100644 --- a/tests/ui/codegen/mismatched-data-layouts.stderr +++ b/tests/ui/codegen/mismatched-data-layouts.stderr @@ -1,4 +1,4 @@ -error: data-layout for target `mismatched-data-layout-7193370089426056427`, `normalized data layout`, differs from LLVM target's `x86_64-unknown-none-gnu` default layout, `normalized data layout` +error: data-layout for target `mismatched-data-layout-`, `normalized data layout`, differs from LLVM target's `x86_64-unknown-none-gnu` default layout, `normalized data layout` error: aborting due to 1 previous error From e5a506251d912d0cfddf2e2e6597234c6929dd10 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Joel=20Wejdenst=C3=A5l?= Date: Mon, 21 Jul 2025 20:28:00 +0200 Subject: [PATCH 12/16] add an error message if you attempt to pass indirect args via guaranteed tail calls. --- compiler/rustc_codegen_ssa/src/mir/block.rs | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/compiler/rustc_codegen_ssa/src/mir/block.rs b/compiler/rustc_codegen_ssa/src/mir/block.rs index 42ff6fff90001..3aa6bb0bd59c6 100644 --- a/compiler/rustc_codegen_ssa/src/mir/block.rs +++ b/compiler/rustc_codegen_ssa/src/mir/block.rs @@ -1045,6 +1045,13 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> { // to generate `lifetime_end` when the call returns. let mut lifetime_ends_after_call: Vec<(Bx::Value, Size)> = Vec::new(); 'make_args: for (i, arg) in first_args.iter().enumerate() { + if tail && matches!(fn_abi.args[i].mode, PassMode::Indirect { .. }) { + bug!( + r"Arguments using PassMode::Indirect are currently not supported for tail calls. + See https://github.com/rust-lang/rust/pull/144232#discussion_r2218543841 for more information." + ); + } + let mut op = self.codegen_operand(bx, &arg.node); if let (0, Some(ty::InstanceKind::Virtual(_, idx))) = (i, instance.map(|i| i.def)) { From ecf34e1d648dc0f70b92e99e869ec02631139f6c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Joel=20Wejdenst=C3=A5l?= Date: Mon, 21 Jul 2025 20:30:27 +0200 Subject: [PATCH 13/16] use span_bug instead of bug --- compiler/rustc_codegen_ssa/src/mir/block.rs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/compiler/rustc_codegen_ssa/src/mir/block.rs b/compiler/rustc_codegen_ssa/src/mir/block.rs index 3aa6bb0bd59c6..91b3d2a1a26fa 100644 --- a/compiler/rustc_codegen_ssa/src/mir/block.rs +++ b/compiler/rustc_codegen_ssa/src/mir/block.rs @@ -1046,9 +1046,9 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> { let mut lifetime_ends_after_call: Vec<(Bx::Value, Size)> = Vec::new(); 'make_args: for (i, arg) in first_args.iter().enumerate() { if tail && matches!(fn_abi.args[i].mode, PassMode::Indirect { .. }) { - bug!( - r"Arguments using PassMode::Indirect are currently not supported for tail calls. - See https://github.com/rust-lang/rust/pull/144232#discussion_r2218543841 for more information." + span_bug!( + fn_span, + "arguments using PassMode::Indirect are currently not supported for tail calls" ); } From c4eb07761643d2fa26d6f609eb23c8d22e14d8eb Mon Sep 17 00:00:00 2001 From: Ben Kimock Date: Thu, 17 Jul 2025 18:41:52 -0400 Subject: [PATCH 14/16] Ensure we codegen and don't internalize the entrypoint --- compiler/rustc_middle/src/mir/mono.rs | 6 ++---- compiler/rustc_middle/src/ty/context.rs | 14 ++++++++++++++ compiler/rustc_monomorphize/src/collector.rs | 9 +++++++++ compiler/rustc_monomorphize/src/partitioning.rs | 15 +++++---------- tests/ui/entry-point/auxiliary/main_functions.rs | 3 +++ .../ui/entry-point/imported_main_local_codegen.rs | 11 +++++++++++ 6 files changed, 44 insertions(+), 14 deletions(-) create mode 100644 tests/ui/entry-point/imported_main_local_codegen.rs diff --git a/compiler/rustc_middle/src/mir/mono.rs b/compiler/rustc_middle/src/mir/mono.rs index 47ba850d50dd4..c2927361d05c4 100644 --- a/compiler/rustc_middle/src/mir/mono.rs +++ b/compiler/rustc_middle/src/mir/mono.rs @@ -143,10 +143,8 @@ impl<'tcx> MonoItem<'tcx> { }; // Similarly, the executable entrypoint must be instantiated exactly once. - if let Some((entry_def_id, _)) = tcx.entry_fn(()) { - if instance.def_id() == entry_def_id { - return InstantiationMode::GloballyShared { may_conflict: false }; - } + if tcx.is_entrypoint(instance.def_id()) { + return InstantiationMode::GloballyShared { may_conflict: false }; } // If the function is #[naked] or contains any other attribute that requires exactly-once diff --git a/compiler/rustc_middle/src/ty/context.rs b/compiler/rustc_middle/src/ty/context.rs index 915b062417f2f..26da2abe126cd 100644 --- a/compiler/rustc_middle/src/ty/context.rs +++ b/compiler/rustc_middle/src/ty/context.rs @@ -3402,6 +3402,20 @@ impl<'tcx> TyCtxt<'tcx> { pub fn do_not_recommend_impl(self, def_id: DefId) -> bool { self.get_diagnostic_attr(def_id, sym::do_not_recommend).is_some() } + + /// Whether this def is one of the special bin crate entrypoint functions that must have a + /// monomorphization and also not be internalized in the bin crate. + pub fn is_entrypoint(self, def_id: DefId) -> bool { + if self.is_lang_item(def_id, LangItem::Start) { + return true; + } + if let Some((entry_def_id, _)) = self.entry_fn(()) + && entry_def_id == def_id + { + return true; + } + false + } } /// Parameter attributes that can only be determined by examining the body of a function instead diff --git a/compiler/rustc_monomorphize/src/collector.rs b/compiler/rustc_monomorphize/src/collector.rs index 91c8e64ce9afe..5071f9f892216 100644 --- a/compiler/rustc_monomorphize/src/collector.rs +++ b/compiler/rustc_monomorphize/src/collector.rs @@ -1582,6 +1582,15 @@ impl<'v> RootCollector<'_, 'v> { return; }; + let main_instance = Instance::mono(self.tcx, main_def_id); + if self.tcx.should_codegen_locally(main_instance) { + self.output.push(create_fn_mono_item( + self.tcx, + main_instance, + self.tcx.def_span(main_def_id), + )); + } + let Some(start_def_id) = self.tcx.lang_items().start_fn() else { self.tcx.dcx().emit_fatal(errors::StartNotFound); }; diff --git a/compiler/rustc_monomorphize/src/partitioning.rs b/compiler/rustc_monomorphize/src/partitioning.rs index 69851511fb1f4..ca8228de57e89 100644 --- a/compiler/rustc_monomorphize/src/partitioning.rs +++ b/compiler/rustc_monomorphize/src/partitioning.rs @@ -223,11 +223,7 @@ where // So even if its mode is LocalCopy, we need to treat it like a root. match mono_item.instantiation_mode(cx.tcx) { InstantiationMode::GloballyShared { .. } => {} - InstantiationMode::LocalCopy => { - if !cx.tcx.is_lang_item(mono_item.def_id(), LangItem::Start) { - continue; - } - } + InstantiationMode::LocalCopy => continue, } let characteristic_def_id = characteristic_def_id_of_mono_item(cx.tcx, mono_item); @@ -821,10 +817,9 @@ fn mono_item_visibility<'tcx>( | InstanceKind::FnPtrAddrShim(..) => return Visibility::Hidden, }; - // The `start_fn` lang item is actually a monomorphized instance of a - // function in the standard library, used for the `main` function. We don't - // want to export it so we tag it with `Hidden` visibility but this symbol - // is only referenced from the actual `main` symbol which we unfortunately + // Both the `start_fn` lang item and `main` itself should not be exported, + // so we give them with `Hidden` visibility but these symbols are + // only referenced from the actual `main` symbol which we unfortunately // don't know anything about during partitioning/collection. As a result we // forcibly keep this symbol out of the `internalization_candidates` set. // @@ -834,7 +829,7 @@ fn mono_item_visibility<'tcx>( // from the `main` symbol we'll generate later. // // This may be fixable with a new `InstanceKind` perhaps? Unsure! - if tcx.is_lang_item(def_id, LangItem::Start) { + if tcx.is_entrypoint(def_id) { *can_be_internalized = false; return Visibility::Hidden; } diff --git a/tests/ui/entry-point/auxiliary/main_functions.rs b/tests/ui/entry-point/auxiliary/main_functions.rs index cc7992a42c187..ab4a09b633100 100644 --- a/tests/ui/entry-point/auxiliary/main_functions.rs +++ b/tests/ui/entry-point/auxiliary/main_functions.rs @@ -1 +1,4 @@ pub fn boilerplate() {} + +#[inline] +pub fn local_codegen() {} diff --git a/tests/ui/entry-point/imported_main_local_codegen.rs b/tests/ui/entry-point/imported_main_local_codegen.rs new file mode 100644 index 0000000000000..1e46c10937302 --- /dev/null +++ b/tests/ui/entry-point/imported_main_local_codegen.rs @@ -0,0 +1,11 @@ +//@ run-pass +//@ aux-build:main_functions.rs +//@ compile-flags: -Ccodegen-units=1024 + +// This is a regression test for https://github.com/rust-lang/rust/issues/144052. +// Entrypoint functions call each other in ways that CGU partitioning doesn't know about. So there +// is a special check to not internalize any of them. But internalizing them can be okay if there +// are few enough CGUs, so we use a lot of CGUs in this test to hit the bad case. + +extern crate main_functions; +pub use main_functions::local_codegen as main; From 6e8762f769c90f7a6ab0428db8ba55066eafd859 Mon Sep 17 00:00:00 2001 From: Camille GILLOT Date: Sun, 1 Oct 2023 15:09:35 +0000 Subject: [PATCH 15/16] Use less HIR in check_private_in_public. --- compiler/rustc_privacy/src/lib.rs | 122 +++++++----------- .../associated-item-privacy-trait.stderr | 22 ++-- .../ui/privacy/private-in-public-warn.stderr | 72 +++++------ 3 files changed, 92 insertions(+), 124 deletions(-) diff --git a/compiler/rustc_privacy/src/lib.rs b/compiler/rustc_privacy/src/lib.rs index 80c13e44d7d8e..5021002e4cbc1 100644 --- a/compiler/rustc_privacy/src/lib.rs +++ b/compiler/rustc_privacy/src/lib.rs @@ -26,7 +26,7 @@ use rustc_errors::{MultiSpan, listify}; use rustc_hir::def::{DefKind, Res}; use rustc_hir::def_id::{CRATE_DEF_ID, DefId, LocalDefId, LocalModDefId}; use rustc_hir::intravisit::{self, InferKind, Visitor}; -use rustc_hir::{AmbigArg, ForeignItemKind, ItemId, ItemKind, PatKind}; +use rustc_hir::{AmbigArg, ForeignItemId, ItemId, PatKind}; use rustc_middle::middle::privacy::{EffectiveVisibilities, EffectiveVisibility, Level}; use rustc_middle::query::Providers; use rustc_middle::ty::print::PrintTraitRefExt as _; @@ -599,18 +599,13 @@ impl<'tcx> EmbargoVisitor<'tcx> { DefKind::Struct | DefKind::Union => { // While structs and unions have type privacy, their fields do not. - let item = self.tcx.hir_expect_item(def_id); - if let hir::ItemKind::Struct(_, _, ref struct_def) - | hir::ItemKind::Union(_, _, ref struct_def) = item.kind - { - for field in struct_def.fields() { - let field_vis = self.tcx.local_visibility(field.def_id); - if field_vis.is_accessible_from(module, self.tcx) { - self.reach(field.def_id, macro_ev).ty(); - } + let struct_def = self.tcx.adt_def(def_id); + for field in struct_def.non_enum_variant().fields.iter() { + let def_id = field.did.expect_local(); + let field_vis = self.tcx.local_visibility(def_id); + if field_vis.is_accessible_from(module, self.tcx) { + self.reach(def_id, macro_ev).ty(); } - } else { - bug!("item {:?} with DefKind {:?}", item, def_kind); } } @@ -1640,66 +1635,29 @@ impl<'tcx> PrivateItemsInPublicInterfacesChecker<'_, 'tcx> { self.check(def_id, item_visibility, effective_vis).generics().predicates(); } DefKind::Enum => { - let item = tcx.hir_item(id); - if let hir::ItemKind::Enum(_, _, ref def) = item.kind { - self.check_unnameable(item.owner_id.def_id, effective_vis); - - self.check(item.owner_id.def_id, item_visibility, effective_vis) - .generics() - .predicates(); - - for variant in def.variants { - for field in variant.data.fields() { - self.check(field.def_id, item_visibility, effective_vis).ty(); - } - } - } - } - // Subitems of foreign modules have their own publicity. - DefKind::ForeignMod => { - let item = tcx.hir_item(id); - if let hir::ItemKind::ForeignMod { items, .. } = item.kind { - for &foreign_item in items { - let foreign_item = tcx.hir_foreign_item(foreign_item); - - let ev = self.get(foreign_item.owner_id.def_id); - let vis = tcx.local_visibility(foreign_item.owner_id.def_id); - - if let ForeignItemKind::Type = foreign_item.kind { - self.check_unnameable(foreign_item.owner_id.def_id, ev); - } + self.check_unnameable(def_id, effective_vis); + self.check(def_id, item_visibility, effective_vis).generics().predicates(); - self.check(foreign_item.owner_id.def_id, vis, ev) - .generics() - .predicates() - .ty(); - } + let adt = tcx.adt_def(id.owner_id); + for field in adt.all_fields() { + self.check(field.did.expect_local(), item_visibility, effective_vis).ty(); } } // Subitems of structs and unions have their own publicity. DefKind::Struct | DefKind::Union => { - let item = tcx.hir_item(id); - if let hir::ItemKind::Struct(_, _, ref struct_def) - | hir::ItemKind::Union(_, _, ref struct_def) = item.kind - { - self.check_unnameable(item.owner_id.def_id, effective_vis); - self.check(item.owner_id.def_id, item_visibility, effective_vis) - .generics() - .predicates(); + self.check_unnameable(def_id, effective_vis); + self.check(def_id, item_visibility, effective_vis).generics().predicates(); - for field in struct_def.fields() { - let field_visibility = tcx.local_visibility(field.def_id); - let field_ev = self.get(field.def_id); + let adt = tcx.adt_def(id.owner_id); + for field in adt.all_fields() { + let visibility = min(item_visibility, field.vis.expect_local(), tcx); + let field_ev = self.get(field.did.expect_local()); - self.check( - field.def_id, - min(item_visibility, field_visibility, tcx), - field_ev, - ) - .ty(); - } + self.check(field.did.expect_local(), visibility, field_ev).ty(); } } + // Subitems of foreign modules have their own publicity. + DefKind::ForeignMod => {} // An inherent impl is public when its type is public // Subitems of inherent impls have their own publicity. // A trait impl is public when both its type and its trait are public @@ -1755,6 +1713,19 @@ impl<'tcx> PrivateItemsInPublicInterfacesChecker<'_, 'tcx> { _ => {} } } + + fn check_foreign_item(&mut self, id: ForeignItemId) { + let tcx = self.tcx; + let def_id = id.owner_id.def_id; + let item_visibility = tcx.local_visibility(def_id); + let effective_vis = self.get(def_id); + + if let DefKind::ForeignTy = self.tcx.def_kind(def_id) { + self.check_unnameable(def_id, effective_vis); + } + + self.check(def_id, item_visibility, effective_vis).generics().predicates().ty(); + } } pub fn provide(providers: &mut Providers) { @@ -1783,20 +1754,13 @@ fn check_mod_privacy(tcx: TyCtxt<'_>, module_def_id: LocalModDefId) { if let Some(body_id) = tcx.hir_maybe_body_owned_by(def_id) { visitor.visit_nested_body(body_id.id()); } - } - for id in module.free_items() { - if let ItemKind::Impl(i) = tcx.hir_item(id).kind { - if let Some(item) = i.of_trait { - let trait_ref = tcx.impl_trait_ref(id.owner_id.def_id).unwrap(); - let trait_ref = trait_ref.instantiate_identity(); - visitor.span = item.path.span; - let _ = visitor.visit_def_id( - trait_ref.def_id, - "trait", - &trait_ref.print_only_trait_path(), - ); - } + if let DefKind::Impl { of_trait: true } = tcx.def_kind(def_id) { + let trait_ref = tcx.impl_trait_ref(def_id).unwrap(); + let trait_ref = trait_ref.instantiate_identity(); + visitor.span = tcx.hir_expect_item(def_id).expect_impl().of_trait.unwrap().path.span; + let _ = + visitor.visit_def_id(trait_ref.def_id, "trait", &trait_ref.print_only_trait_path()); } } } @@ -1887,7 +1851,11 @@ fn check_private_in_public(tcx: TyCtxt<'_>, (): ()) { // Check for private types in public interfaces. let mut checker = PrivateItemsInPublicInterfacesChecker { tcx, effective_visibilities }; - for id in tcx.hir_free_items() { + let crate_items = tcx.hir_crate_items(()); + for id in crate_items.free_items() { checker.check_item(id); } + for id in crate_items.foreign_items() { + checker.check_foreign_item(id); + } } diff --git a/tests/ui/privacy/associated-item-privacy-trait.stderr b/tests/ui/privacy/associated-item-privacy-trait.stderr index f79c4cff72fa2..4e9dfa4a83519 100644 --- a/tests/ui/privacy/associated-item-privacy-trait.stderr +++ b/tests/ui/privacy/associated-item-privacy-trait.stderr @@ -75,6 +75,17 @@ LL | priv_trait::mac!(); | = note: this error originates in the macro `priv_trait::mac` (in Nightly builds, run with -Z macro-backtrace for more info) +error: trait `PrivTr` is private + --> $DIR/associated-item-privacy-trait.rs:29:14 + | +LL | impl PrivTr for u8 {} + | ^^^^^^ private trait +... +LL | priv_trait::mac!(); + | ------------------ in this macro invocation + | + = note: this error originates in the macro `priv_trait::mac` (in Nightly builds, run with -Z macro-backtrace for more info) + error: type `priv_signature::Priv` is private --> $DIR/associated-item-privacy-trait.rs:46:21 | @@ -317,16 +328,5 @@ LL | priv_parent_substs::mac!(); | = note: this error originates in the macro `priv_parent_substs::mac` (in Nightly builds, run with -Z macro-backtrace for more info) -error: trait `PrivTr` is private - --> $DIR/associated-item-privacy-trait.rs:29:14 - | -LL | impl PrivTr for u8 {} - | ^^^^^^ private trait -... -LL | priv_trait::mac!(); - | ------------------ in this macro invocation - | - = note: this error originates in the macro `priv_trait::mac` (in Nightly builds, run with -Z macro-backtrace for more info) - error: aborting due to 30 previous errors diff --git a/tests/ui/privacy/private-in-public-warn.stderr b/tests/ui/privacy/private-in-public-warn.stderr index 3743879ffa616..0343002ea3181 100644 --- a/tests/ui/privacy/private-in-public-warn.stderr +++ b/tests/ui/privacy/private-in-public-warn.stderr @@ -84,42 +84,6 @@ note: but type `types::Priv` is only usable at visibility `pub(self)` LL | struct Priv; | ^^^^^^^^^^^ -error: type `types::Priv` is more private than the item `types::ES` - --> $DIR/private-in-public-warn.rs:27:9 - | -LL | pub static ES: Priv; - | ^^^^^^^^^^^^^^^^^^^ static `types::ES` is reachable at visibility `pub(crate)` - | -note: but type `types::Priv` is only usable at visibility `pub(self)` - --> $DIR/private-in-public-warn.rs:9:5 - | -LL | struct Priv; - | ^^^^^^^^^^^ - -error: type `types::Priv` is more private than the item `types::ef1` - --> $DIR/private-in-public-warn.rs:28:9 - | -LL | pub fn ef1(arg: Priv); - | ^^^^^^^^^^^^^^^^^^^^^^ function `types::ef1` is reachable at visibility `pub(crate)` - | -note: but type `types::Priv` is only usable at visibility `pub(self)` - --> $DIR/private-in-public-warn.rs:9:5 - | -LL | struct Priv; - | ^^^^^^^^^^^ - -error: type `types::Priv` is more private than the item `types::ef2` - --> $DIR/private-in-public-warn.rs:29:9 - | -LL | pub fn ef2() -> Priv; - | ^^^^^^^^^^^^^^^^^^^^^ function `types::ef2` is reachable at visibility `pub(crate)` - | -note: but type `types::Priv` is only usable at visibility `pub(self)` - --> $DIR/private-in-public-warn.rs:9:5 - | -LL | struct Priv; - | ^^^^^^^^^^^ - error[E0446]: private type `types::Priv` in public interface --> $DIR/private-in-public-warn.rs:32:9 | @@ -395,6 +359,42 @@ note: but type `Priv2` is only usable at visibility `pub(self)` LL | struct Priv2; | ^^^^^^^^^^^^ +error: type `types::Priv` is more private than the item `types::ES` + --> $DIR/private-in-public-warn.rs:27:9 + | +LL | pub static ES: Priv; + | ^^^^^^^^^^^^^^^^^^^ static `types::ES` is reachable at visibility `pub(crate)` + | +note: but type `types::Priv` is only usable at visibility `pub(self)` + --> $DIR/private-in-public-warn.rs:9:5 + | +LL | struct Priv; + | ^^^^^^^^^^^ + +error: type `types::Priv` is more private than the item `types::ef1` + --> $DIR/private-in-public-warn.rs:28:9 + | +LL | pub fn ef1(arg: Priv); + | ^^^^^^^^^^^^^^^^^^^^^^ function `types::ef1` is reachable at visibility `pub(crate)` + | +note: but type `types::Priv` is only usable at visibility `pub(self)` + --> $DIR/private-in-public-warn.rs:9:5 + | +LL | struct Priv; + | ^^^^^^^^^^^ + +error: type `types::Priv` is more private than the item `types::ef2` + --> $DIR/private-in-public-warn.rs:29:9 + | +LL | pub fn ef2() -> Priv; + | ^^^^^^^^^^^^^^^^^^^^^ function `types::ef2` is reachable at visibility `pub(crate)` + | +note: but type `types::Priv` is only usable at visibility `pub(self)` + --> $DIR/private-in-public-warn.rs:9:5 + | +LL | struct Priv; + | ^^^^^^^^^^^ + warning: bounds on generic parameters in type aliases are not enforced --> $DIR/private-in-public-warn.rs:41:23 | From 3083d8f73094aed3d0ce80d2182c93181d453446 Mon Sep 17 00:00:00 2001 From: usamoi Date: Sun, 20 Jul 2025 21:40:36 +0800 Subject: [PATCH 16/16] generate elf symbol version in raw-dylib --- .../src/back/link/raw_dylib.rs | 97 +++++++++++++++---- compiler/rustc_metadata/messages.ftl | 3 + compiler/rustc_metadata/src/errors.rs | 7 ++ compiler/rustc_metadata/src/native_libs.rs | 15 ++- .../raw-dylib/elf/glibc-x86_64.rs | 74 ++++++++++++++ .../raw-dylib/elf/malformed-link-name.rs | 20 ++++ .../raw-dylib/elf/malformed-link-name.stderr | 26 +++++ 7 files changed, 222 insertions(+), 20 deletions(-) create mode 100644 tests/ui/linkage-attr/raw-dylib/elf/glibc-x86_64.rs create mode 100644 tests/ui/linkage-attr/raw-dylib/elf/malformed-link-name.rs create mode 100644 tests/ui/linkage-attr/raw-dylib/elf/malformed-link-name.stderr diff --git a/compiler/rustc_codegen_ssa/src/back/link/raw_dylib.rs b/compiler/rustc_codegen_ssa/src/back/link/raw_dylib.rs index 74f39022afb7b..81129b8c39135 100644 --- a/compiler/rustc_codegen_ssa/src/back/link/raw_dylib.rs +++ b/compiler/rustc_codegen_ssa/src/back/link/raw_dylib.rs @@ -4,7 +4,7 @@ use std::path::{Path, PathBuf}; use rustc_abi::Endian; use rustc_data_structures::base_n::{CASE_INSENSITIVE, ToBaseN}; -use rustc_data_structures::fx::FxIndexMap; +use rustc_data_structures::fx::{FxHashMap, FxIndexMap}; use rustc_data_structures::stable_hasher::StableHasher; use rustc_hashes::Hash128; use rustc_session::Session; @@ -230,40 +230,66 @@ fn create_elf_raw_dylib_stub(sess: &Session, soname: &str, symbols: &[DllImport] Endian::Little => object::Endianness::Little, Endian::Big => object::Endianness::Big, }; + let mut stub = write::Writer::new(endianness, true, &mut stub_buf); + let mut vers = Vec::new(); + let mut vers_map = FxHashMap::default(); + let mut syms = Vec::new(); + + for symbol in symbols { + let symbol_name = symbol.name.as_str(); + if let Some((name, version_name)) = symbol_name.split_once('@') { + assert!(!version_name.contains('@')); + let dynstr = stub.add_dynamic_string(name.as_bytes()); + let ver = if let Some(&ver_id) = vers_map.get(version_name) { + ver_id + } else { + let id = vers.len(); + vers_map.insert(version_name, id); + let dynstr = stub.add_dynamic_string(version_name.as_bytes()); + vers.push((version_name, dynstr)); + id + }; + syms.push((name, dynstr, Some(ver))); + } else { + let dynstr = stub.add_dynamic_string(symbol_name.as_bytes()); + syms.push((symbol_name, dynstr, None)); + } + } + + let soname = stub.add_dynamic_string(soname.as_bytes()); + // These initial reservations don't reserve any bytes in the binary yet, // they just allocate in the internal data structures. - // First, we crate the dynamic symbol table. It starts with a null symbol + // First, we create the dynamic symbol table. It starts with a null symbol // and then all the symbols and their dynamic strings. stub.reserve_null_dynamic_symbol_index(); - let dynstrs = symbols - .iter() - .map(|sym| { - stub.reserve_dynamic_symbol_index(); - (sym, stub.add_dynamic_string(sym.name.as_str().as_bytes())) - }) - .collect::>(); - - let soname = stub.add_dynamic_string(soname.as_bytes()); + for _ in syms.iter() { + stub.reserve_dynamic_symbol_index(); + } // Reserve the sections. // We have the minimal sections for a dynamic SO and .text where we point our dummy symbols to. stub.reserve_shstrtab_section_index(); let text_section_name = stub.add_section_name(".text".as_bytes()); let text_section = stub.reserve_section_index(); - stub.reserve_dynstr_section_index(); stub.reserve_dynsym_section_index(); + stub.reserve_dynstr_section_index(); + stub.reserve_gnu_versym_section_index(); + stub.reserve_gnu_verdef_section_index(); stub.reserve_dynamic_section_index(); // These reservations now determine the actual layout order of the object file. stub.reserve_file_header(); stub.reserve_shstrtab(); stub.reserve_section_headers(); - stub.reserve_dynstr(); stub.reserve_dynsym(); + stub.reserve_dynstr(); + stub.reserve_gnu_versym(); + stub.reserve_gnu_verdef(1 + vers.len(), 1 + vers.len()); stub.reserve_dynamic(2); // DT_SONAME, DT_NULL // First write the ELF header with the arch information. @@ -342,18 +368,17 @@ fn create_elf_raw_dylib_stub(sess: &Session, soname: &str, symbols: &[DllImport] sh_addralign: 1, sh_entsize: 0, }); - stub.write_dynstr_section_header(0); stub.write_dynsym_section_header(0, 1); + stub.write_dynstr_section_header(0); + stub.write_gnu_versym_section_header(0); + stub.write_gnu_verdef_section_header(0); stub.write_dynamic_section_header(0); - // .dynstr - stub.write_dynstr(); - // .dynsym stub.write_null_dynamic_symbol(); - for (_, name) in dynstrs { + for (_name, dynstr, _ver) in syms.iter().copied() { stub.write_dynamic_symbol(&write::Sym { - name: Some(name), + name: Some(dynstr), st_info: (elf::STB_GLOBAL << 4) | elf::STT_NOTYPE, st_other: elf::STV_DEFAULT, section: Some(text_section), @@ -363,10 +388,44 @@ fn create_elf_raw_dylib_stub(sess: &Session, soname: &str, symbols: &[DllImport] }); } + // .dynstr + stub.write_dynstr(); + + // .gnu_version + stub.write_null_gnu_versym(); + for (_name, _dynstr, ver) in syms.iter().copied() { + stub.write_gnu_versym(if let Some(ver) = ver { + assert!((2 + ver as u16) < elf::VERSYM_HIDDEN); + elf::VERSYM_HIDDEN | (2 + ver as u16) + } else { + 1 + }); + } + + // .gnu_version_d + stub.write_align_gnu_verdef(); + stub.write_gnu_verdef(&write::Verdef { + version: elf::VER_DEF_CURRENT, + flags: elf::VER_FLG_BASE, + index: 1, + aux_count: 1, + name: soname, + }); + for (ver, (_name, dynstr)) in vers.into_iter().enumerate() { + stub.write_gnu_verdef(&write::Verdef { + version: elf::VER_DEF_CURRENT, + flags: 0, + index: 2 + ver as u16, + aux_count: 1, + name: dynstr, + }); + } + // .dynamic // the DT_SONAME will be used by the linker to populate DT_NEEDED // which the loader uses to find the library. // DT_NULL terminates the .dynamic table. + stub.write_align_dynamic(); stub.write_dynamic_string(elf::DT_SONAME, soname); stub.write_dynamic(elf::DT_NULL, 0); diff --git a/compiler/rustc_metadata/messages.ftl b/compiler/rustc_metadata/messages.ftl index 3bef5ca114b89..4d3e879a098f6 100644 --- a/compiler/rustc_metadata/messages.ftl +++ b/compiler/rustc_metadata/messages.ftl @@ -330,3 +330,6 @@ metadata_wasm_import_form = metadata_whole_archive_needs_static = linking modifier `whole-archive` is only compatible with `static` linking kind + +metadata_raw_dylib_malformed = + link name must be well-formed if link kind is `raw-dylib` diff --git a/compiler/rustc_metadata/src/errors.rs b/compiler/rustc_metadata/src/errors.rs index 4a3b43167cfa4..0332dba1077cd 100644 --- a/compiler/rustc_metadata/src/errors.rs +++ b/compiler/rustc_metadata/src/errors.rs @@ -815,3 +815,10 @@ pub struct AsyncDropTypesInDependency { pub extern_crate: Symbol, pub local_crate: Symbol, } + +#[derive(Diagnostic)] +#[diag(metadata_raw_dylib_malformed)] +pub struct RawDylibMalformed { + #[primary_span] + pub span: Span, +} diff --git a/compiler/rustc_metadata/src/native_libs.rs b/compiler/rustc_metadata/src/native_libs.rs index 4d276f814ef25..ed0f084ea83c9 100644 --- a/compiler/rustc_metadata/src/native_libs.rs +++ b/compiler/rustc_metadata/src/native_libs.rs @@ -700,8 +700,21 @@ impl<'tcx> Collector<'tcx> { .link_ordinal .map_or(import_name_type, |ord| Some(PeImportNameType::Ordinal(ord))); + let name = codegen_fn_attrs.link_name.unwrap_or_else(|| self.tcx.item_name(item)); + + if self.tcx.sess.target.binary_format == BinaryFormat::Elf { + let name = name.as_str(); + if name.contains('\0') { + self.tcx.dcx().emit_err(errors::RawDylibMalformed { span }); + } else if let Some((left, right)) = name.split_once('@') + && (left.is_empty() || right.is_empty() || right.contains('@')) + { + self.tcx.dcx().emit_err(errors::RawDylibMalformed { span }); + } + } + DllImport { - name: codegen_fn_attrs.link_name.unwrap_or_else(|| self.tcx.item_name(item)), + name, import_name_type, calling_convention, span, diff --git a/tests/ui/linkage-attr/raw-dylib/elf/glibc-x86_64.rs b/tests/ui/linkage-attr/raw-dylib/elf/glibc-x86_64.rs new file mode 100644 index 0000000000000..a923684d82061 --- /dev/null +++ b/tests/ui/linkage-attr/raw-dylib/elf/glibc-x86_64.rs @@ -0,0 +1,74 @@ +//@ only-x86_64-unknown-linux-gnu +//@ needs-dynamic-linking +//@ run-pass +//@ compile-flags: -Cpanic=abort +//@ edition: 2024 + +#![allow(incomplete_features)] +#![feature(raw_dylib_elf)] +#![no_std] +#![no_main] + +use core::ffi::{c_char, c_int}; + +extern "C" fn callback( + _fpath: *const c_char, + _sb: *const (), + _tflag: c_int, + _ftwbuf: *const (), +) -> c_int { + 0 +} + +#[link(name = "libc.so.6", kind = "raw-dylib", modifiers = "+verbatim")] +unsafe extern "C" { + #[link_name = "nftw@GLIBC_2.2.5"] + unsafe fn nftw_2_2_5( + dirpath: *const c_char, + f: extern "C" fn(*const c_char, *const (), c_int, *const ()) -> c_int, + nopenfd: c_int, + flags: c_int, + ) -> c_int; + #[link_name = "nftw@GLIBC_2.3.3"] + unsafe fn nftw_2_3_3( + dirpath: *const c_char, + f: extern "C" fn(*const c_char, *const (), c_int, *const ()) -> c_int, + nopenfd: c_int, + flags: c_int, + ) -> c_int; + #[link_name = "exit@GLIBC_2.2.5"] + safe fn exit(status: i32) -> !; + unsafe fn __libc_start_main() -> c_int; +} + +#[unsafe(no_mangle)] +extern "C" fn main() -> ! { + unsafe { + // The old `nftw` does not check whether unknown flags are set. + let res = nftw_2_2_5(c".".as_ptr(), callback, 20, 1 << 30); + assert_eq!(res, 0); + } + unsafe { + // The new `nftw` does. + let res = nftw_2_3_3(c".".as_ptr(), callback, 20, 1 << 30); + assert_eq!(res, -1); + } + exit(0); +} + +#[cfg(not(test))] +#[panic_handler] +fn panic_handler(_: &core::panic::PanicInfo<'_>) -> ! { + exit(1); +} + +#[unsafe(no_mangle)] +extern "C" fn rust_eh_personality( + _version: i32, + _actions: i32, + _exception_class: u64, + _exception_object: *mut (), + _context: *mut (), +) -> i32 { + exit(1); +} diff --git a/tests/ui/linkage-attr/raw-dylib/elf/malformed-link-name.rs b/tests/ui/linkage-attr/raw-dylib/elf/malformed-link-name.rs new file mode 100644 index 0000000000000..46e3798284b25 --- /dev/null +++ b/tests/ui/linkage-attr/raw-dylib/elf/malformed-link-name.rs @@ -0,0 +1,20 @@ +//@ only-elf +//@ needs-dynamic-linking +//@ check-fail + +#![feature(raw_dylib_elf)] +#![allow(incomplete_features)] + +#[link(name = "libc.so.6", kind = "raw-dylib", modifiers = "+verbatim")] +unsafe extern "C" { + #[link_name = "exit@"] + pub safe fn exit_0(status: i32) -> !; //~ ERROR link name must be well-formed if link kind is `raw-dylib` + #[link_name = "@GLIBC_2.2.5"] + pub safe fn exit_1(status: i32) -> !; //~ ERROR link name must be well-formed if link kind is `raw-dylib` + #[link_name = "ex\0it@GLIBC_2.2.5"] + pub safe fn exit_2(status: i32) -> !; //~ ERROR link name must be well-formed if link kind is `raw-dylib` + #[link_name = "exit@@GLIBC_2.2.5"] + pub safe fn exit_3(status: i32) -> !; //~ ERROR link name must be well-formed if link kind is `raw-dylib` +} + +fn main() {} diff --git a/tests/ui/linkage-attr/raw-dylib/elf/malformed-link-name.stderr b/tests/ui/linkage-attr/raw-dylib/elf/malformed-link-name.stderr new file mode 100644 index 0000000000000..5a979e7a3b1af --- /dev/null +++ b/tests/ui/linkage-attr/raw-dylib/elf/malformed-link-name.stderr @@ -0,0 +1,26 @@ +error: link name must be well-formed if link kind is `raw-dylib` + --> $DIR/malformed-link-name.rs:11:5 + | +LL | pub safe fn exit_0(status: i32) -> !; + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +error: link name must be well-formed if link kind is `raw-dylib` + --> $DIR/malformed-link-name.rs:13:5 + | +LL | pub safe fn exit_1(status: i32) -> !; + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +error: link name must be well-formed if link kind is `raw-dylib` + --> $DIR/malformed-link-name.rs:15:5 + | +LL | pub safe fn exit_2(status: i32) -> !; + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +error: link name must be well-formed if link kind is `raw-dylib` + --> $DIR/malformed-link-name.rs:17:5 + | +LL | pub safe fn exit_3(status: i32) -> !; + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +error: aborting due to 4 previous errors +