From 96e7d25891fbac3fb693a6c041b93a98712aba15 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=A9my=20Rakic?= Date: Sun, 14 Apr 2024 16:35:14 +0000 Subject: [PATCH 01/15] add missing lld directive to compiletest --- src/tools/compiletest/src/header.rs | 1 + 1 file changed, 1 insertion(+) diff --git a/src/tools/compiletest/src/header.rs b/src/tools/compiletest/src/header.rs index f78e0363f55..99597875d0f 100644 --- a/src/tools/compiletest/src/header.rs +++ b/src/tools/compiletest/src/header.rs @@ -839,6 +839,7 @@ const KNOWN_DIRECTIVE_NAMES: &[&str] = &[ "needs-profiler-support", "needs-relocation-model-pic", "needs-run-enabled", + "needs-rust-lld", "needs-rust-lldb", "needs-sanitizer-address", "needs-sanitizer-cfi", From 682535e7775efb2f2e4934b2cf5bc5edc3253968 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=A9my=20Rakic?= Date: Sun, 14 Apr 2024 16:36:09 +0000 Subject: [PATCH 02/15] add regex to run_make_support note: version more recent than 1.8 depend on memchr 2.6, which creates conflicts as memchr 2.5.0 is pinned elsewhere in the workspace --- Cargo.lock | 1 + src/tools/run-make-support/Cargo.toml | 1 + src/tools/run-make-support/src/lib.rs | 1 + 3 files changed, 3 insertions(+) diff --git a/Cargo.lock b/Cargo.lock index 1f26dd7c43c..faf2c473ee1 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -3342,6 +3342,7 @@ name = "run_make_support" version = "0.0.0" dependencies = [ "object 0.34.0", + "regex", "wasmparser", ] diff --git a/src/tools/run-make-support/Cargo.toml b/src/tools/run-make-support/Cargo.toml index d8bb8c643d1..3ea35c7940c 100644 --- a/src/tools/run-make-support/Cargo.toml +++ b/src/tools/run-make-support/Cargo.toml @@ -6,3 +6,4 @@ edition = "2021" [dependencies] object = "0.34.0" wasmparser = "0.118.2" +regex = "1.8" # 1.8 to avoid memchr 2.6.0, as 2.5.0 is pinned in the workspace diff --git a/src/tools/run-make-support/src/lib.rs b/src/tools/run-make-support/src/lib.rs index 47b46a0a699..9a4fdff5d15 100644 --- a/src/tools/run-make-support/src/lib.rs +++ b/src/tools/run-make-support/src/lib.rs @@ -13,6 +13,7 @@ use std::path::{Path, PathBuf}; use std::process::{Command, Output}; pub use object; +pub use regex; pub use wasmparser; pub use cc::{cc, extra_c_flags, extra_cxx_flags, Cc}; From 97795923fc06fa3a944337cd5c4461b2c4833cb1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=A9my=20Rakic?= Date: Sun, 14 Apr 2024 17:00:32 +0000 Subject: [PATCH 03/15] port `rust-lld` test to rmake also check that turning off the linker feature does not use lld --- .../tidy/src/allowed_run_make_makefiles.txt | 1 - tests/run-make/rust-lld/Makefile | 12 ---- tests/run-make/rust-lld/rmake.rs | 64 +++++++++++++++++++ 3 files changed, 64 insertions(+), 13 deletions(-) delete mode 100644 tests/run-make/rust-lld/Makefile create mode 100644 tests/run-make/rust-lld/rmake.rs diff --git a/src/tools/tidy/src/allowed_run_make_makefiles.txt b/src/tools/tidy/src/allowed_run_make_makefiles.txt index 3914feb3499..45d3acd8fd4 100644 --- a/src/tools/tidy/src/allowed_run_make_makefiles.txt +++ b/src/tools/tidy/src/allowed_run_make_makefiles.txt @@ -250,7 +250,6 @@ run-make/rlib-format-packed-bundled-libs-3/Makefile run-make/rlib-format-packed-bundled-libs/Makefile run-make/rmeta-preferred/Makefile run-make/rust-lld-custom-target/Makefile -run-make/rust-lld/Makefile run-make/rustc-macro-dep-files/Makefile run-make/rustdoc-determinism/Makefile run-make/rustdoc-error-lines/Makefile diff --git a/tests/run-make/rust-lld/Makefile b/tests/run-make/rust-lld/Makefile deleted file mode 100644 index 1ecac479f41..00000000000 --- a/tests/run-make/rust-lld/Makefile +++ /dev/null @@ -1,12 +0,0 @@ -include ../tools.mk - -# ignore-msvc -# needs-rust-lld -# ignore-s390x lld does not yet support s390x as target -all: - RUSTC_LOG=rustc_codegen_ssa::back::link=info $(RUSTC) -Clink-self-contained=+linker -Zlinker-features=+lld -Zunstable-options -Clink-args=-Wl,-v main.rs 2> $(TMPDIR)/output.txt - $(CGREP) -e "^LLD [0-9]+\.[0-9]+\.[0-9]+" < $(TMPDIR)/output.txt - - # while we're here, also check that the last linker feature flag "wins" - RUSTC_LOG=rustc_codegen_ssa::back::link=info $(RUSTC) -Clink-self-contained=+linker -Zlinker-features=-lld -Zlinker-features=+lld -Zunstable-options -Clink-args=-Wl,-v main.rs 2> $(TMPDIR)/output.txt - $(CGREP) -e "^LLD [0-9]+\.[0-9]+\.[0-9]+" < $(TMPDIR)/output.txt diff --git a/tests/run-make/rust-lld/rmake.rs b/tests/run-make/rust-lld/rmake.rs new file mode 100644 index 00000000000..053b580ebd1 --- /dev/null +++ b/tests/run-make/rust-lld/rmake.rs @@ -0,0 +1,64 @@ +// Test linking using `cc` with `rust-lld`, using the unstable CLI described in MCP 510 +// see https://github.com/rust-lang/compiler-team/issues/510 for more info + +//@ needs-rust-lld +//@ ignore-msvc +//@ ignore-s390x lld does not yet support s390x as target + +extern crate run_make_support; + +use run_make_support::regex::Regex; +use run_make_support::rustc; +use std::process::Output; + +fn main() { + // Opt-in to lld and the self-contained linker, to link with rust-lld. We'll check that by + // asking the linker to display its version number with a link-arg. + let output = rustc() + .env("RUSTC_LOG", "rustc_codegen_ssa::back::link=info") + .arg("-Zlinker-features=+lld") + .arg("-Clink-self-contained=+linker") + .arg("-Zunstable-options") + .arg("-Clink-args=-Wl,-v") + .input("main.rs") + .run(); + assert!( + find_lld_version_in_logs(output), + "the LLD version string should be present in the output logs" + ); + + // It should not be used when we explictly opt-out of lld. + let output = rustc() + .env("RUSTC_LOG", "rustc_codegen_ssa::back::link=info") + .arg("-Clink-args=-Wl,-v") + .arg("-Zlinker-features=-lld") + .input("main.rs") + .run(); + assert!( + !find_lld_version_in_logs(output), + "the LLD version string should not be present in the output logs" + ); + + // While we're here, also check that the last linker feature flag "wins" when passed multiple + // times to rustc. + let output = rustc() + .env("RUSTC_LOG", "rustc_codegen_ssa::back::link=info") + .arg("-Clink-args=-Wl,-v") + .arg("-Clink-self-contained=+linker") + .arg("-Zunstable-options") + .arg("-Zlinker-features=-lld") + .arg("-Zlinker-features=+lld") + .arg("-Zlinker-features=-lld,+lld") + .input("main.rs") + .run(); + assert!( + find_lld_version_in_logs(output), + "the LLD version string should be present in the output logs" + ); +} + +fn find_lld_version_in_logs(output: Output) -> bool { + let lld_version_re = Regex::new(r"^LLD [0-9]+\.[0-9]+\.[0-9]+").unwrap(); + let stderr = std::str::from_utf8(&output.stderr).unwrap(); + stderr.lines().any(|line| lld_version_re.is_match(line)) +} From 8fa6984e8edda921d34620f4eca657dc164c0f6f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=A9my=20Rakic?= Date: Sun, 14 Apr 2024 17:15:48 +0000 Subject: [PATCH 04/15] port `rust-lld-custom-target` test to rmake also make sure that rust-lld can be disabled via linker features, even when enabled by default by the target spec --- .../tidy/src/allowed_run_make_makefiles.txt | 1 - .../run-make/rust-lld-custom-target/Makefile | 7 --- .../run-make/rust-lld-custom-target/rmake.rs | 51 +++++++++++++++++++ 3 files changed, 51 insertions(+), 8 deletions(-) delete mode 100644 tests/run-make/rust-lld-custom-target/Makefile create mode 100644 tests/run-make/rust-lld-custom-target/rmake.rs diff --git a/src/tools/tidy/src/allowed_run_make_makefiles.txt b/src/tools/tidy/src/allowed_run_make_makefiles.txt index 45d3acd8fd4..f0ed0ae806f 100644 --- a/src/tools/tidy/src/allowed_run_make_makefiles.txt +++ b/src/tools/tidy/src/allowed_run_make_makefiles.txt @@ -249,7 +249,6 @@ run-make/rlib-format-packed-bundled-libs-2/Makefile run-make/rlib-format-packed-bundled-libs-3/Makefile run-make/rlib-format-packed-bundled-libs/Makefile run-make/rmeta-preferred/Makefile -run-make/rust-lld-custom-target/Makefile run-make/rustc-macro-dep-files/Makefile run-make/rustdoc-determinism/Makefile run-make/rustdoc-error-lines/Makefile diff --git a/tests/run-make/rust-lld-custom-target/Makefile b/tests/run-make/rust-lld-custom-target/Makefile deleted file mode 100644 index 007493ab0b9..00000000000 --- a/tests/run-make/rust-lld-custom-target/Makefile +++ /dev/null @@ -1,7 +0,0 @@ -include ../tools.mk - -# needs-rust-lld -# only-x86_64-unknown-linux-gnu -all: - RUSTC_LOG=rustc_codegen_ssa::back::link=info $(RUSTC) --crate-type cdylib --target custom-target.json -Clink-args=-Wl,-v lib.rs 2> $(TMPDIR)/output.txt - $(CGREP) -e "^LLD [0-9]+\.[0-9]+\.[0-9]+" < $(TMPDIR)/output.txt diff --git a/tests/run-make/rust-lld-custom-target/rmake.rs b/tests/run-make/rust-lld-custom-target/rmake.rs new file mode 100644 index 00000000000..1b6e7c65b47 --- /dev/null +++ b/tests/run-make/rust-lld-custom-target/rmake.rs @@ -0,0 +1,51 @@ +// Test linking using `cc` with `rust-lld`, using a custom target with features described in MCP 510 +// see https://github.com/rust-lang/compiler-team/issues/510 for more info: +// +// Starting from the `x86_64-unknown-linux-gnu` target spec, we add the following options: +// - a linker-flavor using lld via a C compiler +// - the self-contained linker component is enabled + +//@ needs-rust-lld +//@ only-x86_64-unknown-linux-gnu + +extern crate run_make_support; + +use run_make_support::regex::Regex; +use run_make_support::rustc; +use std::process::Output; + +fn main() { + // Compile to a custom target spec with rust-lld enabled by default. We'll check that by asking + // the linker to display its version number with a link-arg. + let output = rustc() + .env("RUSTC_LOG", "rustc_codegen_ssa::back::link=info") + .crate_type("cdylib") + .target("custom-target.json") + .arg("-Clink-args=-Wl,-v") + .input("lib.rs") + .run(); + assert!( + find_lld_version_in_logs(output), + "the LLD version string should be present in the output logs" + ); + + // But it can also be disabled via linker features. + let output = rustc() + .env("RUSTC_LOG", "rustc_codegen_ssa::back::link=info") + .crate_type("cdylib") + .target("custom-target.json") + .arg("-Zlinker-features=-lld") + .arg("-Clink-args=-Wl,-v") + .input("lib.rs") + .run(); + assert!( + !find_lld_version_in_logs(output), + "the LLD version string should not be present in the output logs" + ); +} + +fn find_lld_version_in_logs(output: Output) -> bool { + let lld_version_re = Regex::new(r"^LLD [0-9]+\.[0-9]+\.[0-9]+").unwrap(); + let stderr = std::str::from_utf8(&output.stderr).unwrap(); + stderr.lines().any(|line| lld_version_re.is_match(line)) +} From 8acfe9a1380f73fade8dfe35aa054b3b6870faee Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=A9my=20Rakic?= Date: Mon, 15 Apr 2024 18:08:55 +0000 Subject: [PATCH 05/15] add `link_arg` helper to `run_make_support` and use it in the `rust-lld` tests --- src/tools/run-make-support/src/rustc.rs | 6 ++++++ tests/run-make/rust-lld-custom-target/rmake.rs | 4 ++-- tests/run-make/rust-lld/rmake.rs | 6 +++--- 3 files changed, 11 insertions(+), 5 deletions(-) diff --git a/src/tools/run-make-support/src/rustc.rs b/src/tools/run-make-support/src/rustc.rs index ebda151b908..88e409a588a 100644 --- a/src/tools/run-make-support/src/rustc.rs +++ b/src/tools/run-make-support/src/rustc.rs @@ -149,6 +149,12 @@ impl Rustc { self } + /// Add an extra argument to the linker invocation, via `-Clink-arg`. + pub fn link_arg(&mut self, link_arg: &str) -> &mut Self { + self.cmd.arg(format!("-Clink-arg={link_arg}")); + self + } + #[track_caller] pub fn run_fail_assert_exit_code(&mut self, code: i32) -> Output { let caller_location = std::panic::Location::caller(); diff --git a/tests/run-make/rust-lld-custom-target/rmake.rs b/tests/run-make/rust-lld-custom-target/rmake.rs index 1b6e7c65b47..b5341725e36 100644 --- a/tests/run-make/rust-lld-custom-target/rmake.rs +++ b/tests/run-make/rust-lld-custom-target/rmake.rs @@ -21,7 +21,7 @@ fn main() { .env("RUSTC_LOG", "rustc_codegen_ssa::back::link=info") .crate_type("cdylib") .target("custom-target.json") - .arg("-Clink-args=-Wl,-v") + .link_arg("-Wl,-v") .input("lib.rs") .run(); assert!( @@ -35,7 +35,7 @@ fn main() { .crate_type("cdylib") .target("custom-target.json") .arg("-Zlinker-features=-lld") - .arg("-Clink-args=-Wl,-v") + .link_arg("-Wl,-v") .input("lib.rs") .run(); assert!( diff --git a/tests/run-make/rust-lld/rmake.rs b/tests/run-make/rust-lld/rmake.rs index 053b580ebd1..acb6d74aaa8 100644 --- a/tests/run-make/rust-lld/rmake.rs +++ b/tests/run-make/rust-lld/rmake.rs @@ -19,7 +19,7 @@ fn main() { .arg("-Zlinker-features=+lld") .arg("-Clink-self-contained=+linker") .arg("-Zunstable-options") - .arg("-Clink-args=-Wl,-v") + .link_arg("-Wl,-v") .input("main.rs") .run(); assert!( @@ -30,7 +30,7 @@ fn main() { // It should not be used when we explictly opt-out of lld. let output = rustc() .env("RUSTC_LOG", "rustc_codegen_ssa::back::link=info") - .arg("-Clink-args=-Wl,-v") + .link_arg("-Wl,-v") .arg("-Zlinker-features=-lld") .input("main.rs") .run(); @@ -43,7 +43,7 @@ fn main() { // times to rustc. let output = rustc() .env("RUSTC_LOG", "rustc_codegen_ssa::back::link=info") - .arg("-Clink-args=-Wl,-v") + .link_arg("-Wl,-v") .arg("-Clink-self-contained=+linker") .arg("-Zunstable-options") .arg("-Zlinker-features=-lld") From af887d3c42e6d2a2885f846ba0a67c052743fa7a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=A9my=20Rakic?= Date: Mon, 15 Apr 2024 19:45:01 +0000 Subject: [PATCH 06/15] mention json target specs in `run_make_support` --- src/tools/run-make-support/src/rustc.rs | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/tools/run-make-support/src/rustc.rs b/src/tools/run-make-support/src/rustc.rs index 88e409a588a..9bf41c6e2e9 100644 --- a/src/tools/run-make-support/src/rustc.rs +++ b/src/tools/run-make-support/src/rustc.rs @@ -128,9 +128,8 @@ impl Rustc { self } - /// Specify target triple. + /// Specify the target triple, or a path to a custom target json spec file. pub fn target(&mut self, target: &str) -> &mut Self { - assert!(!target.contains(char::is_whitespace), "target triple cannot contain spaces"); self.cmd.arg(format!("--target={target}")); self } From 8a981b6fee5bb52af9311bd317dd8a01ec60dd83 Mon Sep 17 00:00:00 2001 From: Michael Goulet Date: Mon, 15 Apr 2024 21:36:52 -0400 Subject: [PATCH 07/15] Use /* value */ as a placeholder --- .../src/traits/error_reporting/suggestions.rs | 2 +- tests/ui/borrowck/borrowck-init-in-fru.stderr | 4 ++-- .../borrowck/borrowck-uninit-ref-chain.stderr | 4 ++-- tests/ui/borrowck/issue-103250.stderr | 4 ++-- .../ui/borrowck/suggest-assign-rvalue.stderr | 4 ++-- .../consts/value-suggestion-ice-123906.stderr | 4 ++-- tests/ui/loops/loop-break-value.stderr | 20 +++++++++---------- .../moves/issue-72649-uninit-in-loop.stderr | 8 ++++---- tests/ui/moves/move-into-dead-array-1.stderr | 4 ++-- tests/ui/moves/move-of-addr-of-mut.stderr | 4 ++-- tests/ui/nll/match-on-borrowed.stderr | 4 ++-- 11 files changed, 31 insertions(+), 31 deletions(-) diff --git a/compiler/rustc_trait_selection/src/traits/error_reporting/suggestions.rs b/compiler/rustc_trait_selection/src/traits/error_reporting/suggestions.rs index af8713ba3ff..f05e91a2995 100644 --- a/compiler/rustc_trait_selection/src/traits/error_reporting/suggestions.rs +++ b/compiler/rustc_trait_selection/src/traits/error_reporting/suggestions.rs @@ -4592,7 +4592,7 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> { .join(", "), if tys.len() == 1 { "," } else { "" } ), - _ => "value".to_string(), + _ => "/* value */".to_string(), }) } } diff --git a/tests/ui/borrowck/borrowck-init-in-fru.stderr b/tests/ui/borrowck/borrowck-init-in-fru.stderr index b5c332a90bc..bfa86b44fe9 100644 --- a/tests/ui/borrowck/borrowck-init-in-fru.stderr +++ b/tests/ui/borrowck/borrowck-init-in-fru.stderr @@ -8,8 +8,8 @@ LL | origin = Point { x: 10, ..origin }; | help: consider assigning a value | -LL | let mut origin: Point = value; - | +++++++ +LL | let mut origin: Point = /* value */; + | +++++++++++++ error: aborting due to 1 previous error diff --git a/tests/ui/borrowck/borrowck-uninit-ref-chain.stderr b/tests/ui/borrowck/borrowck-uninit-ref-chain.stderr index d6759b8e1cf..b1d508e2ac3 100644 --- a/tests/ui/borrowck/borrowck-uninit-ref-chain.stderr +++ b/tests/ui/borrowck/borrowck-uninit-ref-chain.stderr @@ -21,8 +21,8 @@ LL | let _y = &**x; | help: consider assigning a value | -LL | let x: &&S = &&value; - | +++++++++ +LL | let x: &&S = &&/* value */; + | +++++++++++++++ error[E0381]: used binding `x` isn't initialized --> $DIR/borrowck-uninit-ref-chain.rs:14:14 diff --git a/tests/ui/borrowck/issue-103250.stderr b/tests/ui/borrowck/issue-103250.stderr index 104bded5b0b..cd048e03a67 100644 --- a/tests/ui/borrowck/issue-103250.stderr +++ b/tests/ui/borrowck/issue-103250.stderr @@ -9,8 +9,8 @@ LL | Err(last_error) | help: consider assigning a value | -LL | let mut last_error: Box = Box::new(value); - | +++++++++++++++++ +LL | let mut last_error: Box = Box::new(/* value */); + | +++++++++++++++++++++++ error: aborting due to 1 previous error diff --git a/tests/ui/borrowck/suggest-assign-rvalue.stderr b/tests/ui/borrowck/suggest-assign-rvalue.stderr index 4305539f1b6..daaef6e3892 100644 --- a/tests/ui/borrowck/suggest-assign-rvalue.stderr +++ b/tests/ui/borrowck/suggest-assign-rvalue.stderr @@ -50,8 +50,8 @@ LL | println!("demo_no: {:?}", demo_no); = note: this error originates in the macro `$crate::format_args_nl` which comes from the expansion of the macro `println` (in Nightly builds, run with -Z macro-backtrace for more info) help: consider assigning a value | -LL | let demo_no: DemoNoDef = value; - | +++++++ +LL | let demo_no: DemoNoDef = /* value */; + | +++++++++++++ error[E0381]: used binding `arr` isn't initialized --> $DIR/suggest-assign-rvalue.rs:34:27 diff --git a/tests/ui/consts/value-suggestion-ice-123906.stderr b/tests/ui/consts/value-suggestion-ice-123906.stderr index 8e2c316400d..edb91063e5d 100644 --- a/tests/ui/consts/value-suggestion-ice-123906.stderr +++ b/tests/ui/consts/value-suggestion-ice-123906.stderr @@ -10,8 +10,8 @@ LL | break; | help: give the `break` a value of the expected type | -LL | break value; - | +++++ +LL | break /* value */; + | +++++++++++ error: aborting due to 1 previous error diff --git a/tests/ui/loops/loop-break-value.stderr b/tests/ui/loops/loop-break-value.stderr index 0093182422e..0912bdbb221 100644 --- a/tests/ui/loops/loop-break-value.stderr +++ b/tests/ui/loops/loop-break-value.stderr @@ -246,8 +246,8 @@ LL | break; | help: give the `break` a value of the expected type | -LL | break value; - | +++++ +LL | break /* value */; + | +++++++++++ error[E0308]: mismatched types --> $DIR/loop-break-value.rs:112:9 @@ -260,8 +260,8 @@ LL | break; | help: give the `break` a value of the expected type | -LL | break value; - | +++++ +LL | break /* value */; + | +++++++++++ error[E0308]: mismatched types --> $DIR/loop-break-value.rs:124:9 @@ -274,8 +274,8 @@ LL | break 'a; | help: give the `break` a value of the expected type | -LL | break 'a value; - | +++++ +LL | break 'a /* value */; + | +++++++++++ error[E0308]: mismatched types --> $DIR/loop-break-value.rs:135:15 @@ -297,8 +297,8 @@ LL | break 'a; | help: give the `break` a value of the expected type | -LL | break 'a value; - | +++++ +LL | break 'a /* value */; + | +++++++++++ error[E0308]: mismatched types --> $DIR/loop-break-value.rs:147:15 @@ -320,8 +320,8 @@ LL | break 'a; | help: give the `break` a value of the expected type | -LL | break 'a value; - | +++++ +LL | break 'a /* value */; + | +++++++++++ error[E0308]: mismatched types --> $DIR/loop-break-value.rs:159:15 diff --git a/tests/ui/moves/issue-72649-uninit-in-loop.stderr b/tests/ui/moves/issue-72649-uninit-in-loop.stderr index 35216f8a66f..a613f35a35e 100644 --- a/tests/ui/moves/issue-72649-uninit-in-loop.stderr +++ b/tests/ui/moves/issue-72649-uninit-in-loop.stderr @@ -80,8 +80,8 @@ LL | let _used = value; | help: consider assigning a value | -LL | let value: NonCopy = value; - | +++++++ +LL | let value: NonCopy = /* value */; + | +++++++++++++ error[E0381]: used binding `value` isn't initialized --> $DIR/issue-72649-uninit-in-loop.rs:73:21 @@ -94,8 +94,8 @@ LL | let _used = value; | help: consider assigning a value | -LL | let mut value: NonCopy = value; - | +++++++ +LL | let mut value: NonCopy = /* value */; + | +++++++++++++ error: aborting due to 6 previous errors diff --git a/tests/ui/moves/move-into-dead-array-1.stderr b/tests/ui/moves/move-into-dead-array-1.stderr index d9b719730d6..6fb3fd83fc0 100644 --- a/tests/ui/moves/move-into-dead-array-1.stderr +++ b/tests/ui/moves/move-into-dead-array-1.stderr @@ -8,8 +8,8 @@ LL | a[i] = d(); | help: consider assigning a value | -LL | let mut a: [D; 4] = [value; 4]; - | ++++++++++++ +LL | let mut a: [D; 4] = [/* value */; 4]; + | ++++++++++++++++++ error: aborting due to 1 previous error diff --git a/tests/ui/moves/move-of-addr-of-mut.stderr b/tests/ui/moves/move-of-addr-of-mut.stderr index 46f7d39a61a..c36ace6ca0f 100644 --- a/tests/ui/moves/move-of-addr-of-mut.stderr +++ b/tests/ui/moves/move-of-addr-of-mut.stderr @@ -9,8 +9,8 @@ LL | std::ptr::addr_of_mut!(x); = note: this error originates in the macro `std::ptr::addr_of_mut` (in Nightly builds, run with -Z macro-backtrace for more info) help: consider assigning a value | -LL | let mut x: S = value; - | +++++++ +LL | let mut x: S = /* value */; + | +++++++++++++ error: aborting due to 1 previous error diff --git a/tests/ui/nll/match-on-borrowed.stderr b/tests/ui/nll/match-on-borrowed.stderr index 4e0b048fb4b..81163ebe2bc 100644 --- a/tests/ui/nll/match-on-borrowed.stderr +++ b/tests/ui/nll/match-on-borrowed.stderr @@ -43,8 +43,8 @@ LL | match n {} | help: consider assigning a value | -LL | let n: Never = value; - | +++++++ +LL | let n: Never = /* value */; + | +++++++++++++ error: aborting due to 4 previous errors From c95761385ea72929c1901b8a2c74506960a9c220 Mon Sep 17 00:00:00 2001 From: Michael Goulet Date: Mon, 15 Apr 2024 21:45:47 -0400 Subject: [PATCH 08/15] Make array suggestions slightly more accurate --- .../src/traits/error_reporting/suggestions.rs | 13 ++++++++++--- tests/ui/moves/move-into-dead-array-1.stderr | 4 ++-- 2 files changed, 12 insertions(+), 5 deletions(-) diff --git a/compiler/rustc_trait_selection/src/traits/error_reporting/suggestions.rs b/compiler/rustc_trait_selection/src/traits/error_reporting/suggestions.rs index f05e91a2995..8f167711bdf 100644 --- a/compiler/rustc_trait_selection/src/traits/error_reporting/suggestions.rs +++ b/compiler/rustc_trait_selection/src/traits/error_reporting/suggestions.rs @@ -4550,7 +4550,7 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> { self.type_implements_trait(default_trait, [ty], param_env).must_apply_modulo_regions() }; - Some(match ty.kind() { + Some(match *ty.kind() { ty::Never | ty::Error(_) => return None, ty::Bool => "false".to_string(), ty::Char => "\'x\'".to_string(), @@ -4577,12 +4577,19 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> { if let (ty::Str, hir::Mutability::Not) = (ty.kind(), mutability) { "\"\"".to_string() } else { - let ty = self.ty_kind_suggestion(param_env, *ty)?; + let ty = self.ty_kind_suggestion(param_env, ty)?; format!("&{}{ty}", mutability.prefix_str()) } } ty::Array(ty, len) if let Some(len) = len.try_eval_target_usize(tcx, param_env) => { - format!("[{}; {}]", self.ty_kind_suggestion(param_env, *ty)?, len) + if len == 0 { + "[]".to_string() + } else if self.type_is_copy_modulo_regions(param_env, ty) || len == 1 { + // Can only suggest `[ty; 0]` if sz == 1 or copy + format!("[{}; {}]", self.ty_kind_suggestion(param_env, ty)?, len) + } else { + "/* value */".to_string() + } } ty::Tuple(tys) => format!( "({}{})", diff --git a/tests/ui/moves/move-into-dead-array-1.stderr b/tests/ui/moves/move-into-dead-array-1.stderr index 6fb3fd83fc0..14208f5e7aa 100644 --- a/tests/ui/moves/move-into-dead-array-1.stderr +++ b/tests/ui/moves/move-into-dead-array-1.stderr @@ -8,8 +8,8 @@ LL | a[i] = d(); | help: consider assigning a value | -LL | let mut a: [D; 4] = [/* value */; 4]; - | ++++++++++++++++++ +LL | let mut a: [D; 4] = /* value */; + | +++++++++++++ error: aborting due to 1 previous error From 801413ecd18f8f1180cc74ca93f9279f3e95c862 Mon Sep 17 00:00:00 2001 From: Oli Scherer Date: Tue, 9 Apr 2024 10:57:41 +0000 Subject: [PATCH 09/15] Taint const qualifs if a static is referenced that didn't pass wfcheck --- .../src/transform/check_consts/check.rs | 5 +++ tests/crashes/123153.rs | 17 --------- tests/ui/statics/unsized_type2.rs | 21 +++++++++++ tests/ui/statics/unsized_type2.stderr | 37 +++++++++++++++++++ 4 files changed, 63 insertions(+), 17 deletions(-) delete mode 100644 tests/crashes/123153.rs create mode 100644 tests/ui/statics/unsized_type2.rs create mode 100644 tests/ui/statics/unsized_type2.stderr diff --git a/compiler/rustc_const_eval/src/transform/check_consts/check.rs b/compiler/rustc_const_eval/src/transform/check_consts/check.rs index 543996c86ba..eb7f9385730 100644 --- a/compiler/rustc_const_eval/src/transform/check_consts/check.rs +++ b/compiler/rustc_const_eval/src/transform/check_consts/check.rs @@ -331,6 +331,11 @@ impl<'mir, 'tcx> Checker<'mir, 'tcx> { if self.tcx.is_thread_local_static(def_id) { self.tcx.dcx().span_bug(span, "tls access is checked in `Rvalue::ThreadLocalRef`"); } + if let Some(def_id) = def_id.as_local() + && let Err(guar) = self.tcx.at(span).check_well_formed(hir::OwnerId { def_id }) + { + self.error_emitted = Some(guar); + } self.check_op_spanned(ops::StaticAccess, span) } diff --git a/tests/crashes/123153.rs b/tests/crashes/123153.rs deleted file mode 100644 index d2c32ecd73e..00000000000 --- a/tests/crashes/123153.rs +++ /dev/null @@ -1,17 +0,0 @@ -//@ known-bug: #123153 -pub struct wl_interface { - pub version: str, -} - -pub struct Interface { - pub other_interfaces: &'static [&'static Interface], - pub c_ptr: Option<&'static wl_interface>, -} - -pub static mut wl_callback_interface: wl_interface = wl_interface { version: 0 }; - -pub static WL_CALLBACK_INTERFACE: Interface = - Interface { other_interfaces: &[], c_ptr: Some(unsafe { &wl_callback_interface }) }; - - -fn main() {} diff --git a/tests/ui/statics/unsized_type2.rs b/tests/ui/statics/unsized_type2.rs new file mode 100644 index 00000000000..303926849e6 --- /dev/null +++ b/tests/ui/statics/unsized_type2.rs @@ -0,0 +1,21 @@ +//! This test used to actually start evaluating the static even though +//! there were errors in typeck. +//! issue: rust-lang/rust#123153 + +pub struct Foo { + pub version: str, +} + +pub struct Bar { + pub ok: &'static [&'static Bar], + pub bad: &'static Foo, +} + +pub static WITH_ERROR: Foo = Foo { version: 0 }; +//~^ ERROR the size for values of type `str` cannot be known at compilation time +//~| ERROR the size for values of type `str` cannot be known at compilation time +//~| ERROR mismatched types + +pub static USE_WITH_ERROR: Bar = Bar { ok: &[], bad: &WITH_ERROR }; + +fn main() {} diff --git a/tests/ui/statics/unsized_type2.stderr b/tests/ui/statics/unsized_type2.stderr new file mode 100644 index 00000000000..4e47b37afdc --- /dev/null +++ b/tests/ui/statics/unsized_type2.stderr @@ -0,0 +1,37 @@ +error[E0277]: the size for values of type `str` cannot be known at compilation time + --> $DIR/unsized_type2.rs:14:24 + | +LL | pub static WITH_ERROR: Foo = Foo { version: 0 }; + | ^^^ doesn't have a size known at compile-time + | + = help: within `Foo`, the trait `Sized` is not implemented for `str`, which is required by `Foo: Sized` +note: required because it appears within the type `Foo` + --> $DIR/unsized_type2.rs:5:12 + | +LL | pub struct Foo { + | ^^^ + +error[E0277]: the size for values of type `str` cannot be known at compilation time + --> $DIR/unsized_type2.rs:14:30 + | +LL | pub static WITH_ERROR: Foo = Foo { version: 0 }; + | ^^^^^^^^^^^^^^^^^^ doesn't have a size known at compile-time + | + = help: within `Foo`, the trait `Sized` is not implemented for `str`, which is required by `Foo: Sized` +note: required because it appears within the type `Foo` + --> $DIR/unsized_type2.rs:5:12 + | +LL | pub struct Foo { + | ^^^ + = note: constant expressions must have a statically known size + +error[E0308]: mismatched types + --> $DIR/unsized_type2.rs:14:45 + | +LL | pub static WITH_ERROR: Foo = Foo { version: 0 }; + | ^ expected `str`, found integer + +error: aborting due to 3 previous errors + +Some errors have detailed explanations: E0277, E0308. +For more information about an error, try `rustc --explain E0277`. From fe18afe48caa890fc343d99a176db8fe8310dbfc Mon Sep 17 00:00:00 2001 From: Oli Scherer Date: Tue, 9 Apr 2024 10:07:11 +0000 Subject: [PATCH 10/15] Unset test env vars before setting new ones. If you want to override an env var, don't unset it, just set it --- src/tools/compiletest/src/runtest.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/tools/compiletest/src/runtest.rs b/src/tools/compiletest/src/runtest.rs index 38d22fef113..1dd639a8918 100644 --- a/src/tools/compiletest/src/runtest.rs +++ b/src/tools/compiletest/src/runtest.rs @@ -2173,8 +2173,8 @@ impl<'test> TestCx<'test> { let aux_dir = self.aux_output_dir(); self.build_all_auxiliary(&self.testpaths, &aux_dir, &mut rustc); - self.props.unset_rustc_env.iter().fold(&mut rustc, Command::env_remove); rustc.envs(self.props.rustc_env.clone()); + self.props.unset_rustc_env.iter().fold(&mut rustc, Command::env_remove); self.compose_and_run( rustc, self.config.compile_lib_path.to_str().unwrap(), @@ -2220,10 +2220,10 @@ impl<'test> TestCx<'test> { ); aux_cx.build_all_auxiliary(of, &aux_dir, &mut aux_rustc); + aux_rustc.envs(aux_props.rustc_env.clone()); for key in &aux_props.unset_rustc_env { aux_rustc.env_remove(key); } - aux_rustc.envs(aux_props.rustc_env.clone()); let (aux_type, crate_type) = if is_bin { (AuxType::Bin, Some("bin")) From 4f75d67b6fd0bd677c17d5060facd31c70dd4afe Mon Sep 17 00:00:00 2001 From: Oli Scherer Date: Tue, 9 Apr 2024 10:07:56 +0000 Subject: [PATCH 11/15] Make ui_test backtraces short by default --- src/tools/compiletest/src/header.rs | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/tools/compiletest/src/header.rs b/src/tools/compiletest/src/header.rs index f78e0363f55..daa605f6d03 100644 --- a/src/tools/compiletest/src/header.rs +++ b/src/tools/compiletest/src/header.rs @@ -265,7 +265,10 @@ impl TestProps { aux_bins: vec![], aux_crates: vec![], revisions: vec![], - rustc_env: vec![("RUSTC_ICE".to_string(), "0".to_string())], + rustc_env: vec![ + ("RUSTC_ICE".to_string(), "0".to_string()), + ("RUST_BACKTRACE".to_string(), "short".to_string()), + ], unset_rustc_env: vec![("RUSTC_LOG_COLOR".to_string())], exec_env: vec![], unset_exec_env: vec![], From 0a88339a57557152bb32c4969f2f76955793133e Mon Sep 17 00:00:00 2001 From: Oli Scherer Date: Tue, 9 Apr 2024 10:08:20 +0000 Subject: [PATCH 12/15] Don't ICE for kind mismatches during error rendering --- .../error_reporting/type_err_ctxt_ext.rs | 3 ++ tests/ui/const-generics/kind_mismatch.rs | 24 ++++++++++++ tests/ui/const-generics/kind_mismatch.stderr | 39 +++++++++++++++++++ 3 files changed, 66 insertions(+) create mode 100644 tests/ui/const-generics/kind_mismatch.rs create mode 100644 tests/ui/const-generics/kind_mismatch.stderr diff --git a/compiler/rustc_trait_selection/src/traits/error_reporting/type_err_ctxt_ext.rs b/compiler/rustc_trait_selection/src/traits/error_reporting/type_err_ctxt_ext.rs index 3dc54b33801..4aa5f9752ab 100644 --- a/compiler/rustc_trait_selection/src/traits/error_reporting/type_err_ctxt_ext.rs +++ b/compiler/rustc_trait_selection/src/traits/error_reporting/type_err_ctxt_ext.rs @@ -1974,6 +1974,9 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> { for (obligation_arg, impl_arg) in std::iter::zip(obligation_trait_ref.args, impl_trait_ref.args) { + if (obligation_arg, impl_arg).references_error() { + return false; + } if let Err(terr) = ocx.eq(&ObligationCause::dummy(), param_env, impl_arg, obligation_arg) { diff --git a/tests/ui/const-generics/kind_mismatch.rs b/tests/ui/const-generics/kind_mismatch.rs new file mode 100644 index 00000000000..bab58d5952a --- /dev/null +++ b/tests/ui/const-generics/kind_mismatch.rs @@ -0,0 +1,24 @@ +//! This test used to ICE in typeck because of the type/const mismatch, +//! even though wfcheck already errored. +//! issue: rust-lang/rust#123457 + +pub struct KeyHolder {} + +pub trait ContainsKey {} + +pub trait SubsetExcept

{} + +impl ContainsKey for KeyHolder {} +//~^ ERROR: type provided when a constant was expected +//~| ERROR: type provided when a constant was expected + +impl> SubsetExcept

for T {} + +pub fn remove_key>() -> S { + loop {} +} + +fn main() { + let map: KeyHolder<0> = remove_key::<_, _>(); + //~^ ERROR: the trait bound `KeyHolder<0>: SubsetExcept<_>` is not satisfied +} diff --git a/tests/ui/const-generics/kind_mismatch.stderr b/tests/ui/const-generics/kind_mismatch.stderr new file mode 100644 index 00000000000..80968ebea68 --- /dev/null +++ b/tests/ui/const-generics/kind_mismatch.stderr @@ -0,0 +1,39 @@ +error[E0747]: type provided when a constant was expected + --> $DIR/kind_mismatch.rs:11:38 + | +LL | impl ContainsKey for KeyHolder {} + | - ^ + | | + | help: consider changing this type parameter to a const parameter: `const K: u8` + +error[E0747]: type provided when a constant was expected + --> $DIR/kind_mismatch.rs:11:21 + | +LL | impl ContainsKey for KeyHolder {} + | - ^ + | | + | help: consider changing this type parameter to a const parameter: `const K: u8` + +error[E0277]: the trait bound `KeyHolder<0>: SubsetExcept<_>` is not satisfied + --> $DIR/kind_mismatch.rs:22:45 + | +LL | let map: KeyHolder<0> = remove_key::<_, _>(); + | ^ the trait `ContainsKey<0>` is not implemented for `KeyHolder<0>`, which is required by `KeyHolder<0>: SubsetExcept<_>` + | +note: required for `KeyHolder<0>` to implement `SubsetExcept<_>` + --> $DIR/kind_mismatch.rs:15:28 + | +LL | impl> SubsetExcept

for T {} + | -------------- ^^^^^^^^^^^^^^^ ^ + | | + | unsatisfied trait bound introduced here +note: required by a bound in `remove_key` + --> $DIR/kind_mismatch.rs:17:25 + | +LL | pub fn remove_key>() -> S { + | ^^^^^^^^^^^^^^^ required by this bound in `remove_key` + +error: aborting due to 3 previous errors + +Some errors have detailed explanations: E0277, E0747. +For more information about an error, try `rustc --explain E0277`. From 8606efa5d24b1aeefa14b285920a0291953149fa Mon Sep 17 00:00:00 2001 From: Ralf Jung Date: Tue, 16 Apr 2024 14:13:18 +0200 Subject: [PATCH 13/15] Box::into_raw: make Miri understand that this is a box-to-raw cast --- library/alloc/src/boxed.rs | 8 ++++-- .../newtype_pair_retagging.stack.stderr | 2 +- .../newtype_retagging.stack.stderr | 2 +- .../miri/tests/pass/issues/issue-miri-3473.rs | 28 +++++++++++++++++++ .../pass/stacked-borrows/stacked-borrows.rs | 12 ++++++++ 5 files changed, 48 insertions(+), 4 deletions(-) create mode 100644 src/tools/miri/tests/pass/issues/issue-miri-3473.rs diff --git a/library/alloc/src/boxed.rs b/library/alloc/src/boxed.rs index 7c3fa2312e5..ed3ad8b39a5 100644 --- a/library/alloc/src/boxed.rs +++ b/library/alloc/src/boxed.rs @@ -1058,7 +1058,8 @@ impl Box { #[stable(feature = "box_raw", since = "1.4.0")] #[inline] pub fn into_raw(b: Self) -> *mut T { - Self::into_raw_with_allocator(b).0 + // Make sure Miri realizes that we transition from a noalias pointer to a raw pointer here. + unsafe { addr_of_mut!(*&mut *Self::into_raw_with_allocator(b).0) } } /// Consumes the `Box`, returning a wrapped raw pointer and the allocator. @@ -1112,7 +1113,10 @@ impl Box { pub fn into_raw_with_allocator(b: Self) -> (*mut T, A) { let mut b = mem::ManuallyDrop::new(b); // We carefully get the raw pointer out in a way that Miri's aliasing model understands what - // is happening: using the primitive "deref" of `Box`. + // is happening: using the primitive "deref" of `Box`. In case `A` is *not* `Global`, we + // want *no* aliasing requirements here! + // In case `A` *is* `Global`, this does not quite have the right behavior; `into_raw` + // works around that. let ptr = addr_of_mut!(**b); let alloc = unsafe { ptr::read(&b.1) }; (ptr, alloc) diff --git a/src/tools/miri/tests/fail/both_borrows/newtype_pair_retagging.stack.stderr b/src/tools/miri/tests/fail/both_borrows/newtype_pair_retagging.stack.stderr index 867907e98e6..c26c7f397b0 100644 --- a/src/tools/miri/tests/fail/both_borrows/newtype_pair_retagging.stack.stderr +++ b/src/tools/miri/tests/fail/both_borrows/newtype_pair_retagging.stack.stderr @@ -6,7 +6,7 @@ LL | Box(unsafe { Unique::new_unchecked(raw) }, alloc) | = help: this indicates a potential bug in the program: it performed an invalid operation, but the Stacked Borrows rules it violated are still experimental = help: see https://github.com/rust-lang/unsafe-code-guidelines/blob/master/wip/stacked-borrows.md for further information -help: was created by a Unique retag at offsets [0x0..0x4] +help: was created by a SharedReadWrite retag at offsets [0x0..0x4] --> $DIR/newtype_pair_retagging.rs:LL:CC | LL | let ptr = Box::into_raw(Box::new(0i32)); diff --git a/src/tools/miri/tests/fail/both_borrows/newtype_retagging.stack.stderr b/src/tools/miri/tests/fail/both_borrows/newtype_retagging.stack.stderr index 56715938e97..ae54da70fe2 100644 --- a/src/tools/miri/tests/fail/both_borrows/newtype_retagging.stack.stderr +++ b/src/tools/miri/tests/fail/both_borrows/newtype_retagging.stack.stderr @@ -6,7 +6,7 @@ LL | Box(unsafe { Unique::new_unchecked(raw) }, alloc) | = help: this indicates a potential bug in the program: it performed an invalid operation, but the Stacked Borrows rules it violated are still experimental = help: see https://github.com/rust-lang/unsafe-code-guidelines/blob/master/wip/stacked-borrows.md for further information -help: was created by a Unique retag at offsets [0x0..0x4] +help: was created by a SharedReadWrite retag at offsets [0x0..0x4] --> $DIR/newtype_retagging.rs:LL:CC | LL | let ptr = Box::into_raw(Box::new(0i32)); diff --git a/src/tools/miri/tests/pass/issues/issue-miri-3473.rs b/src/tools/miri/tests/pass/issues/issue-miri-3473.rs new file mode 100644 index 00000000000..77b960c1cdc --- /dev/null +++ b/src/tools/miri/tests/pass/issues/issue-miri-3473.rs @@ -0,0 +1,28 @@ +//@revisions: stack tree +//@[tree]compile-flags: -Zmiri-tree-borrows +use std::cell::UnsafeCell; + +#[repr(C)] +#[derive(Default)] +struct Node { + _meta: UnsafeCell, + value: usize, +} + +impl Node { + fn value(&self) -> &usize { + &self.value + } +} + +/// This used to cause Stacked Borrows errors because of trouble around conversion +/// from Box to raw pointer. +fn main() { + unsafe { + let a = Box::into_raw(Box::new(Node::default())); + let ptr = &*a; + *UnsafeCell::raw_get(a.cast::>()) = 2; + assert_eq!(*ptr.value(), 0); + drop(Box::from_raw(a)); + } +} diff --git a/src/tools/miri/tests/pass/stacked-borrows/stacked-borrows.rs b/src/tools/miri/tests/pass/stacked-borrows/stacked-borrows.rs index 734411ccc72..43ba490d5bb 100644 --- a/src/tools/miri/tests/pass/stacked-borrows/stacked-borrows.rs +++ b/src/tools/miri/tests/pass/stacked-borrows/stacked-borrows.rs @@ -20,6 +20,7 @@ fn main() { wide_raw_ptr_in_tuple(); not_unpin_not_protected(); write_does_not_invalidate_all_aliases(); + box_into_raw_allows_interior_mutable_alias(); } // Make sure that reading from an `&mut` does, like reborrowing to `&`, @@ -263,3 +264,14 @@ fn write_does_not_invalidate_all_aliases() { other::lib2(); assert_eq!(*x, 1337); // oops, the value changed! I guess not all pointers were invalidated } + +fn box_into_raw_allows_interior_mutable_alias() { unsafe { + let b = Box::new(std::cell::Cell::new(42)); + let raw = Box::into_raw(b); + let c = &*raw; + let d = raw.cast::(); // bypassing `Cell` -- only okay in Miri tests + // `c` and `d` should permit arbitrary aliasing with each other now. + *d = 1; + c.set(2); + drop(Box::from_raw(raw)); +} } From 9cc4e2361ecffd6848f69f28e926e7ed952fca6d Mon Sep 17 00:00:00 2001 From: Oli Scherer Date: Tue, 16 Apr 2024 15:54:29 +0000 Subject: [PATCH 14/15] Prefer identity equality over equating types during coercion. These types are always generic only over their own generic parameters with no inference variables involved. --- .../src/coherence/builtin.rs | 35 +++++++------------ 1 file changed, 13 insertions(+), 22 deletions(-) diff --git a/compiler/rustc_hir_analysis/src/coherence/builtin.rs b/compiler/rustc_hir_analysis/src/coherence/builtin.rs index 5e404847656..0b6c60e4ba2 100644 --- a/compiler/rustc_hir_analysis/src/coherence/builtin.rs +++ b/compiler/rustc_hir_analysis/src/coherence/builtin.rs @@ -10,8 +10,8 @@ use rustc_hir::def_id::{DefId, LocalDefId}; use rustc_hir::lang_items::LangItem; use rustc_hir::ItemKind; use rustc_infer::infer::outlives::env::OutlivesEnvironment; +use rustc_infer::infer::TyCtxtInferExt; use rustc_infer::infer::{self, RegionResolutionError}; -use rustc_infer::infer::{DefineOpaqueTypes, TyCtxtInferExt}; use rustc_infer::traits::Obligation; use rustc_middle::ty::adjustment::CoerceUnsizedInfo; use rustc_middle::ty::{self, suggest_constraining_type_params, Ty, TyCtxt, TypeVisitableExt}; @@ -189,10 +189,7 @@ fn visit_implementation_of_dispatch_from_dyn(checker: &Checker<'_>) -> Result<() // even if they do not carry that attribute. use rustc_type_ir::TyKind::*; match (source.kind(), target.kind()) { - (&Ref(r_a, _, mutbl_a), Ref(r_b, _, mutbl_b)) - if infcx.at(&cause, param_env).eq(DefineOpaqueTypes::No, r_a, *r_b).is_ok() - && mutbl_a == *mutbl_b => - { + (&Ref(r_a, _, mutbl_a), Ref(r_b, _, mutbl_b)) if r_a == *r_b && mutbl_a == *mutbl_b => { Ok(()) } (&RawPtr(_, a_mutbl), &RawPtr(_, b_mutbl)) if a_mutbl == b_mutbl => Ok(()), @@ -230,18 +227,14 @@ fn visit_implementation_of_dispatch_from_dyn(checker: &Checker<'_>) -> Result<() } } - if let Ok(ok) = - infcx.at(&cause, param_env).eq(DefineOpaqueTypes::No, ty_a, ty_b) - { - if ok.obligations.is_empty() { - res = Err(tcx.dcx().emit_err(errors::DispatchFromDynZST { - span, - name: field.name, - ty: ty_a, - })); + if ty_a == ty_b { + res = Err(tcx.dcx().emit_err(errors::DispatchFromDynZST { + span, + name: field.name, + ty: ty_a, + })); - return false; - } + return false; } return true; @@ -433,14 +426,12 @@ pub fn coerce_unsized_info<'tcx>( // something more accepting, but we use // equality because we want to be able to // perform this check without computing - // variance where possible. (This is because - // we may have to evaluate constraint + // variance or constraining opaque types' hidden types. + // (This is because we may have to evaluate constraint // expressions in the course of execution.) // See e.g., #41936. - if let Ok(ok) = infcx.at(&cause, param_env).eq(DefineOpaqueTypes::No, a, b) { - if ok.obligations.is_empty() { - return None; - } + if a == b { + return None; } // Collect up all fields that were significantly changed From f25668cff5930bc815f84b33861cf57fa5dd4200 Mon Sep 17 00:00:00 2001 From: Alex Crichton Date: Tue, 16 Apr 2024 12:41:44 -0700 Subject: [PATCH 15/15] Remove `default_hidden_visibility: false` from wasm targets To the best of my ability I believe that this is no longer necessary. I don't fully recall why this was first added but I believe it had to do with symbols all being exported by default and this was required to undo that. Regardless nowadays the default output of rustc seems suitable so it seems best to keep wasm in line with other targets. --- compiler/rustc_target/src/spec/base/wasm.rs | 3 --- 1 file changed, 3 deletions(-) diff --git a/compiler/rustc_target/src/spec/base/wasm.rs b/compiler/rustc_target/src/spec/base/wasm.rs index 4b4d2aca26e..f237391016e 100644 --- a/compiler/rustc_target/src/spec/base/wasm.rs +++ b/compiler/rustc_target/src/spec/base/wasm.rs @@ -80,9 +80,6 @@ pub fn options() -> TargetOptions { // threaded model which will legalize atomics to normal operations. singlethread: true, - // no dynamic linking, no need for default visibility! - default_hidden_visibility: true, - // Symbol visibility takes care of this for the WebAssembly. // Additionally the only known linker, LLD, doesn't support the script // arguments just yet