From efaf3eb8a06f2ad55334af6166d324fd79d8c25f Mon Sep 17 00:00:00 2001 From: Folkert de Vries Date: Thu, 12 Jun 2025 15:06:12 +0200 Subject: [PATCH 1/8] ignore `run-make` tests that need `std` on `no_std` targets In particular, anything that includes `none` in the target tripple, and `nvptx64-nvidia-cuda` --- tests/run-make/CURRENT_RUSTC_VERSION/rmake.rs | 1 + .../allow-warnings-cmdline-stability/rmake.rs | 1 + tests/run-make/artifact-incr-cache-no-obj/rmake.rs | 2 ++ tests/run-make/artifact-incr-cache/rmake.rs | 2 ++ tests/run-make/bin-emit-no-symbols/rmake.rs | 2 ++ tests/run-make/box-struct-no-segfault/rmake.rs | 2 ++ tests/run-make/checksum-freshness/rmake.rs | 1 + tests/run-make/compiler-lookup-paths-2/rmake.rs | 2 ++ tests/run-make/compiler-lookup-paths/rmake.rs | 2 ++ tests/run-make/const-trait-stable-toolchain/rmake.rs | 2 ++ tests/run-make/crate-circular-deps-link/rmake.rs | 2 ++ tests/run-make/cross-lang-lto-upstream-rlibs/rmake.rs | 2 ++ tests/run-make/cross-lang-lto/rmake.rs | 2 ++ tests/run-make/debugger-visualizer-dep-info/rmake.rs | 2 ++ tests/run-make/dep-info/rmake.rs | 2 ++ .../diagnostics-traits-from-duplicate-crates/rmake.rs | 2 ++ tests/run-make/doctests-merge/rmake.rs | 1 + tests/run-make/doctests-runtool/rmake.rs | 2 ++ tests/run-make/dump-mono-stats/rmake.rs | 2 ++ tests/run-make/duplicate-output-flavors/rmake.rs | 1 + tests/run-make/embed-metadata/rmake.rs | 2 ++ tests/run-make/embed-source-dwarf/rmake.rs | 1 + tests/run-make/emit-named-files/rmake.rs | 1 + tests/run-make/emit-path-unhashed/rmake.rs | 2 ++ tests/run-make/emit-stack-sizes/rmake.rs | 1 + tests/run-make/emit-to-stdout/rmake.rs | 1 + tests/run-make/env-dep-info/rmake.rs | 2 ++ .../error-found-staticlib-instead-crate/rmake.rs | 2 ++ tests/run-make/exit-code/rmake.rs | 2 ++ tests/run-make/export/disambiguator/rmake.rs | 11 +++-------- tests/run-make/export/extern-opt/rmake.rs | 8 +++----- tests/run-make/export/simple/rmake.rs | 11 +++-------- tests/run-make/extern-diff-internal-name/rmake.rs | 2 ++ tests/run-make/extern-flag-fun/rmake.rs | 2 ++ tests/run-make/extern-flag-rename-transitive/rmake.rs | 2 ++ tests/run-make/extern-multiple-copies/rmake.rs | 2 ++ tests/run-make/extern-multiple-copies2/rmake.rs | 2 ++ tests/run-make/ice-static-mir/rmake.rs | 2 ++ tests/run-make/include-all-symbols-linking/rmake.rs | 1 + tests/run-make/include-bytes-deps/rmake.rs | 2 ++ .../run-make/incremental-debugger-visualizer/rmake.rs | 2 ++ tests/run-make/inline-always-many-cgu/rmake.rs | 1 + tests/run-make/invalid-so/rmake.rs | 2 ++ tests/run-make/invalid-staticlib/rmake.rs | 2 ++ tests/run-make/invalid-symlink-search-path/rmake.rs | 1 + tests/run-make/invalid-tmpdir-env-var/rmake.rs | 2 ++ .../issue-107495-archive-permissions/rmake.rs | 1 + .../run-make/issue-125484-used-dependencies/rmake.rs | 2 ++ tests/run-make/json-error-no-offset/rmake.rs | 2 ++ tests/run-make/lib-trait-for-trait-no-ice/rmake.rs | 2 ++ tests/run-make/link-arg/rmake.rs | 2 ++ tests/run-make/link-args-order/rmake.rs | 2 ++ tests/run-make/link-dedup/rmake.rs | 2 ++ tests/run-make/linker-warning/rmake.rs | 1 + tests/run-make/llvm-outputs/rmake.rs | 1 + tests/run-make/lto-avoid-object-duplication/rmake.rs | 1 + tests/run-make/manual-crate-name/rmake.rs | 1 + tests/run-make/many-crates-but-no-match/rmake.rs | 2 ++ tests/run-make/metadata-dep-info/rmake.rs | 2 ++ tests/run-make/metadata-only-crate-no-ice/rmake.rs | 2 ++ tests/run-make/missing-crate-dependency/rmake.rs | 2 ++ tests/run-make/multiple-emits/rmake.rs | 1 + tests/run-make/native-lib-alt-naming/rmake.rs | 2 ++ .../native-link-modifier-verbatim-linker/rmake.rs | 1 + .../native-link-modifier-verbatim-rustc/rmake.rs | 2 ++ tests/run-make/no-builtins-attribute/rmake.rs | 2 ++ tests/run-make/no-builtins-lto/rmake.rs | 2 ++ tests/run-make/non-unicode-env/rmake.rs | 1 + .../run-make/non-unicode-in-incremental-dir/rmake.rs | 1 + tests/run-make/notify-all-emit-artifacts/rmake.rs | 2 ++ tests/run-make/optimization-remarks-dir/rmake.rs | 2 ++ tests/run-make/overwrite-input/rmake.rs | 2 ++ tests/run-make/parallel-rustc-no-overwrite/rmake.rs | 2 ++ tests/run-make/pass-linker-flags-from-dep/rmake.rs | 2 ++ tests/run-make/pass-linker-flags/rmake.rs | 2 ++ tests/run-make/pgo-gen-no-imp-symbols/rmake.rs | 2 ++ tests/run-make/pretty-print-with-dep-file/rmake.rs | 2 ++ tests/run-make/proc-macro-three-crates/rmake.rs | 2 ++ tests/run-make/remap-path-prefix-dwarf/rmake.rs | 1 + tests/run-make/remap-path-prefix/rmake.rs | 2 ++ tests/run-make/repr128-dwarf/rmake.rs | 1 + tests/run-make/reproducible-build-2/rmake.rs | 1 + tests/run-make/resolve-rename/rmake.rs | 2 ++ .../rlib-format-packed-bundled-libs-2/rmake.rs | 2 ++ tests/run-make/rustc-macro-dep-files/rmake.rs | 2 ++ .../rustdoc-scrape-examples-invalid-expr/rmake.rs | 1 + .../rustdoc-scrape-examples-multiple/rmake.rs | 1 + .../rustdoc-scrape-examples-ordering/rmake.rs | 1 + tests/run-make/rustdoc-scrape-examples-remap/rmake.rs | 1 + tests/run-make/rustdoc-scrape-examples-test/rmake.rs | 1 + .../rustdoc-scrape-examples-whitespace/rmake.rs | 1 + .../rustdoc-with-short-out-dir-option/rmake.rs | 1 + tests/run-make/share-generics-dylib/rmake.rs | 2 ++ tests/run-make/short-ice/rmake.rs | 1 + tests/run-make/stable-symbol-names/rmake.rs | 2 ++ tests/run-make/staticlib-blank-lib/rmake.rs | 2 ++ tests/run-make/staticlib-broken-bitcode/rmake.rs | 2 ++ tests/run-make/staticlib-thin-archive/rmake.rs | 2 ++ tests/run-make/stdin-rustc/rmake.rs | 1 + tests/run-make/symbol-visibility/rmake.rs | 2 ++ tests/run-make/symbols-include-type-name/rmake.rs | 2 ++ tests/run-make/track-path-dep-info/rmake.rs | 2 ++ tests/run-make/type-mismatch-same-crate-name/rmake.rs | 2 ++ tests/run-make/unknown-mod-stdin/rmake.rs | 2 ++ .../rmake.rs | 1 + .../run-make/unstable-feature-usage-metrics/rmake.rs | 1 + tests/run-make/use-suggestions-rust-2018/rmake.rs | 2 ++ tests/run-make/used/rmake.rs | 2 ++ 108 files changed, 184 insertions(+), 21 deletions(-) diff --git a/tests/run-make/CURRENT_RUSTC_VERSION/rmake.rs b/tests/run-make/CURRENT_RUSTC_VERSION/rmake.rs index ba887b3d791d1..8824a498306e4 100644 --- a/tests/run-make/CURRENT_RUSTC_VERSION/rmake.rs +++ b/tests/run-make/CURRENT_RUSTC_VERSION/rmake.rs @@ -1,3 +1,4 @@ +//@ needs-target-std // ignore-tidy-linelength // Check that the `CURRENT_RUSTC_VERSION` placeholder is correctly replaced by the current diff --git a/tests/run-make/allow-warnings-cmdline-stability/rmake.rs b/tests/run-make/allow-warnings-cmdline-stability/rmake.rs index 22a31266176b4..66ca3eb3383bd 100644 --- a/tests/run-make/allow-warnings-cmdline-stability/rmake.rs +++ b/tests/run-make/allow-warnings-cmdline-stability/rmake.rs @@ -1,3 +1,4 @@ +//@ needs-target-std // Test that `-Awarnings` suppresses warnings for unstable APIs. use run_make_support::rustc; diff --git a/tests/run-make/artifact-incr-cache-no-obj/rmake.rs b/tests/run-make/artifact-incr-cache-no-obj/rmake.rs index d5bc46dff4706..8395b38f6125a 100644 --- a/tests/run-make/artifact-incr-cache-no-obj/rmake.rs +++ b/tests/run-make/artifact-incr-cache-no-obj/rmake.rs @@ -1,3 +1,5 @@ +//@ needs-target-std +// // emitting an object file is not necessary if user didn't ask for one // // This test is similar to run-make/artifact-incr-cache but it doesn't diff --git a/tests/run-make/artifact-incr-cache/rmake.rs b/tests/run-make/artifact-incr-cache/rmake.rs index b4b63313cfc40..670c851e1e007 100644 --- a/tests/run-make/artifact-incr-cache/rmake.rs +++ b/tests/run-make/artifact-incr-cache/rmake.rs @@ -1,3 +1,5 @@ +//@ needs-target-std +// // rustc should be able to emit required files (asm, llvm-*, etc) during incremental // compilation on the first pass by running the code gen as well as on subsequent runs - // extracting them from the cache diff --git a/tests/run-make/bin-emit-no-symbols/rmake.rs b/tests/run-make/bin-emit-no-symbols/rmake.rs index 5586e53c05084..2faeb20025bb7 100644 --- a/tests/run-make/bin-emit-no-symbols/rmake.rs +++ b/tests/run-make/bin-emit-no-symbols/rmake.rs @@ -1,3 +1,5 @@ +//@ needs-target-std +// // When setting the crate type as a "bin" (in app.rs), // this could cause a bug where some symbols would not be // emitted in the object files. This has been fixed, and diff --git a/tests/run-make/box-struct-no-segfault/rmake.rs b/tests/run-make/box-struct-no-segfault/rmake.rs index 1bbefd03541a2..06dcf61e9ccd8 100644 --- a/tests/run-make/box-struct-no-segfault/rmake.rs +++ b/tests/run-make/box-struct-no-segfault/rmake.rs @@ -1,3 +1,5 @@ +//@ needs-target-std +// // The crate "foo" tied to this test executes a very specific function, // which involves boxing an instance of the struct Foo. However, // this once caused a segmentation fault in cargo release builds due to an LLVM diff --git a/tests/run-make/checksum-freshness/rmake.rs b/tests/run-make/checksum-freshness/rmake.rs index 071db6b145b51..60e4f81269b17 100644 --- a/tests/run-make/checksum-freshness/rmake.rs +++ b/tests/run-make/checksum-freshness/rmake.rs @@ -1,3 +1,4 @@ +//@ needs-target-std use run_make_support::{rfs, rustc}; fn main() { diff --git a/tests/run-make/compiler-lookup-paths-2/rmake.rs b/tests/run-make/compiler-lookup-paths-2/rmake.rs index 99efb157b5378..5401787b9bf98 100644 --- a/tests/run-make/compiler-lookup-paths-2/rmake.rs +++ b/tests/run-make/compiler-lookup-paths-2/rmake.rs @@ -1,3 +1,5 @@ +//@ needs-target-std +// // This test checks that extern crate declarations in Cargo without a corresponding declaration // in the manifest of a dependency are NOT allowed. The last rustc call does it anyways, which // should result in a compilation failure. diff --git a/tests/run-make/compiler-lookup-paths/rmake.rs b/tests/run-make/compiler-lookup-paths/rmake.rs index 3ffa6e0592f0c..0e00f9b340019 100644 --- a/tests/run-make/compiler-lookup-paths/rmake.rs +++ b/tests/run-make/compiler-lookup-paths/rmake.rs @@ -1,3 +1,5 @@ +//@ needs-target-std +// // Since #19941, rustc can accept specifications on its library search paths. // This test runs Rust programs with varied library dependencies, expecting them // to succeed or fail depending on the situation. diff --git a/tests/run-make/const-trait-stable-toolchain/rmake.rs b/tests/run-make/const-trait-stable-toolchain/rmake.rs index 241de11ed59ca..09a7c27a1064a 100644 --- a/tests/run-make/const-trait-stable-toolchain/rmake.rs +++ b/tests/run-make/const-trait-stable-toolchain/rmake.rs @@ -1,3 +1,5 @@ +//@ needs-target-std +// // Test output of const super trait errors in both stable and nightly. // We don't want to provide suggestions on stable that only make sense in nightly. diff --git a/tests/run-make/crate-circular-deps-link/rmake.rs b/tests/run-make/crate-circular-deps-link/rmake.rs index 7cc28ac93e148..6771fdec7e8a9 100644 --- a/tests/run-make/crate-circular-deps-link/rmake.rs +++ b/tests/run-make/crate-circular-deps-link/rmake.rs @@ -1,3 +1,5 @@ +//@ needs-target-std +// // Test that previously triggered a linker failure with root cause // similar to one found in the issue #69368. // diff --git a/tests/run-make/cross-lang-lto-upstream-rlibs/rmake.rs b/tests/run-make/cross-lang-lto-upstream-rlibs/rmake.rs index f0b8fa75bee3e..7fb0f6903974c 100644 --- a/tests/run-make/cross-lang-lto-upstream-rlibs/rmake.rs +++ b/tests/run-make/cross-lang-lto-upstream-rlibs/rmake.rs @@ -1,3 +1,5 @@ +//@ needs-target-std +// // When using the flag -C linker-plugin-lto, static libraries could lose their upstream object // files during compilation. This bug was fixed in #53031, and this test compiles a staticlib // dependent on upstream, checking that the upstream object file still exists after no LTO and diff --git a/tests/run-make/cross-lang-lto/rmake.rs b/tests/run-make/cross-lang-lto/rmake.rs index 50d37460d8dbb..8773070b1a9e7 100644 --- a/tests/run-make/cross-lang-lto/rmake.rs +++ b/tests/run-make/cross-lang-lto/rmake.rs @@ -1,3 +1,5 @@ +//@ needs-target-std +// // This test checks that the object files we generate are actually // LLVM bitcode files (as used by linker LTO plugins) when compiling with // -Clinker-plugin-lto. diff --git a/tests/run-make/debugger-visualizer-dep-info/rmake.rs b/tests/run-make/debugger-visualizer-dep-info/rmake.rs index f5cf39157ac65..95a095e49d842 100644 --- a/tests/run-make/debugger-visualizer-dep-info/rmake.rs +++ b/tests/run-make/debugger-visualizer-dep-info/rmake.rs @@ -1,3 +1,5 @@ +//@ needs-target-std +// // This test checks that files referenced via #[debugger_visualizer] are // included in `--emit dep-info` output. // See https://github.com/rust-lang/rust/pull/111641 diff --git a/tests/run-make/dep-info/rmake.rs b/tests/run-make/dep-info/rmake.rs index 508569b7671c1..8cef6e87f7cfb 100644 --- a/tests/run-make/dep-info/rmake.rs +++ b/tests/run-make/dep-info/rmake.rs @@ -1,3 +1,5 @@ +//@ needs-target-std +// // This is a simple smoke test for rustc's `--emit dep-info` feature. It prints out // information about dependencies in a Makefile-compatible format, as a `.d` file. // Note that this test does not check that the `.d` file is Makefile-compatible. diff --git a/tests/run-make/diagnostics-traits-from-duplicate-crates/rmake.rs b/tests/run-make/diagnostics-traits-from-duplicate-crates/rmake.rs index 32c4cf3389647..5bc0a0c9519fd 100644 --- a/tests/run-make/diagnostics-traits-from-duplicate-crates/rmake.rs +++ b/tests/run-make/diagnostics-traits-from-duplicate-crates/rmake.rs @@ -1,3 +1,5 @@ +//@ needs-target-std +// // Non-regression test for issue #132920 where multiple versions of the same crate are present in // the dependency graph, and an unexpected error in a dependent crate caused an ICE in the // unsatisfied bounds diagnostics for traits present in multiple crate versions. diff --git a/tests/run-make/doctests-merge/rmake.rs b/tests/run-make/doctests-merge/rmake.rs index a88b050c50fa8..8236997d72d71 100644 --- a/tests/run-make/doctests-merge/rmake.rs +++ b/tests/run-make/doctests-merge/rmake.rs @@ -1,3 +1,4 @@ +//@ needs-target-std use std::path::Path; use run_make_support::{cwd, diff, rustc, rustdoc}; diff --git a/tests/run-make/doctests-runtool/rmake.rs b/tests/run-make/doctests-runtool/rmake.rs index 817001c514b52..aaba417491028 100644 --- a/tests/run-make/doctests-runtool/rmake.rs +++ b/tests/run-make/doctests-runtool/rmake.rs @@ -1,3 +1,5 @@ +//@ needs-target-std +// // Tests behavior of rustdoc `--test-runtool`. use std::path::PathBuf; diff --git a/tests/run-make/dump-mono-stats/rmake.rs b/tests/run-make/dump-mono-stats/rmake.rs index f4142e0a31c3e..8ebc5758d9d79 100644 --- a/tests/run-make/dump-mono-stats/rmake.rs +++ b/tests/run-make/dump-mono-stats/rmake.rs @@ -1,3 +1,5 @@ +//@ needs-target-std +// // A flag named dump-mono-stats was added to the compiler in 2022, which // collects stats on instantiation of items and their associated costs. // This test checks that the output stat file exists, and that it contains diff --git a/tests/run-make/duplicate-output-flavors/rmake.rs b/tests/run-make/duplicate-output-flavors/rmake.rs index 09545228807bc..f07339aceb92b 100644 --- a/tests/run-make/duplicate-output-flavors/rmake.rs +++ b/tests/run-make/duplicate-output-flavors/rmake.rs @@ -1,3 +1,4 @@ +//@ needs-target-std use run_make_support::rustc; fn main() { diff --git a/tests/run-make/embed-metadata/rmake.rs b/tests/run-make/embed-metadata/rmake.rs index acefb18648440..a41716d15429c 100644 --- a/tests/run-make/embed-metadata/rmake.rs +++ b/tests/run-make/embed-metadata/rmake.rs @@ -1,3 +1,5 @@ +//@ needs-target-std +// // Tests the -Zembed-metadata compiler flag. // Tracking issue: https://github.com/rust-lang/rust/issues/139165 diff --git a/tests/run-make/embed-source-dwarf/rmake.rs b/tests/run-make/embed-source-dwarf/rmake.rs index 550c8b9b3c903..99fad359054b6 100644 --- a/tests/run-make/embed-source-dwarf/rmake.rs +++ b/tests/run-make/embed-source-dwarf/rmake.rs @@ -1,3 +1,4 @@ +//@ needs-target-std //@ ignore-windows //@ ignore-apple diff --git a/tests/run-make/emit-named-files/rmake.rs b/tests/run-make/emit-named-files/rmake.rs index 1570e1adc2561..b482fb3268b9e 100644 --- a/tests/run-make/emit-named-files/rmake.rs +++ b/tests/run-make/emit-named-files/rmake.rs @@ -1,3 +1,4 @@ +//@ needs-target-std use std::path::Path; use run_make_support::{rfs, rustc}; diff --git a/tests/run-make/emit-path-unhashed/rmake.rs b/tests/run-make/emit-path-unhashed/rmake.rs index a97153e37dd9c..5d5256621ceaf 100644 --- a/tests/run-make/emit-path-unhashed/rmake.rs +++ b/tests/run-make/emit-path-unhashed/rmake.rs @@ -1,3 +1,5 @@ +//@ needs-target-std +// // Specifying how rustc outputs a file can be done in different ways, such as // the output flag or the KIND=NAME syntax. However, some of these methods used // to result in different hashes on output files even though they yielded the diff --git a/tests/run-make/emit-stack-sizes/rmake.rs b/tests/run-make/emit-stack-sizes/rmake.rs index 53cc9ee5943f8..886e875cfae8c 100644 --- a/tests/run-make/emit-stack-sizes/rmake.rs +++ b/tests/run-make/emit-stack-sizes/rmake.rs @@ -6,6 +6,7 @@ // this diagnostics information should be located. // See https://github.com/rust-lang/rust/pull/51946 +//@ needs-target-std //@ ignore-windows //@ ignore-apple // Reason: this feature only works when the output object format is ELF. diff --git a/tests/run-make/emit-to-stdout/rmake.rs b/tests/run-make/emit-to-stdout/rmake.rs index a9a3796731b4b..19c15b72fe475 100644 --- a/tests/run-make/emit-to-stdout/rmake.rs +++ b/tests/run-make/emit-to-stdout/rmake.rs @@ -1,3 +1,4 @@ +//@ needs-target-std //! If `-o -` or `--emit KIND=-` is provided, output should be written to stdout //! instead. Binary output (`obj`, `llvm-bc`, `link` and `metadata`) //! being written this way will result in an error if stdout is a tty. diff --git a/tests/run-make/env-dep-info/rmake.rs b/tests/run-make/env-dep-info/rmake.rs index 5b51a5476f491..97006a632057a 100644 --- a/tests/run-make/env-dep-info/rmake.rs +++ b/tests/run-make/env-dep-info/rmake.rs @@ -1,3 +1,5 @@ +//@ needs-target-std +// // Inside dep-info emit files, #71858 made it so all accessed environment // variables are usefully printed. This test checks that this feature works // as intended by checking if the environment variables used in compilation diff --git a/tests/run-make/error-found-staticlib-instead-crate/rmake.rs b/tests/run-make/error-found-staticlib-instead-crate/rmake.rs index 8c707092b7e44..15f09c83e2007 100644 --- a/tests/run-make/error-found-staticlib-instead-crate/rmake.rs +++ b/tests/run-make/error-found-staticlib-instead-crate/rmake.rs @@ -1,3 +1,5 @@ +//@ needs-target-std +// // When rustc is looking for a crate but is given a staticlib instead, // the error message should be helpful and indicate precisely the cause // of the compilation failure. diff --git a/tests/run-make/exit-code/rmake.rs b/tests/run-make/exit-code/rmake.rs index d3dcc04428cb6..5fdf920b55a69 100644 --- a/tests/run-make/exit-code/rmake.rs +++ b/tests/run-make/exit-code/rmake.rs @@ -1,3 +1,5 @@ +//@ needs-target-std +// // Test that we exit with the correct exit code for successful / unsuccessful / ICE compilations use run_make_support::{rustc, rustdoc}; diff --git a/tests/run-make/export/disambiguator/rmake.rs b/tests/run-make/export/disambiguator/rmake.rs index 743db1933fb4e..f855e42d08ee8 100644 --- a/tests/run-make/export/disambiguator/rmake.rs +++ b/tests/run-make/export/disambiguator/rmake.rs @@ -1,12 +1,7 @@ +//@ needs-target-std use run_make_support::rustc; fn main() { - rustc() - .env("RUSTC_FORCE_RUSTC_VERSION", "1") - .input("libr.rs") - .run(); - rustc() - .env("RUSTC_FORCE_RUSTC_VERSION", "2") - .input("app.rs") - .run(); + rustc().env("RUSTC_FORCE_RUSTC_VERSION", "1").input("libr.rs").run(); + rustc().env("RUSTC_FORCE_RUSTC_VERSION", "2").input("app.rs").run(); } diff --git a/tests/run-make/export/extern-opt/rmake.rs b/tests/run-make/export/extern-opt/rmake.rs index 821e2eb214919..a2f9ba28c2f5c 100644 --- a/tests/run-make/export/extern-opt/rmake.rs +++ b/tests/run-make/export/extern-opt/rmake.rs @@ -1,10 +1,8 @@ -use run_make_support::{rustc, dynamic_lib_name}; +//@ needs-target-std +use run_make_support::{dynamic_lib_name, rustc}; fn main() { - rustc() - .env("RUSTC_FORCE_RUSTC_VERSION", "1") - .input("libr.rs") - .run(); + rustc().env("RUSTC_FORCE_RUSTC_VERSION", "1").input("libr.rs").run(); rustc() .env("RUSTC_FORCE_RUSTC_VERSION", "2") diff --git a/tests/run-make/export/simple/rmake.rs b/tests/run-make/export/simple/rmake.rs index 743db1933fb4e..f855e42d08ee8 100644 --- a/tests/run-make/export/simple/rmake.rs +++ b/tests/run-make/export/simple/rmake.rs @@ -1,12 +1,7 @@ +//@ needs-target-std use run_make_support::rustc; fn main() { - rustc() - .env("RUSTC_FORCE_RUSTC_VERSION", "1") - .input("libr.rs") - .run(); - rustc() - .env("RUSTC_FORCE_RUSTC_VERSION", "2") - .input("app.rs") - .run(); + rustc().env("RUSTC_FORCE_RUSTC_VERSION", "1").input("libr.rs").run(); + rustc().env("RUSTC_FORCE_RUSTC_VERSION", "2").input("app.rs").run(); } diff --git a/tests/run-make/extern-diff-internal-name/rmake.rs b/tests/run-make/extern-diff-internal-name/rmake.rs index 1a7f34d65bc2a..1bae8decb0528 100644 --- a/tests/run-make/extern-diff-internal-name/rmake.rs +++ b/tests/run-make/extern-diff-internal-name/rmake.rs @@ -1,3 +1,5 @@ +//@ needs-target-std +// // In the following scenario: // 1. The crate foo, is referenced multiple times // 2. --extern foo=./path/to/libbar.rlib is specified to rustc diff --git a/tests/run-make/extern-flag-fun/rmake.rs b/tests/run-make/extern-flag-fun/rmake.rs index c1825f6bbb888..181a76b7cfa0c 100644 --- a/tests/run-make/extern-flag-fun/rmake.rs +++ b/tests/run-make/extern-flag-fun/rmake.rs @@ -1,3 +1,5 @@ +//@ needs-target-std +// // The --extern flag can override the default crate search of // the compiler and directly fetch a given path. There are a few rules // to follow: for example, there can't be more than one rlib, the crates must diff --git a/tests/run-make/extern-flag-rename-transitive/rmake.rs b/tests/run-make/extern-flag-rename-transitive/rmake.rs index 0090d487f03d6..c5bff7bbb696a 100644 --- a/tests/run-make/extern-flag-rename-transitive/rmake.rs +++ b/tests/run-make/extern-flag-rename-transitive/rmake.rs @@ -1,3 +1,5 @@ +//@ needs-target-std +// // In this test, baz.rs is looking for an extern crate "a" which // does not exist, and can only run through the --extern rustc flag // defining that the "a" crate is in fact just "foo". This test diff --git a/tests/run-make/extern-multiple-copies/rmake.rs b/tests/run-make/extern-multiple-copies/rmake.rs index 8b67e6d9facfc..d9d769d178c37 100644 --- a/tests/run-make/extern-multiple-copies/rmake.rs +++ b/tests/run-make/extern-multiple-copies/rmake.rs @@ -1,3 +1,5 @@ +//@ needs-target-std +// // In this test, the rust library foo1 exists in two different locations, but only one // is required by the --extern flag. This test checks that the copy is ignored (as --extern // demands fetching only the original instance of foo1) and that no error is emitted, resulting diff --git a/tests/run-make/extern-multiple-copies2/rmake.rs b/tests/run-make/extern-multiple-copies2/rmake.rs index 59913bfa42bb5..4188d5bdc182f 100644 --- a/tests/run-make/extern-multiple-copies2/rmake.rs +++ b/tests/run-make/extern-multiple-copies2/rmake.rs @@ -1,3 +1,5 @@ +//@ needs-target-std +// // Almost identical to `extern-multiple-copies`, but with a variation in the --extern calls // and the addition of #[macro_use] in the rust code files, which used to break --extern // until #33625. diff --git a/tests/run-make/ice-static-mir/rmake.rs b/tests/run-make/ice-static-mir/rmake.rs index 2d4ffa379b62b..b6a04bf877e7f 100644 --- a/tests/run-make/ice-static-mir/rmake.rs +++ b/tests/run-make/ice-static-mir/rmake.rs @@ -1,3 +1,5 @@ +//@ needs-target-std +// // Trying to access mid-level internal representation (MIR) in statics // used to cause an internal compiler error (ICE), now handled as a proper // error since #100211. This test checks that the correct error is printed diff --git a/tests/run-make/include-all-symbols-linking/rmake.rs b/tests/run-make/include-all-symbols-linking/rmake.rs index bab510fb5be3c..4f85ee179f5f6 100644 --- a/tests/run-make/include-all-symbols-linking/rmake.rs +++ b/tests/run-make/include-all-symbols-linking/rmake.rs @@ -7,6 +7,7 @@ // See https://github.com/rust-lang/rust/pull/95604 // See https://github.com/rust-lang/rust/issues/47384 +//@ needs-target-std //@ ignore-wasm differences in object file formats causes errors in the llvm_objdump step. //@ ignore-windows differences in object file formats causes errors in the llvm_objdump step. diff --git a/tests/run-make/include-bytes-deps/rmake.rs b/tests/run-make/include-bytes-deps/rmake.rs index ea371ddae5675..2938f334243f1 100644 --- a/tests/run-make/include-bytes-deps/rmake.rs +++ b/tests/run-make/include-bytes-deps/rmake.rs @@ -1,3 +1,5 @@ +//@ needs-target-std +// // include_bytes! and include_str! in `main.rs` // should register the included file as of #24423, // and this test checks that this is still the case. diff --git a/tests/run-make/incremental-debugger-visualizer/rmake.rs b/tests/run-make/incremental-debugger-visualizer/rmake.rs index 07c920cc04a6f..3a4fc1d179294 100644 --- a/tests/run-make/incremental-debugger-visualizer/rmake.rs +++ b/tests/run-make/incremental-debugger-visualizer/rmake.rs @@ -1,3 +1,5 @@ +//@ needs-target-std +// // This test ensures that changes to files referenced via #[debugger_visualizer] // (in this case, foo.py and foo.natvis) are picked up when compiling incrementally. // See https://github.com/rust-lang/rust/pull/111641 diff --git a/tests/run-make/inline-always-many-cgu/rmake.rs b/tests/run-make/inline-always-many-cgu/rmake.rs index 678b949bc700d..18068578dd04e 100644 --- a/tests/run-make/inline-always-many-cgu/rmake.rs +++ b/tests/run-make/inline-always-many-cgu/rmake.rs @@ -1,3 +1,4 @@ +//@ needs-target-std use std::ffi::OsStr; use run_make_support::regex::Regex; diff --git a/tests/run-make/invalid-so/rmake.rs b/tests/run-make/invalid-so/rmake.rs index 754c53a49b924..ee886b5ee3a6d 100644 --- a/tests/run-make/invalid-so/rmake.rs +++ b/tests/run-make/invalid-so/rmake.rs @@ -1,3 +1,5 @@ +//@ needs-target-std +// // When a fake library was given to the compiler, it would // result in an obscure and unhelpful error message. This test // creates a false "foo" dylib, and checks that the standard error diff --git a/tests/run-make/invalid-staticlib/rmake.rs b/tests/run-make/invalid-staticlib/rmake.rs index ba9e07dd07b8f..4844bff329aca 100644 --- a/tests/run-make/invalid-staticlib/rmake.rs +++ b/tests/run-make/invalid-staticlib/rmake.rs @@ -1,3 +1,5 @@ +//@ needs-target-std +// // If the static library provided is not valid (in this test, // created as an empty file), // rustc should print a normal error message and not throw diff --git a/tests/run-make/invalid-symlink-search-path/rmake.rs b/tests/run-make/invalid-symlink-search-path/rmake.rs index 7b7e7c7944219..4eb6e6f770694 100644 --- a/tests/run-make/invalid-symlink-search-path/rmake.rs +++ b/tests/run-make/invalid-symlink-search-path/rmake.rs @@ -5,6 +5,7 @@ // // See https://github.com/rust-lang/rust/issues/26006 +//@ needs-target-std //@ needs-symlink //Reason: symlink requires elevated permission in Windows diff --git a/tests/run-make/invalid-tmpdir-env-var/rmake.rs b/tests/run-make/invalid-tmpdir-env-var/rmake.rs index db44debb319eb..c5b9dca33a940 100644 --- a/tests/run-make/invalid-tmpdir-env-var/rmake.rs +++ b/tests/run-make/invalid-tmpdir-env-var/rmake.rs @@ -1,3 +1,5 @@ +//@ needs-target-std +// // When the TMP (on Windows) or TMPDIR (on Unix) variable is set to an invalid // or non-existing directory, this used to cause an internal compiler error (ICE). After the // addition of proper error handling in #28430, this test checks that the expected message is diff --git a/tests/run-make/issue-107495-archive-permissions/rmake.rs b/tests/run-make/issue-107495-archive-permissions/rmake.rs index 87d4faaa77a2e..80474ba32c2ed 100644 --- a/tests/run-make/issue-107495-archive-permissions/rmake.rs +++ b/tests/run-make/issue-107495-archive-permissions/rmake.rs @@ -1,3 +1,4 @@ +//@ needs-target-std #[cfg(unix)] use std::os::unix::fs::PermissionsExt; use std::path::Path; diff --git a/tests/run-make/issue-125484-used-dependencies/rmake.rs b/tests/run-make/issue-125484-used-dependencies/rmake.rs index bc0a18de66e7e..afcea34783f9a 100644 --- a/tests/run-make/issue-125484-used-dependencies/rmake.rs +++ b/tests/run-make/issue-125484-used-dependencies/rmake.rs @@ -1,3 +1,5 @@ +//@ needs-target-std +// // Non-regression test for issues #125474, #125484, #125646, with the repro taken from #125484. Some // queries use "used dependencies" while others use "speculatively loaded dependencies", and an // indexing ICE appeared in some cases when these were unexpectedly used in the same context. diff --git a/tests/run-make/json-error-no-offset/rmake.rs b/tests/run-make/json-error-no-offset/rmake.rs index 629d9c4c16e44..3f45778ca04a1 100644 --- a/tests/run-make/json-error-no-offset/rmake.rs +++ b/tests/run-make/json-error-no-offset/rmake.rs @@ -1,3 +1,5 @@ +//@ needs-target-std +// // The byte positions in json format error logging used to have a small, difficult // to predict offset. This was changed to be the top of the file every time in #42973, // and this test checks that the measurements appearing in the standard error are correct. diff --git a/tests/run-make/lib-trait-for-trait-no-ice/rmake.rs b/tests/run-make/lib-trait-for-trait-no-ice/rmake.rs index 0c5e12055e815..af42911502e08 100644 --- a/tests/run-make/lib-trait-for-trait-no-ice/rmake.rs +++ b/tests/run-make/lib-trait-for-trait-no-ice/rmake.rs @@ -1,3 +1,5 @@ +//@ needs-target-std +// // Inside a library, implementing a trait for another trait // with a lifetime used to cause an internal compiler error (ICE). // This test checks that this bug does not make a resurgence - diff --git a/tests/run-make/link-arg/rmake.rs b/tests/run-make/link-arg/rmake.rs index c0bf8d972af73..bfceaae0dba6f 100644 --- a/tests/run-make/link-arg/rmake.rs +++ b/tests/run-make/link-arg/rmake.rs @@ -1,3 +1,5 @@ +//@ needs-target-std +// // In 2016, the rustc flag "-C link-arg" was introduced - it can be repeatedly used // to add single arguments to the linker. This test passes 2 arguments to the linker using it, // then checks that the compiler's output contains the arguments passed to it. diff --git a/tests/run-make/link-args-order/rmake.rs b/tests/run-make/link-args-order/rmake.rs index fe0d02926eff4..a4591ea3949e0 100644 --- a/tests/run-make/link-args-order/rmake.rs +++ b/tests/run-make/link-args-order/rmake.rs @@ -1,3 +1,5 @@ +//@ needs-target-std +// // Passing linker arguments to the compiler used to be lost or reordered in a messy way // as they were passed further to the linker. This was fixed in #70665, and this test // checks that linker arguments remain intact and in the order they were originally passed in. diff --git a/tests/run-make/link-dedup/rmake.rs b/tests/run-make/link-dedup/rmake.rs index f38603dee8cbb..0148817f98784 100644 --- a/tests/run-make/link-dedup/rmake.rs +++ b/tests/run-make/link-dedup/rmake.rs @@ -1,3 +1,5 @@ +//@ needs-target-std +// // When native libraries are passed to the linker, there used to be an annoyance // where multiple instances of the same library in a row would cause duplication in // outputs. This has been fixed, and this test checks that it stays fixed. diff --git a/tests/run-make/linker-warning/rmake.rs b/tests/run-make/linker-warning/rmake.rs index bc21739fefc6e..eb1bbbff8ef01 100644 --- a/tests/run-make/linker-warning/rmake.rs +++ b/tests/run-make/linker-warning/rmake.rs @@ -1,3 +1,4 @@ +//@ needs-target-std use run_make_support::{Rustc, diff, regex, rustc}; fn run_rustc() -> Rustc { diff --git a/tests/run-make/llvm-outputs/rmake.rs b/tests/run-make/llvm-outputs/rmake.rs index 2ce31b260a164..dabae38c141c9 100644 --- a/tests/run-make/llvm-outputs/rmake.rs +++ b/tests/run-make/llvm-outputs/rmake.rs @@ -1,3 +1,4 @@ +//@ needs-target-std // test that directories get created when emitting llvm bitcode and IR use std::path::PathBuf; diff --git a/tests/run-make/lto-avoid-object-duplication/rmake.rs b/tests/run-make/lto-avoid-object-duplication/rmake.rs index b0e7494cb5132..394aed2b881f9 100644 --- a/tests/run-make/lto-avoid-object-duplication/rmake.rs +++ b/tests/run-make/lto-avoid-object-duplication/rmake.rs @@ -8,6 +8,7 @@ // This test makes sure that functions defined in the upstream crates do not // appear twice in the final staticlib when listing all the symbols from it. +//@ needs-target-std //@ ignore-windows // Reason: `llvm-objdump`'s output looks different on windows than on other platforms. // Only checking on Unix platforms should suffice. diff --git a/tests/run-make/manual-crate-name/rmake.rs b/tests/run-make/manual-crate-name/rmake.rs index 9f480ec6b6af2..ead3b669e2da8 100644 --- a/tests/run-make/manual-crate-name/rmake.rs +++ b/tests/run-make/manual-crate-name/rmake.rs @@ -1,3 +1,4 @@ +//@ needs-target-std use run_make_support::{path, rustc}; fn main() { diff --git a/tests/run-make/many-crates-but-no-match/rmake.rs b/tests/run-make/many-crates-but-no-match/rmake.rs index 938ffce6a036c..449b6e2908d06 100644 --- a/tests/run-make/many-crates-but-no-match/rmake.rs +++ b/tests/run-make/many-crates-but-no-match/rmake.rs @@ -1,3 +1,5 @@ +//@ needs-target-std +// // An extended version of the ui/changing-crates.rs test, this test puts // multiple mismatching crates into the search path of crateC (A2 and A3) // and checks that the standard error contains helpful messages to indicate diff --git a/tests/run-make/metadata-dep-info/rmake.rs b/tests/run-make/metadata-dep-info/rmake.rs index f4bb3ea63fb16..82fa4c014e177 100644 --- a/tests/run-make/metadata-dep-info/rmake.rs +++ b/tests/run-make/metadata-dep-info/rmake.rs @@ -1,3 +1,5 @@ +//@ needs-target-std +// // Emitting dep-info alongside metadata would present subtle discrepancies // in the output file, such as the filename transforming underscores_ into hyphens-. // After the fix in #114750, this test checks that the emitted files are identical diff --git a/tests/run-make/metadata-only-crate-no-ice/rmake.rs b/tests/run-make/metadata-only-crate-no-ice/rmake.rs index e6f852fca413a..2e771d8793330 100644 --- a/tests/run-make/metadata-only-crate-no-ice/rmake.rs +++ b/tests/run-make/metadata-only-crate-no-ice/rmake.rs @@ -1,3 +1,5 @@ +//@ needs-target-std +// // In a dependency hierarchy, metadata-only crates could cause an Internal // Compiler Error (ICE) due to a compiler bug - not correctly fetching sources for // metadata-only crates. This test is a minimal reproduction of a program that triggered diff --git a/tests/run-make/missing-crate-dependency/rmake.rs b/tests/run-make/missing-crate-dependency/rmake.rs index dae77032f7d4a..7abdd11c50988 100644 --- a/tests/run-make/missing-crate-dependency/rmake.rs +++ b/tests/run-make/missing-crate-dependency/rmake.rs @@ -1,3 +1,5 @@ +//@ needs-target-std +// // A simple smoke test to check that rustc fails compilation // and outputs a helpful message when a dependency is missing // in a dependency chain. diff --git a/tests/run-make/multiple-emits/rmake.rs b/tests/run-make/multiple-emits/rmake.rs index 8a5eb1d9d856a..d8a008660c063 100644 --- a/tests/run-make/multiple-emits/rmake.rs +++ b/tests/run-make/multiple-emits/rmake.rs @@ -1,3 +1,4 @@ +//@ needs-target-std use run_make_support::{path, rustc}; fn main() { diff --git a/tests/run-make/native-lib-alt-naming/rmake.rs b/tests/run-make/native-lib-alt-naming/rmake.rs index d1ea0fc868767..a1dc002533f5f 100644 --- a/tests/run-make/native-lib-alt-naming/rmake.rs +++ b/tests/run-make/native-lib-alt-naming/rmake.rs @@ -1,3 +1,5 @@ +//@ needs-target-std +// // On MSVC the alternative naming format for static libraries (`libfoo.a`) is accepted in addition // to the default format (`foo.lib`). diff --git a/tests/run-make/native-link-modifier-verbatim-linker/rmake.rs b/tests/run-make/native-link-modifier-verbatim-linker/rmake.rs index 6868cb368ccc3..e06be13d9b95c 100644 --- a/tests/run-make/native-link-modifier-verbatim-linker/rmake.rs +++ b/tests/run-make/native-link-modifier-verbatim-linker/rmake.rs @@ -3,6 +3,7 @@ // This test is the same as native-link-modifier-rustc, but without rlibs. // See https://github.com/rust-lang/rust/issues/99425 +//@ needs-target-std //@ ignore-apple // Reason: linking fails due to the unusual ".ext" staticlib name. diff --git a/tests/run-make/native-link-modifier-verbatim-rustc/rmake.rs b/tests/run-make/native-link-modifier-verbatim-rustc/rmake.rs index 703b8a80ef3ed..d885df9e79eb4 100644 --- a/tests/run-make/native-link-modifier-verbatim-rustc/rmake.rs +++ b/tests/run-make/native-link-modifier-verbatim-rustc/rmake.rs @@ -1,3 +1,5 @@ +//@ needs-target-std +// // `verbatim` is a native link modifier that forces rustc to only accept libraries with // a specified name. This test checks that this modifier works as intended. // This test is the same as native-link-modifier-linker, but with rlibs. diff --git a/tests/run-make/no-builtins-attribute/rmake.rs b/tests/run-make/no-builtins-attribute/rmake.rs index 7182c65a2c59e..038958f19ed9d 100644 --- a/tests/run-make/no-builtins-attribute/rmake.rs +++ b/tests/run-make/no-builtins-attribute/rmake.rs @@ -1,3 +1,5 @@ +//@ needs-target-std +// // `no_builtins` is an attribute related to LLVM's optimizations. In order to ensure that it has an // effect on link-time optimizations (LTO), it should be added to function declarations in a crate. // This test uses the `llvm-filecheck` tool to determine that this attribute is successfully diff --git a/tests/run-make/no-builtins-lto/rmake.rs b/tests/run-make/no-builtins-lto/rmake.rs index 56fdfde42f04d..a1d9dc43e713d 100644 --- a/tests/run-make/no-builtins-lto/rmake.rs +++ b/tests/run-make/no-builtins-lto/rmake.rs @@ -1,3 +1,5 @@ +//@ needs-target-std +// // The rlib produced by a no_builtins crate should be explicitly linked // during compilation, and as a result be present in the linker arguments. // See the comments inside this file for more details. diff --git a/tests/run-make/non-unicode-env/rmake.rs b/tests/run-make/non-unicode-env/rmake.rs index d708192908c1c..b7a3c51db5bfd 100644 --- a/tests/run-make/non-unicode-env/rmake.rs +++ b/tests/run-make/non-unicode-env/rmake.rs @@ -1,3 +1,4 @@ +//@ needs-target-std use run_make_support::{rfs, rustc}; fn main() { diff --git a/tests/run-make/non-unicode-in-incremental-dir/rmake.rs b/tests/run-make/non-unicode-in-incremental-dir/rmake.rs index 42bd4b1b79990..5c437a3fe00c0 100644 --- a/tests/run-make/non-unicode-in-incremental-dir/rmake.rs +++ b/tests/run-make/non-unicode-in-incremental-dir/rmake.rs @@ -1,3 +1,4 @@ +//@ needs-target-std use run_make_support::{rfs, rustc}; fn main() { diff --git a/tests/run-make/notify-all-emit-artifacts/rmake.rs b/tests/run-make/notify-all-emit-artifacts/rmake.rs index 321eda489410e..5896cffefcce4 100644 --- a/tests/run-make/notify-all-emit-artifacts/rmake.rs +++ b/tests/run-make/notify-all-emit-artifacts/rmake.rs @@ -1,3 +1,5 @@ +//@ needs-target-std +// // rust should produce artifact notifications about files it was asked to --emit. // // It should work in incremental mode both on the first pass where files are generated as well diff --git a/tests/run-make/optimization-remarks-dir/rmake.rs b/tests/run-make/optimization-remarks-dir/rmake.rs index afcb8c3e3ebdb..df656302d789c 100644 --- a/tests/run-make/optimization-remarks-dir/rmake.rs +++ b/tests/run-make/optimization-remarks-dir/rmake.rs @@ -1,3 +1,5 @@ +//@ needs-target-std +// // In this test, the function `bar` has #[inline(never)] and the function `foo` // does not. This test outputs LLVM optimization remarks twice - first for all // functions (including `bar`, and the `inline` mention), and then for only `foo` diff --git a/tests/run-make/overwrite-input/rmake.rs b/tests/run-make/overwrite-input/rmake.rs index b87a7c7e0a851..bdf7860caa8a0 100644 --- a/tests/run-make/overwrite-input/rmake.rs +++ b/tests/run-make/overwrite-input/rmake.rs @@ -1,3 +1,5 @@ +//@ needs-target-std +// // An attempt to set the output `-o` into a directory or a file we cannot write into should indeed // be an error; but not an ICE (Internal Compiler Error). This test attempts both and checks // that the standard error matches what is expected. diff --git a/tests/run-make/parallel-rustc-no-overwrite/rmake.rs b/tests/run-make/parallel-rustc-no-overwrite/rmake.rs index aa38eb664cf5e..f7531ab4bf697 100644 --- a/tests/run-make/parallel-rustc-no-overwrite/rmake.rs +++ b/tests/run-make/parallel-rustc-no-overwrite/rmake.rs @@ -1,3 +1,5 @@ +//@ needs-target-std +// // When two instances of rustc are invoked in parallel, they // can conflict on their temporary files and overwrite each others', // leading to unsuccessful compilation. The -Z temps-dir flag adds diff --git a/tests/run-make/pass-linker-flags-from-dep/rmake.rs b/tests/run-make/pass-linker-flags-from-dep/rmake.rs index 4b8e0486e1427..1cd55468737dd 100644 --- a/tests/run-make/pass-linker-flags-from-dep/rmake.rs +++ b/tests/run-make/pass-linker-flags-from-dep/rmake.rs @@ -1,3 +1,5 @@ +//@ needs-target-std +// // A similar test to pass-linker-flags, testing that the `-l link-arg` flag // respects the order relative to other `-l` flags, but this time, the flags // are passed on the compilation of a dependency. This test checks that the diff --git a/tests/run-make/pass-linker-flags/rmake.rs b/tests/run-make/pass-linker-flags/rmake.rs index de69567a6e60c..a44da7b32ff85 100644 --- a/tests/run-make/pass-linker-flags/rmake.rs +++ b/tests/run-make/pass-linker-flags/rmake.rs @@ -1,3 +1,5 @@ +//@ needs-target-std +// // This test checks the proper function of `-l link-arg=NAME`, which, unlike // -C link-arg, is supposed to guarantee that the order relative to other -l // options will be respected. In this test, compilation fails (because none of the diff --git a/tests/run-make/pgo-gen-no-imp-symbols/rmake.rs b/tests/run-make/pgo-gen-no-imp-symbols/rmake.rs index 85ade7885ce7e..db25eab104a84 100644 --- a/tests/run-make/pgo-gen-no-imp-symbols/rmake.rs +++ b/tests/run-make/pgo-gen-no-imp-symbols/rmake.rs @@ -1,3 +1,5 @@ +//@ needs-target-std +// // LLVM's profiling instrumentation adds a few symbols that are used by the profiler runtime. // Since these show up as globals in the LLVM IR, the compiler generates dllimport-related // __imp_ stubs for them. This can lead to linker errors because the instrumentation diff --git a/tests/run-make/pretty-print-with-dep-file/rmake.rs b/tests/run-make/pretty-print-with-dep-file/rmake.rs index 24ae6bc24560a..e473854a12ea5 100644 --- a/tests/run-make/pretty-print-with-dep-file/rmake.rs +++ b/tests/run-make/pretty-print-with-dep-file/rmake.rs @@ -1,3 +1,5 @@ +//@ needs-target-std +// // Passing --emit=dep-info to the Rust compiler should create a .d file... // but it failed to do so in Rust 1.69.0 when combined with -Z unpretty=expanded // due to a bug. This test checks that -Z unpretty=expanded does not prevent the diff --git a/tests/run-make/proc-macro-three-crates/rmake.rs b/tests/run-make/proc-macro-three-crates/rmake.rs index d3735540fdd47..e5a3385acbc5c 100644 --- a/tests/run-make/proc-macro-three-crates/rmake.rs +++ b/tests/run-make/proc-macro-three-crates/rmake.rs @@ -1,3 +1,5 @@ +//@ needs-target-std +// // A compiler bug caused the following issue: // If a crate A depends on crate B, and crate B // depends on crate C, and crate C contains a procedural diff --git a/tests/run-make/remap-path-prefix-dwarf/rmake.rs b/tests/run-make/remap-path-prefix-dwarf/rmake.rs index 3d6ca014fc2a5..3b88fca0bb7f8 100644 --- a/tests/run-make/remap-path-prefix-dwarf/rmake.rs +++ b/tests/run-make/remap-path-prefix-dwarf/rmake.rs @@ -4,6 +4,7 @@ // It tests several cases, each of them has a detailed description attached to it. // See https://github.com/rust-lang/rust/pull/96867 +//@ needs-target-std //@ ignore-windows // Reason: the remap path prefix is not printed in the dwarf dump. diff --git a/tests/run-make/remap-path-prefix/rmake.rs b/tests/run-make/remap-path-prefix/rmake.rs index b4f7f4769b5ba..b75ca9e796ace 100644 --- a/tests/run-make/remap-path-prefix/rmake.rs +++ b/tests/run-make/remap-path-prefix/rmake.rs @@ -1,3 +1,5 @@ +//@ needs-target-std +// // Generating metadata alongside remap-path-prefix would fail to actually remap the path // in the metadata. After this was fixed in #85344, this test checks that "auxiliary" is being // successfully remapped to "/the/aux" in the rmeta files. diff --git a/tests/run-make/repr128-dwarf/rmake.rs b/tests/run-make/repr128-dwarf/rmake.rs index 8227c51516fa5..1372d2bcc4658 100644 --- a/tests/run-make/repr128-dwarf/rmake.rs +++ b/tests/run-make/repr128-dwarf/rmake.rs @@ -1,3 +1,4 @@ +//@ needs-target-std //@ ignore-windows // This test should be replaced with one in tests/debuginfo once GDB or LLDB support 128-bit enums. diff --git a/tests/run-make/reproducible-build-2/rmake.rs b/tests/run-make/reproducible-build-2/rmake.rs index 8b5825cad3026..0e1781dbfbe46 100644 --- a/tests/run-make/reproducible-build-2/rmake.rs +++ b/tests/run-make/reproducible-build-2/rmake.rs @@ -6,6 +6,7 @@ // Outputs should be identical. // See https://github.com/rust-lang/rust/issues/34902 +//@ needs-target-std //@ ignore-windows // Reasons: // 1. The object files are reproducible, but their paths are not, which causes diff --git a/tests/run-make/resolve-rename/rmake.rs b/tests/run-make/resolve-rename/rmake.rs index 21ec7f8527475..8afdaadbfde17 100644 --- a/tests/run-make/resolve-rename/rmake.rs +++ b/tests/run-make/resolve-rename/rmake.rs @@ -1,3 +1,5 @@ +//@ needs-target-std +// // If a library is compiled with -C extra-filename, the rust compiler // will take this into account when searching for libraries. However, // if that library is then renamed, the rust compiler should fall back diff --git a/tests/run-make/rlib-format-packed-bundled-libs-2/rmake.rs b/tests/run-make/rlib-format-packed-bundled-libs-2/rmake.rs index 5a1460963b64d..70d1ead85b5d2 100644 --- a/tests/run-make/rlib-format-packed-bundled-libs-2/rmake.rs +++ b/tests/run-make/rlib-format-packed-bundled-libs-2/rmake.rs @@ -1,3 +1,5 @@ +//@ needs-target-std +// // `-Z packed_bundled_libs` is an unstable rustc flag that makes the compiler // only require a native library and no supplementary object files to compile. // This test simply checks that this flag can be passed alongside verbatim syntax diff --git a/tests/run-make/rustc-macro-dep-files/rmake.rs b/tests/run-make/rustc-macro-dep-files/rmake.rs index bc02a04c9b8f1..eb4771fea7a6f 100644 --- a/tests/run-make/rustc-macro-dep-files/rmake.rs +++ b/tests/run-make/rustc-macro-dep-files/rmake.rs @@ -1,3 +1,5 @@ +//@ needs-target-std +// // --emit dep-info used to print all macro-generated code it could // find as if it was part of a nonexistent file named "proc-macro source", // which is not a valid path. After this was fixed in #36776, this test checks diff --git a/tests/run-make/rustdoc-scrape-examples-invalid-expr/rmake.rs b/tests/run-make/rustdoc-scrape-examples-invalid-expr/rmake.rs index e9c54fa392237..8996ff184c900 100644 --- a/tests/run-make/rustdoc-scrape-examples-invalid-expr/rmake.rs +++ b/tests/run-make/rustdoc-scrape-examples-invalid-expr/rmake.rs @@ -1,3 +1,4 @@ +//@ needs-target-std #[path = "../rustdoc-scrape-examples-remap/scrape.rs"] mod scrape; diff --git a/tests/run-make/rustdoc-scrape-examples-multiple/rmake.rs b/tests/run-make/rustdoc-scrape-examples-multiple/rmake.rs index e9c54fa392237..8996ff184c900 100644 --- a/tests/run-make/rustdoc-scrape-examples-multiple/rmake.rs +++ b/tests/run-make/rustdoc-scrape-examples-multiple/rmake.rs @@ -1,3 +1,4 @@ +//@ needs-target-std #[path = "../rustdoc-scrape-examples-remap/scrape.rs"] mod scrape; diff --git a/tests/run-make/rustdoc-scrape-examples-ordering/rmake.rs b/tests/run-make/rustdoc-scrape-examples-ordering/rmake.rs index e9c54fa392237..8996ff184c900 100644 --- a/tests/run-make/rustdoc-scrape-examples-ordering/rmake.rs +++ b/tests/run-make/rustdoc-scrape-examples-ordering/rmake.rs @@ -1,3 +1,4 @@ +//@ needs-target-std #[path = "../rustdoc-scrape-examples-remap/scrape.rs"] mod scrape; diff --git a/tests/run-make/rustdoc-scrape-examples-remap/rmake.rs b/tests/run-make/rustdoc-scrape-examples-remap/rmake.rs index 4e3b895aef0c4..ead3920c76132 100644 --- a/tests/run-make/rustdoc-scrape-examples-remap/rmake.rs +++ b/tests/run-make/rustdoc-scrape-examples-remap/rmake.rs @@ -1,3 +1,4 @@ +//@ needs-target-std mod scrape; fn main() { diff --git a/tests/run-make/rustdoc-scrape-examples-test/rmake.rs b/tests/run-make/rustdoc-scrape-examples-test/rmake.rs index f96ba113ff730..0868507c4ae5b 100644 --- a/tests/run-make/rustdoc-scrape-examples-test/rmake.rs +++ b/tests/run-make/rustdoc-scrape-examples-test/rmake.rs @@ -1,3 +1,4 @@ +//@ needs-target-std #[path = "../rustdoc-scrape-examples-remap/scrape.rs"] mod scrape; diff --git a/tests/run-make/rustdoc-scrape-examples-whitespace/rmake.rs b/tests/run-make/rustdoc-scrape-examples-whitespace/rmake.rs index e9c54fa392237..8996ff184c900 100644 --- a/tests/run-make/rustdoc-scrape-examples-whitespace/rmake.rs +++ b/tests/run-make/rustdoc-scrape-examples-whitespace/rmake.rs @@ -1,3 +1,4 @@ +//@ needs-target-std #[path = "../rustdoc-scrape-examples-remap/scrape.rs"] mod scrape; diff --git a/tests/run-make/rustdoc-with-short-out-dir-option/rmake.rs b/tests/run-make/rustdoc-with-short-out-dir-option/rmake.rs index 4a8896cc975bb..49df3bedc8496 100644 --- a/tests/run-make/rustdoc-with-short-out-dir-option/rmake.rs +++ b/tests/run-make/rustdoc-with-short-out-dir-option/rmake.rs @@ -1,3 +1,4 @@ +//@ needs-target-std use run_make_support::{htmldocck, rustdoc}; fn main() { diff --git a/tests/run-make/share-generics-dylib/rmake.rs b/tests/run-make/share-generics-dylib/rmake.rs index e0e647fe19955..2d52cd43db753 100644 --- a/tests/run-make/share-generics-dylib/rmake.rs +++ b/tests/run-make/share-generics-dylib/rmake.rs @@ -1,3 +1,5 @@ +//@ needs-target-std +// // This test makes sure all generic instances get re-exported from Rust dylibs for use by // `-Zshare-generics`. There are two rlibs (`instance_provider_a` and `instance_provider_b`) // which both provide an instance of `Cell::set`. There is `instance_user_dylib` which is diff --git a/tests/run-make/short-ice/rmake.rs b/tests/run-make/short-ice/rmake.rs index 81403931c783e..8377954f46726 100644 --- a/tests/run-make/short-ice/rmake.rs +++ b/tests/run-make/short-ice/rmake.rs @@ -4,6 +4,7 @@ // was shortened down to an appropriate length. // See https://github.com/rust-lang/rust/issues/107910 +//@ needs-target-std //@ ignore-windows // Reason: the assert_eq! on line 32 fails, as error output on Windows is different. diff --git a/tests/run-make/stable-symbol-names/rmake.rs b/tests/run-make/stable-symbol-names/rmake.rs index 402f411c7f5e6..dacee1a9a3ee8 100644 --- a/tests/run-make/stable-symbol-names/rmake.rs +++ b/tests/run-make/stable-symbol-names/rmake.rs @@ -1,3 +1,5 @@ +//@ needs-target-std +// // A typo in rustc caused generic symbol names to be non-deterministic - // that is, it was possible to compile the same file twice with no changes // and get outputs with different symbol names. diff --git a/tests/run-make/staticlib-blank-lib/rmake.rs b/tests/run-make/staticlib-blank-lib/rmake.rs index 11a85d102aadb..1ab527b61689d 100644 --- a/tests/run-make/staticlib-blank-lib/rmake.rs +++ b/tests/run-make/staticlib-blank-lib/rmake.rs @@ -1,3 +1,5 @@ +//@ needs-target-std +// // In this test, the static library foo is made blank, which used to cause // a compilation error. As the compiler now returns Ok upon encountering a blank // staticlib as of #12379, this test checks that compilation is successful despite diff --git a/tests/run-make/staticlib-broken-bitcode/rmake.rs b/tests/run-make/staticlib-broken-bitcode/rmake.rs index 17d17c1f0f5e8..ab406d3217616 100644 --- a/tests/run-make/staticlib-broken-bitcode/rmake.rs +++ b/tests/run-make/staticlib-broken-bitcode/rmake.rs @@ -1,3 +1,5 @@ +//@ needs-target-std +// // Regression test for https://github.com/rust-lang/rust/issues/128955#issuecomment-2657811196 // which checks that rustc can read an archive containing LLVM bitcode with a // newer version from the one rustc links against. diff --git a/tests/run-make/staticlib-thin-archive/rmake.rs b/tests/run-make/staticlib-thin-archive/rmake.rs index 955c50da2011c..1fb56ac053810 100644 --- a/tests/run-make/staticlib-thin-archive/rmake.rs +++ b/tests/run-make/staticlib-thin-archive/rmake.rs @@ -1,3 +1,5 @@ +//@ needs-target-std +// // Regression test for https://github.com/rust-lang/rust/issues/107407 which // checks that rustc can read thin archive. Before the object crate added thin // archive support rustc would add emit object files to the staticlib and after diff --git a/tests/run-make/stdin-rustc/rmake.rs b/tests/run-make/stdin-rustc/rmake.rs index 2d634dd455eb2..318d569a76051 100644 --- a/tests/run-make/stdin-rustc/rmake.rs +++ b/tests/run-make/stdin-rustc/rmake.rs @@ -1,3 +1,4 @@ +//@ needs-target-std //! This test checks rustc `-` (stdin) support use std::path::PathBuf; diff --git a/tests/run-make/symbol-visibility/rmake.rs b/tests/run-make/symbol-visibility/rmake.rs index ec936bc3b07fa..0175158d08b81 100644 --- a/tests/run-make/symbol-visibility/rmake.rs +++ b/tests/run-make/symbol-visibility/rmake.rs @@ -1,3 +1,5 @@ +//@ needs-target-std +// // Dynamic libraries on Rust used to export a very high amount of symbols, // going as far as filling the output with mangled names and generic function // names. After the rework of #38117, this test checks that no mangled Rust symbols diff --git a/tests/run-make/symbols-include-type-name/rmake.rs b/tests/run-make/symbols-include-type-name/rmake.rs index 746c7486bf0c0..3b46050e6620e 100644 --- a/tests/run-make/symbols-include-type-name/rmake.rs +++ b/tests/run-make/symbols-include-type-name/rmake.rs @@ -1,3 +1,5 @@ +//@ needs-target-std +// // Method names used to be obfuscated when exported into symbols, // leaving only an obscure ``. After the fix in #30328, // this test checks that method names are successfully saved in the symbol list. diff --git a/tests/run-make/track-path-dep-info/rmake.rs b/tests/run-make/track-path-dep-info/rmake.rs index 9b21644c41bc5..4b98a1b48d5fa 100644 --- a/tests/run-make/track-path-dep-info/rmake.rs +++ b/tests/run-make/track-path-dep-info/rmake.rs @@ -1,3 +1,5 @@ +//@ needs-target-std +// // This test checks the functionality of `tracked_path::path`, a procedural macro // feature that adds a dependency to another file inside the procmacro. In this case, // the text file is added through this method, and the test checks that the compilation diff --git a/tests/run-make/type-mismatch-same-crate-name/rmake.rs b/tests/run-make/type-mismatch-same-crate-name/rmake.rs index ecf80d88d51c1..b095027071f1c 100644 --- a/tests/run-make/type-mismatch-same-crate-name/rmake.rs +++ b/tests/run-make/type-mismatch-same-crate-name/rmake.rs @@ -1,3 +1,5 @@ +//@ needs-target-std +// // When a compilation failure deals with seemingly identical types, some helpful // errors should be printed. // The main use case of this error is when there are two crates diff --git a/tests/run-make/unknown-mod-stdin/rmake.rs b/tests/run-make/unknown-mod-stdin/rmake.rs index 6be3119c0fd15..101711b0d2c70 100644 --- a/tests/run-make/unknown-mod-stdin/rmake.rs +++ b/tests/run-make/unknown-mod-stdin/rmake.rs @@ -1,3 +1,5 @@ +//@ needs-target-std +// // Rustc displays a compilation error when it finds a `mod` (module) // statement referencing a file that does not exist. However, a bug from 2019 // caused invalid `mod` statements to silently insert empty inline modules diff --git a/tests/run-make/unstable-feature-usage-metrics-incremental/rmake.rs b/tests/run-make/unstable-feature-usage-metrics-incremental/rmake.rs index 7e070d80c7933..a7215ca9d50bc 100644 --- a/tests/run-make/unstable-feature-usage-metrics-incremental/rmake.rs +++ b/tests/run-make/unstable-feature-usage-metrics-incremental/rmake.rs @@ -10,6 +10,7 @@ //! - forked from dump-ice-to-disk test, which has flakeyness issues on i686-mingw, I'm assuming //! those will be present in this test as well on the same platform +//@ needs-target-std //@ ignore-windows //FIXME(#128911): still flakey on i686-mingw. diff --git a/tests/run-make/unstable-feature-usage-metrics/rmake.rs b/tests/run-make/unstable-feature-usage-metrics/rmake.rs index 2183e28e89abe..dbe078bf468a5 100644 --- a/tests/run-make/unstable-feature-usage-metrics/rmake.rs +++ b/tests/run-make/unstable-feature-usage-metrics/rmake.rs @@ -10,6 +10,7 @@ //! - forked from dump-ice-to-disk test, which has flakeyness issues on i686-mingw, I'm assuming //! those will be present in this test as well on the same platform +//@ needs-target-std //@ ignore-windows //FIXME(#128911): still flakey on i686-mingw. diff --git a/tests/run-make/use-suggestions-rust-2018/rmake.rs b/tests/run-make/use-suggestions-rust-2018/rmake.rs index 52c694da75e9a..4d2163e7cc4bd 100644 --- a/tests/run-make/use-suggestions-rust-2018/rmake.rs +++ b/tests/run-make/use-suggestions-rust-2018/rmake.rs @@ -1,3 +1,5 @@ +//@ needs-target-std +// // The compilation error caused by calling on an unimported crate // should have a suggestion to write, say, crate::bar::Foo instead // of just bar::Foo. However, this suggestion used to only appear for diff --git a/tests/run-make/used/rmake.rs b/tests/run-make/used/rmake.rs index 39f36b2eea8f6..daed69c1b3857 100644 --- a/tests/run-make/used/rmake.rs +++ b/tests/run-make/used/rmake.rs @@ -1,3 +1,5 @@ +//@ needs-target-std +// // This test ensures that the compiler is keeping static variables, even if not referenced // by another part of the program, in the output object file. // From 248b7a9490ca05876715e613a0fc5fff6a2826e0 Mon Sep 17 00:00:00 2001 From: Nicholas Nethercote Date: Mon, 9 Jun 2025 18:04:09 +1000 Subject: [PATCH 2/8] Fix `PathSource` lifetimes. It currently has two, which don't accurately capture what's happening -- the `TupleStruct` spans are allocated in `ResolverArenas`, which is different to where the `Expr` is allocated -- and require some "outlives" constraints to be used. This commit adds another lifetime, renames the existing ones, and removes the "outlives" constraints. --- compiler/rustc_resolve/src/late.rs | 24 +++++------ .../rustc_resolve/src/late/diagnostics.rs | 42 +++++++++---------- 2 files changed, 33 insertions(+), 33 deletions(-) diff --git a/compiler/rustc_resolve/src/late.rs b/compiler/rustc_resolve/src/late.rs index fa4b024c422f0..338d9edcd22ff 100644 --- a/compiler/rustc_resolve/src/late.rs +++ b/compiler/rustc_resolve/src/late.rs @@ -415,24 +415,24 @@ pub(crate) enum AliasPossibility { } #[derive(Copy, Clone, Debug)] -pub(crate) enum PathSource<'a, 'c> { +pub(crate) enum PathSource<'a, 'ast, 'ra> { /// Type paths `Path`. Type, /// Trait paths in bounds or impls. Trait(AliasPossibility), /// Expression paths `path`, with optional parent context. - Expr(Option<&'a Expr>), + Expr(Option<&'ast Expr>), /// Paths in path patterns `Path`. Pat, /// Paths in struct expressions and patterns `Path { .. }`. Struct, /// Paths in tuple struct patterns `Path(..)`. - TupleStruct(Span, &'a [Span]), + TupleStruct(Span, &'ra [Span]), /// `m::A::B` in `::B::C`. /// /// Second field holds the "cause" of this one, i.e. the context within /// which the trait item is resolved. Used for diagnostics. - TraitItem(Namespace, &'c PathSource<'a, 'c>), + TraitItem(Namespace, &'a PathSource<'a, 'ast, 'ra>), /// Paths in delegation item Delegation, /// An arg in a `use<'a, N>` precise-capturing bound. @@ -443,7 +443,7 @@ pub(crate) enum PathSource<'a, 'c> { DefineOpaques, } -impl<'a> PathSource<'a, '_> { +impl PathSource<'_, '_, '_> { fn namespace(self) -> Namespace { match self { PathSource::Type @@ -773,7 +773,7 @@ struct LateResolutionVisitor<'a, 'ast, 'ra, 'tcx> { } /// Walks the whole crate in DFS order, visiting each item, resolving names as it goes. -impl<'ra: 'ast, 'ast, 'tcx> Visitor<'ast> for LateResolutionVisitor<'_, 'ast, 'ra, 'tcx> { +impl<'ast, 'ra, 'tcx> Visitor<'ast> for LateResolutionVisitor<'_, 'ast, 'ra, 'tcx> { fn visit_attribute(&mut self, _: &'ast Attribute) { // We do not want to resolve expressions that appear in attributes, // as they do not correspond to actual code. @@ -1462,7 +1462,7 @@ impl<'ra: 'ast, 'ast, 'tcx> Visitor<'ast> for LateResolutionVisitor<'_, 'ast, 'r } } -impl<'a, 'ast, 'ra: 'ast, 'tcx> LateResolutionVisitor<'a, 'ast, 'ra, 'tcx> { +impl<'a, 'ast, 'ra, 'tcx> LateResolutionVisitor<'a, 'ast, 'ra, 'tcx> { fn new(resolver: &'a mut Resolver<'ra, 'tcx>) -> LateResolutionVisitor<'a, 'ast, 'ra, 'tcx> { // During late resolution we only track the module component of the parent scope, // although it may be useful to track other components as well for diagnostics. @@ -2010,7 +2010,7 @@ impl<'a, 'ast, 'ra: 'ast, 'tcx> LateResolutionVisitor<'a, 'ast, 'ra, 'tcx> { &mut self, partial_res: PartialRes, path: &[Segment], - source: PathSource<'_, '_>, + source: PathSource<'_, '_, '_>, path_span: Span, ) { let proj_start = path.len() - partial_res.unresolved_segments(); @@ -4161,7 +4161,7 @@ impl<'a, 'ast, 'ra: 'ast, 'tcx> LateResolutionVisitor<'a, 'ast, 'ra, 'tcx> { id: NodeId, qself: &Option>, path: &Path, - source: PathSource<'ast, '_>, + source: PathSource<'_, 'ast, '_>, ) { self.smart_resolve_path_fragment( qself, @@ -4178,7 +4178,7 @@ impl<'a, 'ast, 'ra: 'ast, 'tcx> LateResolutionVisitor<'a, 'ast, 'ra, 'tcx> { &mut self, qself: &Option>, path: &[Segment], - source: PathSource<'ast, '_>, + source: PathSource<'_, 'ast, '_>, finalize: Finalize, record_partial_res: RecordPartialRes, parent_qself: Option<&QSelf>, @@ -4482,7 +4482,7 @@ impl<'a, 'ast, 'ra: 'ast, 'tcx> LateResolutionVisitor<'a, 'ast, 'ra, 'tcx> { span: Span, defer_to_typeck: bool, finalize: Finalize, - source: PathSource<'ast, '_>, + source: PathSource<'_, 'ast, '_>, ) -> Result, Spanned>> { let mut fin_res = None; @@ -4525,7 +4525,7 @@ impl<'a, 'ast, 'ra: 'ast, 'tcx> LateResolutionVisitor<'a, 'ast, 'ra, 'tcx> { path: &[Segment], ns: Namespace, finalize: Finalize, - source: PathSource<'ast, '_>, + source: PathSource<'_, 'ast, '_>, ) -> Result, Spanned>> { debug!( "resolve_qpath(qself={:?}, path={:?}, ns={:?}, finalize={:?})", diff --git a/compiler/rustc_resolve/src/late/diagnostics.rs b/compiler/rustc_resolve/src/late/diagnostics.rs index 2f6aed35f2524..d5dd3bdb6cd8e 100644 --- a/compiler/rustc_resolve/src/late/diagnostics.rs +++ b/compiler/rustc_resolve/src/late/diagnostics.rs @@ -170,12 +170,12 @@ impl TypoCandidate { } } -impl<'ast, 'ra: 'ast, 'tcx> LateResolutionVisitor<'_, 'ast, 'ra, 'tcx> { +impl<'ast, 'ra, 'tcx> LateResolutionVisitor<'_, 'ast, 'ra, 'tcx> { fn make_base_error( &mut self, path: &[Segment], span: Span, - source: PathSource<'_, '_>, + source: PathSource<'_, '_, '_>, res: Option, ) -> BaseError { // Make the base error. @@ -421,7 +421,7 @@ impl<'ast, 'ra: 'ast, 'tcx> LateResolutionVisitor<'_, 'ast, 'ra, 'tcx> { path: &[Segment], following_seg: Option<&Segment>, span: Span, - source: PathSource<'_, '_>, + source: PathSource<'_, '_, '_>, res: Option, qself: Option<&QSelf>, ) -> (Diag<'tcx>, Vec) { @@ -539,7 +539,7 @@ impl<'ast, 'ra: 'ast, 'tcx> LateResolutionVisitor<'_, 'ast, 'ra, 'tcx> { path: &[Segment], following_seg: Option<&Segment>, span: Span, - source: PathSource<'_, '_>, + source: PathSource<'_, '_, '_>, res: Option, qself: Option<&QSelf>, ) { @@ -650,7 +650,7 @@ impl<'ast, 'ra: 'ast, 'tcx> LateResolutionVisitor<'_, 'ast, 'ra, 'tcx> { fn try_lookup_name_relaxed( &mut self, err: &mut Diag<'_>, - source: PathSource<'_, '_>, + source: PathSource<'_, '_, '_>, path: &[Segment], following_seg: Option<&Segment>, span: Span, @@ -940,7 +940,7 @@ impl<'ast, 'ra: 'ast, 'tcx> LateResolutionVisitor<'_, 'ast, 'ra, 'tcx> { fn suggest_trait_and_bounds( &mut self, err: &mut Diag<'_>, - source: PathSource<'_, '_>, + source: PathSource<'_, '_, '_>, res: Option, span: Span, base_error: &BaseError, @@ -1017,7 +1017,7 @@ impl<'ast, 'ra: 'ast, 'tcx> LateResolutionVisitor<'_, 'ast, 'ra, 'tcx> { fn suggest_typo( &mut self, err: &mut Diag<'_>, - source: PathSource<'_, '_>, + source: PathSource<'_, '_, '_>, path: &[Segment], following_seg: Option<&Segment>, span: Span, @@ -1063,7 +1063,7 @@ impl<'ast, 'ra: 'ast, 'tcx> LateResolutionVisitor<'_, 'ast, 'ra, 'tcx> { fn suggest_shadowed( &mut self, err: &mut Diag<'_>, - source: PathSource<'_, '_>, + source: PathSource<'_, '_, '_>, path: &[Segment], following_seg: Option<&Segment>, span: Span, @@ -1096,7 +1096,7 @@ impl<'ast, 'ra: 'ast, 'tcx> LateResolutionVisitor<'_, 'ast, 'ra, 'tcx> { fn err_code_special_cases( &mut self, err: &mut Diag<'_>, - source: PathSource<'_, '_>, + source: PathSource<'_, '_, '_>, path: &[Segment], span: Span, ) { @@ -1141,7 +1141,7 @@ impl<'ast, 'ra: 'ast, 'tcx> LateResolutionVisitor<'_, 'ast, 'ra, 'tcx> { fn suggest_self_ty( &mut self, err: &mut Diag<'_>, - source: PathSource<'_, '_>, + source: PathSource<'_, '_, '_>, path: &[Segment], span: Span, ) -> bool { @@ -1164,7 +1164,7 @@ impl<'ast, 'ra: 'ast, 'tcx> LateResolutionVisitor<'_, 'ast, 'ra, 'tcx> { fn suggest_self_value( &mut self, err: &mut Diag<'_>, - source: PathSource<'_, '_>, + source: PathSource<'_, '_, '_>, path: &[Segment], span: Span, ) -> bool { @@ -1332,7 +1332,7 @@ impl<'ast, 'ra: 'ast, 'tcx> LateResolutionVisitor<'_, 'ast, 'ra, 'tcx> { fn suggest_swapping_misplaced_self_ty_and_trait( &mut self, err: &mut Diag<'_>, - source: PathSource<'_, '_>, + source: PathSource<'_, '_, '_>, res: Option, span: Span, ) { @@ -1361,7 +1361,7 @@ impl<'ast, 'ra: 'ast, 'tcx> LateResolutionVisitor<'_, 'ast, 'ra, 'tcx> { &mut self, err: &mut Diag<'_>, res: Option, - source: PathSource<'_, '_>, + source: PathSource<'_, '_, '_>, ) { let PathSource::TupleStruct(_, _) = source else { return }; let Some(Res::Def(DefKind::Fn, _)) = res else { return }; @@ -1373,7 +1373,7 @@ impl<'ast, 'ra: 'ast, 'tcx> LateResolutionVisitor<'_, 'ast, 'ra, 'tcx> { &mut self, err: &mut Diag<'_>, res: Option, - source: PathSource<'_, '_>, + source: PathSource<'_, '_, '_>, span: Span, ) { let PathSource::Trait(_) = source else { return }; @@ -1422,7 +1422,7 @@ impl<'ast, 'ra: 'ast, 'tcx> LateResolutionVisitor<'_, 'ast, 'ra, 'tcx> { fn suggest_pattern_match_with_let( &mut self, err: &mut Diag<'_>, - source: PathSource<'_, '_>, + source: PathSource<'_, '_, '_>, span: Span, ) -> bool { if let PathSource::Expr(_) = source @@ -1448,7 +1448,7 @@ impl<'ast, 'ra: 'ast, 'tcx> LateResolutionVisitor<'_, 'ast, 'ra, 'tcx> { fn get_single_associated_item( &mut self, path: &[Segment], - source: &PathSource<'_, '_>, + source: &PathSource<'_, '_, '_>, filter_fn: &impl Fn(Res) -> bool, ) -> Option { if let crate::PathSource::TraitItem(_, _) = source { @@ -1556,7 +1556,7 @@ impl<'ast, 'ra: 'ast, 'tcx> LateResolutionVisitor<'_, 'ast, 'ra, 'tcx> { /// Check if the source is call expression and the first argument is `self`. If true, /// return the span of whole call and the span for all arguments expect the first one (`self`). - fn call_has_self_arg(&self, source: PathSource<'_, '_>) -> Option<(Span, Option)> { + fn call_has_self_arg(&self, source: PathSource<'_, '_, '_>) -> Option<(Span, Option)> { let mut has_self_arg = None; if let PathSource::Expr(Some(parent)) = source && let ExprKind::Call(_, args) = &parent.kind @@ -1614,7 +1614,7 @@ impl<'ast, 'ra: 'ast, 'tcx> LateResolutionVisitor<'_, 'ast, 'ra, 'tcx> { &mut self, err: &mut Diag<'_>, span: Span, - source: PathSource<'_, '_>, + source: PathSource<'_, '_, '_>, path: &[Segment], res: Res, path_str: &str, @@ -1666,7 +1666,7 @@ impl<'ast, 'ra: 'ast, 'tcx> LateResolutionVisitor<'_, 'ast, 'ra, 'tcx> { } }; - let find_span = |source: &PathSource<'_, '_>, err: &mut Diag<'_>| { + let find_span = |source: &PathSource<'_, '_, '_>, err: &mut Diag<'_>| { match source { PathSource::Expr(Some(Expr { span, kind: ExprKind::Call(_, _), .. })) | PathSource::TupleStruct(span, _) => { @@ -2699,7 +2699,7 @@ impl<'ast, 'ra: 'ast, 'tcx> LateResolutionVisitor<'_, 'ast, 'ra, 'tcx> { fn suggest_using_enum_variant( &mut self, err: &mut Diag<'_>, - source: PathSource<'_, '_>, + source: PathSource<'_, '_, '_>, def_id: DefId, span: Span, ) { @@ -2877,7 +2877,7 @@ impl<'ast, 'ra: 'ast, 'tcx> LateResolutionVisitor<'_, 'ast, 'ra, 'tcx> { pub(crate) fn suggest_adding_generic_parameter( &self, path: &[Segment], - source: PathSource<'_, '_>, + source: PathSource<'_, '_, '_>, ) -> Option<(Span, &'static str, String, Applicability)> { let (ident, span) = match path { [segment] From c2b1692be53eb69342906302cacc2a0271d1f07d Mon Sep 17 00:00:00 2001 From: Trevor Gross Date: Mon, 16 Jun 2025 07:00:13 +0000 Subject: [PATCH 3/8] Update the `backtrace` submodule Pick up the following pull requests: * ci: remove binary size check (not relevant in rust-lang/rust) * Upgrade `ruzstd`, `object`, and `addr2line` to the latest versions --- library/backtrace | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/library/backtrace b/library/backtrace index 6c882eb11984d..b65ab935fb2e0 160000 --- a/library/backtrace +++ b/library/backtrace @@ -1 +1 @@ -Subproject commit 6c882eb11984d737f62e85f36703effaf34c2453 +Subproject commit b65ab935fb2e0d59dba8966ffca09c9cc5a5f57c From d28fabeb6ce8f29856696c43e0c38ef8091db056 Mon Sep 17 00:00:00 2001 From: bjorn3 <17426603+bjorn3@users.noreply.github.com> Date: Mon, 16 Jun 2025 08:01:58 +0000 Subject: [PATCH 4/8] Test naked asm for wasm32-unknown-unknown --- tests/assembly/naked-functions/wasm32.rs | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/tests/assembly/naked-functions/wasm32.rs b/tests/assembly/naked-functions/wasm32.rs index 71e4d80764a3a..984152f2b4530 100644 --- a/tests/assembly/naked-functions/wasm32.rs +++ b/tests/assembly/naked-functions/wasm32.rs @@ -1,10 +1,10 @@ -// FIXME: add wasm32-unknown when the wasm32-unknown-unknown ABI is fixed -// see https://github.com/rust-lang/rust/issues/115666 -//@ revisions: wasm64-unknown wasm32-wasip1 +//@ revisions: wasm32-unknown wasm64-unknown wasm32-wasip1 //@ add-core-stubs //@ assembly-output: emit-asm +//@ [wasm32-unknown] compile-flags: --target wasm32-unknown-unknown //@ [wasm64-unknown] compile-flags: --target wasm64-unknown-unknown //@ [wasm32-wasip1] compile-flags: --target wasm32-wasip1 +//@ [wasm32-unknown] needs-llvm-components: webassembly //@ [wasm64-unknown] needs-llvm-components: webassembly //@ [wasm32-wasip1] needs-llvm-components: webassembly @@ -97,6 +97,7 @@ extern "C" fn fn_i64_i64(num: i64) -> i64 { } // CHECK-LABEL: fn_i128_i128: +// wasm32-unknown: .functype fn_i128_i128 (i32, i64, i64) -> () // wasm32-wasip1: .functype fn_i128_i128 (i32, i64, i64) -> () // wasm64-unknown: .functype fn_i128_i128 (i64, i64, i64) -> () #[allow(improper_ctypes_definitions)] @@ -114,6 +115,7 @@ extern "C" fn fn_i128_i128(num: i128) -> i128 { } // CHECK-LABEL: fn_f128_f128: +// wasm32-unknown: .functype fn_f128_f128 (i32, i64, i64) -> () // wasm32-wasip1: .functype fn_f128_f128 (i32, i64, i64) -> () // wasm64-unknown: .functype fn_f128_f128 (i64, i64, i64) -> () #[no_mangle] @@ -136,6 +138,7 @@ struct Compound { } // CHECK-LABEL: fn_compound_compound: +// wasm32-unknown: .functype fn_compound_compound (i32, i32) -> () // wasm32-wasip1: .functype fn_compound_compound (i32, i32) -> () // wasm64-unknown: .functype fn_compound_compound (i64, i64) -> () #[no_mangle] From 5723c9997c41be799fcaec791e591fb8406421ff Mon Sep 17 00:00:00 2001 From: beetrees Date: Thu, 3 Apr 2025 23:53:06 +0100 Subject: [PATCH 5/8] Fix RISC-V C function ABI when passing/returning structs containing floats --- .../src/abi/pass_mode.rs | 66 ++++--- .../rustc_codegen_gcc/src/intrinsic/mod.rs | 2 +- compiler/rustc_codegen_llvm/src/abi.rs | 2 +- compiler/rustc_codegen_ssa/src/mir/block.rs | 54 +++++- compiler/rustc_codegen_ssa/src/mir/mod.rs | 3 +- compiler/rustc_target/src/callconv/mips64.rs | 15 +- compiler/rustc_target/src/callconv/mod.rs | 84 ++++++--- compiler/rustc_target/src/callconv/nvptx64.rs | 25 +-- compiler/rustc_target/src/callconv/riscv.rs | 137 ++++++++++---- compiler/rustc_target/src/callconv/sparc64.rs | 18 +- tests/assembly/riscv-float-struct-abi.rs | 177 ++++++++++++++++++ .../riscv-abi/cast-local-large-enough.rs | 44 +++++ .../ui/abi/numbers-arithmetic/float-struct.rs | 44 +++++ 13 files changed, 537 insertions(+), 134 deletions(-) create mode 100644 tests/assembly/riscv-float-struct-abi.rs create mode 100644 tests/codegen/riscv-abi/cast-local-large-enough.rs create mode 100644 tests/ui/abi/numbers-arithmetic/float-struct.rs diff --git a/compiler/rustc_codegen_cranelift/src/abi/pass_mode.rs b/compiler/rustc_codegen_cranelift/src/abi/pass_mode.rs index 9a0a5b510397a..cd0afee0cfb2f 100644 --- a/compiler/rustc_codegen_cranelift/src/abi/pass_mode.rs +++ b/compiler/rustc_codegen_cranelift/src/abi/pass_mode.rs @@ -40,7 +40,18 @@ fn apply_attrs_to_abi_param(param: AbiParam, arg_attrs: ArgAttributes) -> AbiPar } } -fn cast_target_to_abi_params(cast: &CastTarget) -> SmallVec<[AbiParam; 2]> { +fn cast_target_to_abi_params(cast: &CastTarget) -> SmallVec<[(Size, AbiParam); 2]> { + if let Some(offset_from_start) = cast.rest_offset { + assert!(cast.prefix[1..].iter().all(|p| p.is_none())); + assert_eq!(cast.rest.unit.size, cast.rest.total); + let first = cast.prefix[0].unwrap(); + let second = cast.rest.unit; + return smallvec![ + (Size::ZERO, reg_to_abi_param(first)), + (offset_from_start, reg_to_abi_param(second)) + ]; + } + let (rest_count, rem_bytes) = if cast.rest.unit.size.bytes() == 0 { (0, 0) } else { @@ -55,25 +66,32 @@ fn cast_target_to_abi_params(cast: &CastTarget) -> SmallVec<[AbiParam; 2]> { // different types in Cranelift IR. Instead a single array of primitive types is used. // Create list of fields in the main structure - let mut args = cast + let args = cast .prefix .iter() .flatten() .map(|®| reg_to_abi_param(reg)) - .chain((0..rest_count).map(|_| reg_to_abi_param(cast.rest.unit))) - .collect::>(); + .chain((0..rest_count).map(|_| reg_to_abi_param(cast.rest.unit))); + + let mut res = SmallVec::new(); + let mut offset = Size::ZERO; + + for arg in args { + res.push((offset, arg)); + offset += Size::from_bytes(arg.value_type.bytes()); + } // Append final integer if rem_bytes != 0 { // Only integers can be really split further. assert_eq!(cast.rest.unit.kind, RegKind::Integer); - args.push(reg_to_abi_param(Reg { - kind: RegKind::Integer, - size: Size::from_bytes(rem_bytes), - })); + res.push(( + offset, + reg_to_abi_param(Reg { kind: RegKind::Integer, size: Size::from_bytes(rem_bytes) }), + )); } - args + res } impl<'tcx> ArgAbiExt<'tcx> for ArgAbi<'tcx, Ty<'tcx>> { @@ -104,7 +122,7 @@ impl<'tcx> ArgAbiExt<'tcx> for ArgAbi<'tcx, Ty<'tcx>> { }, PassMode::Cast { ref cast, pad_i32 } => { assert!(!pad_i32, "padding support not yet implemented"); - cast_target_to_abi_params(cast) + cast_target_to_abi_params(cast).into_iter().map(|(_, param)| param).collect() } PassMode::Indirect { attrs, meta_attrs: None, on_stack } => { if on_stack { @@ -160,9 +178,10 @@ impl<'tcx> ArgAbiExt<'tcx> for ArgAbi<'tcx, Ty<'tcx>> { } _ => unreachable!("{:?}", self.layout.backend_repr), }, - PassMode::Cast { ref cast, .. } => { - (None, cast_target_to_abi_params(cast).into_iter().collect()) - } + PassMode::Cast { ref cast, .. } => ( + None, + cast_target_to_abi_params(cast).into_iter().map(|(_, param)| param).collect(), + ), PassMode::Indirect { attrs, meta_attrs: None, on_stack } => { assert!(!on_stack); ( @@ -187,12 +206,14 @@ pub(super) fn to_casted_value<'tcx>( ) -> SmallVec<[Value; 2]> { let (ptr, meta) = arg.force_stack(fx); assert!(meta.is_none()); - let mut offset = 0; cast_target_to_abi_params(cast) .into_iter() - .map(|param| { - let val = ptr.offset_i64(fx, offset).load(fx, param.value_type, MemFlags::new()); - offset += i64::from(param.value_type.bytes()); + .map(|(offset, param)| { + let val = ptr.offset_i64(fx, offset.bytes() as i64).load( + fx, + param.value_type, + MemFlags::new(), + ); val }) .collect() @@ -205,7 +226,7 @@ pub(super) fn from_casted_value<'tcx>( cast: &CastTarget, ) -> CValue<'tcx> { let abi_params = cast_target_to_abi_params(cast); - let abi_param_size: u32 = abi_params.iter().map(|param| param.value_type.bytes()).sum(); + let abi_param_size: u32 = abi_params.iter().map(|(_, param)| param.value_type.bytes()).sum(); let layout_size = u32::try_from(layout.size.bytes()).unwrap(); let ptr = fx.create_stack_slot( // Stack slot size may be bigger for example `[u8; 3]` which is packed into an `i32`. @@ -214,16 +235,13 @@ pub(super) fn from_casted_value<'tcx>( std::cmp::max(abi_param_size, layout_size), u32::try_from(layout.align.abi.bytes()).unwrap(), ); - let mut offset = 0; let mut block_params_iter = block_params.iter().copied(); - for param in abi_params { - let val = ptr.offset_i64(fx, offset).store( + for (offset, _) in abi_params { + ptr.offset_i64(fx, offset.bytes() as i64).store( fx, block_params_iter.next().unwrap(), MemFlags::new(), - ); - offset += i64::from(param.value_type.bytes()); - val + ) } assert_eq!(block_params_iter.next(), None, "Leftover block param"); CValue::by_ref(ptr, layout) diff --git a/compiler/rustc_codegen_gcc/src/intrinsic/mod.rs b/compiler/rustc_codegen_gcc/src/intrinsic/mod.rs index 9e05b8f23aade..c921851b42b9a 100644 --- a/compiler/rustc_codegen_gcc/src/intrinsic/mod.rs +++ b/compiler/rustc_codegen_gcc/src/intrinsic/mod.rs @@ -626,7 +626,7 @@ impl<'gcc, 'tcx> ArgAbiExt<'gcc, 'tcx> for ArgAbi<'tcx, Ty<'tcx>> { bx.lifetime_start(llscratch, scratch_size); // ... where we first store the value... - bx.store(val, llscratch, scratch_align); + rustc_codegen_ssa::mir::store_cast(bx, cast, val, llscratch, scratch_align); // ... and then memcpy it to the intended destination. bx.memcpy( diff --git a/compiler/rustc_codegen_llvm/src/abi.rs b/compiler/rustc_codegen_llvm/src/abi.rs index aba63d75f1dfa..4b07c8aef915b 100644 --- a/compiler/rustc_codegen_llvm/src/abi.rs +++ b/compiler/rustc_codegen_llvm/src/abi.rs @@ -229,7 +229,7 @@ impl<'ll, 'tcx> ArgAbiExt<'ll, 'tcx> for ArgAbi<'tcx, Ty<'tcx>> { let llscratch = bx.alloca(scratch_size, scratch_align); bx.lifetime_start(llscratch, scratch_size); // ...store the value... - bx.store(val, llscratch, scratch_align); + rustc_codegen_ssa::mir::store_cast(bx, cast, val, llscratch, scratch_align); // ... and then memcpy it to the intended destination. bx.memcpy( dst.val.llval, diff --git a/compiler/rustc_codegen_ssa/src/mir/block.rs b/compiler/rustc_codegen_ssa/src/mir/block.rs index 43b87171d510d..3df97429e0931 100644 --- a/compiler/rustc_codegen_ssa/src/mir/block.rs +++ b/compiler/rustc_codegen_ssa/src/mir/block.rs @@ -1,6 +1,6 @@ use std::cmp; -use rustc_abi::{BackendRepr, ExternAbi, HasDataLayout, Reg, Size, WrappingRange}; +use rustc_abi::{Align, BackendRepr, ExternAbi, HasDataLayout, Reg, Size, WrappingRange}; use rustc_ast as ast; use rustc_ast::{InlineAsmOptions, InlineAsmTemplatePiece}; use rustc_data_structures::packed::Pu128; @@ -13,7 +13,7 @@ use rustc_middle::{bug, span_bug}; use rustc_session::config::OptLevel; use rustc_span::Span; use rustc_span::source_map::Spanned; -use rustc_target::callconv::{ArgAbi, FnAbi, PassMode}; +use rustc_target::callconv::{ArgAbi, CastTarget, FnAbi, PassMode}; use tracing::{debug, info}; use super::operand::OperandRef; @@ -558,8 +558,7 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> { } ZeroSized => bug!("ZST return value shouldn't be in PassMode::Cast"), }; - let ty = bx.cast_backend_type(cast_ty); - bx.load(ty, llslot, self.fn_abi.ret.layout.align.abi) + load_cast(bx, cast_ty, llslot, self.fn_abi.ret.layout.align.abi) } }; bx.ret(llval); @@ -1618,8 +1617,7 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> { MemFlags::empty(), ); // ...and then load it with the ABI type. - let cast_ty = bx.cast_backend_type(cast); - llval = bx.load(cast_ty, llscratch, scratch_align); + llval = load_cast(bx, cast, llscratch, scratch_align); bx.lifetime_end(llscratch, scratch_size); } else { // We can't use `PlaceRef::load` here because the argument @@ -1969,3 +1967,47 @@ enum ReturnDest<'tcx, V> { /// Store a direct return value to an operand local place. DirectOperand(mir::Local), } + +fn load_cast<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>>( + bx: &mut Bx, + cast: &CastTarget, + ptr: Bx::Value, + align: Align, +) -> Bx::Value { + let cast_ty = bx.cast_backend_type(cast); + if let Some(offset_from_start) = cast.rest_offset { + assert!(cast.prefix[1..].iter().all(|p| p.is_none())); + assert_eq!(cast.rest.unit.size, cast.rest.total); + let first_ty = bx.reg_backend_type(&cast.prefix[0].unwrap()); + let second_ty = bx.reg_backend_type(&cast.rest.unit); + let first = bx.load(first_ty, ptr, align); + let second_ptr = bx.inbounds_ptradd(ptr, bx.const_usize(offset_from_start.bytes())); + let second = bx.load(second_ty, second_ptr, align.restrict_for_offset(offset_from_start)); + let res = bx.cx().const_poison(cast_ty); + let res = bx.insert_value(res, first, 0); + bx.insert_value(res, second, 1) + } else { + bx.load(cast_ty, ptr, align) + } +} + +pub fn store_cast<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>>( + bx: &mut Bx, + cast: &CastTarget, + value: Bx::Value, + ptr: Bx::Value, + align: Align, +) { + if let Some(offset_from_start) = cast.rest_offset { + assert!(cast.prefix[1..].iter().all(|p| p.is_none())); + assert_eq!(cast.rest.unit.size, cast.rest.total); + assert!(cast.prefix[0].is_some()); + let first = bx.extract_value(value, 0); + let second = bx.extract_value(value, 1); + bx.store(first, ptr, align); + let second_ptr = bx.inbounds_ptradd(ptr, bx.const_usize(offset_from_start.bytes())); + bx.store(second, second_ptr, align.restrict_for_offset(offset_from_start)); + } else { + bx.store(value, ptr, align); + }; +} diff --git a/compiler/rustc_codegen_ssa/src/mir/mod.rs b/compiler/rustc_codegen_ssa/src/mir/mod.rs index 96a04473aba2e..66c4af4c935b5 100644 --- a/compiler/rustc_codegen_ssa/src/mir/mod.rs +++ b/compiler/rustc_codegen_ssa/src/mir/mod.rs @@ -26,6 +26,7 @@ pub mod place; mod rvalue; mod statement; +pub use self::block::store_cast; use self::debuginfo::{FunctionDebugContext, PerLocalVarDebugInfo}; use self::operand::{OperandRef, OperandValue}; use self::place::PlaceRef; @@ -259,7 +260,7 @@ pub fn codegen_mir<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>>( } PassMode::Cast { ref cast, .. } => { debug!("alloc: {:?} (return place) -> place", local); - let size = cast.size(&start_bx); + let size = cast.size(&start_bx).max(layout.size); return LocalRef::Place(PlaceRef::alloca_size(&mut start_bx, size, layout)); } _ => {} diff --git a/compiler/rustc_target/src/callconv/mips64.rs b/compiler/rustc_target/src/callconv/mips64.rs index 89f324bc31308..77c0cf06fc165 100644 --- a/compiler/rustc_target/src/callconv/mips64.rs +++ b/compiler/rustc_target/src/callconv/mips64.rs @@ -2,9 +2,7 @@ use rustc_abi::{ BackendRepr, FieldsShape, Float, HasDataLayout, Primitive, Reg, Size, TyAbiInterface, }; -use crate::callconv::{ - ArgAbi, ArgAttribute, ArgAttributes, ArgExtension, CastTarget, FnAbi, PassMode, Uniform, -}; +use crate::callconv::{ArgAbi, ArgExtension, CastTarget, FnAbi, PassMode, Uniform}; fn extend_integer_width_mips(arg: &mut ArgAbi<'_, Ty>, bits: u64) { // Always sign extend u32 values on 64-bit mips @@ -140,16 +138,7 @@ where // Extract first 8 chunks as the prefix let rest_size = size - Size::from_bytes(8) * prefix_index as u64; - arg.cast_to(CastTarget { - prefix, - rest: Uniform::new(Reg::i64(), rest_size), - attrs: ArgAttributes { - regular: ArgAttribute::default(), - arg_ext: ArgExtension::None, - pointee_size: Size::ZERO, - pointee_align: None, - }, - }); + arg.cast_to(CastTarget::prefixed(prefix, Uniform::new(Reg::i64(), rest_size))); } pub(crate) fn compute_abi_info<'a, Ty, C>(cx: &C, fn_abi: &mut FnAbi<'a, Ty>) diff --git a/compiler/rustc_target/src/callconv/mod.rs b/compiler/rustc_target/src/callconv/mod.rs index 2ff7a71ca823d..71cc2a455638b 100644 --- a/compiler/rustc_target/src/callconv/mod.rs +++ b/compiler/rustc_target/src/callconv/mod.rs @@ -197,6 +197,17 @@ impl ArgAttributes { } } +impl From for ArgAttributes { + fn from(value: ArgAttribute) -> Self { + Self { + regular: value, + arg_ext: ArgExtension::None, + pointee_size: Size::ZERO, + pointee_align: None, + } + } +} + /// An argument passed entirely registers with the /// same kind (e.g., HFA / HVA on PPC64 and AArch64). #[derive(Clone, Copy, PartialEq, Eq, Hash, Debug, HashStable_Generic)] @@ -251,6 +262,9 @@ impl Uniform { #[derive(Clone, PartialEq, Eq, Hash, Debug, HashStable_Generic)] pub struct CastTarget { pub prefix: [Option; 8], + /// The offset of `rest` from the start of the value. Currently only implemented for a `Reg` + /// pair created by the `offset_pair` method. + pub rest_offset: Option, pub rest: Uniform, pub attrs: ArgAttributes, } @@ -263,42 +277,45 @@ impl From for CastTarget { impl From for CastTarget { fn from(uniform: Uniform) -> CastTarget { - CastTarget { - prefix: [None; 8], - rest: uniform, - attrs: ArgAttributes { - regular: ArgAttribute::default(), - arg_ext: ArgExtension::None, - pointee_size: Size::ZERO, - pointee_align: None, - }, - } + Self::prefixed([None; 8], uniform) } } impl CastTarget { - pub fn pair(a: Reg, b: Reg) -> CastTarget { - CastTarget { + pub fn prefixed(prefix: [Option; 8], rest: Uniform) -> Self { + Self { prefix, rest_offset: None, rest, attrs: ArgAttributes::new() } + } + + pub fn offset_pair(a: Reg, offset_from_start: Size, b: Reg) -> Self { + Self { prefix: [Some(a), None, None, None, None, None, None, None], - rest: Uniform::from(b), - attrs: ArgAttributes { - regular: ArgAttribute::default(), - arg_ext: ArgExtension::None, - pointee_size: Size::ZERO, - pointee_align: None, - }, + rest_offset: Some(offset_from_start), + rest: b.into(), + attrs: ArgAttributes::new(), } } + pub fn with_attrs(mut self, attrs: ArgAttributes) -> Self { + self.attrs = attrs; + self + } + + pub fn pair(a: Reg, b: Reg) -> CastTarget { + Self::prefixed([Some(a), None, None, None, None, None, None, None], Uniform::from(b)) + } + /// When you only access the range containing valid data, you can use this unaligned size; /// otherwise, use the safer `size` method. pub fn unaligned_size(&self, _cx: &C) -> Size { // Prefix arguments are passed in specific designated registers - let prefix_size = self - .prefix - .iter() - .filter_map(|x| x.map(|reg| reg.size)) - .fold(Size::ZERO, |acc, size| acc + size); + let prefix_size = if let Some(offset_from_start) = self.rest_offset { + offset_from_start + } else { + self.prefix + .iter() + .filter_map(|x| x.map(|reg| reg.size)) + .fold(Size::ZERO, |acc, size| acc + size) + }; // Remaining arguments are passed in chunks of the unit size let rest_size = self.rest.unit.size * self.rest.total.bytes().div_ceil(self.rest.unit.size.bytes()); @@ -322,9 +339,22 @@ impl CastTarget { /// Checks if these two `CastTarget` are equal enough to be considered "the same for all /// function call ABIs". pub fn eq_abi(&self, other: &Self) -> bool { - let CastTarget { prefix: prefix_l, rest: rest_l, attrs: attrs_l } = self; - let CastTarget { prefix: prefix_r, rest: rest_r, attrs: attrs_r } = other; - prefix_l == prefix_r && rest_l == rest_r && attrs_l.eq_abi(attrs_r) + let CastTarget { + prefix: prefix_l, + rest_offset: rest_offset_l, + rest: rest_l, + attrs: attrs_l, + } = self; + let CastTarget { + prefix: prefix_r, + rest_offset: rest_offset_r, + rest: rest_r, + attrs: attrs_r, + } = other; + prefix_l == prefix_r + && rest_offset_l == rest_offset_r + && rest_l == rest_r + && attrs_l.eq_abi(attrs_r) } } diff --git a/compiler/rustc_target/src/callconv/nvptx64.rs b/compiler/rustc_target/src/callconv/nvptx64.rs index a26e7dac5bafb..44977de7fcbc2 100644 --- a/compiler/rustc_target/src/callconv/nvptx64.rs +++ b/compiler/rustc_target/src/callconv/nvptx64.rs @@ -1,6 +1,6 @@ use rustc_abi::{HasDataLayout, Reg, Size, TyAbiInterface}; -use super::{ArgAttribute, ArgAttributes, ArgExtension, CastTarget}; +use super::CastTarget; use crate::callconv::{ArgAbi, FnAbi, Uniform}; fn classify_ret(ret: &mut ArgAbi<'_, Ty>) { @@ -34,16 +34,10 @@ fn classify_aggregate(arg: &mut ArgAbi<'_, Ty>) { }; if align_bytes == size.bytes() { - arg.cast_to(CastTarget { - prefix: [Some(reg), None, None, None, None, None, None, None], - rest: Uniform::new(Reg::i8(), Size::from_bytes(0)), - attrs: ArgAttributes { - regular: ArgAttribute::default(), - arg_ext: ArgExtension::None, - pointee_size: Size::ZERO, - pointee_align: None, - }, - }); + arg.cast_to(CastTarget::prefixed( + [Some(reg), None, None, None, None, None, None, None], + Uniform::new(Reg::i8(), Size::ZERO), + )); } else { arg.cast_to(Uniform::new(reg, size)); } @@ -78,11 +72,10 @@ where }; if arg.layout.size.bytes() / align_bytes == 1 { // Make sure we pass the struct as array at the LLVM IR level and not as a single integer. - arg.cast_to(CastTarget { - prefix: [Some(unit), None, None, None, None, None, None, None], - rest: Uniform::new(unit, Size::ZERO), - attrs: ArgAttributes::new(), - }); + arg.cast_to(CastTarget::prefixed( + [Some(unit), None, None, None, None, None, None, None], + Uniform::new(unit, Size::ZERO), + )); } else { arg.cast_to(Uniform::new(unit, arg.layout.size)); } diff --git a/compiler/rustc_target/src/callconv/riscv.rs b/compiler/rustc_target/src/callconv/riscv.rs index cd1d3cd1eee05..6a2038f938116 100644 --- a/compiler/rustc_target/src/callconv/riscv.rs +++ b/compiler/rustc_target/src/callconv/riscv.rs @@ -14,16 +14,16 @@ use crate::spec::HasTargetSpec; #[derive(Copy, Clone)] enum RegPassKind { - Float(Reg), - Integer(Reg), + Float { offset_from_start: Size, ty: Reg }, + Integer { offset_from_start: Size, ty: Reg }, Unknown, } #[derive(Copy, Clone)] enum FloatConv { - FloatPair(Reg, Reg), + FloatPair { first_ty: Reg, second_ty_offset_from_start: Size, second_ty: Reg }, Float(Reg), - MixedPair(Reg, Reg), + MixedPair { first_ty: Reg, second_ty_offset_from_start: Size, second_ty: Reg }, } #[derive(Copy, Clone)] @@ -43,6 +43,7 @@ fn should_use_fp_conv_helper<'a, Ty, C>( flen: u64, field1_kind: &mut RegPassKind, field2_kind: &mut RegPassKind, + offset_from_start: Size, ) -> Result<(), CannotUseFpConv> where Ty: TyAbiInterface<'a, C> + Copy, @@ -55,16 +56,16 @@ where } match (*field1_kind, *field2_kind) { (RegPassKind::Unknown, _) => { - *field1_kind = RegPassKind::Integer(Reg { - kind: RegKind::Integer, - size: arg_layout.size, - }); + *field1_kind = RegPassKind::Integer { + offset_from_start, + ty: Reg { kind: RegKind::Integer, size: arg_layout.size }, + }; } - (RegPassKind::Float(_), RegPassKind::Unknown) => { - *field2_kind = RegPassKind::Integer(Reg { - kind: RegKind::Integer, - size: arg_layout.size, - }); + (RegPassKind::Float { .. }, RegPassKind::Unknown) => { + *field2_kind = RegPassKind::Integer { + offset_from_start, + ty: Reg { kind: RegKind::Integer, size: arg_layout.size }, + }; } _ => return Err(CannotUseFpConv), } @@ -75,12 +76,16 @@ where } match (*field1_kind, *field2_kind) { (RegPassKind::Unknown, _) => { - *field1_kind = - RegPassKind::Float(Reg { kind: RegKind::Float, size: arg_layout.size }); + *field1_kind = RegPassKind::Float { + offset_from_start, + ty: Reg { kind: RegKind::Float, size: arg_layout.size }, + }; } (_, RegPassKind::Unknown) => { - *field2_kind = - RegPassKind::Float(Reg { kind: RegKind::Float, size: arg_layout.size }); + *field2_kind = RegPassKind::Float { + offset_from_start, + ty: Reg { kind: RegKind::Float, size: arg_layout.size }, + }; } _ => return Err(CannotUseFpConv), } @@ -102,13 +107,14 @@ where flen, field1_kind, field2_kind, + offset_from_start, ); } return Err(CannotUseFpConv); } } FieldsShape::Array { count, .. } => { - for _ in 0..count { + for i in 0..count { let elem_layout = arg_layout.field(cx, 0); should_use_fp_conv_helper( cx, @@ -117,6 +123,7 @@ where flen, field1_kind, field2_kind, + offset_from_start + elem_layout.size * i, )?; } } @@ -127,7 +134,15 @@ where } for i in arg_layout.fields.index_by_increasing_offset() { let field = arg_layout.field(cx, i); - should_use_fp_conv_helper(cx, &field, xlen, flen, field1_kind, field2_kind)?; + should_use_fp_conv_helper( + cx, + &field, + xlen, + flen, + field1_kind, + field2_kind, + offset_from_start + arg_layout.fields.offset(i), + )?; } } }, @@ -146,14 +161,52 @@ where { let mut field1_kind = RegPassKind::Unknown; let mut field2_kind = RegPassKind::Unknown; - if should_use_fp_conv_helper(cx, arg, xlen, flen, &mut field1_kind, &mut field2_kind).is_err() { + if should_use_fp_conv_helper( + cx, + arg, + xlen, + flen, + &mut field1_kind, + &mut field2_kind, + Size::ZERO, + ) + .is_err() + { return None; } match (field1_kind, field2_kind) { - (RegPassKind::Integer(l), RegPassKind::Float(r)) => Some(FloatConv::MixedPair(l, r)), - (RegPassKind::Float(l), RegPassKind::Integer(r)) => Some(FloatConv::MixedPair(l, r)), - (RegPassKind::Float(l), RegPassKind::Float(r)) => Some(FloatConv::FloatPair(l, r)), - (RegPassKind::Float(f), RegPassKind::Unknown) => Some(FloatConv::Float(f)), + ( + RegPassKind::Integer { offset_from_start, .. } + | RegPassKind::Float { offset_from_start, .. }, + _, + ) if offset_from_start != Size::ZERO => { + panic!("type {:?} has a first field with non-zero offset {offset_from_start:?}", arg.ty) + } + ( + RegPassKind::Integer { ty: first_ty, .. }, + RegPassKind::Float { offset_from_start, ty: second_ty }, + ) => Some(FloatConv::MixedPair { + first_ty, + second_ty_offset_from_start: offset_from_start, + second_ty, + }), + ( + RegPassKind::Float { ty: first_ty, .. }, + RegPassKind::Integer { offset_from_start, ty: second_ty }, + ) => Some(FloatConv::MixedPair { + first_ty, + second_ty_offset_from_start: offset_from_start, + second_ty, + }), + ( + RegPassKind::Float { ty: first_ty, .. }, + RegPassKind::Float { offset_from_start, ty: second_ty }, + ) => Some(FloatConv::FloatPair { + first_ty, + second_ty_offset_from_start: offset_from_start, + second_ty, + }), + (RegPassKind::Float { ty, .. }, RegPassKind::Unknown) => Some(FloatConv::Float(ty)), _ => None, } } @@ -171,11 +224,19 @@ where FloatConv::Float(f) => { arg.cast_to(f); } - FloatConv::FloatPair(l, r) => { - arg.cast_to(CastTarget::pair(l, r)); + FloatConv::FloatPair { first_ty, second_ty_offset_from_start, second_ty } => { + arg.cast_to(CastTarget::offset_pair( + first_ty, + second_ty_offset_from_start, + second_ty, + )); } - FloatConv::MixedPair(l, r) => { - arg.cast_to(CastTarget::pair(l, r)); + FloatConv::MixedPair { first_ty, second_ty_offset_from_start, second_ty } => { + arg.cast_to(CastTarget::offset_pair( + first_ty, + second_ty_offset_from_start, + second_ty, + )); } } return false; @@ -239,15 +300,27 @@ fn classify_arg<'a, Ty, C>( arg.cast_to(f); return; } - Some(FloatConv::FloatPair(l, r)) if *avail_fprs >= 2 => { + Some(FloatConv::FloatPair { first_ty, second_ty_offset_from_start, second_ty }) + if *avail_fprs >= 2 => + { *avail_fprs -= 2; - arg.cast_to(CastTarget::pair(l, r)); + arg.cast_to(CastTarget::offset_pair( + first_ty, + second_ty_offset_from_start, + second_ty, + )); return; } - Some(FloatConv::MixedPair(l, r)) if *avail_fprs >= 1 && *avail_gprs >= 1 => { + Some(FloatConv::MixedPair { first_ty, second_ty_offset_from_start, second_ty }) + if *avail_fprs >= 1 && *avail_gprs >= 1 => + { *avail_gprs -= 1; *avail_fprs -= 1; - arg.cast_to(CastTarget::pair(l, r)); + arg.cast_to(CastTarget::offset_pair( + first_ty, + second_ty_offset_from_start, + second_ty, + )); return; } _ => (), diff --git a/compiler/rustc_target/src/callconv/sparc64.rs b/compiler/rustc_target/src/callconv/sparc64.rs index 7ca0031fc59c0..186826c08fcb8 100644 --- a/compiler/rustc_target/src/callconv/sparc64.rs +++ b/compiler/rustc_target/src/callconv/sparc64.rs @@ -5,9 +5,7 @@ use rustc_abi::{ TyAndLayout, }; -use crate::callconv::{ - ArgAbi, ArgAttribute, ArgAttributes, ArgExtension, CastTarget, FnAbi, Uniform, -}; +use crate::callconv::{ArgAbi, ArgAttribute, CastTarget, FnAbi, Uniform}; use crate::spec::HasTargetSpec; #[derive(Clone, Debug)] @@ -197,16 +195,10 @@ where rest_size = rest_size - Reg::i32().size; } - arg.cast_to(CastTarget { - prefix: data.prefix, - rest: Uniform::new(Reg::i64(), rest_size), - attrs: ArgAttributes { - regular: data.arg_attribute, - arg_ext: ArgExtension::None, - pointee_size: Size::ZERO, - pointee_align: None, - }, - }); + arg.cast_to( + CastTarget::prefixed(data.prefix, Uniform::new(Reg::i64(), rest_size)) + .with_attrs(data.arg_attribute.into()), + ); return; } } diff --git a/tests/assembly/riscv-float-struct-abi.rs b/tests/assembly/riscv-float-struct-abi.rs new file mode 100644 index 0000000000000..5d9ac9d70b831 --- /dev/null +++ b/tests/assembly/riscv-float-struct-abi.rs @@ -0,0 +1,177 @@ +//@ add-core-stubs +//@ assembly-output: emit-asm +//@ compile-flags: -Copt-level=3 --target riscv64gc-unknown-linux-gnu +//@ needs-llvm-components: riscv + +#![feature(no_core, lang_items)] +#![no_std] +#![no_core] +#![crate_type = "lib"] + +extern crate minicore; +use minicore::*; + +#[repr(C, align(64))] +struct Aligned(f64); + +#[repr(C)] +struct Padded(u8, Aligned); + +#[repr(C, packed)] +struct Packed(u8, f32); + +impl Copy for Aligned {} +impl Copy for Padded {} +impl Copy for Packed {} + +extern "C" { + fn take_padded(x: Padded); + fn get_padded() -> Padded; + fn take_packed(x: Packed); + fn get_packed() -> Packed; +} + +// CHECK-LABEL: pass_padded +#[unsafe(no_mangle)] +extern "C" fn pass_padded(out: &mut Padded, x: Padded) { + // CHECK: sb a1, 0(a0) + // CHECK-NEXT: fsd fa0, 64(a0) + // CHECK-NEXT: ret + *out = x; +} + +// CHECK-LABEL: ret_padded +#[unsafe(no_mangle)] +extern "C" fn ret_padded(x: &Padded) -> Padded { + // CHECK: fld fa0, 64(a0) + // CHECK-NEXT: lbu a0, 0(a0) + // CHECK-NEXT: ret + *x +} + +#[unsafe(no_mangle)] +extern "C" fn call_padded(x: &Padded) { + // CHECK: fld fa0, 64(a0) + // CHECK-NEXT: lbu a0, 0(a0) + // CHECK-NEXT: tail take_padded + unsafe { + take_padded(*x); + } +} + +#[unsafe(no_mangle)] +extern "C" fn receive_padded(out: &mut Padded) { + // CHECK: addi sp, sp, -16 + // CHECK-NEXT: .cfi_def_cfa_offset 16 + // CHECK-NEXT: sd ra, [[#%d,RA_SPILL:]](sp) + // CHECK-NEXT: sd [[TEMP:.*]], [[#%d,TEMP_SPILL:]](sp) + // CHECK-NEXT: .cfi_offset ra, [[#%d,RA_SPILL - 16]] + // CHECK-NEXT: .cfi_offset [[TEMP]], [[#%d,TEMP_SPILL - 16]] + // CHECK-NEXT: mv [[TEMP]], a0 + // CHECK-NEXT: call get_padded + // CHECK-NEXT: sb a0, 0([[TEMP]]) + // CHECK-NEXT: fsd fa0, 64([[TEMP]]) + // CHECK-NEXT: ld ra, [[#%d,RA_SPILL]](sp) + // CHECK-NEXT: ld [[TEMP]], [[#%d,TEMP_SPILL]](sp) + // CHECK: addi sp, sp, 16 + // CHECK: ret + unsafe { + *out = get_padded(); + } +} + +// CHECK-LABEL: pass_packed +#[unsafe(no_mangle)] +extern "C" fn pass_packed(out: &mut Packed, x: Packed) { + // CHECK: addi sp, sp, -16 + // CHECK-NEXT: .cfi_def_cfa_offset 16 + // CHECK-NEXT: sb a1, 0(a0) + // CHECK-NEXT: fsw fa0, 8(sp) + // CHECK-NEXT: lw [[VALUE:.*]], 8(sp) + // CHECK-DAG: srli [[BYTE4:.*]], [[VALUE]], 24 + // CHECK-DAG: srli [[BYTE3:.*]], [[VALUE]], 16 + // CHECK-DAG: srli [[BYTE2:.*]], [[VALUE]], 8 + // CHECK-DAG: sb [[VALUE]], 1(a0) + // CHECK-DAG: sb [[BYTE2]], 2(a0) + // CHECK-DAG: sb [[BYTE3]], 3(a0) + // CHECK-DAG: sb [[BYTE4]], 4(a0) + // CHECK-NEXT: addi sp, sp, 16 + // CHECK: ret + *out = x; +} + +// CHECK-LABEL: ret_packed +#[unsafe(no_mangle)] +extern "C" fn ret_packed(x: &Packed) -> Packed { + // CHECK: addi sp, sp, -16 + // CHECK-NEXT: .cfi_def_cfa_offset 16 + // CHECK-NEXT: lbu [[BYTE2:.*]], 2(a0) + // CHECK-NEXT: lbu [[BYTE1:.*]], 1(a0) + // CHECK-NEXT: lbu [[BYTE3:.*]], 3(a0) + // CHECK-NEXT: lbu [[BYTE4:.*]], 4(a0) + // CHECK-NEXT: slli [[SHIFTED2:.*]], [[BYTE2]], 8 + // CHECK-NEXT: or [[BYTE12:.*]], [[SHIFTED2]], [[BYTE1]] + // CHECK-NEXT: slli [[SHIFTED3:.*]], [[BYTE3]], 16 + // CHECK-NEXT: slli [[SHIFTED4:.*]], [[BYTE4]], 24 + // CHECK-NEXT: or [[BYTE34:.*]], [[SHIFTED3]], [[SHIFTED4]] + // CHECK-NEXT: or [[VALUE:.*]], [[BYTE12]], [[BYTE34]] + // CHECK-NEXT: sw [[VALUE]], 8(sp) + // CHECK-NEXT: flw fa0, 8(sp) + // CHECK-NEXT: lbu a0, 0(a0) + // CHECK-NEXT: addi sp, sp, 16 + // CHECK: ret + *x +} + +#[unsafe(no_mangle)] +extern "C" fn call_packed(x: &Packed) { + // CHECK: addi sp, sp, -16 + // CHECK-NEXT: .cfi_def_cfa_offset 16 + // CHECK-NEXT: lbu [[BYTE2:.*]], 2(a0) + // CHECK-NEXT: lbu [[BYTE1:.*]], 1(a0) + // CHECK-NEXT: lbu [[BYTE3:.*]], 3(a0) + // CHECK-NEXT: lbu [[BYTE4:.*]], 4(a0) + // CHECK-NEXT: slli [[SHIFTED2:.*]], [[BYTE2]], 8 + // CHECK-NEXT: or [[BYTE12:.*]], [[SHIFTED2]], [[BYTE1]] + // CHECK-NEXT: slli [[SHIFTED3:.*]], [[BYTE3]], 16 + // CHECK-NEXT: slli [[SHIFTED4:.*]], [[BYTE4]], 24 + // CHECK-NEXT: or [[BYTE34:.*]], [[SHIFTED3]], [[SHIFTED4]] + // CHECK-NEXT: or [[VALUE:.*]], [[BYTE12]], [[BYTE34]] + // CHECK-NEXT: sw [[VALUE]], 8(sp) + // CHECK-NEXT: flw fa0, 8(sp) + // CHECK-NEXT: lbu a0, 0(a0) + // CHECK-NEXT: addi sp, sp, 16 + // CHECK: tail take_packed + unsafe { + take_packed(*x); + } +} + +#[unsafe(no_mangle)] +extern "C" fn receive_packed(out: &mut Packed) { + // CHECK: addi sp, sp, -32 + // CHECK-NEXT: .cfi_def_cfa_offset 32 + // CHECK-NEXT: sd ra, [[#%d,RA_SPILL:]](sp) + // CHECK-NEXT: sd [[TEMP:.*]], [[#%d,TEMP_SPILL:]](sp) + // CHECK-NEXT: .cfi_offset ra, [[#%d,RA_SPILL - 32]] + // CHECK-NEXT: .cfi_offset [[TEMP]], [[#%d,TEMP_SPILL - 32]] + // CHECK-NEXT: mv [[TEMP]], a0 + // CHECK-NEXT: call get_packed + // CHECK-NEXT: sb a0, 0([[TEMP]]) + // CHECK-NEXT: fsw fa0, [[FLOAT_SPILL:.*]](sp) + // CHECK-NEXT: lw [[VALUE:.*]], [[FLOAT_SPILL]](sp) + // CHECK-DAG: srli [[BYTE4:.*]], [[VALUE]], 24 + // CHECK-DAG: srli [[BYTE3:.*]], [[VALUE]], 16 + // CHECK-DAG: srli [[BYTE2:.*]], [[VALUE]], 8 + // CHECK-DAG: sb [[VALUE]], 1([[TEMP]]) + // CHECK-DAG: sb [[BYTE2]], 2([[TEMP]]) + // CHECK-DAG: sb [[BYTE3]], 3([[TEMP]]) + // CHECK-DAG: sb [[BYTE4]], 4([[TEMP]]) + // CHECK-NEXT: ld ra, [[#%d,RA_SPILL]](sp) + // CHECK-NEXT: ld [[TEMP]], [[#%d,TEMP_SPILL]](sp) + // CHECK: addi sp, sp, 32 + // CHECK: ret + unsafe { + *out = get_packed(); + } +} diff --git a/tests/codegen/riscv-abi/cast-local-large-enough.rs b/tests/codegen/riscv-abi/cast-local-large-enough.rs new file mode 100644 index 0000000000000..9d21d73b4597f --- /dev/null +++ b/tests/codegen/riscv-abi/cast-local-large-enough.rs @@ -0,0 +1,44 @@ +//@ add-core-stubs +//@ compile-flags: -Copt-level=0 -Cdebuginfo=0 --target riscv64gc-unknown-linux-gnu +//@ needs-llvm-components: riscv + +#![feature(no_core, lang_items)] +#![no_std] +#![no_core] +#![crate_type = "lib"] + +extern crate minicore; +use minicore::*; + +#[repr(C, align(64))] +struct Aligned(f64); + +#[repr(C, align(64))] +struct AlignedPair(f32, f64); + +impl Copy for Aligned {} +impl Copy for AlignedPair {} + +// CHECK-LABEL: define double @read_aligned +#[unsafe(no_mangle)] +pub extern "C" fn read_aligned(x: &Aligned) -> Aligned { + // CHECK: %[[TEMP:.*]] = alloca [64 x i8], align 64 + // CHECK-NEXT: call void @llvm.memcpy.p0.p0.i64(ptr align 64 %[[TEMP]], ptr align 64 %[[PTR:.*]], i64 64, i1 false) + // CHECK-NEXT: %[[RES:.*]] = load double, ptr %[[TEMP]], align 64 + // CHECK-NEXT: ret double %[[RES]] + *x +} + +// CHECK-LABEL: define { float, double } @read_aligned_pair +#[unsafe(no_mangle)] +pub extern "C" fn read_aligned_pair(x: &AlignedPair) -> AlignedPair { + // CHECK: %[[TEMP:.*]] = alloca [64 x i8], align 64 + // CHECK-NEXT: call void @llvm.memcpy.p0.p0.i64(ptr align 64 %[[TEMP]], ptr align 64 %[[PTR:.*]], i64 64, i1 false) + // CHECK-NEXT: %[[FIRST:.*]] = load float, ptr %[[TEMP]], align 64 + // CHECK-NEXT: %[[SECOND_PTR:.*]] = getelementptr inbounds i8, ptr %[[TEMP]], i64 8 + // CHECK-NEXT: %[[SECOND:.*]] = load double, ptr %[[SECOND_PTR]], align 8 + // CHECK-NEXT: %[[RES1:.*]] = insertvalue { float, double } poison, float %[[FIRST]], 0 + // CHECK-NEXT: %[[RES2:.*]] = insertvalue { float, double } %[[RES1]], double %[[SECOND]], 1 + // CHECK-NEXT: ret { float, double } %[[RES2]] + *x +} diff --git a/tests/ui/abi/numbers-arithmetic/float-struct.rs b/tests/ui/abi/numbers-arithmetic/float-struct.rs new file mode 100644 index 0000000000000..a958dc272722f --- /dev/null +++ b/tests/ui/abi/numbers-arithmetic/float-struct.rs @@ -0,0 +1,44 @@ +//@ run-pass + +use std::fmt::Debug; +use std::hint::black_box; + +#[repr(C)] +#[derive(Copy, Clone, PartialEq, Debug, Default)] +struct Regular(f32, f64); + +#[repr(C, packed)] +#[derive(Copy, Clone, PartialEq, Debug, Default)] +struct Packed(f32, f64); + +#[repr(C, align(64))] +#[derive(Copy, Clone, PartialEq, Debug, Default)] +struct AlignedF32(f32); + +#[repr(C)] +#[derive(Copy, Clone, PartialEq, Debug, Default)] +struct Aligned(f64, AlignedF32); + +#[inline(never)] +extern "C" fn read(x: &T) -> T { + *black_box(x) +} + +#[inline(never)] +extern "C" fn write(x: T, dest: &mut T) { + *dest = black_box(x) +} + +#[track_caller] +fn check(x: T) { + assert_eq!(read(&x), x); + let mut out = T::default(); + write(x, &mut out); + assert_eq!(out, x); +} + +fn main() { + check(Regular(1.0, 2.0)); + check(Packed(3.0, 4.0)); + check(Aligned(5.0, AlignedF32(6.0))); +} From 7fb9284fb3e54db29919c3f2f8bd4212ac6b090d Mon Sep 17 00:00:00 2001 From: lcnr Date: Mon, 16 Jun 2025 14:01:01 +0200 Subject: [PATCH 6/8] candidate_is_applicable to method --- .../rustc_type_ir/src/search_graph/mod.rs | 23 +++++-------------- 1 file changed, 6 insertions(+), 17 deletions(-) diff --git a/compiler/rustc_type_ir/src/search_graph/mod.rs b/compiler/rustc_type_ir/src/search_graph/mod.rs index f0eb96b47b108..b59b4f9285400 100644 --- a/compiler/rustc_type_ir/src/search_graph/mod.rs +++ b/compiler/rustc_type_ir/src/search_graph/mod.rs @@ -842,9 +842,8 @@ impl, X: Cx> SearchGraph { /// evaluating this entry would not have ended up depending on either a goal /// already on the stack or a provisional cache entry. fn candidate_is_applicable( - stack: &Stack, + &self, step_kind_from_parent: PathKind, - provisional_cache: &HashMap>>, nested_goals: &NestedGoals, ) -> bool { // If the global cache entry didn't depend on any nested goals, it always @@ -855,7 +854,7 @@ impl, X: Cx> SearchGraph { // If a nested goal of the global cache entry is on the stack, we would // definitely encounter a cycle. - if stack.iter().any(|e| nested_goals.contains(e.input)) { + if self.stack.iter().any(|e| nested_goals.contains(e.input)) { debug!("cache entry not applicable due to stack"); return false; } @@ -864,7 +863,7 @@ impl, X: Cx> SearchGraph { // would apply for any of its nested goals. #[allow(rustc::potential_query_instability)] for (input, path_from_global_entry) in nested_goals.iter() { - let Some(entries) = provisional_cache.get(&input) else { + let Some(entries) = self.provisional_cache.get(&input) else { continue; }; @@ -890,7 +889,7 @@ impl, X: Cx> SearchGraph { // We check if any of the paths taken while computing the global goal // would end up with an applicable provisional cache entry. let head = heads.highest_cycle_head(); - let head_to_curr = Self::cycle_path_kind(stack, step_kind_from_parent, head); + let head_to_curr = Self::cycle_path_kind(&self.stack, step_kind_from_parent, head); let full_paths = path_from_global_entry.extend_with(head_to_curr); if full_paths.contains(head_to_provisional.into()) { debug!( @@ -918,12 +917,7 @@ impl, X: Cx> SearchGraph { cx.with_global_cache(|cache| { cache .get(cx, input, available_depth, |nested_goals| { - Self::candidate_is_applicable( - &self.stack, - step_kind_from_parent, - &self.provisional_cache, - nested_goals, - ) + self.candidate_is_applicable(step_kind_from_parent, nested_goals) }) .map(|c| c.result) }) @@ -942,12 +936,7 @@ impl, X: Cx> SearchGraph { cx.with_global_cache(|cache| { let CacheData { result, required_depth, encountered_overflow, nested_goals } = cache .get(cx, input, available_depth, |nested_goals| { - Self::candidate_is_applicable( - &self.stack, - step_kind_from_parent, - &self.provisional_cache, - nested_goals, - ) + self.candidate_is_applicable(step_kind_from_parent, nested_goals) })?; // We don't move cycle participants to the global cache, so the From c63665cd73dda46c63aaa17c51d1cd83750fe2e1 Mon Sep 17 00:00:00 2001 From: xizheyin Date: Wed, 11 Jun 2025 15:06:50 +0800 Subject: [PATCH 7/8] Dont suggest converting `///` to regular comment when it appears after missing `,` in list Signed-off-by: xizheyin --- .../rustc_parse/src/parser/diagnostics.rs | 45 ++++++++++++------- ...omment-after-missing-comma-issue-142311.rs | 34 ++++++++++++++ ...nt-after-missing-comma-issue-142311.stderr | 43 ++++++++++++++++++ 3 files changed, 105 insertions(+), 17 deletions(-) create mode 100644 tests/ui/parser/doc-comment-after-missing-comma-issue-142311.rs create mode 100644 tests/ui/parser/doc-comment-after-missing-comma-issue-142311.stderr diff --git a/compiler/rustc_parse/src/parser/diagnostics.rs b/compiler/rustc_parse/src/parser/diagnostics.rs index b49a13ce584fb..26b5548df1731 100644 --- a/compiler/rustc_parse/src/parser/diagnostics.rs +++ b/compiler/rustc_parse/src/parser/diagnostics.rs @@ -686,23 +686,34 @@ impl<'a> Parser<'a> { } if let token::DocComment(kind, style, _) = self.token.kind { - // We have something like `expr //!val` where the user likely meant `expr // !val` - let pos = self.token.span.lo() + BytePos(2); - let span = self.token.span.with_lo(pos).with_hi(pos); - err.span_suggestion_verbose( - span, - format!( - "add a space before {} to write a regular comment", - match (kind, style) { - (token::CommentKind::Line, ast::AttrStyle::Inner) => "`!`", - (token::CommentKind::Block, ast::AttrStyle::Inner) => "`!`", - (token::CommentKind::Line, ast::AttrStyle::Outer) => "the last `/`", - (token::CommentKind::Block, ast::AttrStyle::Outer) => "the last `*`", - }, - ), - " ".to_string(), - Applicability::MachineApplicable, - ); + // This is to avoid suggesting converting a doc comment to a regular comment + // when missing a comma before the doc comment in lists (#142311): + // + // ``` + // enum Foo{ + // A /// xxxxxxx + // B, + // } + // ``` + if !expected.contains(&TokenType::Comma) { + // We have something like `expr //!val` where the user likely meant `expr // !val` + let pos = self.token.span.lo() + BytePos(2); + let span = self.token.span.with_lo(pos).with_hi(pos); + err.span_suggestion_verbose( + span, + format!( + "add a space before {} to write a regular comment", + match (kind, style) { + (token::CommentKind::Line, ast::AttrStyle::Inner) => "`!`", + (token::CommentKind::Block, ast::AttrStyle::Inner) => "`!`", + (token::CommentKind::Line, ast::AttrStyle::Outer) => "the last `/`", + (token::CommentKind::Block, ast::AttrStyle::Outer) => "the last `*`", + }, + ), + " ".to_string(), + Applicability::MaybeIncorrect, + ); + } } let sp = if self.token == token::Eof { diff --git a/tests/ui/parser/doc-comment-after-missing-comma-issue-142311.rs b/tests/ui/parser/doc-comment-after-missing-comma-issue-142311.rs new file mode 100644 index 0000000000000..7ac6fa127f4d3 --- /dev/null +++ b/tests/ui/parser/doc-comment-after-missing-comma-issue-142311.rs @@ -0,0 +1,34 @@ +//! Check that if the parser suggests converting `///` to a regular comment +//! when it appears after a missing comma in an list (e.g. `enum` variants). +//! +//! Related issue +//! - https://github.com/rust-lang/rust/issues/142311 + +enum Foo { + /// Like the noise a sheep makes + Bar + /// Like where people drink + //~^ ERROR expected one of `(`, `,`, `=`, `{`, or `}`, found doc comment `/// Like where people drink` + Baa///xxxxxx + //~^ ERROR expected one of `(`, `,`, `=`, `{`, or `}`, found doc comment `///xxxxxx` + Baz///xxxxxx + //~^ ERROR expected one of `(`, `,`, `=`, `{`, or `}`, found doc comment `///xxxxxx` +} + +fn foo() { + let a = [ + 1///xxxxxx + //~^ ERROR expected one of `,`, `.`, `;`, `?`, `]`, or an operator, found doc comment `///xxxxxx` + 2 + ]; +} + +fn bar() { + let a = [ + 1, + 2///xxxxxx + //~^ ERROR expected one of `,`, `.`, `?`, `]`, or an operator, found doc comment `///xxxxxx` + ]; +} + +fn main() {} diff --git a/tests/ui/parser/doc-comment-after-missing-comma-issue-142311.stderr b/tests/ui/parser/doc-comment-after-missing-comma-issue-142311.stderr new file mode 100644 index 0000000000000..d95cecfc560b8 --- /dev/null +++ b/tests/ui/parser/doc-comment-after-missing-comma-issue-142311.stderr @@ -0,0 +1,43 @@ +error: expected one of `(`, `,`, `=`, `{`, or `}`, found doc comment `/// Like where people drink` + --> $DIR/doc-comment-after-missing-comma-issue-142311.rs:10:5 + | +LL | Bar + | - + | | + | expected one of `(`, `,`, `=`, `{`, or `}` + | help: missing `,` +LL | /// Like where people drink + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ unexpected token + +error: expected one of `(`, `,`, `=`, `{`, or `}`, found doc comment `///xxxxxx` + --> $DIR/doc-comment-after-missing-comma-issue-142311.rs:12:8 + | +LL | Baa///xxxxxx + | -^^^^^^^^ + | | + | expected one of `(`, `,`, `=`, `{`, or `}` + | help: missing `,` + +error: expected one of `(`, `,`, `=`, `{`, or `}`, found doc comment `///xxxxxx` + --> $DIR/doc-comment-after-missing-comma-issue-142311.rs:14:8 + | +LL | Baz///xxxxxx + | ^^^^^^^^^ expected one of `(`, `,`, `=`, `{`, or `}` + | + = help: doc comments must come before what they document, if a comment was intended use `//` + = help: enum variants can be `Variant`, `Variant = `, `Variant(Type, ..., TypeN)` or `Variant { fields: Types }` + +error: expected one of `,`, `.`, `;`, `?`, `]`, or an operator, found doc comment `///xxxxxx` + --> $DIR/doc-comment-after-missing-comma-issue-142311.rs:20:10 + | +LL | 1///xxxxxx + | ^^^^^^^^^ expected one of `,`, `.`, `;`, `?`, `]`, or an operator + +error: expected one of `,`, `.`, `?`, `]`, or an operator, found doc comment `///xxxxxx` + --> $DIR/doc-comment-after-missing-comma-issue-142311.rs:29:10 + | +LL | 2///xxxxxx + | ^^^^^^^^^ expected one of `,`, `.`, `?`, `]`, or an operator + +error: aborting due to 5 previous errors + From da8d6bbd5043e8f4ea83a2431117c32b0339ac54 Mon Sep 17 00:00:00 2001 From: Pavel Grigorenko Date: Sat, 14 Jun 2025 13:01:15 +0300 Subject: [PATCH 8/8] Port `#[rustc_as_ptr]` to the new attribute system --- .../src/attributes.rs | 3 +++ .../src/attributes/lint_helpers.rs | 21 ++++++++++++++++ .../rustc_attr_parsing/src/attributes/mod.rs | 1 + compiler/rustc_attr_parsing/src/context.rs | 2 ++ compiler/rustc_lint/src/dangling.rs | 3 ++- compiler/rustc_passes/src/check_attr.rs | 24 +++++++++---------- 6 files changed, 41 insertions(+), 13 deletions(-) create mode 100644 compiler/rustc_attr_parsing/src/attributes/lint_helpers.rs diff --git a/compiler/rustc_attr_data_structures/src/attributes.rs b/compiler/rustc_attr_data_structures/src/attributes.rs index 845e4d5e5d0fa..32c410cc014b5 100644 --- a/compiler/rustc_attr_data_structures/src/attributes.rs +++ b/compiler/rustc_attr_data_structures/src/attributes.rs @@ -158,6 +158,9 @@ pub enum AttributeKind { /// Represents `#[allow_internal_unstable]`. AllowInternalUnstable(ThinVec<(Symbol, Span)>), + /// Represents `#[rustc_as_ptr]` (used by the `dangling_pointers_from_temporaries` lint). + AsPtr(Span), + /// Represents `#[rustc_default_body_unstable]`. BodyStability { stability: DefaultBodyStability, diff --git a/compiler/rustc_attr_parsing/src/attributes/lint_helpers.rs b/compiler/rustc_attr_parsing/src/attributes/lint_helpers.rs new file mode 100644 index 0000000000000..32a20d4c5b5e4 --- /dev/null +++ b/compiler/rustc_attr_parsing/src/attributes/lint_helpers.rs @@ -0,0 +1,21 @@ +use rustc_attr_data_structures::AttributeKind; +use rustc_span::{Symbol, sym}; + +use crate::attributes::{AttributeOrder, OnDuplicate, SingleAttributeParser}; +use crate::context::{AcceptContext, Stage}; +use crate::parser::ArgParser; + +pub(crate) struct AsPtrParser; + +impl SingleAttributeParser for AsPtrParser { + const PATH: &[Symbol] = &[sym::rustc_as_ptr]; + + const ATTRIBUTE_ORDER: AttributeOrder = AttributeOrder::KeepFirst; + + const ON_DUPLICATE: OnDuplicate = OnDuplicate::Error; + + fn convert(cx: &mut AcceptContext<'_, '_, S>, _args: &ArgParser<'_>) -> Option { + // FIXME: check that there's no args (this is currently checked elsewhere) + Some(AttributeKind::AsPtr(cx.attr_span)) + } +} diff --git a/compiler/rustc_attr_parsing/src/attributes/mod.rs b/compiler/rustc_attr_parsing/src/attributes/mod.rs index caf55e6685efc..df488c89a34fa 100644 --- a/compiler/rustc_attr_parsing/src/attributes/mod.rs +++ b/compiler/rustc_attr_parsing/src/attributes/mod.rs @@ -29,6 +29,7 @@ pub(crate) mod allow_unstable; pub(crate) mod cfg; pub(crate) mod confusables; pub(crate) mod deprecation; +pub(crate) mod lint_helpers; pub(crate) mod repr; pub(crate) mod stability; pub(crate) mod transparency; diff --git a/compiler/rustc_attr_parsing/src/context.rs b/compiler/rustc_attr_parsing/src/context.rs index 47f72232828ee..3193d8975e9fe 100644 --- a/compiler/rustc_attr_parsing/src/context.rs +++ b/compiler/rustc_attr_parsing/src/context.rs @@ -18,6 +18,7 @@ use rustc_span::{DUMMY_SP, ErrorGuaranteed, Span, Symbol, sym}; use crate::attributes::allow_unstable::{AllowConstFnUnstableParser, AllowInternalUnstableParser}; use crate::attributes::confusables::ConfusablesParser; use crate::attributes::deprecation::DeprecationParser; +use crate::attributes::lint_helpers::AsPtrParser; use crate::attributes::repr::ReprParser; use crate::attributes::stability::{ BodyStabilityParser, ConstStabilityIndirectParser, ConstStabilityParser, StabilityParser, @@ -102,6 +103,7 @@ attribute_parsers!( // tidy-alphabetical-end // tidy-alphabetical-start + Single, Single, Single, Single, diff --git a/compiler/rustc_lint/src/dangling.rs b/compiler/rustc_lint/src/dangling.rs index 91c7922638de5..c737919db9c2d 100644 --- a/compiler/rustc_lint/src/dangling.rs +++ b/compiler/rustc_lint/src/dangling.rs @@ -1,4 +1,5 @@ use rustc_ast::visit::{visit_opt, walk_list}; +use rustc_attr_data_structures::{AttributeKind, find_attr}; use rustc_hir::def_id::LocalDefId; use rustc_hir::intravisit::{FnKind, Visitor, walk_expr}; use rustc_hir::{Block, Body, Expr, ExprKind, FnDecl, LangItem}; @@ -133,7 +134,7 @@ fn lint_expr(cx: &LateContext<'_>, expr: &Expr<'_>) { && let ty = cx.typeck_results().expr_ty(receiver) && owns_allocation(cx.tcx, ty) && let Some(fn_id) = cx.typeck_results().type_dependent_def_id(expr.hir_id) - && cx.tcx.has_attr(fn_id, sym::rustc_as_ptr) + && find_attr!(cx.tcx.get_all_attrs(fn_id), AttributeKind::AsPtr(_)) { // FIXME: use `emit_node_lint` when `#[primary_span]` is added. cx.tcx.emit_node_span_lint( diff --git a/compiler/rustc_passes/src/check_attr.rs b/compiler/rustc_passes/src/check_attr.rs index 4e2be8ff0b817..dddbf65db72ea 100644 --- a/compiler/rustc_passes/src/check_attr.rs +++ b/compiler/rustc_passes/src/check_attr.rs @@ -147,6 +147,9 @@ impl<'tcx> CheckAttrVisitor<'tcx> { | AttributeKind::ConstStabilityIndirect | AttributeKind::MacroTransparency(_), ) => { /* do nothing */ } + Attribute::Parsed(AttributeKind::AsPtr(attr_span)) => { + self.check_applied_to_fn_or_method(hir_id, *attr_span, span, target) + } Attribute::Unparsed(_) => { match attr.path().as_slice() { [sym::diagnostic, sym::do_not_recommend, ..] => { @@ -188,26 +191,23 @@ impl<'tcx> CheckAttrVisitor<'tcx> { self.check_rustc_std_internal_symbol(attr, span, target) } [sym::naked, ..] => self.check_naked(hir_id, attr, span, target, attrs), - [sym::rustc_as_ptr, ..] => { - self.check_applied_to_fn_or_method(hir_id, attr, span, target) - } [sym::rustc_no_implicit_autorefs, ..] => { - self.check_applied_to_fn_or_method(hir_id, attr, span, target) + self.check_applied_to_fn_or_method(hir_id, attr.span(), span, target) } [sym::rustc_never_returns_null_ptr, ..] => { - self.check_applied_to_fn_or_method(hir_id, attr, span, target) + self.check_applied_to_fn_or_method(hir_id, attr.span(), span, target) } [sym::rustc_legacy_const_generics, ..] => { self.check_rustc_legacy_const_generics(hir_id, attr, span, target, item) } [sym::rustc_lint_query_instability, ..] => { - self.check_applied_to_fn_or_method(hir_id, attr, span, target) + self.check_applied_to_fn_or_method(hir_id, attr.span(), span, target) } [sym::rustc_lint_untracked_query_information, ..] => { - self.check_applied_to_fn_or_method(hir_id, attr, span, target) + self.check_applied_to_fn_or_method(hir_id, attr.span(), span, target) } [sym::rustc_lint_diagnostics, ..] => { - self.check_applied_to_fn_or_method(hir_id, attr, span, target) + self.check_applied_to_fn_or_method(hir_id, attr.span(), span, target) } [sym::rustc_lint_opt_ty, ..] => self.check_rustc_lint_opt_ty(attr, span, target), [sym::rustc_lint_opt_deny_field_access, ..] => { @@ -1825,15 +1825,15 @@ impl<'tcx> CheckAttrVisitor<'tcx> { fn check_applied_to_fn_or_method( &self, hir_id: HirId, - attr: &Attribute, - span: Span, + attr_span: Span, + defn_span: Span, target: Target, ) { let is_function = matches!(target, Target::Fn | Target::Method(..)); if !is_function { self.dcx().emit_err(errors::AttrShouldBeAppliedToFn { - attr_span: attr.span(), - defn_span: span, + attr_span, + defn_span, on_crate: hir_id == CRATE_HIR_ID, }); }