From 599bcb5cf1ea524a6636949726f0724bb3537425 Mon Sep 17 00:00:00 2001 From: Chris Denton Date: Thu, 8 Aug 2024 01:30:39 +0000 Subject: [PATCH 1/4] run-make: enable msvc for redundant-libs --- tests/run-make/redundant-libs/foo.c | 10 ++++++++-- tests/run-make/redundant-libs/rmake.rs | 6 ------ 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/tests/run-make/redundant-libs/foo.c b/tests/run-make/redundant-libs/foo.c index 339ee86c99eae..551b85d182450 100644 --- a/tests/run-make/redundant-libs/foo.c +++ b/tests/run-make/redundant-libs/foo.c @@ -1,2 +1,8 @@ -void foo1() {} -void foo2() {} +#ifdef _MSC_VER +#define DllExport __declspec(dllexport) +#else +#define DllExport +#endif + +DllExport void foo1() {} +DllExport void foo2() {} diff --git a/tests/run-make/redundant-libs/rmake.rs b/tests/run-make/redundant-libs/rmake.rs index fb1b3bca8ade3..43bb30bde702d 100644 --- a/tests/run-make/redundant-libs/rmake.rs +++ b/tests/run-make/redundant-libs/rmake.rs @@ -10,12 +10,6 @@ //@ ignore-cross-compile // Reason: the compiled binary is executed -//@ ignore-windows-msvc -// Reason: this test links libraries via link.exe, which only accepts the import library -// for the dynamic library, i.e. `foo.dll.lib`. However, build_native_dynamic_lib only -// produces `foo.dll` - the dynamic library itself. To make this test work on MSVC, one -// would need to derive the import library from the dynamic library. -// See https://stackoverflow.com/questions/9360280/ use run_make_support::{ build_native_dynamic_lib, build_native_static_lib, cwd, is_msvc, rfs, run, rustc, From 06d09ad44871454bd0bac175f839d63262781d2a Mon Sep 17 00:00:00 2001 From: Chris Denton Date: Thu, 8 Aug 2024 02:11:55 +0000 Subject: [PATCH 2/4] run-make: run fmt-write-bloat on Windows --- tests/run-make/fmt-write-bloat/main.rs | 3 ++- tests/run-make/fmt-write-bloat/rmake.rs | 7 ++----- 2 files changed, 4 insertions(+), 6 deletions(-) diff --git a/tests/run-make/fmt-write-bloat/main.rs b/tests/run-make/fmt-write-bloat/main.rs index e86c48014c3aa..55e201549ad21 100644 --- a/tests/run-make/fmt-write-bloat/main.rs +++ b/tests/run-make/fmt-write-bloat/main.rs @@ -5,7 +5,8 @@ use core::fmt; use core::fmt::Write; -#[link(name = "c")] +#[cfg_attr(not(target_env = "msvc"), link(name = "c"))] +#[cfg_attr(target_env = "msvc", link(name = "libcmt"))] extern "C" {} struct Dummy; diff --git a/tests/run-make/fmt-write-bloat/rmake.rs b/tests/run-make/fmt-write-bloat/rmake.rs index 4ae226ec0e234..141069cfb7d36 100644 --- a/tests/run-make/fmt-write-bloat/rmake.rs +++ b/tests/run-make/fmt-write-bloat/rmake.rs @@ -15,14 +15,11 @@ //! `NO_DEBUG_ASSERTIONS=1`). If debug assertions are disabled, then we can check for the absence of //! additional `usize` formatting and padding related symbols. -// Reason: This test is `ignore-windows` because the `no_std` test (using `#[link(name = "c")])` -// doesn't link on windows. -//@ ignore-windows //@ ignore-cross-compile use run_make_support::env::no_debug_assertions; -use run_make_support::rustc; use run_make_support::symbols::any_symbol_contains; +use run_make_support::{bin_name, rustc}; fn main() { rustc().input("main.rs").opt().run(); @@ -33,5 +30,5 @@ fn main() { // otherwise, add them to the list of symbols to deny. panic_syms.extend_from_slice(&["panicking", "panic_fmt", "pad_integral", "Display"]); } - assert!(!any_symbol_contains("main", &panic_syms)); + assert!(!any_symbol_contains(&bin_name("main"), &panic_syms)); } From 7869400e589ca4e88cebb1da80a420f8e9042cdf Mon Sep 17 00:00:00 2001 From: Zachary S Date: Wed, 7 Aug 2024 13:04:43 -0500 Subject: [PATCH 3/4] Update E0517 message to reflect RFC 2195. --- .../src/error_codes/E0517.md | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/compiler/rustc_error_codes/src/error_codes/E0517.md b/compiler/rustc_error_codes/src/error_codes/E0517.md index ae802245bd1d7..5354a08bf31a7 100644 --- a/compiler/rustc_error_codes/src/error_codes/E0517.md +++ b/compiler/rustc_error_codes/src/error_codes/E0517.md @@ -25,14 +25,17 @@ impl Foo { These attributes do not work on typedefs, since typedefs are just aliases. Representations like `#[repr(u8)]`, `#[repr(i64)]` are for selecting the -discriminant size for enums with no data fields on any of the variants, e.g. -`enum Color {Red, Blue, Green}`, effectively setting the size of the enum to -the size of the provided type. Such an enum can be cast to a value of the same -type as well. In short, `#[repr(u8)]` makes the enum behave like an integer -with a constrained set of allowed values. +discriminant size for enums. For enums with no data fields on any of the +variants, e.g. `enum Color {Red, Blue, Green}`, this effectively sets the size +of the enum to the size of the provided type. Such an enum can be cast to a +value of the same type as well. In short, `#[repr(u8)]` makes a field-less enum +behave like an integer with a constrained set of allowed values. -Only field-less enums can be cast to numerical primitives, so this attribute -will not apply to structs. +For a description of how `#[repr(C)]` and representations like `#[repr(u8)]` +affect the layout of enums with data fields, see [RFC 2195][rfc2195]. + +Only field-less enums can be cast to numerical primitives. Representations like +`#[repr(u8)]` will not apply to structs. `#[repr(packed)]` reduces padding to make the struct size smaller. The representation of enums isn't strictly defined in Rust, and this attribute @@ -42,3 +45,5 @@ won't work on enums. types (i.e., `u8`, `i32`, etc) a representation that permits vectorization via SIMD. This doesn't make much sense for enums since they don't consist of a single list of data. + +[rfc2195]: https://github.com/rust-lang/rfcs/blob/master/text/2195-really-tagged-unions.md From 67518d0d9763983c7d0f4ea8c992544318fa9c11 Mon Sep 17 00:00:00 2001 From: Chris Denton Date: Thu, 8 Aug 2024 05:12:18 +0000 Subject: [PATCH 4/4] Link to msvcrt if not crt-static --- tests/run-make/fmt-write-bloat/main.rs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/tests/run-make/fmt-write-bloat/main.rs b/tests/run-make/fmt-write-bloat/main.rs index 55e201549ad21..2ca5ff1ad884c 100644 --- a/tests/run-make/fmt-write-bloat/main.rs +++ b/tests/run-make/fmt-write-bloat/main.rs @@ -6,7 +6,8 @@ use core::fmt; use core::fmt::Write; #[cfg_attr(not(target_env = "msvc"), link(name = "c"))] -#[cfg_attr(target_env = "msvc", link(name = "libcmt"))] +#[cfg_attr(all(target_env = "msvc", target_feature = "crt-static"), link(name = "libcmt"))] +#[cfg_attr(all(target_env = "msvc", not(target_feature = "crt-static")), link(name = "msvcrt"))] extern "C" {} struct Dummy;