From a183989e88f2154770de1afd860bffb387c4b525 Mon Sep 17 00:00:00 2001 From: Oli Scherer Date: Mon, 17 Jun 2024 08:15:43 +0000 Subject: [PATCH 01/23] Only check locally for reported errors --- compiler/rustc_hir_typeck/src/writeback.rs | 2 +- ...dings-in-pattern-with-ty-err-doesnt-ice.rs | 1 + ...s-in-pattern-with-ty-err-doesnt-ice.stderr | 15 +++++++++-- tests/ui/wf/conflicting-impls.rs | 2 ++ tests/ui/wf/conflicting-impls.stderr | 27 ++++++++++++++++--- 5 files changed, 41 insertions(+), 6 deletions(-) diff --git a/compiler/rustc_hir_typeck/src/writeback.rs b/compiler/rustc_hir_typeck/src/writeback.rs index b67d29fce9216..2714be1f9b4f3 100644 --- a/compiler/rustc_hir_typeck/src/writeback.rs +++ b/compiler/rustc_hir_typeck/src/writeback.rs @@ -793,7 +793,7 @@ impl<'cx, 'tcx> Resolver<'cx, 'tcx> { } fn report_error(&self, p: impl Into>) -> ErrorGuaranteed { - if let Some(guar) = self.fcx.dcx().has_errors() { + if let Some(guar) = self.fcx.tainted_by_errors() { guar } else { self.fcx diff --git a/tests/ui/sized/ensure-overriding-bindings-in-pattern-with-ty-err-doesnt-ice.rs b/tests/ui/sized/ensure-overriding-bindings-in-pattern-with-ty-err-doesnt-ice.rs index 196da30b86476..d0bf5078165b7 100644 --- a/tests/ui/sized/ensure-overriding-bindings-in-pattern-with-ty-err-doesnt-ice.rs +++ b/tests/ui/sized/ensure-overriding-bindings-in-pattern-with-ty-err-doesnt-ice.rs @@ -4,4 +4,5 @@ fn main() { //~| ERROR cannot find type `T` in this scope //~| ERROR const and type arguments are not allowed on builtin type `str` //~| ERROR expected unit struct, unit variant or constant, found associated function `str< +//~| ERROR type annotations needed } diff --git a/tests/ui/sized/ensure-overriding-bindings-in-pattern-with-ty-err-doesnt-ice.stderr b/tests/ui/sized/ensure-overriding-bindings-in-pattern-with-ty-err-doesnt-ice.stderr index 99f8dbd9a6c87..fc431eb14127f 100644 --- a/tests/ui/sized/ensure-overriding-bindings-in-pattern-with-ty-err-doesnt-ice.stderr +++ b/tests/ui/sized/ensure-overriding-bindings-in-pattern-with-ty-err-doesnt-ice.stderr @@ -32,7 +32,18 @@ error[E0533]: expected unit struct, unit variant or constant, found associated f LL | let str::<{fn str() { let str::T>>::as_bytes; }}, T>::as_bytes; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ not a unit struct, unit variant or constant -error: aborting due to 4 previous errors +error[E0282]: type annotations needed + --> $DIR/ensure-overriding-bindings-in-pattern-with-ty-err-doesnt-ice.rs:2:31 + | +LL | let str::<{fn str() { let str::T>>::as_bytes; }}, T>::as_bytes; + | ^^^^^^^^^^^^^^^^^^ + | +help: consider giving this pattern a type + | +LL | let str::<{fn str() { let str::T>>::as_bytes: /* Type */; }}, T>::as_bytes; + | ++++++++++++ + +error: aborting due to 5 previous errors -Some errors have detailed explanations: E0109, E0412, E0533. +Some errors have detailed explanations: E0109, E0282, E0412, E0533. For more information about an error, try `rustc --explain E0109`. diff --git a/tests/ui/wf/conflicting-impls.rs b/tests/ui/wf/conflicting-impls.rs index 8054eb7c59436..c387199a8bf14 100644 --- a/tests/ui/wf/conflicting-impls.rs +++ b/tests/ui/wf/conflicting-impls.rs @@ -5,6 +5,7 @@ struct Ty; impl TryFrom for u8 { type Error = Ty; fn try_from(_: Ty) -> Result { + //~^ ERROR type annotations needed loop {} } } @@ -13,6 +14,7 @@ impl TryFrom for u8 { //~^ ERROR conflicting implementations of trait type Error = Ty; fn try_from(_: Ty) -> Result { + //~^ ERROR type annotations needed loop {} } } diff --git a/tests/ui/wf/conflicting-impls.stderr b/tests/ui/wf/conflicting-impls.stderr index d31ae17aa8f7d..15222a9b2ccd1 100644 --- a/tests/ui/wf/conflicting-impls.stderr +++ b/tests/ui/wf/conflicting-impls.stderr @@ -1,5 +1,5 @@ error[E0119]: conflicting implementations of trait `TryFrom` for type `u8` - --> $DIR/conflicting-impls.rs:12:1 + --> $DIR/conflicting-impls.rs:13:1 | LL | impl TryFrom for u8 { | ----------------------- first implementation here @@ -7,6 +7,27 @@ LL | impl TryFrom for u8 { LL | impl TryFrom for u8 { | ^^^^^^^^^^^^^^^^^^^^^^^ conflicting implementation for `u8` -error: aborting due to 1 previous error +error[E0282]: type annotations needed + --> $DIR/conflicting-impls.rs:7:53 + | +LL | fn try_from(_: Ty) -> Result { + | _____________________________________________________^ +LL | | +LL | | loop {} +LL | | } + | |_____^ cannot infer type for enum `Result` + +error[E0282]: type annotations needed + --> $DIR/conflicting-impls.rs:16:53 + | +LL | fn try_from(_: Ty) -> Result { + | _____________________________________________________^ +LL | | +LL | | loop {} +LL | | } + | |_____^ cannot infer type for enum `Result` + +error: aborting due to 3 previous errors -For more information about this error, try `rustc --explain E0119`. +Some errors have detailed explanations: E0119, E0282. +For more information about an error, try `rustc --explain E0119`. From fa2b6122135ad18640e2e9b47450f50fa873c54a Mon Sep 17 00:00:00 2001 From: Oneirical Date: Thu, 6 Jun 2024 11:55:24 -0400 Subject: [PATCH 02/23] Rewrite link-args-order to rmake --- src/doc/book | 2 +- src/tools/cargo | 2 +- src/tools/run-make-support/src/rustc.rs | 24 ++++++++++++ .../tidy/src/allowed_run_make_makefiles.txt | 1 - tests/run-make/link-args-order/Makefile | 10 ----- tests/run-make/link-args-order/rmake.rs | 39 +++++++++++++++++++ 6 files changed, 65 insertions(+), 13 deletions(-) delete mode 100644 tests/run-make/link-args-order/Makefile create mode 100644 tests/run-make/link-args-order/rmake.rs diff --git a/src/doc/book b/src/doc/book index 45c1a6d69edfd..5228bfac8267a 160000 --- a/src/doc/book +++ b/src/doc/book @@ -1 +1 @@ -Subproject commit 45c1a6d69edfd1fc91fb7504cb73958dbd09441e +Subproject commit 5228bfac8267ad24659a81b92ec5417976b5edbc diff --git a/src/tools/cargo b/src/tools/cargo index a1f47ec3f7cd0..4dcbca118ab7f 160000 --- a/src/tools/cargo +++ b/src/tools/cargo @@ -1 +1 @@ -Subproject commit a1f47ec3f7cd076986f1bfcd7061f2e8cb1a726e +Subproject commit 4dcbca118ab7f9ffac4728004c983754bc6a04ff diff --git a/src/tools/run-make-support/src/rustc.rs b/src/tools/run-make-support/src/rustc.rs index 331e1a5ab8b32..7e5a637e20e15 100644 --- a/src/tools/run-make-support/src/rustc.rs +++ b/src/tools/run-make-support/src/rustc.rs @@ -230,6 +230,24 @@ impl Rustc { self } + /// Add multiple extra arguments to the linker invocation, via `-Clink-args`. + pub fn link_args(&mut self, link_args: &str) -> &mut Self { + self.cmd.arg(format!("-Clink-args={link_args}")); + self + } + + /// Add an extra argument to prepend the linker invocation, via `-Zpre-link-arg`. + pub fn pre_link_arg(&mut self, link_arg: &str) -> &mut Self { + self.cmd.arg(format!("-Zpre-link-arg={link_arg}")); + self + } + + /// Add multiple extra arguments to the linker invocation, via `-Zpre-link-args`. + pub fn pre_link_args(&mut self, link_args: &str) -> &mut Self { + self.cmd.arg(format!("-Zpre-link-args={link_args}")); + self + } + /// Specify a stdin input pub fn stdin>(&mut self, input: I) -> &mut Self { self.cmd.set_stdin(input.as_ref().to_vec().into_boxed_slice()); @@ -248,4 +266,10 @@ impl Rustc { self.cmd.arg(format!("-Clinker={linker}")); self } + + /// Specify the linker flavor + pub fn linker_flavor(&mut self, linker_flavor: &str) -> &mut Self { + self.cmd.arg(format!("-Clinker-flavor={linker_flavor}")); + self + } } diff --git a/src/tools/tidy/src/allowed_run_make_makefiles.txt b/src/tools/tidy/src/allowed_run_make_makefiles.txt index 1596257747fa9..feb31e25e5f85 100644 --- a/src/tools/tidy/src/allowed_run_make_makefiles.txt +++ b/src/tools/tidy/src/allowed_run_make_makefiles.txt @@ -100,7 +100,6 @@ run-make/libtest-json/Makefile run-make/libtest-junit/Makefile run-make/libtest-padding/Makefile run-make/libtest-thread-limit/Makefile -run-make/link-args-order/Makefile run-make/link-cfg/Makefile run-make/link-framework/Makefile run-make/link-path-order/Makefile diff --git a/tests/run-make/link-args-order/Makefile b/tests/run-make/link-args-order/Makefile deleted file mode 100644 index c562cc1b396fa..0000000000000 --- a/tests/run-make/link-args-order/Makefile +++ /dev/null @@ -1,10 +0,0 @@ -# ignore-msvc - -include ../tools.mk - -RUSTC_FLAGS = -C linker-flavor=ld -C link-arg=a -C link-args="b c" -C link-args="d e" -C link-arg=f -RUSTC_FLAGS_PRE = -C linker-flavor=ld -Z pre-link-arg=a -Z pre-link-args="b c" -Z pre-link-args="d e" -Z pre-link-arg=f - -all: - $(RUSTC) $(RUSTC_FLAGS) empty.rs 2>&1 | $(CGREP) '"a" "b" "c" "d" "e" "f"' - $(RUSTC) $(RUSTC_FLAGS_PRE) empty.rs 2>&1 | $(CGREP) '"a" "b" "c" "d" "e" "f"' diff --git a/tests/run-make/link-args-order/rmake.rs b/tests/run-make/link-args-order/rmake.rs new file mode 100644 index 0000000000000..cd921a031292b --- /dev/null +++ b/tests/run-make/link-args-order/rmake.rs @@ -0,0 +1,39 @@ +// 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. +// See https://github.com/rust-lang/rust/pull/70665 + +use run_make_support::rustc; + +fn main() { + assert!( + String::from_utf8( + rustc() + .input("empty.rs") + .linker_flavor("ld") + .link_arg("a") + .link_args("\"b c\"") + .link_args("\"d e\"") + .link_arg("f") + .run_fail() + .stderr + ) + .unwrap() + .contains("\"a\" \"b\" \"c\" \"d\" \"e\" \"f\"") + ); + assert!( + String::from_utf8( + rustc() + .input("empty.rs") + .linker_flavor("ld") + .pre_link_arg("a") + .pre_link_args("\"b c\"") + .pre_link_args("\"d e\"") + .pre_link_arg("f") + .run_fail() + .stderr + ) + .unwrap() + .contains("\"a\" \"b\" \"c\" \"d\" \"e\" \"f\"") + ); +} From 594135ea370085bfd80ce56f7f08b146cb97f3ca Mon Sep 17 00:00:00 2001 From: Oneirical Date: Thu, 6 Jun 2024 14:51:55 -0400 Subject: [PATCH 03/23] Rewrite ls-metadata to rmake --- .../tidy/src/allowed_run_make_makefiles.txt | 1 - tests/run-make/ls-metadata/Makefile | 8 -------- tests/run-make/ls-metadata/rmake.rs | 17 +++++++++++++++++ 3 files changed, 17 insertions(+), 9 deletions(-) delete mode 100644 tests/run-make/ls-metadata/Makefile create mode 100644 tests/run-make/ls-metadata/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 feb31e25e5f85..57bb326ac954c 100644 --- a/src/tools/tidy/src/allowed_run_make_makefiles.txt +++ b/src/tools/tidy/src/allowed_run_make_makefiles.txt @@ -108,7 +108,6 @@ run-make/llvm-ident/Makefile run-make/long-linker-command-lines-cmd-exe/Makefile run-make/long-linker-command-lines/Makefile run-make/longjmp-across-rust/Makefile -run-make/ls-metadata/Makefile run-make/lto-dylib-dep/Makefile run-make/lto-empty/Makefile run-make/lto-linkage-used-attr/Makefile diff --git a/tests/run-make/ls-metadata/Makefile b/tests/run-make/ls-metadata/Makefile deleted file mode 100644 index f03569baef7f2..0000000000000 --- a/tests/run-make/ls-metadata/Makefile +++ /dev/null @@ -1,8 +0,0 @@ -# ignore-cross-compile -include ../tools.mk - -all: - $(RUSTC) foo.rs - $(RUSTC) -Z ls=root $(TMPDIR)/foo - touch $(TMPDIR)/bar - $(RUSTC) -Z ls=root $(TMPDIR)/bar diff --git a/tests/run-make/ls-metadata/rmake.rs b/tests/run-make/ls-metadata/rmake.rs new file mode 100644 index 0000000000000..61dcd3774a193 --- /dev/null +++ b/tests/run-make/ls-metadata/rmake.rs @@ -0,0 +1,17 @@ +// Passing invalid files to -Z ls (which lists the symbols +// defined by a library crate) used to cause a segmentation fault. +// As this was fixed in #11262, this test checks that no segfault +// occurs when passing the invalid file `bar` to -Z ls. +// See https://github.com/rust-lang/rust/issues/11259 + +//@ ignore-cross-compile + +use run_make_support::fs_wrapper; +use run_make_support::{rmake_out_path, rustc}; + +fn main() { + rustc().input("foo.rs"); + rustc().arg("-Zls=root").input(rmake_out_path("foo")); + fs_wrapper::create_file(rmake_out_path("bar")); + rustc().arg("-Zls=root").input(rmake_out_path("bar")); +} From 03a4259c8b925330d5425e61e7553351c21e55be Mon Sep 17 00:00:00 2001 From: Oneirical Date: Thu, 6 Jun 2024 15:20:42 -0400 Subject: [PATCH 04/23] Rewrite lto-readonly-lib to rmake --- .../tidy/src/allowed_run_make_makefiles.txt | 1 - tests/run-make/link-args-order/rmake.rs | 48 +++++++------------ tests/run-make/ls-metadata/rmake.rs | 10 ++-- tests/run-make/lto-readonly-lib/Makefile | 13 ----- tests/run-make/lto-readonly-lib/rmake.rs | 25 ++++++++++ 5 files changed, 48 insertions(+), 49 deletions(-) delete mode 100644 tests/run-make/lto-readonly-lib/Makefile create mode 100644 tests/run-make/lto-readonly-lib/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 57bb326ac954c..0fdc6de0b644e 100644 --- a/src/tools/tidy/src/allowed_run_make_makefiles.txt +++ b/src/tools/tidy/src/allowed_run_make_makefiles.txt @@ -112,7 +112,6 @@ run-make/lto-dylib-dep/Makefile run-make/lto-empty/Makefile run-make/lto-linkage-used-attr/Makefile run-make/lto-no-link-whole-rlib/Makefile -run-make/lto-readonly-lib/Makefile run-make/lto-smoke-c/Makefile run-make/macos-deployment-target/Makefile run-make/macos-fat-archive/Makefile diff --git a/tests/run-make/link-args-order/rmake.rs b/tests/run-make/link-args-order/rmake.rs index cd921a031292b..4530251c7a585 100644 --- a/tests/run-make/link-args-order/rmake.rs +++ b/tests/run-make/link-args-order/rmake.rs @@ -6,34 +6,22 @@ use run_make_support::rustc; fn main() { - assert!( - String::from_utf8( - rustc() - .input("empty.rs") - .linker_flavor("ld") - .link_arg("a") - .link_args("\"b c\"") - .link_args("\"d e\"") - .link_arg("f") - .run_fail() - .stderr - ) - .unwrap() - .contains("\"a\" \"b\" \"c\" \"d\" \"e\" \"f\"") - ); - assert!( - String::from_utf8( - rustc() - .input("empty.rs") - .linker_flavor("ld") - .pre_link_arg("a") - .pre_link_args("\"b c\"") - .pre_link_args("\"d e\"") - .pre_link_arg("f") - .run_fail() - .stderr - ) - .unwrap() - .contains("\"a\" \"b\" \"c\" \"d\" \"e\" \"f\"") - ); + rustc() + .input("empty.rs") + .linker_flavor("ld") + .link_arg("a") + .link_args("\"b c\"") + .link_args("\"d e\"") + .link_arg("f") + .run_fail() + .assert_stderr_contains("\"a\" \"b\" \"c\" \"d\" \"e\" \"f\""); + rustc() + .input("empty.rs") + .linker_flavor("ld") + .pre_link_arg("a") + .pre_link_args("\"b c\"") + .pre_link_args("\"d e\"") + .pre_link_arg("f") + .run_fail() + .assert_stderr_contains("\"a\" \"b\" \"c\" \"d\" \"e\" \"f\""); } diff --git a/tests/run-make/ls-metadata/rmake.rs b/tests/run-make/ls-metadata/rmake.rs index 61dcd3774a193..0e60f2c46787a 100644 --- a/tests/run-make/ls-metadata/rmake.rs +++ b/tests/run-make/ls-metadata/rmake.rs @@ -7,11 +7,11 @@ //@ ignore-cross-compile use run_make_support::fs_wrapper; -use run_make_support::{rmake_out_path, rustc}; +use run_make_support::rustc; fn main() { - rustc().input("foo.rs"); - rustc().arg("-Zls=root").input(rmake_out_path("foo")); - fs_wrapper::create_file(rmake_out_path("bar")); - rustc().arg("-Zls=root").input(rmake_out_path("bar")); + rustc().input("foo.rs").run(); + rustc().arg("-Zls=root").input("foo").run(); + fs_wrapper::create_file("bar"); + rustc().arg("-Zls=root").input("bar").run(); } diff --git a/tests/run-make/lto-readonly-lib/Makefile b/tests/run-make/lto-readonly-lib/Makefile deleted file mode 100644 index 11d944e3e3d4b..0000000000000 --- a/tests/run-make/lto-readonly-lib/Makefile +++ /dev/null @@ -1,13 +0,0 @@ -# ignore-cross-compile -include ../tools.mk - -all: - $(RUSTC) lib.rs - - # the compiler needs to copy and modify the rlib file when performing - # LTO, so we should ensure that it can cope with the original rlib - # being read-only. - chmod 444 $(TMPDIR)/*.rlib - - $(RUSTC) main.rs -C lto - $(call RUN,main) diff --git a/tests/run-make/lto-readonly-lib/rmake.rs b/tests/run-make/lto-readonly-lib/rmake.rs new file mode 100644 index 0000000000000..bf1dafee697dc --- /dev/null +++ b/tests/run-make/lto-readonly-lib/rmake.rs @@ -0,0 +1,25 @@ +// When the compiler is performing link time optimization, it will +// need to copy the original rlib file, set the copy's permissions to read/write, +// and modify that copy - even if the original +// file is read-only. This test creates a read-only rlib, and checks that +// compilation with LTO succeeds. +// See https://github.com/rust-lang/rust/pull/17619 + +//@ ignore-cross-compile + +use run_make_support::fs_wrapper; +use run_make_support::{cwd, run, rustc}; + +fn main() { + rustc().input("lib.rs").run(); + let entries = fs_wrapper::read_dir(cwd()); + for entry in entries { + if entry.path().extension().and_then(|s| s.to_str()) == Some("rlib") { + let mut perms = fs_wrapper::metadata(entry.path()).permissions(); + perms.set_readonly(true); + fs_wrapper::set_permissions(entry.path(), perms); + } + } + rustc().input("main.rs").arg("-Clto").run(); + run("main"); +} From 62431b73e00eaae0788b53f4ccf6cecb9f7f03ca Mon Sep 17 00:00:00 2001 From: Guillaume Gomez Date: Tue, 18 Jun 2024 15:13:40 +0200 Subject: [PATCH 05/23] Migrate `run-make/compressed-debuginfo` to `rmake.rs` --- .../tidy/src/allowed_run_make_makefiles.txt | 1 - tests/run-make/compressed-debuginfo/Makefile | 14 -------- tests/run-make/compressed-debuginfo/rmake.rs | 36 +++++++++++++++++++ 3 files changed, 36 insertions(+), 15 deletions(-) delete mode 100644 tests/run-make/compressed-debuginfo/Makefile create mode 100644 tests/run-make/compressed-debuginfo/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 24e51b8fee519..61303669ee41d 100644 --- a/src/tools/tidy/src/allowed_run_make_makefiles.txt +++ b/src/tools/tidy/src/allowed_run_make_makefiles.txt @@ -15,7 +15,6 @@ run-make/comment-section/Makefile run-make/compiler-lookup-paths-2/Makefile run-make/compiler-lookup-paths/Makefile run-make/compiler-rt-works-on-mingw/Makefile -run-make/compressed-debuginfo/Makefile run-make/crate-hash-rustc-version/Makefile run-make/crate-name-priority/Makefile run-make/cross-lang-lto-clang/Makefile diff --git a/tests/run-make/compressed-debuginfo/Makefile b/tests/run-make/compressed-debuginfo/Makefile deleted file mode 100644 index d2f24dde00d7b..0000000000000 --- a/tests/run-make/compressed-debuginfo/Makefile +++ /dev/null @@ -1,14 +0,0 @@ -# ignore-cross-compile -include ../tools.mk - -# only-linux -# -# This tests debuginfo-compression. - -all: zlib zstandard - -zlib: - test "`$(RUSTC) --crate-name=foo --crate-type=lib --emit=obj -C debuginfo=full -Z debuginfo-compression=zlib foo.rs 2>&1 | sed 's/.*unknown.*zlib.*/missing/' | head -n 1`" = missing || readelf -t $(TMPDIR)/foo.o | grep -q ZLIB - -zstandard: - test "`$(RUSTC) --crate-name=foo --crate-type=lib --emit=obj -C debuginfo=full -Z debuginfo-compression=zstd foo.rs 2>&1 | sed 's/.*unknown.*zstd.*/missing/' | head -n 1`" = missing || readelf -t $(TMPDIR)/foo.o | grep -q ZST diff --git a/tests/run-make/compressed-debuginfo/rmake.rs b/tests/run-make/compressed-debuginfo/rmake.rs new file mode 100644 index 0000000000000..9c6d50ab243cd --- /dev/null +++ b/tests/run-make/compressed-debuginfo/rmake.rs @@ -0,0 +1,36 @@ +// Checks the `debuginfo-compression` option. + +//@ only-linux +//@ ignore-cross-compile + +// FIXME: This test isn't comprehensive and isn't covering all possible combinations. + +use run_make_support::{assert_contains, cmd, run_in_tmpdir, rustc}; + +fn check_compression(compression: &str, to_find: &str) { + run_in_tmpdir(|| { + let out = rustc() + .crate_name("foo") + .crate_type("lib") + .emit("obj") + .arg("-Cdebuginfo=full") + .arg(&format!("-Zdebuginfo-compression={compression}")) + .input("foo.rs") + .run(); + let stderr = out.stderr_utf8(); + if stderr.is_empty() { + // FIXME: `readelf` might need to be replaced with `llvm-readelf`. + cmd("readelf").arg("-t").arg("foo.o").run().assert_stdout_contains(to_find); + } else { + assert_contains( + &stderr, + &format!("unknown debuginfo compression algorithm {compression}"), + ); + } + }); +} + +fn main() { + check_compression("zlib", "ZLIB"); + check_compression("zstd", "ZSTD"); +} From 060a13e9fd56b1d186ea016070e390067b9e893d Mon Sep 17 00:00:00 2001 From: Oneirical Date: Tue, 18 Jun 2024 15:59:33 -0400 Subject: [PATCH 06/23] rewrite extern-flag-rename-transitive to rmake --- src/tools/tidy/src/allowed_run_make_makefiles.txt | 1 - .../extern-flag-rename-transitive/Makefile | 7 ------- .../extern-flag-rename-transitive/rmake.rs | 14 ++++++++++++++ 3 files changed, 14 insertions(+), 8 deletions(-) delete mode 100644 tests/run-make/extern-flag-rename-transitive/Makefile create mode 100644 tests/run-make/extern-flag-rename-transitive/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 1596257747fa9..6f57cb717ace8 100644 --- a/src/tools/tidy/src/allowed_run_make_makefiles.txt +++ b/src/tools/tidy/src/allowed_run_make_makefiles.txt @@ -40,7 +40,6 @@ run-make/export-executable-symbols/Makefile run-make/extern-diff-internal-name/Makefile run-make/extern-flag-disambiguates/Makefile run-make/extern-flag-pathless/Makefile -run-make/extern-flag-rename-transitive/Makefile run-make/extern-fn-explicit-align/Makefile run-make/extern-fn-generic/Makefile run-make/extern-fn-mangle/Makefile diff --git a/tests/run-make/extern-flag-rename-transitive/Makefile b/tests/run-make/extern-flag-rename-transitive/Makefile deleted file mode 100644 index d16a8e20868ef..0000000000000 --- a/tests/run-make/extern-flag-rename-transitive/Makefile +++ /dev/null @@ -1,7 +0,0 @@ -include ../tools.mk - -all: - $(RUSTC) foo.rs - $(RUSTC) bar.rs - $(RUSTC) baz.rs --extern a=$(TMPDIR)/libfoo.rlib - diff --git a/tests/run-make/extern-flag-rename-transitive/rmake.rs b/tests/run-make/extern-flag-rename-transitive/rmake.rs new file mode 100644 index 0000000000000..0090d487f03d6 --- /dev/null +++ b/tests/run-make/extern-flag-rename-transitive/rmake.rs @@ -0,0 +1,14 @@ +// 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 +// checks that the --extern flag takes precedence over the extern +// crate statement in the code. +// See https://github.com/rust-lang/rust/pull/52723 + +use run_make_support::{rust_lib_name, rustc}; + +fn main() { + rustc().input("foo.rs").run(); + rustc().input("bar.rs").run(); + rustc().input("baz.rs").extern_("a", rust_lib_name("foo")).run(); +} From 9e2ace85f9d2a9fd24af197f2da81eb3a5db51b9 Mon Sep 17 00:00:00 2001 From: Oneirical Date: Tue, 18 Jun 2024 16:05:56 -0400 Subject: [PATCH 07/23] rewrite debugger-visualizer-dep-info to rmake --- src/tools/tidy/src/allowed_run_make_makefiles.txt | 1 - tests/run-make/debugger-visualizer-dep-info/Makefile | 9 --------- tests/run-make/debugger-visualizer-dep-info/rmake.rs | 11 +++++++++++ 3 files changed, 11 insertions(+), 10 deletions(-) delete mode 100644 tests/run-make/debugger-visualizer-dep-info/Makefile create mode 100644 tests/run-make/debugger-visualizer-dep-info/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 6f57cb717ace8..4091cbbbcb89c 100644 --- a/src/tools/tidy/src/allowed_run_make_makefiles.txt +++ b/src/tools/tidy/src/allowed_run_make_makefiles.txt @@ -23,7 +23,6 @@ run-make/cross-lang-lto-pgo-smoketest/Makefile run-make/cross-lang-lto-upstream-rlibs/Makefile run-make/cross-lang-lto/Makefile run-make/debug-assertions/Makefile -run-make/debugger-visualizer-dep-info/Makefile run-make/dep-info-doesnt-run-much/Makefile run-make/dep-info-spaces/Makefile run-make/dep-info/Makefile diff --git a/tests/run-make/debugger-visualizer-dep-info/Makefile b/tests/run-make/debugger-visualizer-dep-info/Makefile deleted file mode 100644 index 0877998a74fe7..0000000000000 --- a/tests/run-make/debugger-visualizer-dep-info/Makefile +++ /dev/null @@ -1,9 +0,0 @@ -include ../tools.mk - -# This test makes sure that files referenced via #[debugger_visualizer] are -# included in `--emit dep-info` output. - -all: - $(RUSTC) --emit dep-info main.rs - $(CGREP) "foo.py" < $(TMPDIR)/main.d - $(CGREP) "my_visualizers/bar.natvis" < $(TMPDIR)/main.d diff --git a/tests/run-make/debugger-visualizer-dep-info/rmake.rs b/tests/run-make/debugger-visualizer-dep-info/rmake.rs new file mode 100644 index 0000000000000..65ffb2373e7c4 --- /dev/null +++ b/tests/run-make/debugger-visualizer-dep-info/rmake.rs @@ -0,0 +1,11 @@ +// 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 + +use run_make_support::{invalid_utf8_contains, rustc}; + +fn main() { + rustc().emit("dep-info").input("main.rs").run(); + invalid_utf8_contains("main.d", "foo.py"); + invalid_utf8_contains("main.d", "my_visualizers/bar.natvis"); +} From dff354e57fe030f8fa0467f092b75e8979a3cce9 Mon Sep 17 00:00:00 2001 From: Oneirical Date: Tue, 18 Jun 2024 16:20:32 -0400 Subject: [PATCH 08/23] rewrite metadata-flag-frobs-symbols to rmake --- src/tools/run-make-support/src/rustc.rs | 6 ++++++ .../tidy/src/allowed_run_make_makefiles.txt | 1 - .../metadata-flag-frobs-symbols/Makefile | 11 ---------- .../metadata-flag-frobs-symbols/rmake.rs | 21 +++++++++++++++++++ 4 files changed, 27 insertions(+), 12 deletions(-) delete mode 100644 tests/run-make/metadata-flag-frobs-symbols/Makefile create mode 100644 tests/run-make/metadata-flag-frobs-symbols/rmake.rs diff --git a/src/tools/run-make-support/src/rustc.rs b/src/tools/run-make-support/src/rustc.rs index 331e1a5ab8b32..125f4b4bd6291 100644 --- a/src/tools/run-make-support/src/rustc.rs +++ b/src/tools/run-make-support/src/rustc.rs @@ -73,6 +73,12 @@ impl Rustc { self } + /// Incorporate a hashed string to mangled symbols. + pub fn metadata(&mut self, meta: &str) -> &mut Self { + self.cmd.arg(format!("-Cmetadata={meta}")); + self + } + /// Add a suffix in each output filename. pub fn extra_filename(&mut self, suffix: &str) -> &mut Self { self.cmd.arg(format!("-Cextra-filename={suffix}")); diff --git a/src/tools/tidy/src/allowed_run_make_makefiles.txt b/src/tools/tidy/src/allowed_run_make_makefiles.txt index 4091cbbbcb89c..691248ea260b6 100644 --- a/src/tools/tidy/src/allowed_run_make_makefiles.txt +++ b/src/tools/tidy/src/allowed_run_make_makefiles.txt @@ -119,7 +119,6 @@ run-make/macos-fat-archive/Makefile run-make/manual-link/Makefile run-make/many-crates-but-no-match/Makefile run-make/metadata-dep-info/Makefile -run-make/metadata-flag-frobs-symbols/Makefile run-make/min-global-align/Makefile run-make/mingw-export-call-convention/Makefile run-make/mismatching-target-triples/Makefile diff --git a/tests/run-make/metadata-flag-frobs-symbols/Makefile b/tests/run-make/metadata-flag-frobs-symbols/Makefile deleted file mode 100644 index 53d7d0657695f..0000000000000 --- a/tests/run-make/metadata-flag-frobs-symbols/Makefile +++ /dev/null @@ -1,11 +0,0 @@ -# ignore-cross-compile -include ../tools.mk - -all: - $(RUSTC) foo.rs -C metadata=a -C extra-filename=-a - $(RUSTC) foo.rs -C metadata=b -C extra-filename=-b - $(RUSTC) bar.rs \ - --extern foo1=$(TMPDIR)/libfoo-a.rlib \ - --extern foo2=$(TMPDIR)/libfoo-b.rlib \ - --print link-args - $(call RUN,bar) diff --git a/tests/run-make/metadata-flag-frobs-symbols/rmake.rs b/tests/run-make/metadata-flag-frobs-symbols/rmake.rs new file mode 100644 index 0000000000000..12c07f9e3aeec --- /dev/null +++ b/tests/run-make/metadata-flag-frobs-symbols/rmake.rs @@ -0,0 +1,21 @@ +// In this test, foo.rs is compiled twice with different hashes tied to its +// symbols thanks to the metadata flag. bar.rs then ensures that the memory locations +// of foo's symbols are different even though they came from the same original source code. +// This checks that the metadata flag is doing its job. +// See https://github.com/rust-lang/rust/issues/14471 + +//@ ignore-cross-compile + +use run_make_support::{run, rust_lib_name, rustc}; + +fn main() { + rustc().input("foo.rs").metadata("a").extra_filename("-a").run(); + rustc().input("foo.rs").metadata("b").extra_filename("-b").run(); + rustc() + .input("bar.rs") + .extern_("foo1", rust_lib_name("foo-a")) + .extern_("foo2", rust_lib_name("foo-b")) + .print("link-args") + .run(); + run("bar"); +} From d1e8c6bc7e93b6649e9dab0604dcc591dde03af0 Mon Sep 17 00:00:00 2001 From: Oneirical Date: Tue, 18 Jun 2024 16:30:26 -0400 Subject: [PATCH 09/23] rewrite extern-overrides-distribution to rmake --- src/tools/tidy/src/allowed_run_make_makefiles.txt | 1 - .../extern-overrides-distribution/Makefile | 6 ------ .../extern-overrides-distribution/rmake.rs | 14 ++++++++++++++ 3 files changed, 14 insertions(+), 7 deletions(-) delete mode 100644 tests/run-make/extern-overrides-distribution/Makefile create mode 100644 tests/run-make/extern-overrides-distribution/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 691248ea260b6..8eee16e87a88e 100644 --- a/src/tools/tidy/src/allowed_run_make_makefiles.txt +++ b/src/tools/tidy/src/allowed_run_make_makefiles.txt @@ -49,7 +49,6 @@ run-make/extern-fn-with-packed-struct/Makefile run-make/extern-fn-with-union/Makefile run-make/extern-multiple-copies/Makefile run-make/extern-multiple-copies2/Makefile -run-make/extern-overrides-distribution/Makefile run-make/extra-filename-with-temp-outputs/Makefile run-make/fmt-write-bloat/Makefile run-make/forced-unwind-terminate-pof/Makefile diff --git a/tests/run-make/extern-overrides-distribution/Makefile b/tests/run-make/extern-overrides-distribution/Makefile deleted file mode 100644 index bfd0dd6991ba7..0000000000000 --- a/tests/run-make/extern-overrides-distribution/Makefile +++ /dev/null @@ -1,6 +0,0 @@ -# ignore-cross-compile -include ../tools.mk - -all: - $(RUSTC) libc.rs -Cmetadata=foo - $(RUSTC) main.rs --extern libc=$(TMPDIR)/liblibc.rlib diff --git a/tests/run-make/extern-overrides-distribution/rmake.rs b/tests/run-make/extern-overrides-distribution/rmake.rs new file mode 100644 index 0000000000000..bd2553d4134a4 --- /dev/null +++ b/tests/run-make/extern-overrides-distribution/rmake.rs @@ -0,0 +1,14 @@ +// The --extern flag should override any "crate_type" declarations in the +// Rust files themselves. In this test, libc is compiled as "lib", but +// main.rs will only run with an rlib, which checks if the --extern flag +// is successfully overriding the default behaviour. +// See https://github.com/rust-lang/rust/pull/21782 + +//@ ignore-cross-compile + +use run_make_support::{rust_lib_name, rustc}; + +fn main() { + rustc().input("libc.rs").metadata("foo").run(); + rustc().input("main.rs").extern_("libc", rust_lib_name("libc")).run(); +} From ec88615e7444865072d34e9237b6b0e19ef0036d Mon Sep 17 00:00:00 2001 From: Michael Goulet Date: Tue, 18 Jun 2024 19:13:54 -0400 Subject: [PATCH 10/23] Rename a bunch of things --- .../rustc_borrowck/src/region_infer/mod.rs | 2 +- .../src/check/compare_impl_item.rs | 16 +- .../src/check/compare_impl_item/refine.rs | 2 +- .../src/coherence/orphan.rs | 2 +- .../src/collect/item_bounds.rs | 2 +- compiler/rustc_hir_typeck/src/writeback.rs | 2 +- .../src/infer/canonical/canonicalizer.rs | 4 +- .../infer/error_reporting/need_type_info.rs | 2 +- compiler/rustc_infer/src/infer/freshen.rs | 4 +- compiler/rustc_infer/src/infer/mod.rs | 4 +- compiler/rustc_infer/src/infer/resolve.rs | 8 +- .../rustc_infer/src/infer/snapshot/fudge.rs | 2 +- compiler/rustc_lint/src/non_local_def.rs | 2 +- compiler/rustc_middle/src/traits/solve.rs | 22 ++- .../rustc_middle/src/ty/abstract_const.rs | 2 +- compiler/rustc_middle/src/ty/diagnostics.rs | 2 +- compiler/rustc_middle/src/ty/erase_regions.rs | 2 +- compiler/rustc_middle/src/ty/fold.rs | 6 +- compiler/rustc_middle/src/ty/generic_args.rs | 6 +- compiler/rustc_middle/src/ty/instance.rs | 2 +- .../src/ty/normalize_erasing_regions.rs | 4 +- compiler/rustc_middle/src/ty/opaque_types.rs | 4 +- compiler/rustc_middle/src/ty/print/pretty.rs | 2 +- .../rustc_middle/src/ty/structural_impls.rs | 8 +- compiler/rustc_middle/src/ty/util.rs | 6 +- .../src/canonicalizer.rs | 48 +++--- .../src/{infcx.rs => delegate.rs} | 6 +- compiler/rustc_next_trait_solver/src/lib.rs | 2 +- .../rustc_next_trait_solver/src/resolve.rs | 32 ++-- .../src/solve/alias_relate.rs | 8 +- .../src/solve/assembly/mod.rs | 115 +++++++------ .../src/solve/assembly/structural_traits.rs | 58 +++---- .../src/solve/eval_ctxt/canonical.rs | 85 +++++----- .../src/solve/eval_ctxt/mod.rs | 153 +++++++++--------- .../src/solve/eval_ctxt/probe.rs | 49 +++--- .../src/solve/inspect/build.rs | 55 +++---- .../rustc_next_trait_solver/src/solve/mod.rs | 18 +-- .../src/solve/normalizes_to/anon_const.rs | 6 +- .../src/solve/normalizes_to/inherent.rs | 8 +- .../src/solve/normalizes_to/mod.rs | 112 ++++++------- .../src/solve/normalizes_to/opaque_types.rs | 10 +- .../src/solve/normalizes_to/weak_types.rs | 8 +- .../src/solve/project_goals.rs | 8 +- .../src/solve/search_graph.rs | 20 +-- .../src/solve/trait_goals.rs | 116 +++++++------ .../cfi/typeid/itanium_cxx_abi/transform.rs | 2 +- compiler/rustc_trait_selection/src/solve.rs | 2 +- .../src/solve/{infcx.rs => delegate.rs} | 4 +- .../src/solve/fulfill.rs | 2 +- .../src/solve/inspect/analyse.rs | 2 +- .../src/solve/normalize.rs | 4 +- .../src/traits/error_reporting/suggestions.rs | 2 +- .../error_reporting/type_err_ctxt_ext.rs | 2 +- .../rustc_trait_selection/src/traits/mod.rs | 2 +- .../src/traits/normalize.rs | 10 +- .../src/traits/query/normalize.rs | 12 +- .../rustc_trait_selection/src/traits/util.rs | 6 +- compiler/rustc_type_ir/src/binder.rs | 4 +- compiler/rustc_type_ir/src/fold.rs | 10 +- compiler/rustc_type_ir/src/ty_kind/closure.rs | 2 +- 60 files changed, 536 insertions(+), 565 deletions(-) rename compiler/rustc_next_trait_solver/src/{infcx.rs => delegate.rs} (98%) rename compiler/rustc_trait_selection/src/solve/{infcx.rs => delegate.rs} (99%) diff --git a/compiler/rustc_borrowck/src/region_infer/mod.rs b/compiler/rustc_borrowck/src/region_infer/mod.rs index 40b5850059820..bf1c1b1433ea6 100644 --- a/compiler/rustc_borrowck/src/region_infer/mod.rs +++ b/compiler/rustc_borrowck/src/region_infer/mod.rs @@ -1110,7 +1110,7 @@ impl<'tcx> RegionInferenceContext<'tcx> { tcx: TyCtxt<'tcx>, } impl<'tcx> ty::TypeFolder> for OpaqueFolder<'tcx> { - fn interner(&self) -> TyCtxt<'tcx> { + fn cx(&self) -> TyCtxt<'tcx> { self.tcx } fn fold_ty(&mut self, t: Ty<'tcx>) -> Ty<'tcx> { diff --git a/compiler/rustc_hir_analysis/src/check/compare_impl_item.rs b/compiler/rustc_hir_analysis/src/check/compare_impl_item.rs index 82b57cdd10691..550f38af8b5da 100644 --- a/compiler/rustc_hir_analysis/src/check/compare_impl_item.rs +++ b/compiler/rustc_hir_analysis/src/check/compare_impl_item.rs @@ -397,7 +397,7 @@ struct RemapLateBound<'a, 'tcx> { } impl<'tcx> TypeFolder> for RemapLateBound<'_, 'tcx> { - fn interner(&self) -> TyCtxt<'tcx> { + fn cx(&self) -> TyCtxt<'tcx> { self.tcx } @@ -790,13 +790,13 @@ impl<'tcx, E> TypeFolder> for ImplTraitInTraitCollector<'_, 'tcx, E where E: 'tcx, { - fn interner(&self) -> TyCtxt<'tcx> { + fn cx(&self) -> TyCtxt<'tcx> { self.ocx.infcx.tcx } fn fold_ty(&mut self, ty: Ty<'tcx>) -> Ty<'tcx> { if let ty::Alias(ty::Projection, proj) = ty.kind() - && self.interner().is_impl_trait_in_trait(proj.def_id) + && self.cx().is_impl_trait_in_trait(proj.def_id) { if let Some((ty, _)) = self.types.get(&proj.def_id) { return *ty; @@ -810,9 +810,9 @@ where self.types.insert(proj.def_id, (infer_ty, proj.args)); // Recurse into bounds for (pred, pred_span) in self - .interner() + .cx() .explicit_item_bounds(proj.def_id) - .iter_instantiated_copied(self.interner(), proj.args) + .iter_instantiated_copied(self.cx(), proj.args) { let pred = pred.fold_with(self); let pred = self.ocx.normalize( @@ -822,7 +822,7 @@ where ); self.ocx.register_obligation(traits::Obligation::new( - self.interner(), + self.cx(), ObligationCause::new( self.span, self.body_id, @@ -853,7 +853,7 @@ struct RemapHiddenTyRegions<'tcx> { impl<'tcx> ty::FallibleTypeFolder> for RemapHiddenTyRegions<'tcx> { type Error = ErrorGuaranteed; - fn interner(&self) -> TyCtxt<'tcx> { + fn cx(&self) -> TyCtxt<'tcx> { self.tcx } @@ -2072,7 +2072,7 @@ struct ReplaceTy<'tcx> { } impl<'tcx> TypeFolder> for ReplaceTy<'tcx> { - fn interner(&self) -> TyCtxt<'tcx> { + fn cx(&self) -> TyCtxt<'tcx> { self.tcx } diff --git a/compiler/rustc_hir_analysis/src/check/compare_impl_item/refine.rs b/compiler/rustc_hir_analysis/src/check/compare_impl_item/refine.rs index 10b097a1060f3..6cdbd692f73be 100644 --- a/compiler/rustc_hir_analysis/src/check/compare_impl_item/refine.rs +++ b/compiler/rustc_hir_analysis/src/check/compare_impl_item/refine.rs @@ -322,7 +322,7 @@ struct Anonymize<'tcx> { } impl<'tcx> TypeFolder> for Anonymize<'tcx> { - fn interner(&self) -> TyCtxt<'tcx> { + fn cx(&self) -> TyCtxt<'tcx> { self.tcx } diff --git a/compiler/rustc_hir_analysis/src/coherence/orphan.rs b/compiler/rustc_hir_analysis/src/coherence/orphan.rs index 9421269e51ea6..5cb91603fd067 100644 --- a/compiler/rustc_hir_analysis/src/coherence/orphan.rs +++ b/compiler/rustc_hir_analysis/src/coherence/orphan.rs @@ -539,7 +539,7 @@ struct TyVarReplacer<'cx, 'tcx> { } impl<'cx, 'tcx> TypeFolder> for TyVarReplacer<'cx, 'tcx> { - fn interner(&self) -> TyCtxt<'tcx> { + fn cx(&self) -> TyCtxt<'tcx> { self.infcx.tcx } diff --git a/compiler/rustc_hir_analysis/src/collect/item_bounds.rs b/compiler/rustc_hir_analysis/src/collect/item_bounds.rs index 50c93e9f1d7e2..8b18cf33d038f 100644 --- a/compiler/rustc_hir_analysis/src/collect/item_bounds.rs +++ b/compiler/rustc_hir_analysis/src/collect/item_bounds.rs @@ -203,7 +203,7 @@ struct AssocTyToOpaque<'tcx> { } impl<'tcx> TypeFolder> for AssocTyToOpaque<'tcx> { - fn interner(&self) -> TyCtxt<'tcx> { + fn cx(&self) -> TyCtxt<'tcx> { self.tcx } diff --git a/compiler/rustc_hir_typeck/src/writeback.rs b/compiler/rustc_hir_typeck/src/writeback.rs index b67d29fce9216..a290075a23e71 100644 --- a/compiler/rustc_hir_typeck/src/writeback.rs +++ b/compiler/rustc_hir_typeck/src/writeback.rs @@ -847,7 +847,7 @@ impl<'cx, 'tcx> Resolver<'cx, 'tcx> { } impl<'cx, 'tcx> TypeFolder> for Resolver<'cx, 'tcx> { - fn interner(&self) -> TyCtxt<'tcx> { + fn cx(&self) -> TyCtxt<'tcx> { self.fcx.tcx } diff --git a/compiler/rustc_infer/src/infer/canonical/canonicalizer.rs b/compiler/rustc_infer/src/infer/canonical/canonicalizer.rs index bc2592b43f3d3..1659f3d049370 100644 --- a/compiler/rustc_infer/src/infer/canonical/canonicalizer.rs +++ b/compiler/rustc_infer/src/infer/canonical/canonicalizer.rs @@ -304,7 +304,7 @@ struct Canonicalizer<'cx, 'tcx> { } impl<'cx, 'tcx> TypeFolder> for Canonicalizer<'cx, 'tcx> { - fn interner(&self) -> TyCtxt<'tcx> { + fn cx(&self) -> TyCtxt<'tcx> { self.tcx } @@ -773,7 +773,7 @@ impl<'cx, 'tcx> Canonicalizer<'cx, 'tcx> { ) -> ty::Region<'tcx> { let var = self.canonical_var(info, r.into()); let br = ty::BoundRegion { var, kind: ty::BrAnon }; - ty::Region::new_bound(self.interner(), self.binder_index, br) + ty::Region::new_bound(self.cx(), self.binder_index, br) } /// Given a type variable `ty_var` of the given kind, first check diff --git a/compiler/rustc_infer/src/infer/error_reporting/need_type_info.rs b/compiler/rustc_infer/src/infer/error_reporting/need_type_info.rs index cb0e13652e800..d7349abc44c24 100644 --- a/compiler/rustc_infer/src/infer/error_reporting/need_type_info.rs +++ b/compiler/rustc_infer/src/infer/error_reporting/need_type_info.rs @@ -158,7 +158,7 @@ struct ClosureEraser<'tcx> { } impl<'tcx> TypeFolder> for ClosureEraser<'tcx> { - fn interner(&self) -> TyCtxt<'tcx> { + fn cx(&self) -> TyCtxt<'tcx> { self.tcx } diff --git a/compiler/rustc_infer/src/infer/freshen.rs b/compiler/rustc_infer/src/infer/freshen.rs index 4bb59bd9037c3..4b32a2d2dd2fa 100644 --- a/compiler/rustc_infer/src/infer/freshen.rs +++ b/compiler/rustc_infer/src/infer/freshen.rs @@ -100,7 +100,7 @@ impl<'a, 'tcx> TypeFreshener<'a, 'tcx> { } impl<'a, 'tcx> TypeFolder> for TypeFreshener<'a, 'tcx> { - fn interner(&self) -> TyCtxt<'tcx> { + fn cx(&self) -> TyCtxt<'tcx> { self.infcx.tcx } @@ -117,7 +117,7 @@ impl<'a, 'tcx> TypeFolder> for TypeFreshener<'a, 'tcx> { | ty::RePlaceholder(..) | ty::ReStatic | ty::ReError(_) - | ty::ReErased => self.interner().lifetimes.re_erased, + | ty::ReErased => self.cx().lifetimes.re_erased, } } diff --git a/compiler/rustc_infer/src/infer/mod.rs b/compiler/rustc_infer/src/infer/mod.rs index 510e9a06dfb06..0703c53679506 100644 --- a/compiler/rustc_infer/src/infer/mod.rs +++ b/compiler/rustc_infer/src/infer/mod.rs @@ -1719,7 +1719,7 @@ struct InferenceLiteralEraser<'tcx> { } impl<'tcx> TypeFolder> for InferenceLiteralEraser<'tcx> { - fn interner(&self) -> TyCtxt<'tcx> { + fn cx(&self) -> TyCtxt<'tcx> { self.tcx } @@ -1859,7 +1859,7 @@ fn replace_param_and_infer_args_with_placeholder<'tcx>( } impl<'tcx> TypeFolder> for ReplaceParamAndInferWithPlaceholder<'tcx> { - fn interner(&self) -> TyCtxt<'tcx> { + fn cx(&self) -> TyCtxt<'tcx> { self.tcx } diff --git a/compiler/rustc_infer/src/infer/resolve.rs b/compiler/rustc_infer/src/infer/resolve.rs index 830d79f52b945..ed75fd183f29d 100644 --- a/compiler/rustc_infer/src/infer/resolve.rs +++ b/compiler/rustc_infer/src/infer/resolve.rs @@ -24,7 +24,7 @@ impl<'a, 'tcx> OpportunisticVarResolver<'a, 'tcx> { } impl<'a, 'tcx> TypeFolder> for OpportunisticVarResolver<'a, 'tcx> { - fn interner(&self) -> TyCtxt<'tcx> { + fn cx(&self) -> TyCtxt<'tcx> { self.infcx.tcx } @@ -66,7 +66,7 @@ impl<'a, 'tcx> OpportunisticRegionResolver<'a, 'tcx> { } impl<'a, 'tcx> TypeFolder> for OpportunisticRegionResolver<'a, 'tcx> { - fn interner(&self) -> TyCtxt<'tcx> { + fn cx(&self) -> TyCtxt<'tcx> { self.infcx.tcx } @@ -85,7 +85,7 @@ impl<'a, 'tcx> TypeFolder> for OpportunisticRegionResolver<'a, 'tcx .inner .borrow_mut() .unwrap_region_constraints() - .opportunistic_resolve_var(TypeFolder::interner(self), vid), + .opportunistic_resolve_var(TypeFolder::cx(self), vid), _ => r, } } @@ -121,7 +121,7 @@ struct FullTypeResolver<'a, 'tcx> { impl<'a, 'tcx> FallibleTypeFolder> for FullTypeResolver<'a, 'tcx> { type Error = FixupError; - fn interner(&self) -> TyCtxt<'tcx> { + fn cx(&self) -> TyCtxt<'tcx> { self.infcx.tcx } diff --git a/compiler/rustc_infer/src/infer/snapshot/fudge.rs b/compiler/rustc_infer/src/infer/snapshot/fudge.rs index a086c82c92e8a..f15bd0babee5c 100644 --- a/compiler/rustc_infer/src/infer/snapshot/fudge.rs +++ b/compiler/rustc_infer/src/infer/snapshot/fudge.rs @@ -183,7 +183,7 @@ pub struct InferenceFudger<'a, 'tcx> { } impl<'a, 'tcx> TypeFolder> for InferenceFudger<'a, 'tcx> { - fn interner(&self) -> TyCtxt<'tcx> { + fn cx(&self) -> TyCtxt<'tcx> { self.infcx.tcx } diff --git a/compiler/rustc_lint/src/non_local_def.rs b/compiler/rustc_lint/src/non_local_def.rs index b0ec6e06658f3..706d99ed74fbb 100644 --- a/compiler/rustc_lint/src/non_local_def.rs +++ b/compiler/rustc_lint/src/non_local_def.rs @@ -383,7 +383,7 @@ struct ReplaceLocalTypesWithInfer<'a, 'tcx, F: FnMut(DefId) -> bool> { impl<'a, 'tcx, F: FnMut(DefId) -> bool> TypeFolder> for ReplaceLocalTypesWithInfer<'a, 'tcx, F> { - fn interner(&self) -> TyCtxt<'tcx> { + fn cx(&self) -> TyCtxt<'tcx> { self.infcx.tcx } diff --git a/compiler/rustc_middle/src/traits/solve.rs b/compiler/rustc_middle/src/traits/solve.rs index 90f80f90767d9..7bc4c60f10272 100644 --- a/compiler/rustc_middle/src/traits/solve.rs +++ b/compiler/rustc_middle/src/traits/solve.rs @@ -53,7 +53,7 @@ impl<'tcx> TypeFoldable> for ExternalConstraints<'tcx> { self, folder: &mut F, ) -> Result { - Ok(FallibleTypeFolder::interner(folder).mk_external_constraints(ExternalConstraintsData { + Ok(FallibleTypeFolder::cx(folder).mk_external_constraints(ExternalConstraintsData { region_constraints: self.region_constraints.clone().try_fold_with(folder)?, opaque_types: self .opaque_types @@ -68,7 +68,7 @@ impl<'tcx> TypeFoldable> for ExternalConstraints<'tcx> { } fn fold_with>>(self, folder: &mut F) -> Self { - TypeFolder::interner(folder).mk_external_constraints(ExternalConstraintsData { + TypeFolder::cx(folder).mk_external_constraints(ExternalConstraintsData { region_constraints: self.region_constraints.clone().fold_with(folder), opaque_types: self.opaque_types.iter().map(|opaque| opaque.fold_with(folder)).collect(), normalization_nested_goals: self.normalization_nested_goals.clone().fold_with(folder), @@ -94,19 +94,17 @@ impl<'tcx> TypeFoldable> for PredefinedOpaques<'tcx> { self, folder: &mut F, ) -> Result { - Ok(FallibleTypeFolder::interner(folder).mk_predefined_opaques_in_body( - PredefinedOpaquesData { - opaque_types: self - .opaque_types - .iter() - .map(|opaque| opaque.try_fold_with(folder)) - .collect::>()?, - }, - )) + Ok(FallibleTypeFolder::cx(folder).mk_predefined_opaques_in_body(PredefinedOpaquesData { + opaque_types: self + .opaque_types + .iter() + .map(|opaque| opaque.try_fold_with(folder)) + .collect::>()?, + })) } fn fold_with>>(self, folder: &mut F) -> Self { - TypeFolder::interner(folder).mk_predefined_opaques_in_body(PredefinedOpaquesData { + TypeFolder::cx(folder).mk_predefined_opaques_in_body(PredefinedOpaquesData { opaque_types: self.opaque_types.iter().map(|opaque| opaque.fold_with(folder)).collect(), }) } diff --git a/compiler/rustc_middle/src/ty/abstract_const.rs b/compiler/rustc_middle/src/ty/abstract_const.rs index 254e1b5448197..50d00f31bd024 100644 --- a/compiler/rustc_middle/src/ty/abstract_const.rs +++ b/compiler/rustc_middle/src/ty/abstract_const.rs @@ -40,7 +40,7 @@ impl<'tcx> TyCtxt<'tcx> { } impl<'tcx> TypeFolder> for Expander<'tcx> { - fn interner(&self) -> TyCtxt<'tcx> { + fn cx(&self) -> TyCtxt<'tcx> { self.tcx } fn fold_ty(&mut self, ty: Ty<'tcx>) -> Ty<'tcx> { diff --git a/compiler/rustc_middle/src/ty/diagnostics.rs b/compiler/rustc_middle/src/ty/diagnostics.rs index 8c3ee6955f5d2..4bf2233799130 100644 --- a/compiler/rustc_middle/src/ty/diagnostics.rs +++ b/compiler/rustc_middle/src/ty/diagnostics.rs @@ -579,7 +579,7 @@ pub struct MakeSuggestableFolder<'tcx> { impl<'tcx> FallibleTypeFolder> for MakeSuggestableFolder<'tcx> { type Error = (); - fn interner(&self) -> TyCtxt<'tcx> { + fn cx(&self) -> TyCtxt<'tcx> { self.tcx } diff --git a/compiler/rustc_middle/src/ty/erase_regions.rs b/compiler/rustc_middle/src/ty/erase_regions.rs index cd6e7df31f7cd..9d5481f3df376 100644 --- a/compiler/rustc_middle/src/ty/erase_regions.rs +++ b/compiler/rustc_middle/src/ty/erase_regions.rs @@ -37,7 +37,7 @@ struct RegionEraserVisitor<'tcx> { } impl<'tcx> TypeFolder> for RegionEraserVisitor<'tcx> { - fn interner(&self) -> TyCtxt<'tcx> { + fn cx(&self) -> TyCtxt<'tcx> { self.tcx } diff --git a/compiler/rustc_middle/src/ty/fold.rs b/compiler/rustc_middle/src/ty/fold.rs index 9b5b1430c27f7..81ea8738e7269 100644 --- a/compiler/rustc_middle/src/ty/fold.rs +++ b/compiler/rustc_middle/src/ty/fold.rs @@ -28,7 +28,7 @@ where G: FnMut(ty::Region<'tcx>) -> ty::Region<'tcx>, H: FnMut(ty::Const<'tcx>) -> ty::Const<'tcx>, { - fn interner(&self) -> TyCtxt<'tcx> { + fn cx(&self) -> TyCtxt<'tcx> { self.tcx } @@ -99,7 +99,7 @@ impl<'a, 'tcx> RegionFolder<'a, 'tcx> { } impl<'a, 'tcx> TypeFolder> for RegionFolder<'a, 'tcx> { - fn interner(&self) -> TyCtxt<'tcx> { + fn cx(&self) -> TyCtxt<'tcx> { self.tcx } @@ -176,7 +176,7 @@ impl<'tcx, D> TypeFolder> for BoundVarReplacer<'tcx, D> where D: BoundVarReplacerDelegate<'tcx>, { - fn interner(&self) -> TyCtxt<'tcx> { + fn cx(&self) -> TyCtxt<'tcx> { self.tcx } diff --git a/compiler/rustc_middle/src/ty/generic_args.rs b/compiler/rustc_middle/src/ty/generic_args.rs index 83d45ca78d9d9..5ac3168196ad7 100644 --- a/compiler/rustc_middle/src/ty/generic_args.rs +++ b/compiler/rustc_middle/src/ty/generic_args.rs @@ -591,7 +591,7 @@ impl<'tcx> TypeFoldable> for GenericArgsRef<'tcx> { match self.len() { 1 => { let param0 = self[0].try_fold_with(folder)?; - if param0 == self[0] { Ok(self) } else { Ok(folder.interner().mk_args(&[param0])) } + if param0 == self[0] { Ok(self) } else { Ok(folder.cx().mk_args(&[param0])) } } 2 => { let param0 = self[0].try_fold_with(folder)?; @@ -599,7 +599,7 @@ impl<'tcx> TypeFoldable> for GenericArgsRef<'tcx> { if param0 == self[0] && param1 == self[1] { Ok(self) } else { - Ok(folder.interner().mk_args(&[param0, param1])) + Ok(folder.cx().mk_args(&[param0, param1])) } } 0 => Ok(self), @@ -635,7 +635,7 @@ impl<'tcx> TypeFoldable> for &'tcx ty::List> { if param0 == self[0] && param1 == self[1] { Ok(self) } else { - Ok(folder.interner().mk_type_list(&[param0, param1])) + Ok(folder.cx().mk_type_list(&[param0, param1])) } } _ => ty::util::fold_list(self, folder, |tcx, v| tcx.mk_type_list(v)), diff --git a/compiler/rustc_middle/src/ty/instance.rs b/compiler/rustc_middle/src/ty/instance.rs index 5718264c94466..324ee99f903fa 100644 --- a/compiler/rustc_middle/src/ty/instance.rs +++ b/compiler/rustc_middle/src/ty/instance.rs @@ -864,7 +864,7 @@ fn polymorphize<'tcx>( } impl<'tcx> ty::TypeFolder> for PolymorphizationFolder<'tcx> { - fn interner(&self) -> TyCtxt<'tcx> { + fn cx(&self) -> TyCtxt<'tcx> { self.tcx } diff --git a/compiler/rustc_middle/src/ty/normalize_erasing_regions.rs b/compiler/rustc_middle/src/ty/normalize_erasing_regions.rs index fb16cf5bd3632..96f00e1d3063a 100644 --- a/compiler/rustc_middle/src/ty/normalize_erasing_regions.rs +++ b/compiler/rustc_middle/src/ty/normalize_erasing_regions.rs @@ -173,7 +173,7 @@ impl<'tcx> NormalizeAfterErasingRegionsFolder<'tcx> { } impl<'tcx> TypeFolder> for NormalizeAfterErasingRegionsFolder<'tcx> { - fn interner(&self) -> TyCtxt<'tcx> { + fn cx(&self) -> TyCtxt<'tcx> { self.tcx } @@ -211,7 +211,7 @@ impl<'tcx> TryNormalizeAfterErasingRegionsFolder<'tcx> { impl<'tcx> FallibleTypeFolder> for TryNormalizeAfterErasingRegionsFolder<'tcx> { type Error = NormalizationError<'tcx>; - fn interner(&self) -> TyCtxt<'tcx> { + fn cx(&self) -> TyCtxt<'tcx> { self.tcx } diff --git a/compiler/rustc_middle/src/ty/opaque_types.rs b/compiler/rustc_middle/src/ty/opaque_types.rs index 08b2f9e892031..70a54e96d3678 100644 --- a/compiler/rustc_middle/src/ty/opaque_types.rs +++ b/compiler/rustc_middle/src/ty/opaque_types.rs @@ -95,7 +95,7 @@ impl<'tcx> ReverseMapper<'tcx> { } impl<'tcx> TypeFolder> for ReverseMapper<'tcx> { - fn interner(&self) -> TyCtxt<'tcx> { + fn cx(&self) -> TyCtxt<'tcx> { self.tcx } @@ -144,7 +144,7 @@ impl<'tcx> TypeFolder> for ReverseMapper<'tcx> { ) .emit(); - ty::Region::new_error(self.interner(), e) + ty::Region::new_error(self.cx(), e) } } } diff --git a/compiler/rustc_middle/src/ty/print/pretty.rs b/compiler/rustc_middle/src/ty/print/pretty.rs index de1796d480021..a48f49988042a 100644 --- a/compiler/rustc_middle/src/ty/print/pretty.rs +++ b/compiler/rustc_middle/src/ty/print/pretty.rs @@ -2521,7 +2521,7 @@ struct RegionFolder<'a, 'tcx> { } impl<'a, 'tcx> ty::TypeFolder> for RegionFolder<'a, 'tcx> { - fn interner(&self) -> TyCtxt<'tcx> { + fn cx(&self) -> TyCtxt<'tcx> { self.tcx } diff --git a/compiler/rustc_middle/src/ty/structural_impls.rs b/compiler/rustc_middle/src/ty/structural_impls.rs index 71e2e3e9f9942..a9dca47ab4373 100644 --- a/compiler/rustc_middle/src/ty/structural_impls.rs +++ b/compiler/rustc_middle/src/ty/structural_impls.rs @@ -335,7 +335,7 @@ impl<'tcx> TypeFoldable> for Pattern<'tcx> { folder: &mut F, ) -> Result { let pat = (*self).clone().try_fold_with(folder)?; - Ok(if pat == *self { self } else { folder.interner().mk_pat(pat) }) + Ok(if pat == *self { self } else { folder.cx().mk_pat(pat) }) } } @@ -407,7 +407,7 @@ impl<'tcx> TypeSuperFoldable> for Ty<'tcx> { | ty::Foreign(..) => return Ok(self), }; - Ok(if *self.kind() == kind { self } else { folder.interner().mk_ty_from_kind(kind) }) + Ok(if *self.kind() == kind { self } else { folder.cx().mk_ty_from_kind(kind) }) } } @@ -512,7 +512,7 @@ impl<'tcx> TypeSuperFoldable> for ty::Predicate<'tcx> { folder: &mut F, ) -> Result { let new = self.kind().try_fold_with(folder)?; - Ok(folder.interner().reuse_or_mk_predicate(self, new)) + Ok(folder.cx().reuse_or_mk_predicate(self, new)) } } @@ -577,7 +577,7 @@ impl<'tcx> TypeSuperFoldable> for ty::Const<'tcx> { ConstKind::Error(e) => ConstKind::Error(e.try_fold_with(folder)?), ConstKind::Expr(e) => ConstKind::Expr(e.try_fold_with(folder)?), }; - if kind != self.kind() { Ok(folder.interner().mk_ct_from_kind(kind)) } else { Ok(self) } + if kind != self.kind() { Ok(folder.cx().mk_ct_from_kind(kind)) } else { Ok(self) } } } diff --git a/compiler/rustc_middle/src/ty/util.rs b/compiler/rustc_middle/src/ty/util.rs index b079ed521d34c..1b5efcee90355 100644 --- a/compiler/rustc_middle/src/ty/util.rs +++ b/compiler/rustc_middle/src/ty/util.rs @@ -1083,7 +1083,7 @@ impl<'tcx> OpaqueTypeExpander<'tcx> { } impl<'tcx> TypeFolder> for OpaqueTypeExpander<'tcx> { - fn interner(&self) -> TyCtxt<'tcx> { + fn cx(&self) -> TyCtxt<'tcx> { self.tcx } @@ -1130,7 +1130,7 @@ struct WeakAliasTypeExpander<'tcx> { } impl<'tcx> TypeFolder> for WeakAliasTypeExpander<'tcx> { - fn interner(&self) -> TyCtxt<'tcx> { + fn cx(&self) -> TyCtxt<'tcx> { self.tcx } @@ -1795,7 +1795,7 @@ where for t in iter { new_list.push(t.try_fold_with(folder)?) } - Ok(intern(folder.interner(), &new_list)) + Ok(intern(folder.cx(), &new_list)) } Some((_, Err(err))) => { return Err(err); diff --git a/compiler/rustc_next_trait_solver/src/canonicalizer.rs b/compiler/rustc_next_trait_solver/src/canonicalizer.rs index a81fd03d034f7..695d02705abd2 100644 --- a/compiler/rustc_next_trait_solver/src/canonicalizer.rs +++ b/compiler/rustc_next_trait_solver/src/canonicalizer.rs @@ -7,7 +7,7 @@ use rustc_type_ir::{ self as ty, Canonical, CanonicalTyVarKind, CanonicalVarInfo, CanonicalVarKind, Interner, }; -use crate::infcx::SolverDelegate; +use crate::delegate::SolverDelegate; /// Whether we're canonicalizing a query input or the query response. /// @@ -38,8 +38,8 @@ pub enum CanonicalizeMode { }, } -pub struct Canonicalizer<'a, Infcx: SolverDelegate, I: Interner> { - infcx: &'a Infcx, +pub struct Canonicalizer<'a, D: SolverDelegate, I: Interner> { + delegate: &'a D, canonicalize_mode: CanonicalizeMode, variables: &'a mut Vec, @@ -47,15 +47,15 @@ pub struct Canonicalizer<'a, Infcx: SolverDelegate, I: Interner> { binder_index: ty::DebruijnIndex, } -impl<'a, Infcx: SolverDelegate, I: Interner> Canonicalizer<'a, Infcx, I> { +impl<'a, D: SolverDelegate, I: Interner> Canonicalizer<'a, D, I> { pub fn canonicalize>( - infcx: &'a Infcx, + delegate: &'a D, canonicalize_mode: CanonicalizeMode, variables: &'a mut Vec, value: T, ) -> ty::Canonical { let mut canonicalizer = Canonicalizer { - infcx, + delegate, canonicalize_mode, variables, @@ -70,7 +70,7 @@ impl<'a, Infcx: SolverDelegate, I: Interner> Canonicalizer<'a, Inf let (max_universe, variables) = canonicalizer.finalize(); - let defining_opaque_types = infcx.defining_opaque_types(); + let defining_opaque_types = delegate.defining_opaque_types(); Canonical { defining_opaque_types, max_universe, variables, value } } @@ -102,7 +102,7 @@ impl<'a, Infcx: SolverDelegate, I: Interner> Canonicalizer<'a, Inf .max() .unwrap_or(ty::UniverseIndex::ROOT); - let var_infos = self.infcx.interner().mk_canonical_var_infos(&var_infos); + let var_infos = self.delegate.cx().mk_canonical_var_infos(&var_infos); return (max_universe, var_infos); } } @@ -206,16 +206,14 @@ impl<'a, Infcx: SolverDelegate, I: Interner> Canonicalizer<'a, Inf } } - let var_infos = self.infcx.interner().mk_canonical_var_infos(&var_infos); + let var_infos = self.delegate.cx().mk_canonical_var_infos(&var_infos); (curr_compressed_uv, var_infos) } } -impl, I: Interner> TypeFolder - for Canonicalizer<'_, Infcx, I> -{ - fn interner(&self) -> I { - self.infcx.interner() +impl, I: Interner> TypeFolder for Canonicalizer<'_, D, I> { + fn cx(&self) -> I { + self.delegate.cx() } fn fold_binder(&mut self, t: ty::Binder) -> ty::Binder @@ -267,14 +265,14 @@ impl, I: Interner> TypeFolder ty::ReVar(vid) => { assert_eq!( - self.infcx.opportunistic_resolve_lt_var(vid), + self.delegate.opportunistic_resolve_lt_var(vid), r, "region vid should have been resolved fully before canonicalization" ); match self.canonicalize_mode { CanonicalizeMode::Input => CanonicalVarKind::Region(ty::UniverseIndex::ROOT), CanonicalizeMode::Response { .. } => { - CanonicalVarKind::Region(self.infcx.universe_of_lt(vid).unwrap()) + CanonicalVarKind::Region(self.delegate.universe_of_lt(vid).unwrap()) } } } @@ -294,7 +292,7 @@ impl, I: Interner> TypeFolder var }); - Region::new_anon_bound(self.interner(), self.binder_index, var) + Region::new_anon_bound(self.cx(), self.binder_index, var) } fn fold_ty(&mut self, t: I::Ty) -> I::Ty { @@ -302,20 +300,20 @@ impl, I: Interner> TypeFolder ty::Infer(i) => match i { ty::TyVar(vid) => { assert_eq!( - self.infcx.opportunistic_resolve_ty_var(vid), + self.delegate.opportunistic_resolve_ty_var(vid), t, "ty vid should have been resolved fully before canonicalization" ); CanonicalVarKind::Ty(CanonicalTyVarKind::General( - self.infcx + self.delegate .universe_of_ty(vid) .unwrap_or_else(|| panic!("ty var should have been resolved: {t:?}")), )) } ty::IntVar(vid) => { assert_eq!( - self.infcx.opportunistic_resolve_int_var(vid), + self.delegate.opportunistic_resolve_int_var(vid), t, "ty vid should have been resolved fully before canonicalization" ); @@ -323,7 +321,7 @@ impl, I: Interner> TypeFolder } ty::FloatVar(vid) => { assert_eq!( - self.infcx.opportunistic_resolve_float_var(vid), + self.delegate.opportunistic_resolve_float_var(vid), t, "ty vid should have been resolved fully before canonicalization" ); @@ -383,7 +381,7 @@ impl, I: Interner> TypeFolder }), ); - Ty::new_anon_bound(self.interner(), self.binder_index, var) + Ty::new_anon_bound(self.cx(), self.binder_index, var) } fn fold_const(&mut self, c: I::Const) -> I::Const { @@ -391,11 +389,11 @@ impl, I: Interner> TypeFolder ty::ConstKind::Infer(i) => match i { ty::InferConst::Var(vid) => { assert_eq!( - self.infcx.opportunistic_resolve_ct_var(vid), + self.delegate.opportunistic_resolve_ct_var(vid), c, "const vid should have been resolved fully before canonicalization" ); - CanonicalVarKind::Const(self.infcx.universe_of_ct(vid).unwrap()) + CanonicalVarKind::Const(self.delegate.universe_of_ct(vid).unwrap()) } ty::InferConst::EffectVar(_) => CanonicalVarKind::Effect, ty::InferConst::Fresh(_) => todo!(), @@ -431,6 +429,6 @@ impl, I: Interner> TypeFolder }), ); - Const::new_anon_bound(self.interner(), self.binder_index, var) + Const::new_anon_bound(self.cx(), self.binder_index, var) } } diff --git a/compiler/rustc_next_trait_solver/src/infcx.rs b/compiler/rustc_next_trait_solver/src/delegate.rs similarity index 98% rename from compiler/rustc_next_trait_solver/src/infcx.rs rename to compiler/rustc_next_trait_solver/src/delegate.rs index c249eb94cf654..6626acfe9639e 100644 --- a/compiler/rustc_next_trait_solver/src/infcx.rs +++ b/compiler/rustc_next_trait_solver/src/delegate.rs @@ -7,14 +7,14 @@ use rustc_type_ir::{self as ty, Interner}; pub trait SolverDelegate: Sized { type Interner: Interner; - fn interner(&self) -> Self::Interner; + fn cx(&self) -> Self::Interner; type Span: Copy; fn solver_mode(&self) -> SolverMode; fn build_with_canonical( - interner: Self::Interner, + cx: Self::Interner, solver_mode: SolverMode, canonical: &ty::Canonical, ) -> (Self, V, ty::CanonicalVarValues) @@ -102,7 +102,7 @@ pub trait SolverDelegate: Sized { // FIXME: This is only here because elaboration lives in `rustc_infer`! fn elaborate_supertraits( - interner: Self::Interner, + cx: Self::Interner, trait_ref: ty::Binder>, ) -> impl Iterator>>; diff --git a/compiler/rustc_next_trait_solver/src/lib.rs b/compiler/rustc_next_trait_solver/src/lib.rs index 79c6925221e14..5751be895bdd0 100644 --- a/compiler/rustc_next_trait_solver/src/lib.rs +++ b/compiler/rustc_next_trait_solver/src/lib.rs @@ -7,6 +7,6 @@ #![feature(let_chains)] pub mod canonicalizer; -pub mod infcx; +pub mod delegate; pub mod resolve; pub mod solve; diff --git a/compiler/rustc_next_trait_solver/src/resolve.rs b/compiler/rustc_next_trait_solver/src/resolve.rs index 3d8d957eaae4f..6ed58d0e4fb66 100644 --- a/compiler/rustc_next_trait_solver/src/resolve.rs +++ b/compiler/rustc_next_trait_solver/src/resolve.rs @@ -1,4 +1,4 @@ -use crate::infcx::SolverDelegate; +use crate::delegate::SolverDelegate; use rustc_type_ir::fold::{TypeFoldable, TypeFolder, TypeSuperFoldable}; use rustc_type_ir::inherent::*; use rustc_type_ir::visit::TypeVisitableExt; @@ -8,37 +8,37 @@ use rustc_type_ir::{self as ty, Interner}; // EAGER RESOLUTION /// Resolves ty, region, and const vars to their inferred values or their root vars. -pub struct EagerResolver<'a, Infcx, I = ::Interner> +pub struct EagerResolver<'a, D, I = ::Interner> where - Infcx: SolverDelegate, + D: SolverDelegate, I: Interner, { - infcx: &'a Infcx, + delegate: &'a D, } -impl<'a, Infcx: SolverDelegate> EagerResolver<'a, Infcx> { - pub fn new(infcx: &'a Infcx) -> Self { - EagerResolver { infcx } +impl<'a, D: SolverDelegate> EagerResolver<'a, D> { + pub fn new(delegate: &'a D) -> Self { + EagerResolver { delegate } } } -impl, I: Interner> TypeFolder for EagerResolver<'_, Infcx> { - fn interner(&self) -> I { - self.infcx.interner() +impl, I: Interner> TypeFolder for EagerResolver<'_, D> { + fn cx(&self) -> I { + self.delegate.cx() } fn fold_ty(&mut self, t: I::Ty) -> I::Ty { match t.kind() { ty::Infer(ty::TyVar(vid)) => { - let resolved = self.infcx.opportunistic_resolve_ty_var(vid); + let resolved = self.delegate.opportunistic_resolve_ty_var(vid); if t != resolved && resolved.has_infer() { resolved.fold_with(self) } else { resolved } } - ty::Infer(ty::IntVar(vid)) => self.infcx.opportunistic_resolve_int_var(vid), - ty::Infer(ty::FloatVar(vid)) => self.infcx.opportunistic_resolve_float_var(vid), + ty::Infer(ty::IntVar(vid)) => self.delegate.opportunistic_resolve_int_var(vid), + ty::Infer(ty::FloatVar(vid)) => self.delegate.opportunistic_resolve_float_var(vid), _ => { if t.has_infer() { t.super_fold_with(self) @@ -51,7 +51,7 @@ impl, I: Interner> TypeFolder for EagerRe fn fold_region(&mut self, r: I::Region) -> I::Region { match r.kind() { - ty::ReVar(vid) => self.infcx.opportunistic_resolve_lt_var(vid), + ty::ReVar(vid) => self.delegate.opportunistic_resolve_lt_var(vid), _ => r, } } @@ -59,7 +59,7 @@ impl, I: Interner> TypeFolder for EagerRe fn fold_const(&mut self, c: I::Const) -> I::Const { match c.kind() { ty::ConstKind::Infer(ty::InferConst::Var(vid)) => { - let resolved = self.infcx.opportunistic_resolve_ct_var(vid); + let resolved = self.delegate.opportunistic_resolve_ct_var(vid); if c != resolved && resolved.has_infer() { resolved.fold_with(self) } else { @@ -67,7 +67,7 @@ impl, I: Interner> TypeFolder for EagerRe } } ty::ConstKind::Infer(ty::InferConst::EffectVar(vid)) => { - self.infcx.opportunistic_resolve_effect_var(vid) + self.delegate.opportunistic_resolve_effect_var(vid) } _ => { if c.has_infer() { diff --git a/compiler/rustc_next_trait_solver/src/solve/alias_relate.rs b/compiler/rustc_next_trait_solver/src/solve/alias_relate.rs index fbc8ac1d5d5c5..5a95f4edf1915 100644 --- a/compiler/rustc_next_trait_solver/src/solve/alias_relate.rs +++ b/compiler/rustc_next_trait_solver/src/solve/alias_relate.rs @@ -19,12 +19,12 @@ use rustc_type_ir::inherent::*; use rustc_type_ir::{self as ty, Interner}; use tracing::{instrument, trace}; -use crate::infcx::SolverDelegate; +use crate::delegate::SolverDelegate; use crate::solve::{Certainty, EvalCtxt, Goal, QueryResult}; -impl EvalCtxt<'_, Infcx> +impl EvalCtxt<'_, D> where - Infcx: SolverDelegate, + D: SolverDelegate, I: Interner, { #[instrument(level = "trace", skip(self), ret)] @@ -32,7 +32,7 @@ where &mut self, goal: Goal, ) -> QueryResult { - let tcx = self.interner(); + let tcx = self.cx(); let Goal { param_env, predicate: (lhs, rhs, direction) } = goal; debug_assert!(lhs.to_alias_term().is_some() || rhs.to_alias_term().is_some()); diff --git a/compiler/rustc_next_trait_solver/src/solve/assembly/mod.rs b/compiler/rustc_next_trait_solver/src/solve/assembly/mod.rs index 9a1537d260608..cae9c5c85678e 100644 --- a/compiler/rustc_next_trait_solver/src/solve/assembly/mod.rs +++ b/compiler/rustc_next_trait_solver/src/solve/assembly/mod.rs @@ -9,7 +9,7 @@ use rustc_type_ir::visit::TypeVisitableExt as _; use rustc_type_ir::{self as ty, Interner, Upcast as _}; use tracing::{debug, instrument}; -use crate::infcx::SolverDelegate; +use crate::delegate::SolverDelegate; use crate::solve::inspect::ProbeKind; use crate::solve::{ BuiltinImplSource, CandidateSource, CanonicalResponse, Certainty, EvalCtxt, Goal, GoalSource, @@ -28,10 +28,10 @@ pub(super) struct Candidate { } /// Methods used to assemble candidates for either trait or projection goals. -pub(super) trait GoalKind::Interner>: +pub(super) trait GoalKind::Interner>: TypeFoldable + Copy + Eq + std::fmt::Display where - Infcx: SolverDelegate, + D: SolverDelegate, I: Interner, { fn self_ty(self) -> I::Ty; @@ -47,18 +47,18 @@ where /// work, then produce a response (typically by executing /// [`EvalCtxt::evaluate_added_goals_and_make_canonical_response`]). fn probe_and_match_goal_against_assumption( - ecx: &mut EvalCtxt<'_, Infcx>, + ecx: &mut EvalCtxt<'_, D>, source: CandidateSource, goal: Goal, assumption: I::Clause, - then: impl FnOnce(&mut EvalCtxt<'_, Infcx>) -> QueryResult, + then: impl FnOnce(&mut EvalCtxt<'_, D>) -> QueryResult, ) -> Result, NoSolution>; /// Consider a clause, which consists of a "assumption" and some "requirements", /// to satisfy a goal. If the requirements hold, then attempt to satisfy our /// goal by equating it with the assumption. fn probe_and_consider_implied_clause( - ecx: &mut EvalCtxt<'_, Infcx>, + ecx: &mut EvalCtxt<'_, D>, parent_source: CandidateSource, goal: Goal, assumption: I::Clause, @@ -76,13 +76,13 @@ where /// additionally checking all of the supertraits and object bounds to hold, /// since they're not implied by the well-formedness of the object type. fn probe_and_consider_object_bound_candidate( - ecx: &mut EvalCtxt<'_, Infcx>, + ecx: &mut EvalCtxt<'_, D>, source: CandidateSource, goal: Goal, assumption: I::Clause, ) -> Result, NoSolution> { Self::probe_and_match_goal_against_assumption(ecx, source, goal, assumption, |ecx| { - let tcx = ecx.interner(); + let tcx = ecx.cx(); let ty::Dynamic(bounds, _, _) = goal.predicate.self_ty().kind() else { panic!("expected object type in `probe_and_consider_object_bound_candidate`"); }; @@ -100,7 +100,7 @@ where } fn consider_impl_candidate( - ecx: &mut EvalCtxt<'_, Infcx>, + ecx: &mut EvalCtxt<'_, D>, goal: Goal, impl_def_id: I::DefId, ) -> Result, NoSolution>; @@ -112,7 +112,7 @@ where /// Trait goals always hold while projection goals never do. This is a bit arbitrary /// but prevents incorrect normalization while hiding any trait errors. fn consider_error_guaranteed_candidate( - ecx: &mut EvalCtxt<'_, Infcx>, + ecx: &mut EvalCtxt<'_, D>, guar: I::ErrorGuaranteed, ) -> Result, NoSolution>; @@ -121,13 +121,13 @@ where /// These components are given by built-in rules from /// [`structural_traits::instantiate_constituent_tys_for_auto_trait`]. fn consider_auto_trait_candidate( - ecx: &mut EvalCtxt<'_, Infcx>, + ecx: &mut EvalCtxt<'_, D>, goal: Goal, ) -> Result, NoSolution>; /// A trait alias holds if the RHS traits and `where` clauses hold. fn consider_trait_alias_candidate( - ecx: &mut EvalCtxt<'_, Infcx>, + ecx: &mut EvalCtxt<'_, D>, goal: Goal, ) -> Result, NoSolution>; @@ -136,7 +136,7 @@ where /// These components are given by built-in rules from /// [`structural_traits::instantiate_constituent_tys_for_sized_trait`]. fn consider_builtin_sized_candidate( - ecx: &mut EvalCtxt<'_, Infcx>, + ecx: &mut EvalCtxt<'_, D>, goal: Goal, ) -> Result, NoSolution>; @@ -145,27 +145,27 @@ where /// These components are given by built-in rules from /// [`structural_traits::instantiate_constituent_tys_for_copy_clone_trait`]. fn consider_builtin_copy_clone_candidate( - ecx: &mut EvalCtxt<'_, Infcx>, + ecx: &mut EvalCtxt<'_, D>, goal: Goal, ) -> Result, NoSolution>; /// A type is `PointerLike` if we can compute its layout, and that layout /// matches the layout of `usize`. fn consider_builtin_pointer_like_candidate( - ecx: &mut EvalCtxt<'_, Infcx>, + ecx: &mut EvalCtxt<'_, D>, goal: Goal, ) -> Result, NoSolution>; /// A type is a `FnPtr` if it is of `FnPtr` type. fn consider_builtin_fn_ptr_trait_candidate( - ecx: &mut EvalCtxt<'_, Infcx>, + ecx: &mut EvalCtxt<'_, D>, goal: Goal, ) -> Result, NoSolution>; /// A callable type (a closure, fn def, or fn ptr) is known to implement the `Fn` /// family of traits where `A` is given by the signature of the type. fn consider_builtin_fn_trait_candidates( - ecx: &mut EvalCtxt<'_, Infcx>, + ecx: &mut EvalCtxt<'_, D>, goal: Goal, kind: ty::ClosureKind, ) -> Result, NoSolution>; @@ -173,7 +173,7 @@ where /// An async closure is known to implement the `AsyncFn` family of traits /// where `A` is given by the signature of the type. fn consider_builtin_async_fn_trait_candidates( - ecx: &mut EvalCtxt<'_, Infcx>, + ecx: &mut EvalCtxt<'_, D>, goal: Goal, kind: ty::ClosureKind, ) -> Result, NoSolution>; @@ -182,13 +182,13 @@ where /// is used internally to delay computation for async closures until after /// upvar analysis is performed in HIR typeck. fn consider_builtin_async_fn_kind_helper_candidate( - ecx: &mut EvalCtxt<'_, Infcx>, + ecx: &mut EvalCtxt<'_, D>, goal: Goal, ) -> Result, NoSolution>; /// `Tuple` is implemented if the `Self` type is a tuple. fn consider_builtin_tuple_candidate( - ecx: &mut EvalCtxt<'_, Infcx>, + ecx: &mut EvalCtxt<'_, D>, goal: Goal, ) -> Result, NoSolution>; @@ -198,7 +198,7 @@ where /// the built-in types. For structs, the metadata type is given by the struct /// tail. fn consider_builtin_pointee_candidate( - ecx: &mut EvalCtxt<'_, Infcx>, + ecx: &mut EvalCtxt<'_, D>, goal: Goal, ) -> Result, NoSolution>; @@ -206,7 +206,7 @@ where /// `Future`, where `O` is given by the coroutine's return type /// that was computed during type-checking. fn consider_builtin_future_candidate( - ecx: &mut EvalCtxt<'_, Infcx>, + ecx: &mut EvalCtxt<'_, D>, goal: Goal, ) -> Result, NoSolution>; @@ -214,19 +214,19 @@ where /// `Iterator`, where `O` is given by the generator's yield type /// that was computed during type-checking. fn consider_builtin_iterator_candidate( - ecx: &mut EvalCtxt<'_, Infcx>, + ecx: &mut EvalCtxt<'_, D>, goal: Goal, ) -> Result, NoSolution>; /// A coroutine (that comes from a `gen` desugaring) is known to implement /// `FusedIterator` fn consider_builtin_fused_iterator_candidate( - ecx: &mut EvalCtxt<'_, Infcx>, + ecx: &mut EvalCtxt<'_, D>, goal: Goal, ) -> Result, NoSolution>; fn consider_builtin_async_iterator_candidate( - ecx: &mut EvalCtxt<'_, Infcx>, + ecx: &mut EvalCtxt<'_, D>, goal: Goal, ) -> Result, NoSolution>; @@ -234,27 +234,27 @@ where /// implement `Coroutine`, given the resume, yield, /// and return types of the coroutine computed during type-checking. fn consider_builtin_coroutine_candidate( - ecx: &mut EvalCtxt<'_, Infcx>, + ecx: &mut EvalCtxt<'_, D>, goal: Goal, ) -> Result, NoSolution>; fn consider_builtin_discriminant_kind_candidate( - ecx: &mut EvalCtxt<'_, Infcx>, + ecx: &mut EvalCtxt<'_, D>, goal: Goal, ) -> Result, NoSolution>; fn consider_builtin_async_destruct_candidate( - ecx: &mut EvalCtxt<'_, Infcx>, + ecx: &mut EvalCtxt<'_, D>, goal: Goal, ) -> Result, NoSolution>; fn consider_builtin_destruct_candidate( - ecx: &mut EvalCtxt<'_, Infcx>, + ecx: &mut EvalCtxt<'_, D>, goal: Goal, ) -> Result, NoSolution>; fn consider_builtin_transmute_candidate( - ecx: &mut EvalCtxt<'_, Infcx>, + ecx: &mut EvalCtxt<'_, D>, goal: Goal, ) -> Result, NoSolution>; @@ -266,17 +266,17 @@ where /// otherwise recompute this for codegen. This is a bit of a mess but the /// easiest way to maintain the existing behavior for now. fn consider_structural_builtin_unsize_candidates( - ecx: &mut EvalCtxt<'_, Infcx>, + ecx: &mut EvalCtxt<'_, D>, goal: Goal, ) -> Vec>; } -impl EvalCtxt<'_, Infcx> +impl EvalCtxt<'_, D> where - Infcx: SolverDelegate, + D: SolverDelegate, I: Interner, { - pub(super) fn assemble_and_evaluate_candidates>( + pub(super) fn assemble_and_evaluate_candidates>( &mut self, goal: Goal, ) -> Vec> { @@ -291,10 +291,8 @@ where return self.forced_ambiguity(MaybeCause::Ambiguity).into_iter().collect(); } - let goal: Goal = goal.with( - self.interner(), - goal.predicate.with_self_ty(self.interner(), normalized_self_ty), - ); + let goal: Goal = + goal.with(self.cx(), goal.predicate.with_self_ty(self.cx(), normalized_self_ty)); // Vars that show up in the rest of the goal substs may have been constrained by // normalizing the self type as well, since type variables are not uniquified. let goal = self.resolve_vars_if_possible(goal); @@ -337,12 +335,12 @@ where } #[instrument(level = "trace", skip_all)] - fn assemble_impl_candidates>( + fn assemble_impl_candidates>( &mut self, goal: Goal, candidates: &mut Vec>, ) { - let tcx = self.interner(); + let tcx = self.cx(); tcx.for_each_relevant_impl( goal.predicate.trait_def_id(tcx), goal.predicate.self_ty(), @@ -363,12 +361,12 @@ where } #[instrument(level = "trace", skip_all)] - fn assemble_builtin_impl_candidates>( + fn assemble_builtin_impl_candidates>( &mut self, goal: Goal, candidates: &mut Vec>, ) { - let tcx = self.interner(); + let tcx = self.cx(); let trait_def_id = goal.predicate.trait_def_id(tcx); // N.B. When assembling built-in candidates for lang items that are also @@ -394,9 +392,9 @@ where G::consider_builtin_pointer_like_candidate(self, goal) } else if tcx.is_lang_item(trait_def_id, TraitSolverLangItem::FnPtrTrait) { G::consider_builtin_fn_ptr_trait_candidate(self, goal) - } else if let Some(kind) = self.interner().fn_trait_kind_from_def_id(trait_def_id) { + } else if let Some(kind) = self.cx().fn_trait_kind_from_def_id(trait_def_id) { G::consider_builtin_fn_trait_candidates(self, goal, kind) - } else if let Some(kind) = self.interner().async_fn_trait_kind_from_def_id(trait_def_id) { + } else if let Some(kind) = self.cx().async_fn_trait_kind_from_def_id(trait_def_id) { G::consider_builtin_async_fn_trait_candidates(self, goal, kind) } else if tcx.is_lang_item(trait_def_id, TraitSolverLangItem::AsyncFnKindHelper) { G::consider_builtin_async_fn_kind_helper_candidate(self, goal) @@ -436,7 +434,7 @@ where } #[instrument(level = "trace", skip_all)] - fn assemble_param_env_candidates>( + fn assemble_param_env_candidates>( &mut self, goal: Goal, candidates: &mut Vec>, @@ -453,7 +451,7 @@ where } #[instrument(level = "trace", skip_all)] - fn assemble_alias_bound_candidates>( + fn assemble_alias_bound_candidates>( &mut self, goal: Goal, candidates: &mut Vec>, @@ -472,7 +470,7 @@ where /// If so, continue searching by recursively calling after normalization. // FIXME: This may recurse infinitely, but I can't seem to trigger it without // hitting another overflow error something. Add a depth parameter needed later. - fn assemble_alias_bound_candidates_recur>( + fn assemble_alias_bound_candidates_recur>( &mut self, self_ty: I::Ty, goal: Goal, @@ -523,15 +521,13 @@ where ty::Alias(kind @ (ty::Projection | ty::Opaque), alias_ty) => (kind, alias_ty), ty::Alias(ty::Inherent | ty::Weak, _) => { - self.interner().delay_bug(format!("could not normalize {self_ty:?}, it is not WF")); + self.cx().delay_bug(format!("could not normalize {self_ty:?}, it is not WF")); return; } }; - for assumption in self - .interner() - .item_bounds(alias_ty.def_id) - .iter_instantiated(self.interner(), &alias_ty.args) + for assumption in + self.cx().item_bounds(alias_ty.def_id).iter_instantiated(self.cx(), &alias_ty.args) { candidates.extend(G::probe_and_consider_implied_clause( self, @@ -556,12 +552,12 @@ where } #[instrument(level = "trace", skip_all)] - fn assemble_object_bound_candidates>( + fn assemble_object_bound_candidates>( &mut self, goal: Goal, candidates: &mut Vec>, ) { - let tcx = self.interner(); + let tcx = self.cx(); if !tcx.trait_may_be_implemented_via_object(goal.predicate.trait_def_id(tcx)) { return; } @@ -629,8 +625,7 @@ where // a projection goal. if let Some(principal) = bounds.principal() { let principal_trait_ref = principal.with_self_ty(tcx, self_ty); - for (idx, assumption) in - Infcx::elaborate_supertraits(tcx, principal_trait_ref).enumerate() + for (idx, assumption) in D::elaborate_supertraits(tcx, principal_trait_ref).enumerate() { candidates.extend(G::probe_and_consider_object_bound_candidate( self, @@ -649,12 +644,12 @@ where /// To do so we add an ambiguous candidate in case such an unknown impl could /// apply to the current goal. #[instrument(level = "trace", skip_all)] - fn assemble_coherence_unknowable_candidates>( + fn assemble_coherence_unknowable_candidates>( &mut self, goal: Goal, candidates: &mut Vec>, ) { - let tcx = self.interner(); + let tcx = self.cx(); candidates.extend(self.probe_trait_candidate(CandidateSource::CoherenceUnknowable).enter( |ecx| { @@ -678,12 +673,12 @@ where // to improve this however. However, this should make it fairly straightforward to refine // the filtering going forward, so it seems alright-ish for now. #[instrument(level = "debug", skip(self, goal))] - fn discard_impls_shadowed_by_env>( + fn discard_impls_shadowed_by_env>( &mut self, goal: Goal, candidates: &mut Vec>, ) { - let tcx = self.interner(); + let tcx = self.cx(); let trait_goal: Goal> = goal.with(tcx, goal.predicate.trait_ref(tcx)); diff --git a/compiler/rustc_next_trait_solver/src/solve/assembly/structural_traits.rs b/compiler/rustc_next_trait_solver/src/solve/assembly/structural_traits.rs index 202af76565a88..a8cf5f70ec863 100644 --- a/compiler/rustc_next_trait_solver/src/solve/assembly/structural_traits.rs +++ b/compiler/rustc_next_trait_solver/src/solve/assembly/structural_traits.rs @@ -10,20 +10,20 @@ use rustc_type_ir::{self as ty, Interner, Upcast as _}; use rustc_type_ir_macros::{TypeFoldable_Generic, TypeVisitable_Generic}; use tracing::instrument; -use crate::infcx::SolverDelegate; +use crate::delegate::SolverDelegate; use crate::solve::{EvalCtxt, Goal, NoSolution}; // Calculates the constituent types of a type for `auto trait` purposes. #[instrument(level = "trace", skip(ecx), ret)] -pub(in crate::solve) fn instantiate_constituent_tys_for_auto_trait( - ecx: &EvalCtxt<'_, Infcx>, +pub(in crate::solve) fn instantiate_constituent_tys_for_auto_trait( + ecx: &EvalCtxt<'_, D>, ty: I::Ty, ) -> Result>, NoSolution> where - Infcx: SolverDelegate, + D: SolverDelegate, I: Interner, { - let tcx = ecx.interner(); + let tcx = ecx.cx(); match ty.kind() { ty::Uint(_) | ty::Int(_) @@ -76,7 +76,7 @@ where } ty::CoroutineWitness(def_id, args) => Ok(ecx - .interner() + .cx() .bound_coroutine_hidden_types(def_id) .into_iter() .map(|bty| bty.instantiate(tcx, &args)) @@ -101,12 +101,12 @@ where } #[instrument(level = "trace", skip(ecx), ret)] -pub(in crate::solve) fn instantiate_constituent_tys_for_sized_trait( - ecx: &EvalCtxt<'_, Infcx>, +pub(in crate::solve) fn instantiate_constituent_tys_for_sized_trait( + ecx: &EvalCtxt<'_, D>, ty: I::Ty, ) -> Result>, NoSolution> where - Infcx: SolverDelegate, + D: SolverDelegate, I: Interner, { match ty.kind() { @@ -159,8 +159,8 @@ where // "best effort" optimization and `sized_constraint` may return `Some`, even // if the ADT is sized for all possible args. ty::Adt(def, args) => { - if let Some(sized_crit) = def.sized_constraint(ecx.interner()) { - Ok(vec![ty::Binder::dummy(sized_crit.instantiate(ecx.interner(), &args))]) + if let Some(sized_crit) = def.sized_constraint(ecx.cx()) { + Ok(vec![ty::Binder::dummy(sized_crit.instantiate(ecx.cx(), &args))]) } else { Ok(vec![]) } @@ -169,12 +169,12 @@ where } #[instrument(level = "trace", skip(ecx), ret)] -pub(in crate::solve) fn instantiate_constituent_tys_for_copy_clone_trait( - ecx: &EvalCtxt<'_, Infcx>, +pub(in crate::solve) fn instantiate_constituent_tys_for_copy_clone_trait( + ecx: &EvalCtxt<'_, D>, ty: I::Ty, ) -> Result>, NoSolution> where - Infcx: SolverDelegate, + D: SolverDelegate, I: Interner, { match ty.kind() { @@ -222,10 +222,10 @@ where // only when `coroutine_clone` is enabled and the coroutine is movable // impl Copy/Clone for Coroutine where T: Copy/Clone forall T in (upvars, witnesses) - ty::Coroutine(def_id, args) => match ecx.interner().coroutine_movability(def_id) { + ty::Coroutine(def_id, args) => match ecx.cx().coroutine_movability(def_id) { Movability::Static => Err(NoSolution), Movability::Movable => { - if ecx.interner().features().coroutine_clone() { + if ecx.cx().features().coroutine_clone() { let coroutine = args.as_coroutine(); Ok(vec![ ty::Binder::dummy(coroutine.tupled_upvars_ty()), @@ -239,10 +239,10 @@ where // impl Copy/Clone for CoroutineWitness where T: Copy/Clone forall T in coroutine_hidden_types ty::CoroutineWitness(def_id, args) => Ok(ecx - .interner() + .cx() .bound_coroutine_hidden_types(def_id) .into_iter() - .map(|bty| bty.instantiate(ecx.interner(), &args)) + .map(|bty| bty.instantiate(ecx.cx(), &args)) .collect()), } } @@ -654,17 +654,17 @@ fn coroutine_closure_to_ambiguous_coroutine( // This is unsound in general and once that is fixed, we don't need to // normalize eagerly here. See https://github.com/lcnr/solver-woes/issues/9 // for more details. -pub(in crate::solve) fn predicates_for_object_candidate( - ecx: &EvalCtxt<'_, Infcx>, +pub(in crate::solve) fn predicates_for_object_candidate( + ecx: &EvalCtxt<'_, D>, param_env: I::ParamEnv, trait_ref: ty::TraitRef, object_bounds: I::BoundExistentialPredicates, ) -> Vec> where - Infcx: SolverDelegate, + D: SolverDelegate, I: Interner, { - let tcx = ecx.interner(); + let tcx = ecx.cx(); let mut requirements = vec![]; requirements .extend(tcx.super_predicates_of(trait_ref.def_id).iter_instantiated(tcx, &trait_ref.args)); @@ -710,18 +710,18 @@ where .collect() } -struct ReplaceProjectionWith<'a, Infcx: SolverDelegate, I: Interner> { - ecx: &'a EvalCtxt<'a, Infcx>, +struct ReplaceProjectionWith<'a, D: SolverDelegate, I: Interner> { + ecx: &'a EvalCtxt<'a, D>, param_env: I::ParamEnv, mapping: FxHashMap>>, nested: Vec>, } -impl, I: Interner> TypeFolder - for ReplaceProjectionWith<'_, Infcx, I> +impl, I: Interner> TypeFolder + for ReplaceProjectionWith<'_, D, I> { - fn interner(&self) -> I { - self.ecx.interner() + fn cx(&self) -> I { + self.ecx.cx() } fn fold_ty(&mut self, ty: I::Ty) -> I::Ty { @@ -738,7 +738,7 @@ impl, I: Interner> TypeFolder .eq_and_get_goals( self.param_env, alias_ty, - proj.projection_term.expect_ty(self.ecx.interner()), + proj.projection_term.expect_ty(self.ecx.cx()), ) .expect("expected to be able to unify goal projection with dyn's projection"), ); diff --git a/compiler/rustc_next_trait_solver/src/solve/eval_ctxt/canonical.rs b/compiler/rustc_next_trait_solver/src/solve/eval_ctxt/canonical.rs index c6611285a3bed..f1d4864a84b74 100644 --- a/compiler/rustc_next_trait_solver/src/solve/eval_ctxt/canonical.rs +++ b/compiler/rustc_next_trait_solver/src/solve/eval_ctxt/canonical.rs @@ -18,7 +18,7 @@ use rustc_type_ir::{self as ty, Canonical, CanonicalVarValues, Interner}; use tracing::{instrument, trace}; use crate::canonicalizer::{CanonicalizeMode, Canonicalizer}; -use crate::infcx::SolverDelegate; +use crate::delegate::SolverDelegate; use crate::resolve::EagerResolver; use crate::solve::eval_ctxt::NestedGoals; use crate::solve::inspect; @@ -44,9 +44,9 @@ impl ResponseT for inspect::State { } } -impl EvalCtxt<'_, Infcx> +impl EvalCtxt<'_, D> where - Infcx: SolverDelegate, + D: SolverDelegate, I: Interner, { /// Canonicalizes the goal remembering the original values @@ -55,19 +55,19 @@ where &self, goal: Goal, ) -> (Vec, CanonicalInput) { - let opaque_types = self.infcx.clone_opaque_types_for_query_response(); + let opaque_types = self.delegate.clone_opaque_types_for_query_response(); let (goal, opaque_types) = - (goal, opaque_types).fold_with(&mut EagerResolver::new(self.infcx)); + (goal, opaque_types).fold_with(&mut EagerResolver::new(self.delegate)); let mut orig_values = Default::default(); let canonical_goal = Canonicalizer::canonicalize( - self.infcx, + self.delegate, CanonicalizeMode::Input, &mut orig_values, QueryInput { goal, predefined_opaques_in_body: self - .interner() + .cx() .mk_predefined_opaques_in_body(PredefinedOpaquesData { opaque_types }), }, ); @@ -97,7 +97,7 @@ where // We only check for leaks from universes which were entered inside // of the query. - self.infcx.leak_check(self.max_input_universe).map_err(|NoSolution| { + self.delegate.leak_check(self.max_input_universe).map_err(|NoSolution| { trace!("failed the leak check"); NoSolution })?; @@ -125,21 +125,21 @@ where let external_constraints = self.compute_external_query_constraints(certainty, normalization_nested_goals); - let (var_values, mut external_constraints) = - (self.var_values, external_constraints).fold_with(&mut EagerResolver::new(self.infcx)); + let (var_values, mut external_constraints) = (self.var_values, external_constraints) + .fold_with(&mut EagerResolver::new(self.delegate)); // Remove any trivial region constraints once we've resolved regions external_constraints .region_constraints .retain(|outlives| outlives.0.as_region().map_or(true, |re| re != outlives.1)); let canonical = Canonicalizer::canonicalize( - self.infcx, + self.delegate, CanonicalizeMode::Response { max_input_universe: self.max_input_universe }, &mut Default::default(), Response { var_values, certainty, - external_constraints: self.interner().mk_external_constraints(external_constraints), + external_constraints: self.cx().mk_external_constraints(external_constraints), }, ); @@ -155,7 +155,7 @@ where maybe_cause: MaybeCause, ) -> CanonicalResponse { response_no_constraints_raw( - self.interner(), + self.cx(), self.max_input_universe, self.variables, Certainty::Maybe(maybe_cause), @@ -184,7 +184,7 @@ where // `tests/ui/higher-ranked/leak-check/leak-check-in-selection-5-ambig.rs` and // `tests/ui/higher-ranked/leak-check/leak-check-in-selection-6-ambig-unify.rs`. let region_constraints = if certainty == Certainty::Yes { - self.infcx.make_deduplicated_outlives_constraints() + self.delegate.make_deduplicated_outlives_constraints() } else { Default::default() }; @@ -192,7 +192,7 @@ where ExternalConstraintsData { region_constraints, opaque_types: self - .infcx + .delegate .clone_opaque_types_for_query_response() .into_iter() // Only return *newly defined* opaque types. @@ -219,15 +219,15 @@ where response: CanonicalResponse, ) -> (NestedNormalizationGoals, Certainty) { let instantiation = Self::compute_query_response_instantiation_values( - self.infcx, + self.delegate, &original_values, &response, ); let Response { var_values, external_constraints, certainty } = - self.infcx.instantiate_canonical(response, instantiation); + self.delegate.instantiate_canonical(response, instantiation); - Self::unify_query_var_values(self.infcx, param_env, &original_values, var_values); + Self::unify_query_var_values(self.delegate, param_env, &original_values, var_values); let ExternalConstraintsData { region_constraints, @@ -243,17 +243,17 @@ where /// the canonical response. This depends on the `original_values` for the /// bound variables. fn compute_query_response_instantiation_values>( - infcx: &Infcx, + delegate: &D, original_values: &[I::GenericArg], response: &Canonical, ) -> CanonicalVarValues { // FIXME: Longterm canonical queries should deal with all placeholders // created inside of the query directly instead of returning them to the // caller. - let prev_universe = infcx.universe(); + let prev_universe = delegate.universe(); let universes_created_in_query = response.max_universe.index(); for _ in 0..universes_created_in_query { - infcx.create_next_universe(); + delegate.create_next_universe(); } let var_values = response.value.var_values(); @@ -290,13 +290,13 @@ where } } - let var_values = infcx.interner().mk_args_from_iter( + let var_values = delegate.cx().mk_args_from_iter( response.variables.into_iter().enumerate().map(|(index, info)| { if info.universe() != ty::UniverseIndex::ROOT { // A variable from inside a binder of the query. While ideally these shouldn't // exist at all (see the FIXME at the start of this method), we have to deal with // them for now. - infcx.instantiate_canonical_var_with_infer(info, |idx| { + delegate.instantiate_canonical_var_with_infer(info, |idx| { ty::UniverseIndex::from(prev_universe.index() + idx.index()) }) } else if info.is_existential() { @@ -310,7 +310,7 @@ where if let Some(v) = opt_values[ty::BoundVar::from_usize(index)] { v } else { - infcx.instantiate_canonical_var_with_infer(info, |_| prev_universe) + delegate.instantiate_canonical_var_with_infer(info, |_| prev_universe) } } else { // For placeholders which were already part of the input, we simply map this @@ -335,9 +335,9 @@ where /// whether an alias is rigid by using the trait solver. When instantiating a response /// from the solver we assume that the solver correctly handled aliases and therefore /// always relate them structurally here. - #[instrument(level = "trace", skip(infcx))] + #[instrument(level = "trace", skip(delegate))] fn unify_query_var_values( - infcx: &Infcx, + delegate: &D, param_env: I::ParamEnv, original_values: &[I::GenericArg], var_values: CanonicalVarValues, @@ -345,7 +345,8 @@ where assert_eq!(original_values.len(), var_values.len()); for (&orig, response) in iter::zip(original_values, var_values.var_values) { - let goals = infcx.eq_structurally_relating_aliases(param_env, orig, response).unwrap(); + let goals = + delegate.eq_structurally_relating_aliases(param_env, orig, response).unwrap(); assert!(goals.is_empty()); } } @@ -365,7 +366,7 @@ where fn register_new_opaque_types(&mut self, opaque_types: &[(ty::OpaqueTypeKey, I::Ty)]) { for &(key, ty) in opaque_types { - self.infcx.inject_new_hidden_type_unchecked(key, ty); + self.delegate.inject_new_hidden_type_unchecked(key, ty); } } } @@ -374,22 +375,22 @@ where /// evaluating a goal. The `var_values` not only include the bound variables /// of the query input, but also contain all unconstrained inference vars /// created while evaluating this goal. -pub(in crate::solve) fn make_canonical_state( - infcx: &Infcx, +pub(in crate::solve) fn make_canonical_state( + delegate: &D, var_values: &[I::GenericArg], max_input_universe: ty::UniverseIndex, data: T, ) -> inspect::CanonicalState where - Infcx: SolverDelegate, + D: SolverDelegate, I: Interner, T: TypeFoldable, { - let var_values = CanonicalVarValues { var_values: infcx.interner().mk_args(var_values) }; + let var_values = CanonicalVarValues { var_values: delegate.cx().mk_args(var_values) }; let state = inspect::State { var_values, data }; - let state = state.fold_with(&mut EagerResolver::new(infcx)); + let state = state.fold_with(&mut EagerResolver::new(delegate)); Canonicalizer::canonicalize( - infcx, + delegate, CanonicalizeMode::Response { max_input_universe }, &mut vec![], state, @@ -398,15 +399,15 @@ where // FIXME: needs to be pub to be accessed by downstream // `rustc_trait_selection::solve::inspect::analyse`. -pub fn instantiate_canonical_state>( - infcx: &Infcx, - span: Infcx::Span, +pub fn instantiate_canonical_state>( + delegate: &D, + span: D::Span, param_env: I::ParamEnv, orig_values: &mut Vec, state: inspect::CanonicalState, ) -> T where - Infcx: SolverDelegate, + D: SolverDelegate, I: Interner, { // In case any fresh inference variables have been created between `state` @@ -415,15 +416,15 @@ where for &arg in &state.value.var_values.var_values[orig_values.len()..state.value.var_values.len()] { // FIXME: This is so ugly. - let unconstrained = infcx.fresh_var_for_kind_with_span(arg, span); + let unconstrained = delegate.fresh_var_for_kind_with_span(arg, span); orig_values.push(unconstrained); } let instantiation = - EvalCtxt::compute_query_response_instantiation_values(infcx, orig_values, &state); + EvalCtxt::compute_query_response_instantiation_values(delegate, orig_values, &state); - let inspect::State { var_values, data } = infcx.instantiate_canonical(state, instantiation); + let inspect::State { var_values, data } = delegate.instantiate_canonical(state, instantiation); - EvalCtxt::unify_query_var_values(infcx, param_env, orig_values, var_values); + EvalCtxt::unify_query_var_values(delegate, param_env, orig_values, var_values); data } diff --git a/compiler/rustc_next_trait_solver/src/solve/eval_ctxt/mod.rs b/compiler/rustc_next_trait_solver/src/solve/eval_ctxt/mod.rs index 485758b91a285..3390d7323d55a 100644 --- a/compiler/rustc_next_trait_solver/src/solve/eval_ctxt/mod.rs +++ b/compiler/rustc_next_trait_solver/src/solve/eval_ctxt/mod.rs @@ -10,7 +10,7 @@ use rustc_type_ir::{self as ty, CanonicalVarValues, Interner}; use rustc_type_ir_macros::{Lift_Generic, TypeFoldable_Generic, TypeVisitable_Generic}; use tracing::{instrument, trace}; -use crate::infcx::SolverDelegate; +use crate::delegate::SolverDelegate; use crate::solve::inspect::{self, ProofTreeBuilder}; use crate::solve::search_graph::SearchGraph; use crate::solve::{ @@ -22,9 +22,9 @@ use crate::solve::{ pub(super) mod canonical; mod probe; -pub struct EvalCtxt<'a, Infcx, I = ::Interner> +pub struct EvalCtxt<'a, D, I = ::Interner> where - Infcx: SolverDelegate, + D: SolverDelegate, I: Interner, { /// The inference context that backs (mostly) inference and placeholder terms @@ -42,7 +42,7 @@ where /// If some `InferCtxt` method is missing, please first think defensively about /// the method's compatibility with this solver, or if an existing one does /// the job already. - infcx: &'a Infcx, + delegate: &'a D, /// The variable info for the `var_values`, only used to make an ambiguous response /// with no constraints. @@ -82,7 +82,7 @@ where // evaluation code. tainted: Result<(), NoSolution>, - pub(super) inspect: ProofTreeBuilder, + pub(super) inspect: ProofTreeBuilder, } #[derive(derivative::Derivative)] @@ -141,9 +141,9 @@ pub trait SolverDelegateEvalExt: SolverDelegate { ); } -impl SolverDelegateEvalExt for Infcx +impl SolverDelegateEvalExt for D where - Infcx: SolverDelegate, + D: SolverDelegate, I: Interner, { /// Evaluates a goal from **outside** of the trait solver. @@ -176,9 +176,9 @@ where } } -impl<'a, Infcx, I> EvalCtxt<'a, Infcx> +impl<'a, D, I> EvalCtxt<'a, D> where - Infcx: SolverDelegate, + D: SolverDelegate, I: Interner, { pub(super) fn solver_mode(&self) -> SolverMode { @@ -193,22 +193,22 @@ where /// used from outside of any evaluation, and other methods should be preferred /// over using this manually (such as [`SolverDelegateEvalExt::evaluate_root_goal`]). pub(super) fn enter_root( - infcx: &Infcx, + delegate: &D, generate_proof_tree: GenerateProofTree, - f: impl FnOnce(&mut EvalCtxt<'_, Infcx>) -> R, + f: impl FnOnce(&mut EvalCtxt<'_, D>) -> R, ) -> (R, Option>) { - let mut search_graph = search_graph::SearchGraph::new(infcx.solver_mode()); + let mut search_graph = search_graph::SearchGraph::new(delegate.solver_mode()); let mut ecx = EvalCtxt { - infcx, + delegate, search_graph: &mut search_graph, nested_goals: NestedGoals::new(), inspect: ProofTreeBuilder::new_maybe_root(generate_proof_tree), // Only relevant when canonicalizing the response, // which we don't do within this evaluation context. - predefined_opaques_in_body: infcx - .interner() + predefined_opaques_in_body: delegate + .cx() .mk_predefined_opaques_in_body(PredefinedOpaquesData::default()), max_input_universe: ty::UniverseIndex::ROOT, variables: Default::default(), @@ -240,14 +240,14 @@ where tcx: I, search_graph: &'a mut search_graph::SearchGraph, canonical_input: CanonicalInput, - canonical_goal_evaluation: &mut ProofTreeBuilder, - f: impl FnOnce(&mut EvalCtxt<'_, Infcx>, Goal) -> R, + canonical_goal_evaluation: &mut ProofTreeBuilder, + f: impl FnOnce(&mut EvalCtxt<'_, D>, Goal) -> R, ) -> R { - let (ref infcx, input, var_values) = + let (ref delegate, input, var_values) = SolverDelegate::build_with_canonical(tcx, search_graph.solver_mode(), &canonical_input); let mut ecx = EvalCtxt { - infcx, + delegate, variables: canonical_input.variables, var_values, is_normalizes_to_goal: false, @@ -260,7 +260,7 @@ where }; for &(key, ty) in &input.predefined_opaques_in_body.opaque_types { - ecx.infcx.inject_new_hidden_type_unchecked(key, ty); + ecx.delegate.inject_new_hidden_type_unchecked(key, ty); } if !ecx.nested_goals.is_empty() { @@ -268,7 +268,7 @@ where } let result = f(&mut ecx, input.goal); - ecx.inspect.probe_final_state(ecx.infcx, ecx.max_input_universe); + ecx.inspect.probe_final_state(ecx.delegate, ecx.max_input_universe); canonical_goal_evaluation.goal_evaluation_step(ecx.inspect); // When creating a query response we clone the opaque type constraints @@ -276,7 +276,7 @@ where // assertions against dropping an `InferCtxt` without taking opaques. // FIXME: Once we remove support for the old impl we can remove this. // FIXME: Could we make `build_with_canonical` into `enter_with_canonical` and call this at the end? - infcx.reset_opaque_types(); + delegate.reset_opaque_types(); result } @@ -295,7 +295,7 @@ where tcx: I, search_graph: &'a mut search_graph::SearchGraph, canonical_input: CanonicalInput, - goal_evaluation: &mut ProofTreeBuilder, + goal_evaluation: &mut ProofTreeBuilder, ) -> QueryResult { let mut canonical_goal_evaluation = goal_evaluation.new_canonical_goal_evaluation(canonical_input); @@ -362,7 +362,7 @@ where let mut goal_evaluation = self.inspect.new_goal_evaluation(goal, &orig_values, goal_evaluation_kind); let canonical_response = EvalCtxt::evaluate_canonical_goal( - self.interner(), + self.cx(), self.search_graph, canonical_goal, &mut goal_evaluation, @@ -464,8 +464,8 @@ where } } } else { - self.infcx.enter_forall(kind, |kind| { - let goal = goal.with(self.interner(), ty::Binder::dummy(kind)); + self.delegate.enter_forall(kind, |kind| { + let goal = goal.with(self.cx(), ty::Binder::dummy(kind)); self.add_goal(GoalSource::InstantiateHigherRanked, goal); self.evaluate_added_goals_and_make_canonical_response(Certainty::Yes) }) @@ -504,7 +504,7 @@ where /// /// Goals for the next step get directly added to the nested goals of the `EvalCtxt`. fn evaluate_added_goals_step(&mut self) -> Result, NoSolution> { - let tcx = self.interner(); + let tcx = self.cx(); let mut goals = core::mem::take(&mut self.nested_goals); // If this loop did not result in any progress, what's our final certainty. @@ -586,11 +586,11 @@ where /// Record impl args in the proof tree for later access by `InspectCandidate`. pub(crate) fn record_impl_args(&mut self, impl_args: I::GenericArgs) { - self.inspect.record_impl_args(self.infcx, self.max_input_universe, impl_args) + self.inspect.record_impl_args(self.delegate, self.max_input_universe, impl_args) } - pub(super) fn interner(&self) -> I { - self.infcx.interner() + pub(super) fn cx(&self) -> I { + self.delegate.cx() } #[instrument(level = "trace", skip(self))] @@ -598,7 +598,7 @@ where goal.predicate = goal .predicate .fold_with(&mut ReplaceAliasWithInfer { ecx: self, param_env: goal.param_env }); - self.inspect.add_normalizes_to_goal(self.infcx, self.max_input_universe, goal); + self.inspect.add_normalizes_to_goal(self.delegate, self.max_input_universe, goal); self.nested_goals.normalizes_to_goals.push(goal); } @@ -607,7 +607,7 @@ where goal.predicate = goal .predicate .fold_with(&mut ReplaceAliasWithInfer { ecx: self, param_env: goal.param_env }); - self.inspect.add_goal(self.infcx, self.max_input_universe, source, goal); + self.inspect.add_goal(self.delegate, self.max_input_universe, source, goal); self.nested_goals.goals.push((source, goal)); } @@ -623,13 +623,13 @@ where } pub(super) fn next_ty_infer(&mut self) -> I::Ty { - let ty = self.infcx.next_ty_infer(); + let ty = self.delegate.next_ty_infer(); self.inspect.add_var_value(ty); ty } pub(super) fn next_const_infer(&mut self) -> I::Const { - let ct = self.infcx.next_const_infer(); + let ct = self.delegate.next_const_infer(); self.inspect.add_var_value(ct); ct } @@ -652,27 +652,27 @@ where let universe_of_term = match goal.predicate.term.kind() { ty::TermKind::Ty(ty) => { if let ty::Infer(ty::TyVar(vid)) = ty.kind() { - self.infcx.universe_of_ty(vid).unwrap() + self.delegate.universe_of_ty(vid).unwrap() } else { return false; } } ty::TermKind::Const(ct) => { if let ty::ConstKind::Infer(ty::InferConst::Var(vid)) = ct.kind() { - self.infcx.universe_of_ct(vid).unwrap() + self.delegate.universe_of_ct(vid).unwrap() } else { return false; } } }; - struct ContainsTermOrNotNameable<'a, Infcx: SolverDelegate, I: Interner> { + struct ContainsTermOrNotNameable<'a, D: SolverDelegate, I: Interner> { term: I::Term, universe_of_term: ty::UniverseIndex, - infcx: &'a Infcx, + delegate: &'a D, } - impl, I: Interner> ContainsTermOrNotNameable<'_, Infcx, I> { + impl, I: Interner> ContainsTermOrNotNameable<'_, D, I> { fn check_nameable(&self, universe: ty::UniverseIndex) -> ControlFlow<()> { if self.universe_of_term.can_name(universe) { ControlFlow::Continue(()) @@ -682,8 +682,8 @@ where } } - impl, I: Interner> TypeVisitor - for ContainsTermOrNotNameable<'_, Infcx, I> + impl, I: Interner> TypeVisitor + for ContainsTermOrNotNameable<'_, D, I> { type Result = ControlFlow<()>; fn visit_ty(&mut self, t: I::Ty) -> Self::Result { @@ -691,11 +691,11 @@ where ty::Infer(ty::TyVar(vid)) => { if let ty::TermKind::Ty(term) = self.term.kind() && let ty::Infer(ty::TyVar(term_vid)) = term.kind() - && self.infcx.root_ty_var(vid) == self.infcx.root_ty_var(term_vid) + && self.delegate.root_ty_var(vid) == self.delegate.root_ty_var(term_vid) { ControlFlow::Break(()) } else { - self.check_nameable(self.infcx.universe_of_ty(vid).unwrap()) + self.check_nameable(self.delegate.universe_of_ty(vid).unwrap()) } } ty::Placeholder(p) => self.check_nameable(p.universe()), @@ -714,11 +714,12 @@ where ty::ConstKind::Infer(ty::InferConst::Var(vid)) => { if let ty::TermKind::Const(term) = self.term.kind() && let ty::ConstKind::Infer(ty::InferConst::Var(term_vid)) = term.kind() - && self.infcx.root_const_var(vid) == self.infcx.root_const_var(term_vid) + && self.delegate.root_const_var(vid) + == self.delegate.root_const_var(term_vid) { ControlFlow::Break(()) } else { - self.check_nameable(self.infcx.universe_of_ct(vid).unwrap()) + self.check_nameable(self.delegate.universe_of_ct(vid).unwrap()) } } ty::ConstKind::Placeholder(p) => self.check_nameable(p.universe()), @@ -734,7 +735,7 @@ where } let mut visitor = ContainsTermOrNotNameable { - infcx: self.infcx, + delegate: self.delegate, universe_of_term, term: goal.predicate.term, }; @@ -768,7 +769,7 @@ where // NOTE: this check is purely an optimization, the structural eq would // always fail if the term is not an inference variable. if term.is_infer() { - let tcx = self.interner(); + let tcx = self.cx(); // We need to relate `alias` to `term` treating only the outermost // constructor as rigid, relating any contained generic arguments as // normal. We do this by first structurally equating the `term` @@ -781,7 +782,7 @@ where let rigid_ctor = ty::AliasTerm::new(tcx, alias.def_id, identity_args); let ctor_term = rigid_ctor.to_term(tcx); let obligations = - self.infcx.eq_structurally_relating_aliases(param_env, term, ctor_term)?; + self.delegate.eq_structurally_relating_aliases(param_env, term, ctor_term)?; debug_assert!(obligations.is_empty()); self.relate(param_env, alias, variance, rigid_ctor) } else { @@ -799,7 +800,7 @@ where lhs: T, rhs: T, ) -> Result<(), NoSolution> { - let result = self.infcx.eq_structurally_relating_aliases(param_env, lhs, rhs)?; + let result = self.delegate.eq_structurally_relating_aliases(param_env, lhs, rhs)?; assert_eq!(result, vec![]); Ok(()) } @@ -822,7 +823,7 @@ where variance: ty::Variance, rhs: T, ) -> Result<(), NoSolution> { - let goals = self.infcx.relate(param_env, lhs, variance, rhs)?; + let goals = self.delegate.relate(param_env, lhs, variance, rhs)?; self.add_goals(GoalSource::Misc, goals); Ok(()) } @@ -839,14 +840,14 @@ where lhs: T, rhs: T, ) -> Result>, NoSolution> { - self.infcx.relate(param_env, lhs, ty::Variance::Invariant, rhs) + self.delegate.relate(param_env, lhs, ty::Variance::Invariant, rhs) } pub(super) fn instantiate_binder_with_infer + Copy>( &self, value: ty::Binder, ) -> T { - self.infcx.instantiate_binder_with_infer(value) + self.delegate.instantiate_binder_with_infer(value) } pub(super) fn enter_forall + Copy, U>( @@ -854,18 +855,18 @@ where value: ty::Binder, f: impl FnOnce(T) -> U, ) -> U { - self.infcx.enter_forall(value, f) + self.delegate.enter_forall(value, f) } pub(super) fn resolve_vars_if_possible(&self, value: T) -> T where T: TypeFoldable, { - self.infcx.resolve_vars_if_possible(value) + self.delegate.resolve_vars_if_possible(value) } pub(super) fn fresh_args_for_item(&mut self, def_id: I::DefId) -> I::GenericArgs { - let args = self.infcx.fresh_args_for_item(def_id); + let args = self.delegate.fresh_args_for_item(def_id); for arg in args { self.inspect.add_var_value(arg); } @@ -873,12 +874,12 @@ where } pub(super) fn register_ty_outlives(&self, ty: I::Ty, lt: I::Region) { - self.infcx.register_ty_outlives(ty, lt); + self.delegate.register_ty_outlives(ty, lt); } pub(super) fn register_region_outlives(&self, a: I::Region, b: I::Region) { // `b : a` ==> `a <= b` - self.infcx.sub_regions(b, a); + self.delegate.sub_regions(b, a); } /// Computes the list of goals required for `arg` to be well-formed @@ -887,7 +888,7 @@ where param_env: I::ParamEnv, arg: I::GenericArg, ) -> Option>> { - self.infcx.well_formed_goals(param_env, arg) + self.delegate.well_formed_goals(param_env, arg) } pub(super) fn trait_ref_is_knowable( @@ -895,9 +896,9 @@ where param_env: I::ParamEnv, trait_ref: ty::TraitRef, ) -> Result { - let infcx = self.infcx; + let delegate = self.delegate; let lazily_normalize_ty = |ty| self.structurally_normalize_ty(param_env, ty); - infcx.trait_ref_is_knowable(trait_ref, lazily_normalize_ty) + delegate.trait_ref_is_knowable(trait_ref, lazily_normalize_ty) } pub(super) fn fetch_eligible_assoc_item( @@ -907,7 +908,7 @@ where trait_assoc_def_id: I::DefId, impl_def_id: I::DefId, ) -> Result, NoSolution> { - self.infcx.fetch_eligible_assoc_item( + self.delegate.fetch_eligible_assoc_item( param_env, goal_trait_ref, trait_assoc_def_id, @@ -916,7 +917,7 @@ where } pub(super) fn can_define_opaque_ty(&self, def_id: I::LocalDefId) -> bool { - self.infcx.defining_opaque_types().contains(&def_id) + self.delegate.defining_opaque_types().contains(&def_id) } pub(super) fn insert_hidden_type( @@ -926,7 +927,7 @@ where hidden_ty: I::Ty, ) -> Result<(), NoSolution> { let mut goals = Vec::new(); - self.infcx.insert_hidden_type(opaque_type_key, param_env, hidden_ty, &mut goals)?; + self.delegate.insert_hidden_type(opaque_type_key, param_env, hidden_ty, &mut goals)?; self.add_goals(GoalSource::Misc, goals); Ok(()) } @@ -939,7 +940,7 @@ where hidden_ty: I::Ty, ) { let mut goals = Vec::new(); - self.infcx.add_item_bounds_for_hidden_type( + self.delegate.add_item_bounds_for_hidden_type( opaque_def_id, opaque_args, param_env, @@ -958,7 +959,7 @@ where ty: I::Ty, ) -> Vec> { // FIXME: Super inefficient to be cloning this... - let opaques = self.infcx.clone_opaque_types_for_query_response(); + let opaques = self.delegate.clone_opaque_types_for_query_response(); let mut values = vec![]; for (candidate_key, candidate_ty) in opaques { @@ -995,7 +996,7 @@ where param_env: I::ParamEnv, unevaluated: ty::UnevaluatedConst, ) -> Option { - self.infcx.try_const_eval_resolve(param_env, unevaluated) + self.delegate.try_const_eval_resolve(param_env, unevaluated) } pub(super) fn is_transmutable( @@ -1005,7 +1006,7 @@ where src: I::Ty, assume: I::Const, ) -> Result { - self.infcx.is_transmutable(param_env, dst, src, assume) + self.delegate.is_transmutable(param_env, dst, src, assume) } } @@ -1016,22 +1017,22 @@ where /// /// This is a performance optimization to more eagerly detect cycles during trait /// solving. See tests/ui/traits/next-solver/cycles/cycle-modulo-ambig-aliases.rs. -struct ReplaceAliasWithInfer<'me, 'a, Infcx, I> +struct ReplaceAliasWithInfer<'me, 'a, D, I> where - Infcx: SolverDelegate, + D: SolverDelegate, I: Interner, { - ecx: &'me mut EvalCtxt<'a, Infcx>, + ecx: &'me mut EvalCtxt<'a, D>, param_env: I::ParamEnv, } -impl TypeFolder for ReplaceAliasWithInfer<'_, '_, Infcx, I> +impl TypeFolder for ReplaceAliasWithInfer<'_, '_, D, I> where - Infcx: SolverDelegate, + D: SolverDelegate, I: Interner, { - fn interner(&self) -> I { - self.ecx.interner() + fn cx(&self) -> I { + self.ecx.cx() } fn fold_ty(&mut self, ty: I::Ty) -> I::Ty { @@ -1045,7 +1046,7 @@ where ); self.ecx.add_goal( GoalSource::Misc, - Goal::new(self.interner(), self.param_env, normalizes_to), + Goal::new(self.cx(), self.param_env, normalizes_to), ); infer_ty } @@ -1064,7 +1065,7 @@ where ); self.ecx.add_goal( GoalSource::Misc, - Goal::new(self.interner(), self.param_env, normalizes_to), + Goal::new(self.cx(), self.param_env, normalizes_to), ); infer_ct } diff --git a/compiler/rustc_next_trait_solver/src/solve/eval_ctxt/probe.rs b/compiler/rustc_next_trait_solver/src/solve/eval_ctxt/probe.rs index 1c5358b3edb4d..e9516c60c70f9 100644 --- a/compiler/rustc_next_trait_solver/src/solve/eval_ctxt/probe.rs +++ b/compiler/rustc_next_trait_solver/src/solve/eval_ctxt/probe.rs @@ -3,34 +3,34 @@ use std::marker::PhantomData; use rustc_type_ir::Interner; use tracing::instrument; -use crate::infcx::SolverDelegate; +use crate::delegate::SolverDelegate; use crate::solve::assembly::Candidate; use crate::solve::inspect; use crate::solve::{BuiltinImplSource, CandidateSource, EvalCtxt, NoSolution, QueryResult}; -pub(in crate::solve) struct ProbeCtxt<'me, 'a, Infcx, I, F, T> +pub(in crate::solve) struct ProbeCtxt<'me, 'a, D, I, F, T> where - Infcx: SolverDelegate, + D: SolverDelegate, I: Interner, { - ecx: &'me mut EvalCtxt<'a, Infcx, I>, + ecx: &'me mut EvalCtxt<'a, D, I>, probe_kind: F, _result: PhantomData, } -impl ProbeCtxt<'_, '_, Infcx, I, F, T> +impl ProbeCtxt<'_, '_, D, I, F, T> where F: FnOnce(&T) -> inspect::ProbeKind, - Infcx: SolverDelegate, + D: SolverDelegate, I: Interner, { - pub(in crate::solve) fn enter(self, f: impl FnOnce(&mut EvalCtxt<'_, Infcx>) -> T) -> T { + pub(in crate::solve) fn enter(self, f: impl FnOnce(&mut EvalCtxt<'_, D>) -> T) -> T { let ProbeCtxt { ecx: outer_ecx, probe_kind, _result } = self; - let infcx = outer_ecx.infcx; + let delegate = outer_ecx.delegate; let max_input_universe = outer_ecx.max_input_universe; let mut nested_ecx = EvalCtxt { - infcx, + delegate, variables: outer_ecx.variables, var_values: outer_ecx.var_values, is_normalizes_to_goal: outer_ecx.is_normalizes_to_goal, @@ -41,9 +41,9 @@ where tainted: outer_ecx.tainted, inspect: outer_ecx.inspect.take_and_enter_probe(), }; - let r = nested_ecx.infcx.probe(|| { + let r = nested_ecx.delegate.probe(|| { let r = f(&mut nested_ecx); - nested_ecx.inspect.probe_final_state(infcx, max_input_universe); + nested_ecx.inspect.probe_final_state(delegate, max_input_universe); r }); if !nested_ecx.inspect.is_noop() { @@ -55,41 +55,38 @@ where } } -pub(in crate::solve) struct TraitProbeCtxt<'me, 'a, Infcx, I, F> +pub(in crate::solve) struct TraitProbeCtxt<'me, 'a, D, I, F> where - Infcx: SolverDelegate, + D: SolverDelegate, I: Interner, { - cx: ProbeCtxt<'me, 'a, Infcx, I, F, QueryResult>, + cx: ProbeCtxt<'me, 'a, D, I, F, QueryResult>, source: CandidateSource, } -impl TraitProbeCtxt<'_, '_, Infcx, I, F> +impl TraitProbeCtxt<'_, '_, D, I, F> where - Infcx: SolverDelegate, + D: SolverDelegate, I: Interner, F: FnOnce(&QueryResult) -> inspect::ProbeKind, { #[instrument(level = "debug", skip_all, fields(source = ?self.source))] pub(in crate::solve) fn enter( self, - f: impl FnOnce(&mut EvalCtxt<'_, Infcx>) -> QueryResult, + f: impl FnOnce(&mut EvalCtxt<'_, D>) -> QueryResult, ) -> Result, NoSolution> { self.cx.enter(|ecx| f(ecx)).map(|result| Candidate { source: self.source, result }) } } -impl<'a, Infcx, I> EvalCtxt<'a, Infcx, I> +impl<'a, D, I> EvalCtxt<'a, D, I> where - Infcx: SolverDelegate, + D: SolverDelegate, I: Interner, { /// `probe_kind` is only called when proof tree building is enabled so it can be /// as expensive as necessary to output the desired information. - pub(in crate::solve) fn probe( - &mut self, - probe_kind: F, - ) -> ProbeCtxt<'_, 'a, Infcx, I, F, T> + pub(in crate::solve) fn probe(&mut self, probe_kind: F) -> ProbeCtxt<'_, 'a, D, I, F, T> where F: FnOnce(&T) -> inspect::ProbeKind, { @@ -99,16 +96,14 @@ where pub(in crate::solve) fn probe_builtin_trait_candidate( &mut self, source: BuiltinImplSource, - ) -> TraitProbeCtxt<'_, 'a, Infcx, I, impl FnOnce(&QueryResult) -> inspect::ProbeKind> - { + ) -> TraitProbeCtxt<'_, 'a, D, I, impl FnOnce(&QueryResult) -> inspect::ProbeKind> { self.probe_trait_candidate(CandidateSource::BuiltinImpl(source)) } pub(in crate::solve) fn probe_trait_candidate( &mut self, source: CandidateSource, - ) -> TraitProbeCtxt<'_, 'a, Infcx, I, impl FnOnce(&QueryResult) -> inspect::ProbeKind> - { + ) -> TraitProbeCtxt<'_, 'a, D, I, impl FnOnce(&QueryResult) -> inspect::ProbeKind> { TraitProbeCtxt { cx: ProbeCtxt { ecx: self, diff --git a/compiler/rustc_next_trait_solver/src/solve/inspect/build.rs b/compiler/rustc_next_trait_solver/src/solve/inspect/build.rs index 5fbec4b28d434..ae59f0c5e9572 100644 --- a/compiler/rustc_next_trait_solver/src/solve/inspect/build.rs +++ b/compiler/rustc_next_trait_solver/src/solve/inspect/build.rs @@ -9,7 +9,7 @@ use std::mem; use rustc_type_ir::{self as ty, Interner}; -use crate::infcx::SolverDelegate; +use crate::delegate::SolverDelegate; use crate::solve::eval_ctxt::canonical; use crate::solve::inspect; use crate::solve::{ @@ -37,12 +37,12 @@ use crate::solve::{ /// trees. At the end of trait solving `ProofTreeBuilder::finalize` /// is called to recursively convert the whole structure to a /// finished proof tree. -pub(in crate::solve) struct ProofTreeBuilder::Interner> +pub(in crate::solve) struct ProofTreeBuilder::Interner> where - Infcx: SolverDelegate, + D: SolverDelegate, I: Interner, { - _infcx: PhantomData, + _infcx: PhantomData, state: Option>>, } @@ -235,8 +235,8 @@ impl WipProbeStep { } } -impl, I: Interner> ProofTreeBuilder { - fn new(state: impl Into>) -> ProofTreeBuilder { +impl, I: Interner> ProofTreeBuilder { + fn new(state: impl Into>) -> ProofTreeBuilder { ProofTreeBuilder { state: Some(Box::new(state.into())), _infcx: PhantomData } } @@ -258,7 +258,7 @@ impl, I: Interner> ProofTreeBuilder { self.state.as_deref_mut() } - pub fn take_and_enter_probe(&mut self) -> ProofTreeBuilder { + pub fn take_and_enter_probe(&mut self) -> ProofTreeBuilder { let mut nested = ProofTreeBuilder { state: self.state.take(), _infcx: PhantomData }; nested.enter_probe(); nested @@ -273,18 +273,18 @@ impl, I: Interner> ProofTreeBuilder { } } - pub fn new_maybe_root(generate_proof_tree: GenerateProofTree) -> ProofTreeBuilder { + pub fn new_maybe_root(generate_proof_tree: GenerateProofTree) -> ProofTreeBuilder { match generate_proof_tree { GenerateProofTree::No => ProofTreeBuilder::new_noop(), GenerateProofTree::Yes => ProofTreeBuilder::new_root(), } } - pub fn new_root() -> ProofTreeBuilder { + pub fn new_root() -> ProofTreeBuilder { ProofTreeBuilder::new(DebugSolver::Root) } - pub fn new_noop() -> ProofTreeBuilder { + pub fn new_noop() -> ProofTreeBuilder { ProofTreeBuilder { state: None, _infcx: PhantomData } } @@ -297,7 +297,7 @@ impl, I: Interner> ProofTreeBuilder { goal: Goal, orig_values: &[I::GenericArg], kind: GoalEvaluationKind, - ) -> ProofTreeBuilder { + ) -> ProofTreeBuilder { self.opt_nested(|| match kind { GoalEvaluationKind::Root => Some(WipGoalEvaluation { uncanonicalized_goal: goal, @@ -311,7 +311,7 @@ impl, I: Interner> ProofTreeBuilder { pub fn new_canonical_goal_evaluation( &mut self, goal: CanonicalInput, - ) -> ProofTreeBuilder { + ) -> ProofTreeBuilder { self.nested(|| WipCanonicalGoalEvaluation { goal, kind: None, @@ -337,10 +337,7 @@ impl, I: Interner> ProofTreeBuilder { }) } - pub fn canonical_goal_evaluation( - &mut self, - canonical_goal_evaluation: ProofTreeBuilder, - ) { + pub fn canonical_goal_evaluation(&mut self, canonical_goal_evaluation: ProofTreeBuilder) { if let Some(this) = self.as_mut() { match (this, *canonical_goal_evaluation.state.unwrap()) { ( @@ -366,7 +363,7 @@ impl, I: Interner> ProofTreeBuilder { } } - pub fn goal_evaluation(&mut self, goal_evaluation: ProofTreeBuilder) { + pub fn goal_evaluation(&mut self, goal_evaluation: ProofTreeBuilder) { if let Some(this) = self.as_mut() { match this { DebugSolver::Root => *this = *goal_evaluation.state.unwrap(), @@ -382,7 +379,7 @@ impl, I: Interner> ProofTreeBuilder { &mut self, var_values: ty::CanonicalVarValues, instantiated_goal: QueryInput, - ) -> ProofTreeBuilder { + ) -> ProofTreeBuilder { self.nested(|| WipCanonicalGoalEvaluationStep { var_values: var_values.var_values.to_vec(), instantiated_goal, @@ -396,7 +393,7 @@ impl, I: Interner> ProofTreeBuilder { }) } - pub fn goal_evaluation_step(&mut self, goal_evaluation_step: ProofTreeBuilder) { + pub fn goal_evaluation_step(&mut self, goal_evaluation_step: ProofTreeBuilder) { if let Some(this) = self.as_mut() { match (this, *goal_evaluation_step.state.unwrap()) { ( @@ -448,12 +445,12 @@ impl, I: Interner> ProofTreeBuilder { } } - pub fn probe_final_state(&mut self, infcx: &Infcx, max_input_universe: ty::UniverseIndex) { + pub fn probe_final_state(&mut self, delegate: &D, max_input_universe: ty::UniverseIndex) { match self.as_mut() { None => {} Some(DebugSolver::CanonicalGoalEvaluationStep(state)) => { let final_state = canonical::make_canonical_state( - infcx, + delegate, &state.var_values, max_input_universe, (), @@ -467,21 +464,21 @@ impl, I: Interner> ProofTreeBuilder { pub fn add_normalizes_to_goal( &mut self, - infcx: &Infcx, + delegate: &D, max_input_universe: ty::UniverseIndex, goal: Goal>, ) { self.add_goal( - infcx, + delegate, max_input_universe, GoalSource::Misc, - goal.with(infcx.interner(), goal.predicate), + goal.with(delegate.cx(), goal.predicate), ); } pub fn add_goal( &mut self, - infcx: &Infcx, + delegate: &D, max_input_universe: ty::UniverseIndex, source: GoalSource, goal: Goal, @@ -490,7 +487,7 @@ impl, I: Interner> ProofTreeBuilder { None => {} Some(DebugSolver::CanonicalGoalEvaluationStep(state)) => { let goal = canonical::make_canonical_state( - infcx, + delegate, &state.var_values, max_input_universe, goal, @@ -503,14 +500,14 @@ impl, I: Interner> ProofTreeBuilder { pub(crate) fn record_impl_args( &mut self, - infcx: &Infcx, + delegate: &D, max_input_universe: ty::UniverseIndex, impl_args: I::GenericArgs, ) { match self.as_mut() { Some(DebugSolver::CanonicalGoalEvaluationStep(state)) => { let impl_args = canonical::make_canonical_state( - infcx, + delegate, &state.var_values, max_input_universe, impl_args, @@ -538,7 +535,7 @@ impl, I: Interner> ProofTreeBuilder { } } - pub fn finish_probe(mut self) -> ProofTreeBuilder { + pub fn finish_probe(mut self) -> ProofTreeBuilder { match self.as_mut() { None => {} Some(DebugSolver::CanonicalGoalEvaluationStep(state)) => { diff --git a/compiler/rustc_next_trait_solver/src/solve/mod.rs b/compiler/rustc_next_trait_solver/src/solve/mod.rs index 02069016c2bde..b76b4c098523e 100644 --- a/compiler/rustc_next_trait_solver/src/solve/mod.rs +++ b/compiler/rustc_next_trait_solver/src/solve/mod.rs @@ -29,7 +29,7 @@ use rustc_type_ir::{self as ty, Interner}; use tracing::instrument; pub use self::eval_ctxt::{EvalCtxt, GenerateProofTree, SolverDelegateEvalExt}; -use crate::infcx::SolverDelegate; +use crate::delegate::SolverDelegate; /// How many fixpoint iterations we should attempt inside of the solver before bailing /// with overflow. @@ -56,9 +56,9 @@ fn has_no_inference_or_external_constraints( && response.value.external_constraints.opaque_types.is_empty() } -impl<'a, Infcx, I> EvalCtxt<'a, Infcx> +impl<'a, D, I> EvalCtxt<'a, D> where - Infcx: SolverDelegate, + D: SolverDelegate, I: Interner, { #[instrument(level = "trace", skip(self))] @@ -104,7 +104,7 @@ where } fn compute_object_safe_goal(&mut self, trait_def_id: I::DefId) -> QueryResult { - if self.interner().trait_is_object_safe(trait_def_id) { + if self.cx().trait_is_object_safe(trait_def_id) { self.evaluate_added_goals_and_make_canonical_response(Certainty::Yes) } else { Err(NoSolution) @@ -182,7 +182,7 @@ where return self.evaluate_added_goals_and_make_canonical_response(Certainty::Yes); } ty::ConstKind::Unevaluated(uv) => { - self.interner().type_of(uv.def).instantiate(self.interner(), &uv.args) + self.cx().type_of(uv.def).instantiate(self.cx(), &uv.args) } ty::ConstKind::Expr(_) => unimplemented!( "`feature(generic_const_exprs)` is not supported in the new trait solver" @@ -193,7 +193,7 @@ where ty::ConstKind::Bound(_, _) => panic!("escaping bound vars in {:?}", ct), ty::ConstKind::Value(ty, _) => ty, ty::ConstKind::Placeholder(placeholder) => { - self.interner().find_const_ty_from_env(goal.param_env, placeholder) + self.cx().find_const_ty_from_env(goal.param_env, placeholder) } }; @@ -202,9 +202,9 @@ where } } -impl EvalCtxt<'_, Infcx> +impl EvalCtxt<'_, D> where - Infcx: SolverDelegate, + D: SolverDelegate, I: Interner, { /// Try to merge multiple possible ways to prove a goal, if that is not possible returns `None`. @@ -267,7 +267,7 @@ where if let ty::Alias(..) = ty.kind() { let normalized_ty = self.next_ty_infer(); let alias_relate_goal = Goal::new( - self.interner(), + self.cx(), param_env, ty::PredicateKind::AliasRelate( ty.into(), diff --git a/compiler/rustc_next_trait_solver/src/solve/normalizes_to/anon_const.rs b/compiler/rustc_next_trait_solver/src/solve/normalizes_to/anon_const.rs index 0f1c1f13c165e..5d5597429da45 100644 --- a/compiler/rustc_next_trait_solver/src/solve/normalizes_to/anon_const.rs +++ b/compiler/rustc_next_trait_solver/src/solve/normalizes_to/anon_const.rs @@ -1,12 +1,12 @@ use rustc_type_ir::{self as ty, Interner}; use tracing::instrument; -use crate::infcx::SolverDelegate; +use crate::delegate::SolverDelegate; use crate::solve::{Certainty, EvalCtxt, Goal, QueryResult}; -impl EvalCtxt<'_, Infcx> +impl EvalCtxt<'_, D> where - Infcx: SolverDelegate, + D: SolverDelegate, I: Interner, { #[instrument(level = "trace", skip(self), ret)] diff --git a/compiler/rustc_next_trait_solver/src/solve/normalizes_to/inherent.rs b/compiler/rustc_next_trait_solver/src/solve/normalizes_to/inherent.rs index 8436f3ad48417..827fe5f2ca405 100644 --- a/compiler/rustc_next_trait_solver/src/solve/normalizes_to/inherent.rs +++ b/compiler/rustc_next_trait_solver/src/solve/normalizes_to/inherent.rs @@ -7,19 +7,19 @@ use rustc_type_ir::{self as ty, Interner}; -use crate::infcx::SolverDelegate; +use crate::delegate::SolverDelegate; use crate::solve::{Certainty, EvalCtxt, Goal, GoalSource, QueryResult}; -impl EvalCtxt<'_, Infcx> +impl EvalCtxt<'_, D> where - Infcx: SolverDelegate, + D: SolverDelegate, I: Interner, { pub(super) fn normalize_inherent_associated_type( &mut self, goal: Goal>, ) -> QueryResult { - let tcx = self.interner(); + let tcx = self.cx(); let inherent = goal.predicate.alias.expect_ty(tcx); let impl_def_id = tcx.parent(inherent.def_id); diff --git a/compiler/rustc_next_trait_solver/src/solve/normalizes_to/mod.rs b/compiler/rustc_next_trait_solver/src/solve/normalizes_to/mod.rs index ebc83bef5137b..f58384d86cd68 100644 --- a/compiler/rustc_next_trait_solver/src/solve/normalizes_to/mod.rs +++ b/compiler/rustc_next_trait_solver/src/solve/normalizes_to/mod.rs @@ -9,7 +9,7 @@ use rustc_type_ir::Upcast as _; use rustc_type_ir::{self as ty, Interner, NormalizesTo}; use tracing::instrument; -use crate::infcx::SolverDelegate; +use crate::delegate::SolverDelegate; use crate::solve::assembly::structural_traits::{self, AsyncCallableRelevantTypes}; use crate::solve::assembly::{self, Candidate}; use crate::solve::inspect::ProbeKind; @@ -18,9 +18,9 @@ use crate::solve::{ NoSolution, QueryResult, }; -impl EvalCtxt<'_, Infcx> +impl EvalCtxt<'_, D> where - Infcx: SolverDelegate, + D: SolverDelegate, I: Interner, { #[instrument(level = "trace", skip(self), ret)] @@ -48,7 +48,7 @@ where /// returns `NoSolution`. #[instrument(level = "trace", skip(self), ret)] fn normalize_at_least_one_step(&mut self, goal: Goal>) -> QueryResult { - match goal.predicate.alias.kind(self.interner()) { + match goal.predicate.alias.kind(self.cx()) { ty::AliasTermKind::ProjectionTy | ty::AliasTermKind::ProjectionConst => { let candidates = self.assemble_and_evaluate_candidates(goal); self.merge_candidates(candidates) @@ -75,9 +75,9 @@ where } } -impl assembly::GoalKind for NormalizesTo +impl assembly::GoalKind for NormalizesTo where - Infcx: SolverDelegate, + D: SolverDelegate, I: Interner, { fn self_ty(self) -> I::Ty { @@ -97,15 +97,15 @@ where } fn probe_and_match_goal_against_assumption( - ecx: &mut EvalCtxt<'_, Infcx>, + ecx: &mut EvalCtxt<'_, D>, source: CandidateSource, goal: Goal, assumption: I::Clause, - then: impl FnOnce(&mut EvalCtxt<'_, Infcx>) -> QueryResult, + then: impl FnOnce(&mut EvalCtxt<'_, D>) -> QueryResult, ) -> Result, NoSolution> { if let Some(projection_pred) = assumption.as_projection_clause() { if projection_pred.projection_def_id() == goal.predicate.def_id() { - let tcx = ecx.interner(); + let tcx = ecx.cx(); ecx.probe_trait_candidate(source).enter(|ecx| { let assumption_projection_pred = ecx.instantiate_binder_with_infer(projection_pred); @@ -136,15 +136,15 @@ where } fn consider_impl_candidate( - ecx: &mut EvalCtxt<'_, Infcx>, + ecx: &mut EvalCtxt<'_, D>, goal: Goal>, impl_def_id: I::DefId, ) -> Result, NoSolution> { - let tcx = ecx.interner(); + let tcx = ecx.cx(); let goal_trait_ref = goal.predicate.alias.trait_ref(tcx); let impl_trait_ref = tcx.impl_trait_ref(impl_def_id); - if !ecx.interner().args_may_unify_deep( + if !ecx.cx().args_may_unify_deep( goal.predicate.alias.trait_ref(tcx).args, impl_trait_ref.skip_binder().args, ) { @@ -194,7 +194,7 @@ where return ecx.evaluate_added_goals_and_make_canonical_response(Certainty::AMBIGUOUS); }; - let error_response = |ecx: &mut EvalCtxt<'_, Infcx>, msg: &str| { + let error_response = |ecx: &mut EvalCtxt<'_, D>, msg: &str| { let guar = tcx.delay_bug(msg); let error_term = match goal.predicate.alias.kind(tcx) { ty::AliasTermKind::ProjectionTy => Ty::new_error(tcx, guar).into(), @@ -262,61 +262,61 @@ where /// Fail to normalize if the predicate contains an error, alternatively, we could normalize to `ty::Error` /// and succeed. Can experiment with this to figure out what results in better error messages. fn consider_error_guaranteed_candidate( - _ecx: &mut EvalCtxt<'_, Infcx>, + _ecx: &mut EvalCtxt<'_, D>, _guar: I::ErrorGuaranteed, ) -> Result, NoSolution> { Err(NoSolution) } fn consider_auto_trait_candidate( - ecx: &mut EvalCtxt<'_, Infcx>, + ecx: &mut EvalCtxt<'_, D>, _goal: Goal, ) -> Result, NoSolution> { - ecx.interner().delay_bug("associated types not allowed on auto traits"); + ecx.cx().delay_bug("associated types not allowed on auto traits"); Err(NoSolution) } fn consider_trait_alias_candidate( - _ecx: &mut EvalCtxt<'_, Infcx>, + _ecx: &mut EvalCtxt<'_, D>, goal: Goal, ) -> Result, NoSolution> { panic!("trait aliases do not have associated types: {:?}", goal); } fn consider_builtin_sized_candidate( - _ecx: &mut EvalCtxt<'_, Infcx>, + _ecx: &mut EvalCtxt<'_, D>, goal: Goal, ) -> Result, NoSolution> { panic!("`Sized` does not have an associated type: {:?}", goal); } fn consider_builtin_copy_clone_candidate( - _ecx: &mut EvalCtxt<'_, Infcx>, + _ecx: &mut EvalCtxt<'_, D>, goal: Goal, ) -> Result, NoSolution> { panic!("`Copy`/`Clone` does not have an associated type: {:?}", goal); } fn consider_builtin_pointer_like_candidate( - _ecx: &mut EvalCtxt<'_, Infcx>, + _ecx: &mut EvalCtxt<'_, D>, goal: Goal, ) -> Result, NoSolution> { panic!("`PointerLike` does not have an associated type: {:?}", goal); } fn consider_builtin_fn_ptr_trait_candidate( - _ecx: &mut EvalCtxt<'_, Infcx>, + _ecx: &mut EvalCtxt<'_, D>, goal: Goal, ) -> Result, NoSolution> { panic!("`FnPtr` does not have an associated type: {:?}", goal); } fn consider_builtin_fn_trait_candidates( - ecx: &mut EvalCtxt<'_, Infcx>, + ecx: &mut EvalCtxt<'_, D>, goal: Goal, goal_kind: ty::ClosureKind, ) -> Result, NoSolution> { - let tcx = ecx.interner(); + let tcx = ecx.cx(); let tupled_inputs_and_output = match structural_traits::extract_tupled_inputs_and_output_from_callable( tcx, @@ -355,11 +355,11 @@ where } fn consider_builtin_async_fn_trait_candidates( - ecx: &mut EvalCtxt<'_, Infcx>, + ecx: &mut EvalCtxt<'_, D>, goal: Goal, goal_kind: ty::ClosureKind, ) -> Result, NoSolution> { - let tcx = ecx.interner(); + let tcx = ecx.cx(); let env_region = match goal_kind { ty::ClosureKind::Fn | ty::ClosureKind::FnMut => goal.predicate.alias.args.region_at(2), @@ -457,7 +457,7 @@ where } fn consider_builtin_async_fn_kind_helper_candidate( - ecx: &mut EvalCtxt<'_, Infcx>, + ecx: &mut EvalCtxt<'_, D>, goal: Goal, ) -> Result, NoSolution> { let [ @@ -489,7 +489,7 @@ where } let upvars_ty = ty::CoroutineClosureSignature::tupled_upvars_by_closure_kind( - ecx.interner(), + ecx.cx(), goal_kind, tupled_inputs_ty.expect_ty(), tupled_upvars_ty.expect_ty(), @@ -504,17 +504,17 @@ where } fn consider_builtin_tuple_candidate( - _ecx: &mut EvalCtxt<'_, Infcx>, + _ecx: &mut EvalCtxt<'_, D>, goal: Goal, ) -> Result, NoSolution> { panic!("`Tuple` does not have an associated type: {:?}", goal); } fn consider_builtin_pointee_candidate( - ecx: &mut EvalCtxt<'_, Infcx>, + ecx: &mut EvalCtxt<'_, D>, goal: Goal, ) -> Result, NoSolution> { - let tcx = ecx.interner(); + let tcx = ecx.cx(); let metadata_def_id = tcx.require_lang_item(TraitSolverLangItem::Metadata); assert_eq!(metadata_def_id, goal.predicate.def_id()); ecx.probe_builtin_trait_candidate(BuiltinImplSource::Misc).enter(|ecx| { @@ -592,7 +592,7 @@ where } fn consider_builtin_future_candidate( - ecx: &mut EvalCtxt<'_, Infcx>, + ecx: &mut EvalCtxt<'_, D>, goal: Goal, ) -> Result, NoSolution> { let self_ty = goal.predicate.self_ty(); @@ -601,7 +601,7 @@ where }; // Coroutines are not futures unless they come from `async` desugaring - let tcx = ecx.interner(); + let tcx = ecx.cx(); if !tcx.coroutine_is_async(def_id) { return Err(NoSolution); } @@ -613,11 +613,7 @@ where CandidateSource::BuiltinImpl(BuiltinImplSource::Misc), goal, ty::ProjectionPredicate { - projection_term: ty::AliasTerm::new( - ecx.interner(), - goal.predicate.def_id(), - [self_ty], - ), + projection_term: ty::AliasTerm::new(ecx.cx(), goal.predicate.def_id(), [self_ty]), term, } .upcast(tcx), @@ -628,7 +624,7 @@ where } fn consider_builtin_iterator_candidate( - ecx: &mut EvalCtxt<'_, Infcx>, + ecx: &mut EvalCtxt<'_, D>, goal: Goal, ) -> Result, NoSolution> { let self_ty = goal.predicate.self_ty(); @@ -637,7 +633,7 @@ where }; // Coroutines are not Iterators unless they come from `gen` desugaring - let tcx = ecx.interner(); + let tcx = ecx.cx(); if !tcx.coroutine_is_gen(def_id) { return Err(NoSolution); } @@ -649,11 +645,7 @@ where CandidateSource::BuiltinImpl(BuiltinImplSource::Misc), goal, ty::ProjectionPredicate { - projection_term: ty::AliasTerm::new( - ecx.interner(), - goal.predicate.def_id(), - [self_ty], - ), + projection_term: ty::AliasTerm::new(ecx.cx(), goal.predicate.def_id(), [self_ty]), term, } .upcast(tcx), @@ -664,14 +656,14 @@ where } fn consider_builtin_fused_iterator_candidate( - _ecx: &mut EvalCtxt<'_, Infcx>, + _ecx: &mut EvalCtxt<'_, D>, goal: Goal, ) -> Result, NoSolution> { panic!("`FusedIterator` does not have an associated type: {:?}", goal); } fn consider_builtin_async_iterator_candidate( - ecx: &mut EvalCtxt<'_, Infcx>, + ecx: &mut EvalCtxt<'_, D>, goal: Goal, ) -> Result, NoSolution> { let self_ty = goal.predicate.self_ty(); @@ -680,7 +672,7 @@ where }; // Coroutines are not AsyncIterators unless they come from `gen` desugaring - let tcx = ecx.interner(); + let tcx = ecx.cx(); if !tcx.coroutine_is_async_gen(def_id) { return Err(NoSolution); } @@ -707,7 +699,7 @@ where } fn consider_builtin_coroutine_candidate( - ecx: &mut EvalCtxt<'_, Infcx>, + ecx: &mut EvalCtxt<'_, D>, goal: Goal, ) -> Result, NoSolution> { let self_ty = goal.predicate.self_ty(); @@ -716,7 +708,7 @@ where }; // `async`-desugared coroutines do not implement the coroutine trait - let tcx = ecx.interner(); + let tcx = ecx.cx(); if !tcx.is_general_coroutine(def_id) { return Err(NoSolution); } @@ -739,7 +731,7 @@ where goal, ty::ProjectionPredicate { projection_term: ty::AliasTerm::new( - ecx.interner(), + ecx.cx(), goal.predicate.def_id(), [self_ty, coroutine.resume_ty()], ), @@ -753,14 +745,14 @@ where } fn consider_structural_builtin_unsize_candidates( - _ecx: &mut EvalCtxt<'_, Infcx>, + _ecx: &mut EvalCtxt<'_, D>, goal: Goal, ) -> Vec> { panic!("`Unsize` does not have an associated type: {:?}", goal); } fn consider_builtin_discriminant_kind_candidate( - ecx: &mut EvalCtxt<'_, Infcx>, + ecx: &mut EvalCtxt<'_, D>, goal: Goal, ) -> Result, NoSolution> { let self_ty = goal.predicate.self_ty(); @@ -788,7 +780,7 @@ where | ty::Slice(_) | ty::Dynamic(_, _, _) | ty::Tuple(_) - | ty::Error(_) => self_ty.discriminant_ty(ecx.interner()), + | ty::Error(_) => self_ty.discriminant_ty(ecx.cx()), // We do not call `Ty::discriminant_ty` on alias, param, or placeholder // types, which return `::Discriminant` @@ -812,7 +804,7 @@ where } fn consider_builtin_async_destruct_candidate( - ecx: &mut EvalCtxt<'_, Infcx>, + ecx: &mut EvalCtxt<'_, D>, goal: Goal, ) -> Result, NoSolution> { let self_ty = goal.predicate.self_ty(); @@ -835,7 +827,7 @@ where | ty::Str | ty::Slice(_) | ty::Tuple(_) - | ty::Error(_) => self_ty.async_destructor_ty(ecx.interner()), + | ty::Error(_) => self_ty.async_destructor_ty(ecx.cx()), // We do not call `Ty::async_destructor_ty` on alias, param, or placeholder // types, which return `::AsyncDestructor` @@ -865,23 +857,23 @@ where } fn consider_builtin_destruct_candidate( - _ecx: &mut EvalCtxt<'_, Infcx>, + _ecx: &mut EvalCtxt<'_, D>, goal: Goal, ) -> Result, NoSolution> { panic!("`Destruct` does not have an associated type: {:?}", goal); } fn consider_builtin_transmute_candidate( - _ecx: &mut EvalCtxt<'_, Infcx>, + _ecx: &mut EvalCtxt<'_, D>, goal: Goal, ) -> Result, NoSolution> { panic!("`BikeshedIntrinsicFrom` does not have an associated type: {:?}", goal) } } -impl EvalCtxt<'_, Infcx> +impl EvalCtxt<'_, D> where - Infcx: SolverDelegate, + D: SolverDelegate, I: Interner, { fn translate_args( @@ -892,7 +884,7 @@ where impl_trait_ref: rustc_type_ir::TraitRef, target_container_def_id: I::DefId, ) -> Result { - let tcx = self.interner(); + let tcx = self.cx(); Ok(if target_container_def_id == impl_trait_ref.def_id { // Default value from the trait definition. No need to rebase. goal.predicate.alias.args diff --git a/compiler/rustc_next_trait_solver/src/solve/normalizes_to/opaque_types.rs b/compiler/rustc_next_trait_solver/src/solve/normalizes_to/opaque_types.rs index 710671b45d0e7..f3494328d9e48 100644 --- a/compiler/rustc_next_trait_solver/src/solve/normalizes_to/opaque_types.rs +++ b/compiler/rustc_next_trait_solver/src/solve/normalizes_to/opaque_types.rs @@ -6,19 +6,19 @@ use rustc_index::bit_set::GrowableBitSet; use rustc_type_ir::inherent::*; use rustc_type_ir::{self as ty, Interner}; -use crate::infcx::SolverDelegate; +use crate::delegate::SolverDelegate; use crate::solve::{Certainty, EvalCtxt, Goal, NoSolution, QueryResult, Reveal, SolverMode}; -impl EvalCtxt<'_, Infcx> +impl EvalCtxt<'_, D> where - Infcx: SolverDelegate, + D: SolverDelegate, I: Interner, { pub(super) fn normalize_opaque_type( &mut self, goal: Goal>, ) -> QueryResult { - let tcx = self.interner(); + let tcx = self.cx(); let opaque_ty = goal.predicate.alias; let expected = goal.predicate.term.as_type().expect("no such thing as an opaque const"); @@ -34,7 +34,7 @@ where return Err(NoSolution); } // FIXME: This may have issues when the args contain aliases... - match uses_unique_placeholders_ignoring_regions(self.interner(), opaque_ty.args) { + match uses_unique_placeholders_ignoring_regions(self.cx(), opaque_ty.args) { Err(NotUniqueParam::NotParam(param)) if param.is_non_region_infer() => { return self.evaluate_added_goals_and_make_canonical_response( Certainty::AMBIGUOUS, diff --git a/compiler/rustc_next_trait_solver/src/solve/normalizes_to/weak_types.rs b/compiler/rustc_next_trait_solver/src/solve/normalizes_to/weak_types.rs index 45341917bb24b..27d5ae07729a6 100644 --- a/compiler/rustc_next_trait_solver/src/solve/normalizes_to/weak_types.rs +++ b/compiler/rustc_next_trait_solver/src/solve/normalizes_to/weak_types.rs @@ -6,19 +6,19 @@ use rustc_type_ir::{self as ty, Interner}; -use crate::infcx::SolverDelegate; +use crate::delegate::SolverDelegate; use crate::solve::{Certainty, EvalCtxt, Goal, GoalSource, QueryResult}; -impl EvalCtxt<'_, Infcx> +impl EvalCtxt<'_, D> where - Infcx: SolverDelegate, + D: SolverDelegate, I: Interner, { pub(super) fn normalize_weak_type( &mut self, goal: Goal>, ) -> QueryResult { - let tcx = self.interner(); + let tcx = self.cx(); let weak_ty = goal.predicate.alias; // Check where clauses diff --git a/compiler/rustc_next_trait_solver/src/solve/project_goals.rs b/compiler/rustc_next_trait_solver/src/solve/project_goals.rs index 4bb1fe5be6f01..a430dbb408c5c 100644 --- a/compiler/rustc_next_trait_solver/src/solve/project_goals.rs +++ b/compiler/rustc_next_trait_solver/src/solve/project_goals.rs @@ -1,12 +1,12 @@ use rustc_type_ir::{self as ty, Interner, ProjectionPredicate}; use tracing::instrument; -use crate::infcx::SolverDelegate; +use crate::delegate::SolverDelegate; use crate::solve::{Certainty, EvalCtxt, Goal, GoalSource, QueryResult}; -impl EvalCtxt<'_, Infcx> +impl EvalCtxt<'_, D> where - Infcx: SolverDelegate, + D: SolverDelegate, I: Interner, { #[instrument(level = "trace", skip(self), ret)] @@ -14,7 +14,7 @@ where &mut self, goal: Goal>, ) -> QueryResult { - let tcx = self.interner(); + let tcx = self.cx(); let projection_term = goal.predicate.projection_term.to_term(tcx); let goal = goal.with( tcx, diff --git a/compiler/rustc_next_trait_solver/src/solve/search_graph.rs b/compiler/rustc_next_trait_solver/src/solve/search_graph.rs index b923a121d814c..91e051af20b5b 100644 --- a/compiler/rustc_next_trait_solver/src/solve/search_graph.rs +++ b/compiler/rustc_next_trait_solver/src/solve/search_graph.rs @@ -6,7 +6,7 @@ use rustc_type_ir::inherent::*; use rustc_type_ir::Interner; use tracing::debug; -use crate::infcx::SolverDelegate; +use crate::delegate::SolverDelegate; use crate::solve::inspect::{self, ProofTreeBuilder}; use crate::solve::{ CacheData, CanonicalInput, Certainty, QueryResult, SolverMode, FIXPOINT_STEP_LIMIT, @@ -250,12 +250,12 @@ impl SearchGraph { /// /// Given some goal which is proven via the `prove_goal` closure, this /// handles caching, overflow, and coinductive cycles. - pub(super) fn with_new_goal>( + pub(super) fn with_new_goal>( &mut self, tcx: I, input: CanonicalInput, - inspect: &mut ProofTreeBuilder, - mut prove_goal: impl FnMut(&mut Self, &mut ProofTreeBuilder) -> QueryResult, + inspect: &mut ProofTreeBuilder, + mut prove_goal: impl FnMut(&mut Self, &mut ProofTreeBuilder) -> QueryResult, ) -> QueryResult { self.check_invariants(); // Check for overflow. @@ -411,12 +411,12 @@ impl SearchGraph { /// Try to fetch a previously computed result from the global cache, /// making sure to only do so if it would match the result of reevaluating /// this goal. - fn lookup_global_cache>( + fn lookup_global_cache>( &mut self, tcx: I, input: CanonicalInput, available_depth: SolverLimit, - inspect: &mut ProofTreeBuilder, + inspect: &mut ProofTreeBuilder, ) -> Option> { let CacheData { result, proof_tree, additional_depth, encountered_overflow } = self .global_cache(tcx) @@ -460,16 +460,16 @@ impl SearchGraph { /// of this we continuously recompute the cycle until the result /// of the previous iteration is equal to the final result, at which /// point we are done. - fn fixpoint_step_in_task( + fn fixpoint_step_in_task( &mut self, tcx: I, input: CanonicalInput, - inspect: &mut ProofTreeBuilder, + inspect: &mut ProofTreeBuilder, prove_goal: &mut F, ) -> StepResult where - Infcx: SolverDelegate, - F: FnMut(&mut Self, &mut ProofTreeBuilder) -> QueryResult, + D: SolverDelegate, + F: FnMut(&mut Self, &mut ProofTreeBuilder) -> QueryResult, { let result = prove_goal(self, inspect); let stack_entry = self.pop_stack(); diff --git a/compiler/rustc_next_trait_solver/src/solve/trait_goals.rs b/compiler/rustc_next_trait_solver/src/solve/trait_goals.rs index d1419bf5db9a5..4042fc4f756b2 100644 --- a/compiler/rustc_next_trait_solver/src/solve/trait_goals.rs +++ b/compiler/rustc_next_trait_solver/src/solve/trait_goals.rs @@ -8,7 +8,7 @@ use rustc_type_ir::visit::TypeVisitableExt as _; use rustc_type_ir::{self as ty, Interner, TraitPredicate, Upcast as _}; use tracing::{instrument, trace}; -use crate::infcx::SolverDelegate; +use crate::delegate::SolverDelegate; use crate::solve::assembly::structural_traits::{self, AsyncCallableRelevantTypes}; use crate::solve::assembly::{self, Candidate}; use crate::solve::inspect::ProbeKind; @@ -17,9 +17,9 @@ use crate::solve::{ NoSolution, QueryResult, Reveal, SolverMode, }; -impl assembly::GoalKind for TraitPredicate +impl assembly::GoalKind for TraitPredicate where - Infcx: SolverDelegate, + D: SolverDelegate, I: Interner, { fn self_ty(self) -> I::Ty { @@ -39,11 +39,11 @@ where } fn consider_impl_candidate( - ecx: &mut EvalCtxt<'_, Infcx>, + ecx: &mut EvalCtxt<'_, D>, goal: Goal>, impl_def_id: I::DefId, ) -> Result, NoSolution> { - let tcx = ecx.interner(); + let tcx = ecx.cx(); let impl_trait_ref = tcx.impl_trait_ref(impl_def_id); if !tcx @@ -91,7 +91,7 @@ where } fn consider_error_guaranteed_candidate( - ecx: &mut EvalCtxt<'_, Infcx>, + ecx: &mut EvalCtxt<'_, D>, _guar: I::ErrorGuaranteed, ) -> Result, NoSolution> { // FIXME: don't need to enter a probe here. @@ -100,11 +100,11 @@ where } fn probe_and_match_goal_against_assumption( - ecx: &mut EvalCtxt<'_, Infcx>, + ecx: &mut EvalCtxt<'_, D>, source: CandidateSource, goal: Goal, assumption: I::Clause, - then: impl FnOnce(&mut EvalCtxt<'_, Infcx>) -> QueryResult, + then: impl FnOnce(&mut EvalCtxt<'_, D>) -> QueryResult, ) -> Result, NoSolution> { if let Some(trait_clause) = assumption.as_trait_clause() { if trait_clause.def_id() == goal.predicate.def_id() @@ -128,7 +128,7 @@ where } fn consider_auto_trait_candidate( - ecx: &mut EvalCtxt<'_, Infcx>, + ecx: &mut EvalCtxt<'_, D>, goal: Goal, ) -> Result, NoSolution> { if goal.predicate.polarity != ty::PredicatePolarity::Positive { @@ -174,14 +174,14 @@ where } fn consider_trait_alias_candidate( - ecx: &mut EvalCtxt<'_, Infcx>, + ecx: &mut EvalCtxt<'_, D>, goal: Goal, ) -> Result, NoSolution> { if goal.predicate.polarity != ty::PredicatePolarity::Positive { return Err(NoSolution); } - let tcx = ecx.interner(); + let tcx = ecx.cx(); ecx.probe_builtin_trait_candidate(BuiltinImplSource::Misc).enter(|ecx| { let nested_obligations = tcx @@ -195,7 +195,7 @@ where } fn consider_builtin_sized_candidate( - ecx: &mut EvalCtxt<'_, Infcx>, + ecx: &mut EvalCtxt<'_, D>, goal: Goal, ) -> Result, NoSolution> { if goal.predicate.polarity != ty::PredicatePolarity::Positive { @@ -210,7 +210,7 @@ where } fn consider_builtin_copy_clone_candidate( - ecx: &mut EvalCtxt<'_, Infcx>, + ecx: &mut EvalCtxt<'_, D>, goal: Goal, ) -> Result, NoSolution> { if goal.predicate.polarity != ty::PredicatePolarity::Positive { @@ -225,14 +225,14 @@ where } fn consider_builtin_pointer_like_candidate( - ecx: &mut EvalCtxt<'_, Infcx>, + ecx: &mut EvalCtxt<'_, D>, goal: Goal, ) -> Result, NoSolution> { if goal.predicate.polarity != ty::PredicatePolarity::Positive { return Err(NoSolution); } - let tcx = ecx.interner(); + let tcx = ecx.cx(); // But if there are inference variables, we have to wait until it's resolved. if (goal.param_env, goal.predicate.self_ty()).has_non_region_infer() { return ecx.forced_ambiguity(MaybeCause::Ambiguity); @@ -247,7 +247,7 @@ where } fn consider_builtin_fn_ptr_trait_candidate( - ecx: &mut EvalCtxt<'_, Infcx>, + ecx: &mut EvalCtxt<'_, D>, goal: Goal, ) -> Result, NoSolution> { let self_ty = goal.predicate.self_ty(); @@ -278,7 +278,7 @@ where } fn consider_builtin_fn_trait_candidates( - ecx: &mut EvalCtxt<'_, Infcx>, + ecx: &mut EvalCtxt<'_, D>, goal: Goal, goal_kind: ty::ClosureKind, ) -> Result, NoSolution> { @@ -286,7 +286,7 @@ where return Err(NoSolution); } - let tcx = ecx.interner(); + let tcx = ecx.cx(); let tupled_inputs_and_output = match structural_traits::extract_tupled_inputs_and_output_from_callable( tcx, @@ -319,7 +319,7 @@ where } fn consider_builtin_async_fn_trait_candidates( - ecx: &mut EvalCtxt<'_, Infcx>, + ecx: &mut EvalCtxt<'_, D>, goal: Goal, goal_kind: ty::ClosureKind, ) -> Result, NoSolution> { @@ -327,7 +327,7 @@ where return Err(NoSolution); } - let tcx = ecx.interner(); + let tcx = ecx.cx(); let (tupled_inputs_and_output_and_coroutine, nested_preds) = structural_traits::extract_tupled_inputs_and_output_from_async_callable( tcx, @@ -370,7 +370,7 @@ where } fn consider_builtin_async_fn_kind_helper_candidate( - ecx: &mut EvalCtxt<'_, Infcx>, + ecx: &mut EvalCtxt<'_, D>, goal: Goal, ) -> Result, NoSolution> { let [closure_fn_kind_ty, goal_kind_ty] = **goal.predicate.trait_ref.args else { @@ -397,7 +397,7 @@ where /// impl Tuple for (T1, .., Tn) {} /// ``` fn consider_builtin_tuple_candidate( - ecx: &mut EvalCtxt<'_, Infcx>, + ecx: &mut EvalCtxt<'_, D>, goal: Goal, ) -> Result, NoSolution> { if goal.predicate.polarity != ty::PredicatePolarity::Positive { @@ -413,7 +413,7 @@ where } fn consider_builtin_pointee_candidate( - ecx: &mut EvalCtxt<'_, Infcx>, + ecx: &mut EvalCtxt<'_, D>, goal: Goal, ) -> Result, NoSolution> { if goal.predicate.polarity != ty::PredicatePolarity::Positive { @@ -425,7 +425,7 @@ where } fn consider_builtin_future_candidate( - ecx: &mut EvalCtxt<'_, Infcx>, + ecx: &mut EvalCtxt<'_, D>, goal: Goal, ) -> Result, NoSolution> { if goal.predicate.polarity != ty::PredicatePolarity::Positive { @@ -437,7 +437,7 @@ where }; // Coroutines are not futures unless they come from `async` desugaring - let tcx = ecx.interner(); + let tcx = ecx.cx(); if !tcx.coroutine_is_async(def_id) { return Err(NoSolution); } @@ -451,7 +451,7 @@ where } fn consider_builtin_iterator_candidate( - ecx: &mut EvalCtxt<'_, Infcx>, + ecx: &mut EvalCtxt<'_, D>, goal: Goal, ) -> Result, NoSolution> { if goal.predicate.polarity != ty::PredicatePolarity::Positive { @@ -463,7 +463,7 @@ where }; // Coroutines are not iterators unless they come from `gen` desugaring - let tcx = ecx.interner(); + let tcx = ecx.cx(); if !tcx.coroutine_is_gen(def_id) { return Err(NoSolution); } @@ -477,7 +477,7 @@ where } fn consider_builtin_fused_iterator_candidate( - ecx: &mut EvalCtxt<'_, Infcx>, + ecx: &mut EvalCtxt<'_, D>, goal: Goal, ) -> Result, NoSolution> { if goal.predicate.polarity != ty::PredicatePolarity::Positive { @@ -489,7 +489,7 @@ where }; // Coroutines are not iterators unless they come from `gen` desugaring - let tcx = ecx.interner(); + let tcx = ecx.cx(); if !tcx.coroutine_is_gen(def_id) { return Err(NoSolution); } @@ -501,7 +501,7 @@ where } fn consider_builtin_async_iterator_candidate( - ecx: &mut EvalCtxt<'_, Infcx>, + ecx: &mut EvalCtxt<'_, D>, goal: Goal, ) -> Result, NoSolution> { if goal.predicate.polarity != ty::PredicatePolarity::Positive { @@ -513,7 +513,7 @@ where }; // Coroutines are not iterators unless they come from `gen` desugaring - let tcx = ecx.interner(); + let tcx = ecx.cx(); if !tcx.coroutine_is_async_gen(def_id) { return Err(NoSolution); } @@ -527,7 +527,7 @@ where } fn consider_builtin_coroutine_candidate( - ecx: &mut EvalCtxt<'_, Infcx>, + ecx: &mut EvalCtxt<'_, D>, goal: Goal, ) -> Result, NoSolution> { if goal.predicate.polarity != ty::PredicatePolarity::Positive { @@ -540,7 +540,7 @@ where }; // `async`-desugared coroutines do not implement the coroutine trait - let tcx = ecx.interner(); + let tcx = ecx.cx(); if !tcx.is_general_coroutine(def_id) { return Err(NoSolution); } @@ -559,7 +559,7 @@ where } fn consider_builtin_discriminant_kind_candidate( - ecx: &mut EvalCtxt<'_, Infcx>, + ecx: &mut EvalCtxt<'_, D>, goal: Goal, ) -> Result, NoSolution> { if goal.predicate.polarity != ty::PredicatePolarity::Positive { @@ -572,7 +572,7 @@ where } fn consider_builtin_async_destruct_candidate( - ecx: &mut EvalCtxt<'_, Infcx>, + ecx: &mut EvalCtxt<'_, D>, goal: Goal, ) -> Result, NoSolution> { if goal.predicate.polarity != ty::PredicatePolarity::Positive { @@ -585,7 +585,7 @@ where } fn consider_builtin_destruct_candidate( - ecx: &mut EvalCtxt<'_, Infcx>, + ecx: &mut EvalCtxt<'_, D>, goal: Goal, ) -> Result, NoSolution> { if goal.predicate.polarity != ty::PredicatePolarity::Positive { @@ -601,7 +601,7 @@ where } fn consider_builtin_transmute_candidate( - ecx: &mut EvalCtxt<'_, Infcx>, + ecx: &mut EvalCtxt<'_, D>, goal: Goal, ) -> Result, NoSolution> { if goal.predicate.polarity != ty::PredicatePolarity::Positive { @@ -634,7 +634,7 @@ where /// impl<'a, T: Trait + 'a> Unsize for T {} /// ``` fn consider_structural_builtin_unsize_candidates( - ecx: &mut EvalCtxt<'_, Infcx>, + ecx: &mut EvalCtxt<'_, D>, goal: Goal, ) -> Vec> { if goal.predicate.polarity != ty::PredicatePolarity::Positive { @@ -657,7 +657,7 @@ where return vec![]; }; - let goal = goal.with(ecx.interner(), (a_ty, b_ty)); + let goal = goal.with(ecx.cx(), (a_ty, b_ty)); match (a_ty.kind(), b_ty.kind()) { (ty::Infer(ty::TyVar(..)), ..) => panic!("unexpected infer {a_ty:?} {b_ty:?}"), @@ -705,9 +705,9 @@ where } } -impl EvalCtxt<'_, Infcx> +impl EvalCtxt<'_, D> where - Infcx: SolverDelegate, + D: SolverDelegate, I: Interner, { /// Trait upcasting allows for coercions between trait objects: @@ -727,7 +727,7 @@ where b_data: I::BoundExistentialPredicates, b_region: I::Region, ) -> Vec> { - let tcx = self.interner(); + let tcx = self.cx(); let Goal { predicate: (a_ty, _b_ty), .. } = goal; let mut responses = vec![]; @@ -745,8 +745,7 @@ where )); } else if let Some(a_principal) = a_data.principal() { for new_a_principal in - Infcx::elaborate_supertraits(self.interner(), a_principal.with_self_ty(tcx, a_ty)) - .skip(1) + D::elaborate_supertraits(self.cx(), a_principal.with_self_ty(tcx, a_ty)).skip(1) { responses.extend(self.consider_builtin_upcast_to_principal( goal, @@ -771,7 +770,7 @@ where b_data: I::BoundExistentialPredicates, b_region: I::Region, ) -> Result, NoSolution> { - let tcx = self.interner(); + let tcx = self.cx(); let Goal { predicate: (a_ty, _), .. } = goal; // Can only unsize to an object-safe trait. @@ -825,10 +824,10 @@ where .auto_traits() .into_iter() .chain(a_data.principal_def_id().into_iter().flat_map(|principal_def_id| { - self.interner() + self.cx() .supertrait_def_ids(principal_def_id) .into_iter() - .filter(|def_id| self.interner().trait_is_auto(*def_id)) + .filter(|def_id| self.cx().trait_is_auto(*def_id)) })) .collect(); @@ -837,7 +836,7 @@ where // having any inference side-effects. We process obligations because // unification may initially succeed due to deferred projection equality. let projection_may_match = - |ecx: &mut EvalCtxt<'_, Infcx>, + |ecx: &mut EvalCtxt<'_, D>, source_projection: ty::Binder>, target_projection: ty::Binder>| { source_projection.item_def_id() == target_projection.item_def_id() @@ -896,7 +895,7 @@ where // Also require that a_ty's lifetime outlives b_ty's lifetime. ecx.add_goal( GoalSource::ImplWhereBound, - Goal::new(ecx.interner(), param_env, ty::OutlivesPredicate(a_region, b_region)), + Goal::new(ecx.cx(), param_env, ty::OutlivesPredicate(a_region, b_region)), ); ecx.evaluate_added_goals_and_make_canonical_response(Certainty::Yes) @@ -942,7 +941,7 @@ where a_args: I::GenericArgs, b_args: I::GenericArgs, ) -> Result, NoSolution> { - let tcx = self.interner(); + let tcx = self.cx(); let Goal { predicate: (_a_ty, b_ty), .. } = goal; let unsizing_params = tcx.unsizing_params_for_adt(def.def_id()); @@ -1002,7 +1001,7 @@ where a_tys: I::Tys, b_tys: I::Tys, ) -> Result, NoSolution> { - let tcx = self.interner(); + let tcx = self.cx(); let Goal { predicate: (_a_ty, b_ty), .. } = goal; let (&a_last_ty, a_rest_tys) = a_tys.split_last().unwrap(); @@ -1062,11 +1061,9 @@ where // takes precedence over the structural auto trait candidate being // assembled. ty::Coroutine(def_id, _) - if self - .interner() - .is_lang_item(goal.predicate.def_id(), TraitSolverLangItem::Unpin) => + if self.cx().is_lang_item(goal.predicate.def_id(), TraitSolverLangItem::Unpin) => { - match self.interner().coroutine_movability(def_id) { + match self.cx().coroutine_movability(def_id) { Movability::Static => Some(Err(NoSolution)), Movability::Movable => Some( self.probe_builtin_trait_candidate(BuiltinImplSource::Misc).enter(|ecx| { @@ -1111,7 +1108,7 @@ where | ty::Tuple(_) | ty::Adt(_, _) => { let mut disqualifying_impl = None; - self.interner().for_each_relevant_impl( + self.cx().for_each_relevant_impl( goal.predicate.def_id(), goal.predicate.self_ty(), |impl_def_id| { @@ -1140,7 +1137,7 @@ where source: CandidateSource, goal: Goal>, constituent_tys: impl Fn( - &EvalCtxt<'_, Infcx>, + &EvalCtxt<'_, D>, I::Ty, ) -> Result>, NoSolution>, ) -> Result, NoSolution> { @@ -1151,10 +1148,7 @@ where .into_iter() .map(|ty| { ecx.enter_forall(ty, |ty| { - goal.with( - ecx.interner(), - goal.predicate.with_self_ty(ecx.interner(), ty), - ) + goal.with(ecx.cx(), goal.predicate.with_self_ty(ecx.cx(), ty)) }) }) .collect::>(), diff --git a/compiler/rustc_sanitizers/src/cfi/typeid/itanium_cxx_abi/transform.rs b/compiler/rustc_sanitizers/src/cfi/typeid/itanium_cxx_abi/transform.rs index 832efb1199926..44c50ffcef61c 100644 --- a/compiler/rustc_sanitizers/src/cfi/typeid/itanium_cxx_abi/transform.rs +++ b/compiler/rustc_sanitizers/src/cfi/typeid/itanium_cxx_abi/transform.rs @@ -213,7 +213,7 @@ impl<'tcx> TypeFolder> for TransformTy<'tcx> { } } - fn interner(&self) -> TyCtxt<'tcx> { + fn cx(&self) -> TyCtxt<'tcx> { self.tcx } } diff --git a/compiler/rustc_trait_selection/src/solve.rs b/compiler/rustc_trait_selection/src/solve.rs index a7c8cc5a32b60..e47f5389cd180 100644 --- a/compiler/rustc_trait_selection/src/solve.rs +++ b/compiler/rustc_trait_selection/src/solve.rs @@ -1,7 +1,7 @@ pub use rustc_next_trait_solver::solve::*; +mod delegate; mod fulfill; -mod infcx; pub mod inspect; mod normalize; mod select; diff --git a/compiler/rustc_trait_selection/src/solve/infcx.rs b/compiler/rustc_trait_selection/src/solve/delegate.rs similarity index 99% rename from compiler/rustc_trait_selection/src/solve/infcx.rs rename to compiler/rustc_trait_selection/src/solve/delegate.rs index e574166cbfc26..643d5f804808a 100644 --- a/compiler/rustc_trait_selection/src/solve/infcx.rs +++ b/compiler/rustc_trait_selection/src/solve/delegate.rs @@ -39,10 +39,10 @@ impl<'tcx> Deref for SolverDelegate<'tcx> { } } -impl<'tcx> rustc_next_trait_solver::infcx::SolverDelegate for SolverDelegate<'tcx> { +impl<'tcx> rustc_next_trait_solver::delegate::SolverDelegate for SolverDelegate<'tcx> { type Interner = TyCtxt<'tcx>; - fn interner(&self) -> TyCtxt<'tcx> { + fn cx(&self) -> TyCtxt<'tcx> { self.0.tcx } diff --git a/compiler/rustc_trait_selection/src/solve/fulfill.rs b/compiler/rustc_trait_selection/src/solve/fulfill.rs index 8937ed467a1fd..76b88aeb0f7e6 100644 --- a/compiler/rustc_trait_selection/src/solve/fulfill.rs +++ b/compiler/rustc_trait_selection/src/solve/fulfill.rs @@ -17,7 +17,7 @@ use rustc_span::symbol::sym; use crate::traits::{FulfillmentError, FulfillmentErrorCode, ScrubbedTraitError}; -use super::infcx::SolverDelegate; +use super::delegate::SolverDelegate; use super::inspect::{self, ProofTreeInferCtxtExt, ProofTreeVisitor}; use super::Certainty; diff --git a/compiler/rustc_trait_selection/src/solve/inspect/analyse.rs b/compiler/rustc_trait_selection/src/solve/inspect/analyse.rs index cb621487125f7..e8de8457440ff 100644 --- a/compiler/rustc_trait_selection/src/solve/inspect/analyse.rs +++ b/compiler/rustc_trait_selection/src/solve/inspect/analyse.rs @@ -22,7 +22,7 @@ use rustc_next_trait_solver::solve::inspect::{self, instantiate_canonical_state} use rustc_next_trait_solver::solve::{GenerateProofTree, MaybeCause, SolverDelegateEvalExt as _}; use rustc_span::{Span, DUMMY_SP}; -use crate::solve::infcx::SolverDelegate; +use crate::solve::delegate::SolverDelegate; use crate::traits::ObligationCtxt; pub struct InspectConfig { diff --git a/compiler/rustc_trait_selection/src/solve/normalize.rs b/compiler/rustc_trait_selection/src/solve/normalize.rs index f42edebfcc42e..2679da942b763 100644 --- a/compiler/rustc_trait_selection/src/solve/normalize.rs +++ b/compiler/rustc_trait_selection/src/solve/normalize.rs @@ -156,7 +156,7 @@ where { type Error = Vec; - fn interner(&self) -> TyCtxt<'tcx> { + fn cx(&self) -> TyCtxt<'tcx> { self.at.infcx.tcx } @@ -244,7 +244,7 @@ struct DeeplyNormalizeForDiagnosticsFolder<'a, 'tcx> { } impl<'tcx> TypeFolder> for DeeplyNormalizeForDiagnosticsFolder<'_, 'tcx> { - fn interner(&self) -> TyCtxt<'tcx> { + fn cx(&self) -> TyCtxt<'tcx> { self.at.infcx.tcx } 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 038f11c60b80a..0370c22d151eb 100644 --- a/compiler/rustc_trait_selection/src/traits/error_reporting/suggestions.rs +++ b/compiler/rustc_trait_selection/src/traits/error_reporting/suggestions.rs @@ -4918,7 +4918,7 @@ impl<'tcx> TypeFolder> for ReplaceImplTraitFolder<'tcx> { t.super_fold_with(self) } - fn interner(&self) -> TyCtxt<'tcx> { + fn cx(&self) -> TyCtxt<'tcx> { self.tcx } } 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 e38f795119772..58e29ca868696 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 @@ -2847,7 +2847,7 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> { } impl<'a, 'tcx> TypeFolder> for ParamToVarFolder<'a, 'tcx> { - fn interner(&self) -> TyCtxt<'tcx> { + fn cx(&self) -> TyCtxt<'tcx> { self.infcx.tcx } diff --git a/compiler/rustc_trait_selection/src/traits/mod.rs b/compiler/rustc_trait_selection/src/traits/mod.rs index af6bfdae44029..662d95db8ba5c 100644 --- a/compiler/rustc_trait_selection/src/traits/mod.rs +++ b/compiler/rustc_trait_selection/src/traits/mod.rs @@ -350,7 +350,7 @@ pub fn normalize_param_env_or_error<'tcx>( struct ConstNormalizer<'tcx>(TyCtxt<'tcx>); impl<'tcx> TypeFolder> for ConstNormalizer<'tcx> { - fn interner(&self) -> TyCtxt<'tcx> { + fn cx(&self) -> TyCtxt<'tcx> { self.0 } diff --git a/compiler/rustc_trait_selection/src/traits/normalize.rs b/compiler/rustc_trait_selection/src/traits/normalize.rs index e7ab0b7791c43..3826cb6f8f89d 100644 --- a/compiler/rustc_trait_selection/src/traits/normalize.rs +++ b/compiler/rustc_trait_selection/src/traits/normalize.rs @@ -162,7 +162,7 @@ impl<'a, 'b, 'tcx> AssocTypeNormalizer<'a, 'b, 'tcx> { } impl<'a, 'b, 'tcx> TypeFolder> for AssocTypeNormalizer<'a, 'b, 'tcx> { - fn interner(&self) -> TyCtxt<'tcx> { + fn cx(&self) -> TyCtxt<'tcx> { self.selcx.tcx() } @@ -216,7 +216,7 @@ impl<'a, 'b, 'tcx> TypeFolder> for AssocTypeNormalizer<'a, 'b, 'tcx Reveal::UserFacing => ty.super_fold_with(self), Reveal::All => { - let recursion_limit = self.interner().recursion_limit(); + let recursion_limit = self.cx().recursion_limit(); if !recursion_limit.value_within_limit(self.depth) { self.selcx.infcx.err_ctxt().report_overflow_error( OverflowCause::DeeplyNormalize(data.into()), @@ -227,8 +227,8 @@ impl<'a, 'b, 'tcx> TypeFolder> for AssocTypeNormalizer<'a, 'b, 'tcx } let args = data.args.fold_with(self); - let generic_ty = self.interner().type_of(data.def_id); - let concrete_ty = generic_ty.instantiate(self.interner(), args); + let generic_ty = self.cx().type_of(data.def_id); + let concrete_ty = generic_ty.instantiate(self.cx(), args); self.depth += 1; let folded_ty = self.fold_ty(concrete_ty); self.depth -= 1; @@ -312,7 +312,7 @@ impl<'a, 'b, 'tcx> TypeFolder> for AssocTypeNormalizer<'a, 'b, 'tcx normalized_ty } ty::Weak => { - let recursion_limit = self.interner().recursion_limit(); + let recursion_limit = self.cx().recursion_limit(); if !recursion_limit.value_within_limit(self.depth) { self.selcx.infcx.err_ctxt().report_overflow_error( OverflowCause::DeeplyNormalize(data.into()), diff --git a/compiler/rustc_trait_selection/src/traits/query/normalize.rs b/compiler/rustc_trait_selection/src/traits/query/normalize.rs index e170d7cae9379..bed76b84ee075 100644 --- a/compiler/rustc_trait_selection/src/traits/query/normalize.rs +++ b/compiler/rustc_trait_selection/src/traits/query/normalize.rs @@ -172,7 +172,7 @@ struct QueryNormalizer<'cx, 'tcx> { impl<'cx, 'tcx> FallibleTypeFolder> for QueryNormalizer<'cx, 'tcx> { type Error = NoSolution; - fn interner(&self) -> TyCtxt<'tcx> { + fn cx(&self) -> TyCtxt<'tcx> { self.infcx.tcx } @@ -217,7 +217,7 @@ impl<'cx, 'tcx> FallibleTypeFolder> for QueryNormalizer<'cx, 'tcx> Reveal::All => { let args = data.args.try_fold_with(self)?; - let recursion_limit = self.interner().recursion_limit(); + let recursion_limit = self.cx().recursion_limit(); if !recursion_limit.value_within_limit(self.anon_depth) { let guar = self @@ -229,15 +229,15 @@ impl<'cx, 'tcx> FallibleTypeFolder> for QueryNormalizer<'cx, 'tcx> true, ) .delay_as_bug(); - return Ok(Ty::new_error(self.interner(), guar)); + return Ok(Ty::new_error(self.cx(), guar)); } - let generic_ty = self.interner().type_of(data.def_id); - let mut concrete_ty = generic_ty.instantiate(self.interner(), args); + let generic_ty = self.cx().type_of(data.def_id); + let mut concrete_ty = generic_ty.instantiate(self.cx(), args); self.anon_depth += 1; if concrete_ty == ty { concrete_ty = Ty::new_error_with_message( - self.interner(), + self.cx(), DUMMY_SP, "recursive opaque type", ); diff --git a/compiler/rustc_trait_selection/src/traits/util.rs b/compiler/rustc_trait_selection/src/traits/util.rs index c3fe816028e33..f132e36468ac2 100644 --- a/compiler/rustc_trait_selection/src/traits/util.rs +++ b/compiler/rustc_trait_selection/src/traits/util.rs @@ -394,7 +394,7 @@ impl<'me, 'tcx> BoundVarReplacer<'me, 'tcx> { } impl<'tcx> TypeFolder> for BoundVarReplacer<'_, 'tcx> { - fn interner(&self) -> TyCtxt<'tcx> { + fn cx(&self) -> TyCtxt<'tcx> { self.infcx.tcx } @@ -509,7 +509,7 @@ impl<'me, 'tcx> PlaceholderReplacer<'me, 'tcx> { } impl<'tcx> TypeFolder> for PlaceholderReplacer<'_, 'tcx> { - fn interner(&self) -> TyCtxt<'tcx> { + fn cx(&self) -> TyCtxt<'tcx> { self.infcx.tcx } @@ -550,7 +550,7 @@ impl<'tcx> TypeFolder> for PlaceholderReplacer<'_, 'tcx> { let db = ty::DebruijnIndex::from_usize( self.universe_indices.len() - index + self.current_index.as_usize() - 1, ); - ty::Region::new_bound(self.interner(), db, *replace_var) + ty::Region::new_bound(self.cx(), db, *replace_var) } None => r1, } diff --git a/compiler/rustc_type_ir/src/binder.rs b/compiler/rustc_type_ir/src/binder.rs index e50d59ba5f0e6..dab96c05fdca7 100644 --- a/compiler/rustc_type_ir/src/binder.rs +++ b/compiler/rustc_type_ir/src/binder.rs @@ -620,7 +620,7 @@ struct ArgFolder<'a, I: Interner> { impl<'a, I: Interner> TypeFolder for ArgFolder<'a, I> { #[inline] - fn interner(&self) -> I { + fn cx(&self) -> I { self.tcx } @@ -840,7 +840,7 @@ impl<'a, I: Interner> ArgFolder<'a, I> { return val; } - let result = ty::fold::shift_vars(TypeFolder::interner(self), val, self.binders_passed); + let result = ty::fold::shift_vars(TypeFolder::cx(self), val, self.binders_passed); debug!("shift_vars: shifted result = {:?}", result); result diff --git a/compiler/rustc_type_ir/src/fold.rs b/compiler/rustc_type_ir/src/fold.rs index ee3e5ce66d038..0c6b137114391 100644 --- a/compiler/rustc_type_ir/src/fold.rs +++ b/compiler/rustc_type_ir/src/fold.rs @@ -128,7 +128,7 @@ pub trait TypeSuperFoldable: TypeFoldable { /// the infallible methods of this trait to ensure that the two APIs /// are coherent. pub trait TypeFolder: FallibleTypeFolder { - fn interner(&self) -> I; + fn cx(&self) -> I; fn fold_binder(&mut self, t: ty::Binder) -> ty::Binder where @@ -166,7 +166,7 @@ pub trait TypeFolder: FallibleTypeFolder { pub trait FallibleTypeFolder: Sized { type Error; - fn interner(&self) -> I; + fn cx(&self) -> I; fn try_fold_binder(&mut self, t: ty::Binder) -> Result, Self::Error> where @@ -202,8 +202,8 @@ where { type Error = Never; - fn interner(&self) -> I { - TypeFolder::interner(self) + fn cx(&self) -> I { + TypeFolder::cx(self) } fn try_fold_binder(&mut self, t: ty::Binder) -> Result, Never> @@ -350,7 +350,7 @@ impl Shifter { } impl TypeFolder for Shifter { - fn interner(&self) -> I { + fn cx(&self) -> I { self.tcx } diff --git a/compiler/rustc_type_ir/src/ty_kind/closure.rs b/compiler/rustc_type_ir/src/ty_kind/closure.rs index 97752934632c4..3a17a27bd03bb 100644 --- a/compiler/rustc_type_ir/src/ty_kind/closure.rs +++ b/compiler/rustc_type_ir/src/ty_kind/closure.rs @@ -521,7 +521,7 @@ struct FoldEscapingRegions { } impl TypeFolder for FoldEscapingRegions { - fn interner(&self) -> I { + fn cx(&self) -> I { self.interner } From 3594a19f2ae792cf99a1a78a5454e52cfd7affde Mon Sep 17 00:00:00 2001 From: Oli Scherer Date: Mon, 17 Jun 2024 08:34:26 +0000 Subject: [PATCH 11/23] Taint infcx when reporting errors --- .../error_reporting/type_err_ctxt_ext.rs | 23 ++--- tests/crashes/122044.rs | 38 -------- tests/crashes/123255.rs | 13 --- .../incremental/const-generics/issue-64087.rs | 2 + .../const-generics/defaults/doesnt_infer.rs | 1 + .../defaults/doesnt_infer.stderr | 31 ++++++- .../defaults/rp_impl_trait_fail.stderr | 9 +- .../generic_arg_infer/issue-91614.rs | 1 + .../generic_arg_infer/issue-91614.stderr | 28 +++--- .../issue-62504.full.stderr | 33 ++++++- .../issue-62504.min.stderr | 33 ++++++- .../generic_const_exprs/issue-62504.rs | 1 + .../object-safety-ok-infer-err.rs | 1 + .../object-safety-ok-infer-err.stderr | 27 +++++- .../infer/cannot-infer-const-args.stderr | 9 +- tests/ui/const-generics/infer/issue-77092.rs | 5 +- .../const-generics/infer/issue-77092.stderr | 29 +++++- .../const-generics/infer/method-chain.stderr | 9 +- .../infer/one-param-uninferred.stderr | 9 +- .../const-generics/infer/uninferred-consts.rs | 1 + .../infer/uninferred-consts.stderr | 27 +++++- .../const-generics/mistyped_const_in_pat.rs} | 4 +- .../mistyped_const_in_pat.stderr | 12 +++ ...ent_generics_of_encoding_impl_trait.stderr | 4 +- .../unify_with_nested_expr.stderr | 7 +- tests/ui/impl-trait/upvar_captures.rs | 16 ++++ tests/ui/impl-trait/upvar_captures.stderr | 14 +++ tests/ui/inference/issue-83606.stderr | 11 ++- tests/ui/issues/issue-98299.rs | 2 + tests/ui/issues/issue-98299.stderr | 55 ++++++++++- .../const_derives/derive-const-use.stderr | 34 ++++++- .../trait-default-body-stability.stderr | 92 ++++++++++++++++++- tests/ui/wf/conflicting-impls.rs | 2 - tests/ui/wf/conflicting-impls.stderr | 27 +----- .../normalization-of-unknown-type.rs} | 8 +- .../normalization-of-unknown-type.stderr | 9 ++ 36 files changed, 470 insertions(+), 157 deletions(-) delete mode 100644 tests/crashes/122044.rs delete mode 100644 tests/crashes/123255.rs rename tests/{crashes/125799.rs => ui/const-generics/mistyped_const_in_pat.rs} (64%) create mode 100644 tests/ui/const-generics/mistyped_const_in_pat.stderr create mode 100644 tests/ui/impl-trait/upvar_captures.rs create mode 100644 tests/ui/impl-trait/upvar_captures.stderr rename tests/{crashes/123276.rs => ui/where-clauses/normalization-of-unknown-type.rs} (59%) create mode 100644 tests/ui/where-clauses/normalization-of-unknown-type.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 e38f795119772..b5f2d34852fc1 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 @@ -179,6 +179,7 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> { for (error, suppressed) in iter::zip(&errors, &is_suppressed) { if !suppressed && error.obligation.cause.span.from_expansion() == from_expansion { let guar = self.report_fulfillment_error(error); + self.infcx.set_tainted_by_errors(guar); reported = Some(guar); // We want to ignore desugarings here: spans are equivalent even // if one is the result of a desugaring and the other is not. @@ -2686,22 +2687,14 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> { } } - // Given some `ConstArgHasType(?x, usize)`, we should not emit an error such as - // "type annotations needed: cannot satisfy the constant `_` has type `usize`" - // Instead we should emit a normal error suggesting the user to turbofish the - // const parameter that is currently being inferred. Unfortunately we cannot - // nicely emit such an error so we delay an ICE incase nobody else reports it - // for us. - ty::PredicateKind::Clause(ty::ClauseKind::ConstArgHasType(ct, ty)) => { - return self.tcx.sess.dcx().span_delayed_bug( + ty::PredicateKind::Clause(ty::ClauseKind::ConstArgHasType(ct, ..)) => self + .emit_inference_failure_err( + obligation.cause.body_id, span, - format!( - "`ambiguous ConstArgHasType({:?}, {:?}) unaccompanied by inference error`", - ct, ty - ), - ); - } - + ct.into(), + ErrorCode::E0284, + true, + ), ty::PredicateKind::NormalizesTo(ty::NormalizesTo { alias, term }) if term.is_infer() => { diff --git a/tests/crashes/122044.rs b/tests/crashes/122044.rs deleted file mode 100644 index 4c1d0de5719e8..0000000000000 --- a/tests/crashes/122044.rs +++ /dev/null @@ -1,38 +0,0 @@ -//@ known-bug: #122044 -use std::hint::black_box; - -trait Func { - type Ret: Id; -} - -trait Id { - type Assoc; -} -impl Id for u32 {} -impl Id for u32 {} - -impl R, R: Id> Func for F { - type Ret = R; -} - -fn bar() -> impl Copy + Id { - 0u32 -} - -struct Foo { - _func: T, - value: Option<<::Ret as Id>::Assoc>, -} - -fn main() { - let mut fn_def = black_box(Foo { - _func: bar, - value: None, - }); - let fn_ptr = black_box(Foo { - _func: bar as fn() -> _, - value: None, - }); - - fn_def.value = fn_ptr.value; -} diff --git a/tests/crashes/123255.rs b/tests/crashes/123255.rs deleted file mode 100644 index a94a2a0422e7e..0000000000000 --- a/tests/crashes/123255.rs +++ /dev/null @@ -1,13 +0,0 @@ -//@ known-bug: rust-lang/rust#123255 -//@ edition:2021 -#![crate_type = "lib"] - -pub fn a() {} - -mod handlers { - pub struct C(&()); - pub fn c() -> impl Fn() -> C { - let a1 = (); - || C((crate::a(), a1).into()) - } -} diff --git a/tests/incremental/const-generics/issue-64087.rs b/tests/incremental/const-generics/issue-64087.rs index 97f212b3fbba7..787f2af8aa396 100644 --- a/tests/incremental/const-generics/issue-64087.rs +++ b/tests/incremental/const-generics/issue-64087.rs @@ -6,4 +6,6 @@ fn combinator() -> [T; S] {} fn main() { combinator().into_iter(); //[cfail1]~^ ERROR type annotations needed + //[cfail1]~| ERROR type annotations needed + //[cfail1]~| ERROR type annotations needed } diff --git a/tests/ui/const-generics/defaults/doesnt_infer.rs b/tests/ui/const-generics/defaults/doesnt_infer.rs index 016685eee9df7..f62088210fed7 100644 --- a/tests/ui/const-generics/defaults/doesnt_infer.rs +++ b/tests/ui/const-generics/defaults/doesnt_infer.rs @@ -12,4 +12,5 @@ fn main() { let foo = Foo::<1>::foo(); let foo = Foo::foo(); //~^ ERROR type annotations needed for `Foo<_>` + //~| ERROR type annotations needed } diff --git a/tests/ui/const-generics/defaults/doesnt_infer.stderr b/tests/ui/const-generics/defaults/doesnt_infer.stderr index 1e779f75ce081..e099289827e93 100644 --- a/tests/ui/const-generics/defaults/doesnt_infer.stderr +++ b/tests/ui/const-generics/defaults/doesnt_infer.stderr @@ -1,14 +1,37 @@ -error[E0282]: type annotations needed for `Foo<_>` +error[E0284]: type annotations needed for `Foo<_>` --> $DIR/doesnt_infer.rs:13:9 | LL | let foo = Foo::foo(); - | ^^^ + | ^^^ ---------- type must be known at this point | +note: required by a bound in `Foo::::foo` + --> $DIR/doesnt_infer.rs:5:6 + | +LL | impl Foo { + | ^^^^^^^^^^^^ required by this bound in `Foo::::foo` +LL | fn foo() -> Self { + | --- required by a bound in this associated function +help: consider giving `foo` an explicit type, where the value of const parameter `N` is specified + | +LL | let foo: Foo = Foo::foo(); + | ++++++++ + +error[E0284]: type annotations needed for `Foo<_>` + --> $DIR/doesnt_infer.rs:13:9 + | +LL | let foo = Foo::foo(); + | ^^^ --- type must be known at this point + | +note: required by a bound in `Foo` + --> $DIR/doesnt_infer.rs:3:12 + | +LL | struct Foo; + | ^^^^^^^^^^^^^^^^ required by this bound in `Foo` help: consider giving `foo` an explicit type, where the value of const parameter `N` is specified | LL | let foo: Foo = Foo::foo(); | ++++++++ -error: aborting due to 1 previous error +error: aborting due to 2 previous errors -For more information about this error, try `rustc --explain E0282`. +For more information about this error, try `rustc --explain E0284`. diff --git a/tests/ui/const-generics/defaults/rp_impl_trait_fail.stderr b/tests/ui/const-generics/defaults/rp_impl_trait_fail.stderr index 4ed1c0ded9f86..d91e717b3ebe5 100644 --- a/tests/ui/const-generics/defaults/rp_impl_trait_fail.stderr +++ b/tests/ui/const-generics/defaults/rp_impl_trait_fail.stderr @@ -31,12 +31,17 @@ LL | 1_u64 | = help: the trait `Traitor<1, 2>` is implemented for `u64` -error[E0282]: type annotations needed +error[E0284]: type annotations needed --> $DIR/rp_impl_trait_fail.rs:28:5 | LL | uwu(); | ^^^ cannot infer the value of the const parameter `N` declared on the function `uwu` | +note: required by a bound in `uwu` + --> $DIR/rp_impl_trait_fail.rs:16:8 + | +LL | fn uwu() -> impl Traitor { + | ^^^^^^^^^^^ required by this bound in `uwu` help: consider specifying the generic argument | LL | uwu::(); @@ -44,5 +49,5 @@ LL | uwu::(); error: aborting due to 4 previous errors -Some errors have detailed explanations: E0277, E0282. +Some errors have detailed explanations: E0277, E0284. For more information about an error, try `rustc --explain E0277`. diff --git a/tests/ui/const-generics/generic_arg_infer/issue-91614.rs b/tests/ui/const-generics/generic_arg_infer/issue-91614.rs index cfbc5faecd9cc..a386b1e5c2bf5 100644 --- a/tests/ui/const-generics/generic_arg_infer/issue-91614.rs +++ b/tests/ui/const-generics/generic_arg_infer/issue-91614.rs @@ -5,4 +5,5 @@ use std::simd::Mask; fn main() { let y = Mask::<_, _>::splat(false); //~^ ERROR: type annotations needed + //~| ERROR type annotations needed } diff --git a/tests/ui/const-generics/generic_arg_infer/issue-91614.stderr b/tests/ui/const-generics/generic_arg_infer/issue-91614.stderr index 563406ad5eaa9..b6982e05b8895 100644 --- a/tests/ui/const-generics/generic_arg_infer/issue-91614.stderr +++ b/tests/ui/const-generics/generic_arg_infer/issue-91614.stderr @@ -1,23 +1,29 @@ -error[E0283]: type annotations needed for `Mask<_, _>` +error[E0284]: type annotations needed for `Mask<_, _>` --> $DIR/issue-91614.rs:6:9 | LL | let y = Mask::<_, _>::splat(false); | ^ -------------------------- type must be known at this point | - = note: cannot satisfy `_: MaskElement` - = help: the following types implement trait `MaskElement`: - i16 - i32 - i64 - i8 - isize note: required by a bound in `Mask::::splat` --> $SRC_DIR/core/src/../../portable-simd/crates/core_simd/src/masks.rs:LL:COL -help: consider giving `y` an explicit type, where the type for type parameter `T` is specified +help: consider giving `y` an explicit type, where the value of const parameter `N` is specified | LL | let y: Mask = Mask::<_, _>::splat(false); | ++++++++++++ -error: aborting due to 1 previous error +error[E0284]: type annotations needed for `Mask<_, _>` + --> $DIR/issue-91614.rs:6:9 + | +LL | let y = Mask::<_, _>::splat(false); + | ^ ------------ type must be known at this point + | +note: required by a bound in `Mask` + --> $SRC_DIR/core/src/../../portable-simd/crates/core_simd/src/masks.rs:LL:COL +help: consider giving `y` an explicit type, where the value of const parameter `N` is specified + | +LL | let y: Mask = Mask::<_, _>::splat(false); + | ++++++++++++ + +error: aborting due to 2 previous errors -For more information about this error, try `rustc --explain E0283`. +For more information about this error, try `rustc --explain E0284`. diff --git a/tests/ui/const-generics/generic_const_exprs/issue-62504.full.stderr b/tests/ui/const-generics/generic_const_exprs/issue-62504.full.stderr index 5cda4681b5c8b..27411646cb72e 100644 --- a/tests/ui/const-generics/generic_const_exprs/issue-62504.full.stderr +++ b/tests/ui/const-generics/generic_const_exprs/issue-62504.full.stderr @@ -18,18 +18,41 @@ help: try adding a `where` bound LL | pub const fn new() -> Self where [(); Self::SIZE]: { | +++++++++++++++++++++++ -error[E0282]: type annotations needed for `ArrayHolder<_>` +error[E0284]: type annotations needed for `ArrayHolder<_>` --> $DIR/issue-62504.rs:26:9 | LL | let mut array = ArrayHolder::new(); - | ^^^^^^^^^ + | ^^^^^^^^^ ------------------ type must be known at this point | +note: required by a bound in `ArrayHolder::::new` + --> $DIR/issue-62504.rs:16:6 + | +LL | impl ArrayHolder { + | ^^^^^^^^^^^^^^ required by this bound in `ArrayHolder::::new` +LL | pub const fn new() -> Self { + | --- required by a bound in this associated function +help: consider giving `array` an explicit type, where the value of const parameter `X` is specified + | +LL | let mut array: ArrayHolder = ArrayHolder::new(); + | ++++++++++++++++ + +error[E0284]: type annotations needed for `ArrayHolder<_>` + --> $DIR/issue-62504.rs:26:9 + | +LL | let mut array = ArrayHolder::new(); + | ^^^^^^^^^ ----------- type must be known at this point + | +note: required by a bound in `ArrayHolder` + --> $DIR/issue-62504.rs:14:20 + | +LL | struct ArrayHolder([u32; X]); + | ^^^^^^^^^^^^^^ required by this bound in `ArrayHolder` help: consider giving `array` an explicit type, where the value of const parameter `X` is specified | LL | let mut array: ArrayHolder = ArrayHolder::new(); | ++++++++++++++++ -error: aborting due to 3 previous errors +error: aborting due to 4 previous errors -Some errors have detailed explanations: E0282, E0308. -For more information about an error, try `rustc --explain E0282`. +Some errors have detailed explanations: E0284, E0308. +For more information about an error, try `rustc --explain E0284`. diff --git a/tests/ui/const-generics/generic_const_exprs/issue-62504.min.stderr b/tests/ui/const-generics/generic_const_exprs/issue-62504.min.stderr index beb159779ff5c..036b9001c03db 100644 --- a/tests/ui/const-generics/generic_const_exprs/issue-62504.min.stderr +++ b/tests/ui/const-generics/generic_const_exprs/issue-62504.min.stderr @@ -22,18 +22,41 @@ note: tuple struct defined here LL | struct ArrayHolder([u32; X]); | ^^^^^^^^^^^ -error[E0282]: type annotations needed for `ArrayHolder<_>` +error[E0284]: type annotations needed for `ArrayHolder<_>` --> $DIR/issue-62504.rs:26:9 | LL | let mut array = ArrayHolder::new(); - | ^^^^^^^^^ + | ^^^^^^^^^ ------------------ type must be known at this point | +note: required by a bound in `ArrayHolder::::new` + --> $DIR/issue-62504.rs:16:6 + | +LL | impl ArrayHolder { + | ^^^^^^^^^^^^^^ required by this bound in `ArrayHolder::::new` +LL | pub const fn new() -> Self { + | --- required by a bound in this associated function +help: consider giving `array` an explicit type, where the value of const parameter `X` is specified + | +LL | let mut array: ArrayHolder = ArrayHolder::new(); + | ++++++++++++++++ + +error[E0284]: type annotations needed for `ArrayHolder<_>` + --> $DIR/issue-62504.rs:26:9 + | +LL | let mut array = ArrayHolder::new(); + | ^^^^^^^^^ ----------- type must be known at this point + | +note: required by a bound in `ArrayHolder` + --> $DIR/issue-62504.rs:14:20 + | +LL | struct ArrayHolder([u32; X]); + | ^^^^^^^^^^^^^^ required by this bound in `ArrayHolder` help: consider giving `array` an explicit type, where the value of const parameter `X` is specified | LL | let mut array: ArrayHolder = ArrayHolder::new(); | ++++++++++++++++ -error: aborting due to 3 previous errors +error: aborting due to 4 previous errors -Some errors have detailed explanations: E0282, E0308. -For more information about an error, try `rustc --explain E0282`. +Some errors have detailed explanations: E0284, E0308. +For more information about an error, try `rustc --explain E0284`. diff --git a/tests/ui/const-generics/generic_const_exprs/issue-62504.rs b/tests/ui/const-generics/generic_const_exprs/issue-62504.rs index b6a6a277843af..f021e1036143b 100644 --- a/tests/ui/const-generics/generic_const_exprs/issue-62504.rs +++ b/tests/ui/const-generics/generic_const_exprs/issue-62504.rs @@ -25,4 +25,5 @@ impl ArrayHolder { fn main() { let mut array = ArrayHolder::new(); //~^ ERROR: type annotations needed + //~| ERROR type annotations needed } diff --git a/tests/ui/const-generics/generic_const_exprs/object-safety-ok-infer-err.rs b/tests/ui/const-generics/generic_const_exprs/object-safety-ok-infer-err.rs index 79e9834b54ed2..298cfb512e418 100644 --- a/tests/ui/const-generics/generic_const_exprs/object-safety-ok-infer-err.rs +++ b/tests/ui/const-generics/generic_const_exprs/object-safety-ok-infer-err.rs @@ -18,4 +18,5 @@ fn use_dyn(v: &dyn Foo) where [u8; N + 1]: Sized { fn main() { use_dyn(&()); //~^ ERROR type annotations needed + //~| ERROR type annotations needed } diff --git a/tests/ui/const-generics/generic_const_exprs/object-safety-ok-infer-err.stderr b/tests/ui/const-generics/generic_const_exprs/object-safety-ok-infer-err.stderr index e800c5d059f43..0c290448fc5a8 100644 --- a/tests/ui/const-generics/generic_const_exprs/object-safety-ok-infer-err.stderr +++ b/tests/ui/const-generics/generic_const_exprs/object-safety-ok-infer-err.stderr @@ -5,15 +5,36 @@ LL | use_dyn(&()); | ^^^^^^^ cannot infer the value of the const parameter `N` declared on the function `use_dyn` | note: required by a bound in `use_dyn` - --> $DIR/object-safety-ok-infer-err.rs:14:55 + --> $DIR/object-safety-ok-infer-err.rs:14:12 | LL | fn use_dyn(v: &dyn Foo) where [u8; N + 1]: Sized { - | ^^^^^ required by this bound in `use_dyn` + | ^^^^^^^^^^^^^^ required by this bound in `use_dyn` help: consider specifying the generic argument | LL | use_dyn::(&()); | +++++ -error: aborting due to 1 previous error +error[E0284]: type annotations needed + --> $DIR/object-safety-ok-infer-err.rs:19:5 + | +LL | use_dyn(&()); + | ^^^^^^^ --- type must be known at this point + | | + | cannot infer the value of the const parameter `N` declared on the function `use_dyn` + | +note: required for `()` to implement `Foo<_>` + --> $DIR/object-safety-ok-infer-err.rs:8:22 + | +LL | impl Foo for () { + | -------------- ^^^^^^ ^^ + | | + | unsatisfied trait bound introduced here + = note: required for the cast from `&()` to `&dyn Foo<_>` +help: consider specifying the generic argument + | +LL | use_dyn::(&()); + | +++++ + +error: aborting due to 2 previous errors For more information about this error, try `rustc --explain E0284`. diff --git a/tests/ui/const-generics/infer/cannot-infer-const-args.stderr b/tests/ui/const-generics/infer/cannot-infer-const-args.stderr index e3caefef10f81..2180ba2f80954 100644 --- a/tests/ui/const-generics/infer/cannot-infer-const-args.stderr +++ b/tests/ui/const-generics/infer/cannot-infer-const-args.stderr @@ -1,9 +1,14 @@ -error[E0282]: type annotations needed +error[E0284]: type annotations needed --> $DIR/cannot-infer-const-args.rs:6:5 | LL | foo(); | ^^^ cannot infer the value of the const parameter `X` declared on the function `foo` | +note: required by a bound in `foo` + --> $DIR/cannot-infer-const-args.rs:1:8 + | +LL | fn foo() -> usize { + | ^^^^^^^^^^^^^^ required by this bound in `foo` help: consider specifying the generic argument | LL | foo::(); @@ -11,4 +16,4 @@ LL | foo::(); error: aborting due to 1 previous error -For more information about this error, try `rustc --explain E0282`. +For more information about this error, try `rustc --explain E0284`. diff --git a/tests/ui/const-generics/infer/issue-77092.rs b/tests/ui/const-generics/infer/issue-77092.rs index fcf7d3282b439..47c594e5b11ea 100644 --- a/tests/ui/const-generics/infer/issue-77092.rs +++ b/tests/ui/const-generics/infer/issue-77092.rs @@ -1,14 +1,15 @@ use std::convert::TryInto; fn take_array_from_mut(data: &mut [T], start: usize) -> &mut [T; N] { - (&mut data[start .. start + N]).try_into().unwrap() + (&mut data[start..start + N]).try_into().unwrap() } fn main() { let mut arr = [0, 1, 2, 3, 4, 5, 6, 7, 8]; - for i in 1 .. 4 { + for i in 1..4 { println!("{:?}", take_array_from_mut(&mut arr, i)); //~^ ERROR type annotations needed + //~| ERROR type annotations needed } } diff --git a/tests/ui/const-generics/infer/issue-77092.stderr b/tests/ui/const-generics/infer/issue-77092.stderr index 5b411269862a2..1579d217c2d47 100644 --- a/tests/ui/const-generics/infer/issue-77092.stderr +++ b/tests/ui/const-generics/infer/issue-77092.stderr @@ -1,14 +1,37 @@ -error[E0282]: type annotations needed +error[E0284]: type annotations needed --> $DIR/issue-77092.rs:11:26 | LL | println!("{:?}", take_array_from_mut(&mut arr, i)); | ^^^^^^^^^^^^^^^^^^^ cannot infer the value of the const parameter `N` declared on the function `take_array_from_mut` | +note: required by a bound in `take_array_from_mut` + --> $DIR/issue-77092.rs:3:27 + | +LL | fn take_array_from_mut(data: &mut [T], start: usize) -> &mut [T; N] { + | ^^^^^^^^^^^^^^ required by this bound in `take_array_from_mut` +help: consider specifying the generic arguments + | +LL | println!("{:?}", take_array_from_mut::(&mut arr, i)); + | ++++++++++ + +error[E0284]: type annotations needed + --> $DIR/issue-77092.rs:11:26 + | +LL | println!("{:?}", take_array_from_mut(&mut arr, i)); + | ---- ^^^^^^^^^^^^^^^^^^^ cannot infer the value of the const parameter `N` declared on the function `take_array_from_mut` + | | + | type must be known at this point + | + = note: required for `[i32; _]` to implement `Debug` + = note: 1 redundant requirement hidden + = note: required for `&mut [i32; _]` to implement `Debug` +note: required by a bound in `core::fmt::rt::Argument::<'a>::new_debug` + --> $SRC_DIR/core/src/fmt/rt.rs:LL:COL help: consider specifying the generic arguments | LL | println!("{:?}", take_array_from_mut::(&mut arr, i)); | ++++++++++ -error: aborting due to 1 previous error +error: aborting due to 2 previous errors -For more information about this error, try `rustc --explain E0282`. +For more information about this error, try `rustc --explain E0284`. diff --git a/tests/ui/const-generics/infer/method-chain.stderr b/tests/ui/const-generics/infer/method-chain.stderr index 2def9e85ab75a..08c664e82f7e9 100644 --- a/tests/ui/const-generics/infer/method-chain.stderr +++ b/tests/ui/const-generics/infer/method-chain.stderr @@ -1,9 +1,14 @@ -error[E0282]: type annotations needed +error[E0284]: type annotations needed --> $DIR/method-chain.rs:15:33 | LL | Foo.bar().bar().bar().bar().baz(); | ^^^ cannot infer the value of the const parameter `N` declared on the method `baz` | +note: required by a bound in `Foo::baz` + --> $DIR/method-chain.rs:8:12 + | +LL | fn baz(self) -> Foo { + | ^^^^^^^^^^^^^^ required by this bound in `Foo::baz` help: consider specifying the generic argument | LL | Foo.bar().bar().bar().bar().baz::(); @@ -11,4 +16,4 @@ LL | Foo.bar().bar().bar().bar().baz::(); error: aborting due to 1 previous error -For more information about this error, try `rustc --explain E0282`. +For more information about this error, try `rustc --explain E0284`. diff --git a/tests/ui/const-generics/infer/one-param-uninferred.stderr b/tests/ui/const-generics/infer/one-param-uninferred.stderr index 3e33fec9cefe5..68bec93e82626 100644 --- a/tests/ui/const-generics/infer/one-param-uninferred.stderr +++ b/tests/ui/const-generics/infer/one-param-uninferred.stderr @@ -1,9 +1,14 @@ -error[E0282]: type annotations needed +error[E0284]: type annotations needed --> $DIR/one-param-uninferred.rs:9:23 | LL | let _: [u8; 17] = foo(); | ^^^ cannot infer the value of the const parameter `M` declared on the function `foo` | +note: required by a bound in `foo` + --> $DIR/one-param-uninferred.rs:2:24 + | +LL | fn foo() -> [u8; N] { + | ^^^^^^^^^^^^^^ required by this bound in `foo` help: consider specifying the generic arguments | LL | let _: [u8; 17] = foo::<17, M>(); @@ -11,4 +16,4 @@ LL | let _: [u8; 17] = foo::<17, M>(); error: aborting due to 1 previous error -For more information about this error, try `rustc --explain E0282`. +For more information about this error, try `rustc --explain E0284`. diff --git a/tests/ui/const-generics/infer/uninferred-consts.rs b/tests/ui/const-generics/infer/uninferred-consts.rs index 657f4b513042c..552e2a15c23b0 100644 --- a/tests/ui/const-generics/infer/uninferred-consts.rs +++ b/tests/ui/const-generics/infer/uninferred-consts.rs @@ -8,4 +8,5 @@ impl Foo { fn main() { Foo.foo(); //~^ ERROR type annotations needed + //~| ERROR type annotations needed } diff --git a/tests/ui/const-generics/infer/uninferred-consts.stderr b/tests/ui/const-generics/infer/uninferred-consts.stderr index 0ec6ac9c22e53..e8ad336af70cb 100644 --- a/tests/ui/const-generics/infer/uninferred-consts.stderr +++ b/tests/ui/const-generics/infer/uninferred-consts.stderr @@ -1,14 +1,35 @@ -error[E0282]: type annotations needed +error[E0284]: type annotations needed --> $DIR/uninferred-consts.rs:9:9 | LL | Foo.foo(); | ^^^ cannot infer the value of the const parameter `A` declared on the method `foo` | +note: required by a bound in `Foo::foo` + --> $DIR/uninferred-consts.rs:6:12 + | +LL | fn foo(self) {} + | ^^^^^^^^^^^^^^ required by this bound in `Foo::foo` +help: consider specifying the generic arguments + | +LL | Foo.foo::(); + | ++++++++ + +error[E0284]: type annotations needed + --> $DIR/uninferred-consts.rs:9:9 + | +LL | Foo.foo(); + | ^^^ cannot infer the value of the const parameter `B` declared on the method `foo` + | +note: required by a bound in `Foo::foo` + --> $DIR/uninferred-consts.rs:6:28 + | +LL | fn foo(self) {} + | ^^^^^^^^^^^^^^ required by this bound in `Foo::foo` help: consider specifying the generic arguments | LL | Foo.foo::(); | ++++++++ -error: aborting due to 1 previous error +error: aborting due to 2 previous errors -For more information about this error, try `rustc --explain E0282`. +For more information about this error, try `rustc --explain E0284`. diff --git a/tests/crashes/125799.rs b/tests/ui/const-generics/mistyped_const_in_pat.rs similarity index 64% rename from tests/crashes/125799.rs rename to tests/ui/const-generics/mistyped_const_in_pat.rs index 62d5438b4e400..6f1dd52872f65 100644 --- a/tests/crashes/125799.rs +++ b/tests/ui/const-generics/mistyped_const_in_pat.rs @@ -1,4 +1,5 @@ -//@ known-bug: rust-lang/rust#125799 +//! Used to ICE rust-lang/rust#125799 due to `isize` != `()` +//! not being detected early due to the conflicting impls. //@ only-x86_64 trait Trait { @@ -10,6 +11,7 @@ impl Trait for Vec { } impl Trait for Vec {} +//~^ ERROR: conflicting implementations const BAR: as Trait>::Assoc = 3; diff --git a/tests/ui/const-generics/mistyped_const_in_pat.stderr b/tests/ui/const-generics/mistyped_const_in_pat.stderr new file mode 100644 index 0000000000000..de7516fa37f1f --- /dev/null +++ b/tests/ui/const-generics/mistyped_const_in_pat.stderr @@ -0,0 +1,12 @@ +error[E0119]: conflicting implementations of trait `Trait` for type `Vec` + --> $DIR/mistyped_const_in_pat.rs:13:1 + | +LL | impl Trait for Vec { + | --------------------------- first implementation here +... +LL | impl Trait for Vec {} + | ^^^^^^^^^^^^^^^^^^^^^^^^^^ conflicting implementation for `Vec` + +error: aborting due to 1 previous error + +For more information about this error, try `rustc --explain E0119`. diff --git a/tests/ui/const-generics/parent_generics_of_encoding_impl_trait.stderr b/tests/ui/const-generics/parent_generics_of_encoding_impl_trait.stderr index 5bef6f3c795ed..cb8f56c6bb089 100644 --- a/tests/ui/const-generics/parent_generics_of_encoding_impl_trait.stderr +++ b/tests/ui/const-generics/parent_generics_of_encoding_impl_trait.stderr @@ -5,10 +5,10 @@ LL | generics_of_parent_impl_trait::foo([()]); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ cannot infer the value of const parameter `N` declared on the function `foo` | note: required by a bound in `foo` - --> $DIR/auxiliary/generics_of_parent_impl_trait.rs:5:48 + --> $DIR/auxiliary/generics_of_parent_impl_trait.rs:5:12 | LL | pub fn foo(foo: impl Into<[(); N + 1]>) { - | ^^^^^ required by this bound in `foo` + | ^^^^^^^^^^^^^^ required by this bound in `foo` error: aborting due to 1 previous error diff --git a/tests/ui/const-generics/unify_with_nested_expr.stderr b/tests/ui/const-generics/unify_with_nested_expr.stderr index e050254a3e9d2..87610db67ae4c 100644 --- a/tests/ui/const-generics/unify_with_nested_expr.stderr +++ b/tests/ui/const-generics/unify_with_nested_expr.stderr @@ -5,13 +5,10 @@ LL | bar(); | ^^^ cannot infer the value of the const parameter `N` declared on the function `bar` | note: required by a bound in `bar` - --> $DIR/unify_with_nested_expr.rs:14:10 + --> $DIR/unify_with_nested_expr.rs:12:8 | LL | fn bar() - | --- required by a bound in this function -LL | where -LL | [(); N + 1]:, - | ^^^^^ required by this bound in `bar` + | ^^^^^^^^^^^^^^ required by this bound in `bar` help: consider specifying the generic argument | LL | bar::(); diff --git a/tests/ui/impl-trait/upvar_captures.rs b/tests/ui/impl-trait/upvar_captures.rs new file mode 100644 index 0000000000000..61e3cda66f57f --- /dev/null +++ b/tests/ui/impl-trait/upvar_captures.rs @@ -0,0 +1,16 @@ +//! This test used to ICE: rust-lang/rust#123255 +//! Because the errors on `C` were ignored when trying +//! to compute the MIR of the closure, which thus ended +//! up with broken upvars. +//@ edition:2021 +#![crate_type = "lib"] + +pub fn a() {} + +mod handlers { + pub struct C(&()); //~ ERROR missing lifetime specifier + pub fn c() -> impl Fn() -> C { + let a1 = (); + || C((crate::a(), a1).into()) + } +} diff --git a/tests/ui/impl-trait/upvar_captures.stderr b/tests/ui/impl-trait/upvar_captures.stderr new file mode 100644 index 0000000000000..b87a16606cc55 --- /dev/null +++ b/tests/ui/impl-trait/upvar_captures.stderr @@ -0,0 +1,14 @@ +error[E0106]: missing lifetime specifier + --> $DIR/upvar_captures.rs:11:18 + | +LL | pub struct C(&()); + | ^ expected named lifetime parameter + | +help: consider introducing a named lifetime parameter + | +LL | pub struct C<'a>(&'a ()); + | ++++ ++ + +error: aborting due to 1 previous error + +For more information about this error, try `rustc --explain E0106`. diff --git a/tests/ui/inference/issue-83606.stderr b/tests/ui/inference/issue-83606.stderr index 8e6ff6d568de7..2d74024bb2873 100644 --- a/tests/ui/inference/issue-83606.stderr +++ b/tests/ui/inference/issue-83606.stderr @@ -1,9 +1,14 @@ -error[E0282]: type annotations needed for `[usize; _]` +error[E0284]: type annotations needed for `[usize; _]` --> $DIR/issue-83606.rs:8:9 | LL | let _ = foo("foo"); - | ^ + | ^ ---------- type must be known at this point | +note: required by a bound in `foo` + --> $DIR/issue-83606.rs:3:8 + | +LL | fn foo(_: impl std::fmt::Display) -> [usize; N] { + | ^^^^^^^^^^^^^^ required by this bound in `foo` help: consider giving this pattern a type, where the value of const parameter `N` is specified | LL | let _: [usize; N] = foo("foo"); @@ -11,4 +16,4 @@ LL | let _: [usize; N] = foo("foo"); error: aborting due to 1 previous error -For more information about this error, try `rustc --explain E0282`. +For more information about this error, try `rustc --explain E0284`. diff --git a/tests/ui/issues/issue-98299.rs b/tests/ui/issues/issue-98299.rs index 63c058f91fc7c..ba63d963475af 100644 --- a/tests/ui/issues/issue-98299.rs +++ b/tests/ui/issues/issue-98299.rs @@ -3,6 +3,8 @@ use std::convert::TryFrom; pub fn test_usage(p: ()) { SmallCString::try_from(p).map(|cstr| cstr); //~^ ERROR: type annotations needed + //~| ERROR: type annotations needed + //~| ERROR: type annotations needed } pub struct SmallCString {} diff --git a/tests/ui/issues/issue-98299.stderr b/tests/ui/issues/issue-98299.stderr index becf16d1db91b..f4b40cbbd1955 100644 --- a/tests/ui/issues/issue-98299.stderr +++ b/tests/ui/issues/issue-98299.stderr @@ -1,14 +1,61 @@ -error[E0282]: type annotations needed for `SmallCString<_>` +error[E0284]: type annotations needed for `SmallCString<_>` --> $DIR/issue-98299.rs:4:36 | LL | SmallCString::try_from(p).map(|cstr| cstr); - | ^^^^ + | ------------ ^^^^ + | | + | type must be known at this point | +note: required by a bound in `SmallCString` + --> $DIR/issue-98299.rs:10:25 + | +LL | pub struct SmallCString {} + | ^^^^^^^^^^^^^^ required by this bound in `SmallCString` +help: consider giving this closure parameter an explicit type, where the value of const parameter `N` is specified + | +LL | SmallCString::try_from(p).map(|cstr: SmallCString| cstr); + | +++++++++++++++++ + +error[E0284]: type annotations needed for `SmallCString<_>` + --> $DIR/issue-98299.rs:4:36 + | +LL | SmallCString::try_from(p).map(|cstr| cstr); + | ------------ ^^^^ + | | + | type must be known at this point + | +note: required for `SmallCString<_>` to implement `TryFrom<()>` + --> $DIR/issue-98299.rs:12:22 + | +LL | impl TryFrom<()> for SmallCString { + | -------------- ^^^^^^^^^^^ ^^^^^^^^^^^^^^^ + | | + | unsatisfied trait bound introduced here +help: consider giving this closure parameter an explicit type, where the value of const parameter `N` is specified + | +LL | SmallCString::try_from(p).map(|cstr: SmallCString| cstr); + | +++++++++++++++++ + +error[E0284]: type annotations needed for `SmallCString<_>` + --> $DIR/issue-98299.rs:4:36 + | +LL | SmallCString::try_from(p).map(|cstr| cstr); + | ------------------------- ^^^^ + | | + | type must be known at this point + | +note: required for `SmallCString<_>` to implement `TryFrom<()>` + --> $DIR/issue-98299.rs:12:22 + | +LL | impl TryFrom<()> for SmallCString { + | -------------- ^^^^^^^^^^^ ^^^^^^^^^^^^^^^ + | | + | unsatisfied trait bound introduced here help: consider giving this closure parameter an explicit type, where the value of const parameter `N` is specified | LL | SmallCString::try_from(p).map(|cstr: SmallCString| cstr); | +++++++++++++++++ -error: aborting due to 1 previous error +error: aborting due to 3 previous errors -For more information about this error, try `rustc --explain E0282`. +For more information about this error, try `rustc --explain E0284`. diff --git a/tests/ui/rfcs/rfc-2632-const-trait-impl/const_derives/derive-const-use.stderr b/tests/ui/rfcs/rfc-2632-const-trait-impl/const_derives/derive-const-use.stderr index e45c1a1f46fb6..86dfc521fea72 100644 --- a/tests/ui/rfcs/rfc-2632-const-trait-impl/const_derives/derive-const-use.stderr +++ b/tests/ui/rfcs/rfc-2632-const-trait-impl/const_derives/derive-const-use.stderr @@ -37,6 +37,19 @@ error[E0207]: the const parameter `host` is not constrained by the impl trait, s = note: expressions using a const parameter must map each value to a distinct output value = note: proving the result of expressions other than the parameter are unique is not supported +error[E0284]: type annotations needed + --> $DIR/derive-const-use.rs:18:35 + | +LL | const _: () = assert!(S((), A) == S::default()); + | ^^^^^^^^^^^^ cannot infer the value of the constant `_` + | +note: required for `S` to implement `Default` + --> $DIR/derive-const-use.rs:15:16 + | +LL | #[derive_const(Default, PartialEq)] + | ^^^^^^^ unsatisfied trait bound introduced in this `derive` macro + = note: this error originates in the derive macro `Default` (in Nightly builds, run with -Z macro-backtrace for more info) + error[E0308]: mismatched types --> $DIR/derive-const-use.rs:16:14 | @@ -49,7 +62,24 @@ LL | pub struct S((), A); found constant `true` = note: this error originates in the derive macro `PartialEq` (in Nightly builds, run with -Z macro-backtrace for more info) -error: aborting due to 6 previous errors +error[E0284]: type annotations needed + --> $DIR/derive-const-use.rs:16:18 + | +LL | #[derive_const(Default, PartialEq)] + | ------- in this derive macro expansion +LL | pub struct S((), A); + | ^ cannot infer the value of the constant `_` + | +note: required for `A` to implement `Default` + --> $DIR/derive-const-use.rs:7:12 + | +LL | impl const Default for A { + | ----- ^^^^^^^ ^ + | | + | unsatisfied trait bound introduced here + = note: this error originates in the derive macro `Default` (in Nightly builds, run with -Z macro-backtrace for more info) + +error: aborting due to 8 previous errors -Some errors have detailed explanations: E0207, E0308, E0635. +Some errors have detailed explanations: E0207, E0284, E0308, E0635. For more information about an error, try `rustc --explain E0207`. diff --git a/tests/ui/rfcs/rfc-2632-const-trait-impl/trait-default-body-stability.stderr b/tests/ui/rfcs/rfc-2632-const-trait-impl/trait-default-body-stability.stderr index 62c4bc3b7ae60..b58af6bb9d007 100644 --- a/tests/ui/rfcs/rfc-2632-const-trait-impl/trait-default-body-stability.stderr +++ b/tests/ui/rfcs/rfc-2632-const-trait-impl/trait-default-body-stability.stderr @@ -34,6 +34,94 @@ LL | impl const FromResidual for T { = note: expressions using a const parameter must map each value to a distinct output value = note: proving the result of expressions other than the parameter are unique is not supported -error: aborting due to 4 previous errors +error[E0284]: type annotations needed + --> $DIR/trait-default-body-stability.rs:33:6 + | +LL | impl const FromResidual for T { + | ^^^^^ cannot infer the value of the constant `_` + | +note: required for `T` to implement `Try` + --> $DIR/trait-default-body-stability.rs:18:12 + | +LL | impl const Try for T { + | ----- ^^^ ^ + | | + | unsatisfied trait bound introduced here + +error[E0284]: type annotations needed + --> $DIR/trait-default-body-stability.rs:44:9 + | +LL | T? + | ^^ cannot infer the value of the constant `_` + | +note: required for `T` to implement `Try` + --> $DIR/trait-default-body-stability.rs:18:12 + | +LL | impl const Try for T { + | ----- ^^^ ^ + | | + | unsatisfied trait bound introduced here + +error[E0284]: type annotations needed + --> $DIR/trait-default-body-stability.rs:44:9 + | +LL | T? + | ^^ cannot infer the value of the constant `_` + | +note: required for `T` to implement `FromResidual` + --> $DIR/trait-default-body-stability.rs:33:12 + | +LL | impl const FromResidual for T { + | ----- ^^^^^^^^^^^^ ^ + | | + | unsatisfied trait bound introduced here + +error[E0284]: type annotations needed + --> $DIR/trait-default-body-stability.rs:44:9 + | +LL | T? + | ^^ cannot infer the value of the constant `_` + | +note: required for `T` to implement `Try` + --> $DIR/trait-default-body-stability.rs:18:12 + | +LL | impl const Try for T { + | ----- ^^^ ^ + | | + | unsatisfied trait bound introduced here + = note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no` + +error[E0284]: type annotations needed + --> $DIR/trait-default-body-stability.rs:44:9 + | +LL | T? + | ^^ cannot infer the value of the constant `_` + | +note: required for `T` to implement `FromResidual` + --> $DIR/trait-default-body-stability.rs:33:12 + | +LL | impl const FromResidual for T { + | ----- ^^^^^^^^^^^^ ^ + | | + | unsatisfied trait bound introduced here + = note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no` + +error[E0284]: type annotations needed + --> $DIR/trait-default-body-stability.rs:44:9 + | +LL | T? + | ^^ cannot infer the value of the constant `_` + | +note: required for `T` to implement `Try` + --> $DIR/trait-default-body-stability.rs:18:12 + | +LL | impl const Try for T { + | ----- ^^^ ^ + | | + | unsatisfied trait bound introduced here + = note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no` + +error: aborting due to 10 previous errors -For more information about this error, try `rustc --explain E0207`. +Some errors have detailed explanations: E0207, E0284. +For more information about an error, try `rustc --explain E0207`. diff --git a/tests/ui/wf/conflicting-impls.rs b/tests/ui/wf/conflicting-impls.rs index c387199a8bf14..8054eb7c59436 100644 --- a/tests/ui/wf/conflicting-impls.rs +++ b/tests/ui/wf/conflicting-impls.rs @@ -5,7 +5,6 @@ struct Ty; impl TryFrom for u8 { type Error = Ty; fn try_from(_: Ty) -> Result { - //~^ ERROR type annotations needed loop {} } } @@ -14,7 +13,6 @@ impl TryFrom for u8 { //~^ ERROR conflicting implementations of trait type Error = Ty; fn try_from(_: Ty) -> Result { - //~^ ERROR type annotations needed loop {} } } diff --git a/tests/ui/wf/conflicting-impls.stderr b/tests/ui/wf/conflicting-impls.stderr index 15222a9b2ccd1..d31ae17aa8f7d 100644 --- a/tests/ui/wf/conflicting-impls.stderr +++ b/tests/ui/wf/conflicting-impls.stderr @@ -1,5 +1,5 @@ error[E0119]: conflicting implementations of trait `TryFrom` for type `u8` - --> $DIR/conflicting-impls.rs:13:1 + --> $DIR/conflicting-impls.rs:12:1 | LL | impl TryFrom for u8 { | ----------------------- first implementation here @@ -7,27 +7,6 @@ LL | impl TryFrom for u8 { LL | impl TryFrom for u8 { | ^^^^^^^^^^^^^^^^^^^^^^^ conflicting implementation for `u8` -error[E0282]: type annotations needed - --> $DIR/conflicting-impls.rs:7:53 - | -LL | fn try_from(_: Ty) -> Result { - | _____________________________________________________^ -LL | | -LL | | loop {} -LL | | } - | |_____^ cannot infer type for enum `Result` - -error[E0282]: type annotations needed - --> $DIR/conflicting-impls.rs:16:53 - | -LL | fn try_from(_: Ty) -> Result { - | _____________________________________________________^ -LL | | -LL | | loop {} -LL | | } - | |_____^ cannot infer type for enum `Result` - -error: aborting due to 3 previous errors +error: aborting due to 1 previous error -Some errors have detailed explanations: E0119, E0282. -For more information about an error, try `rustc --explain E0119`. +For more information about this error, try `rustc --explain E0119`. diff --git a/tests/crashes/123276.rs b/tests/ui/where-clauses/normalization-of-unknown-type.rs similarity index 59% rename from tests/crashes/123276.rs rename to tests/ui/where-clauses/normalization-of-unknown-type.rs index d2246f595838d..c3ff7ed125acf 100644 --- a/tests/crashes/123276.rs +++ b/tests/ui/where-clauses/normalization-of-unknown-type.rs @@ -1,4 +1,6 @@ -//@ known-bug: rust-lang/rust#123276 +//! This test used to ICE: rust-lang/rust#123276 because we did +//! not taint when failing to find the `Foo` type and then tried +//! to normalize it. //@ edition:2021 async fn create_task() { @@ -19,7 +21,9 @@ struct AndThen; impl Filter for AndThen where - Foo: Filter, + Foo: Filter, //~ ERROR: cannot find type `Foo` { type Future = (); } + +fn main() {} diff --git a/tests/ui/where-clauses/normalization-of-unknown-type.stderr b/tests/ui/where-clauses/normalization-of-unknown-type.stderr new file mode 100644 index 0000000000000..11b83224352b8 --- /dev/null +++ b/tests/ui/where-clauses/normalization-of-unknown-type.stderr @@ -0,0 +1,9 @@ +error[E0412]: cannot find type `Foo` in this scope + --> $DIR/normalization-of-unknown-type.rs:24:5 + | +LL | Foo: Filter, + | ^^^ not found in this scope + +error: aborting due to 1 previous error + +For more information about this error, try `rustc --explain E0412`. From 1cb75dc4a92ef131b2b88bd9faeaa1d39c3d5f4e Mon Sep 17 00:00:00 2001 From: Oli Scherer Date: Mon, 17 Jun 2024 08:53:45 +0000 Subject: [PATCH 12/23] Remove a hack that isn't needed anymore --- compiler/rustc_hir_analysis/src/check/wfcheck.rs | 11 +---------- 1 file changed, 1 insertion(+), 10 deletions(-) diff --git a/compiler/rustc_hir_analysis/src/check/wfcheck.rs b/compiler/rustc_hir_analysis/src/check/wfcheck.rs index b206d8046ee9c..a188c1b12aeb6 100644 --- a/compiler/rustc_hir_analysis/src/check/wfcheck.rs +++ b/compiler/rustc_hir_analysis/src/check/wfcheck.rs @@ -119,16 +119,7 @@ where let errors = wfcx.select_all_or_error(); if !errors.is_empty() { - let err = infcx.err_ctxt().report_fulfillment_errors(errors); - if tcx.dcx().has_errors().is_some() { - return Err(err); - } else { - // HACK(oli-obk): tests/ui/specialization/min_specialization/specialize_on_type_error.rs - // causes an delayed bug during normalization, without reporting an error, so we need - // to act as if no error happened, in order to let our callers continue and report an - // error later in check_impl_items_against_trait. - return Ok(()); - } + return Err(infcx.err_ctxt().report_fulfillment_errors(errors)); } debug!(?assumed_wf_types); From 2e7e4ef72e10104583b0d69b691893fdac06afe1 Mon Sep 17 00:00:00 2001 From: Oneirical Date: Wed, 19 Jun 2024 10:45:45 -0400 Subject: [PATCH 13/23] rewrite unknown-mod-stdin to rmake --- .../tidy/src/allowed_run_make_makefiles.txt | 1 - tests/run-make/unknown-mod-stdin/Makefile | 8 ------ tests/run-make/unknown-mod-stdin/rmake.rs | 25 +++++++++++++++++++ 3 files changed, 25 insertions(+), 9 deletions(-) delete mode 100644 tests/run-make/unknown-mod-stdin/Makefile create mode 100644 tests/run-make/unknown-mod-stdin/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 eb2e8c2542e8b..235ea5c5c82b3 100644 --- a/src/tools/tidy/src/allowed_run_make_makefiles.txt +++ b/src/tools/tidy/src/allowed_run_make_makefiles.txt @@ -212,7 +212,6 @@ run-make/track-path-dep-info/Makefile run-make/track-pgo-dep-info/Makefile run-make/translation/Makefile run-make/type-mismatch-same-crate-name/Makefile -run-make/unknown-mod-stdin/Makefile run-make/unstable-flag-required/Makefile run-make/use-suggestions-rust-2018/Makefile run-make/used-cdylib-macos/Makefile diff --git a/tests/run-make/unknown-mod-stdin/Makefile b/tests/run-make/unknown-mod-stdin/Makefile deleted file mode 100644 index 313b0ba837e83..0000000000000 --- a/tests/run-make/unknown-mod-stdin/Makefile +++ /dev/null @@ -1,8 +0,0 @@ -# ignore-windows - -include ../tools.mk - -all: - echo 'mod unknown;' | $(RUSTC) --crate-type rlib - >$(TMPDIR)/unknown-mod.stdout 2>$(TMPDIR)/unknown-mod.stderr || echo "failed successfully" - $(RUSTC_TEST_OP) "$(TMPDIR)"/unknown-mod.stdout unknown-mod.stdout - $(RUSTC_TEST_OP) "$(TMPDIR)"/unknown-mod.stderr unknown-mod.stderr diff --git a/tests/run-make/unknown-mod-stdin/rmake.rs b/tests/run-make/unknown-mod-stdin/rmake.rs new file mode 100644 index 0000000000000..0fe5c78ed0ff0 --- /dev/null +++ b/tests/run-make/unknown-mod-stdin/rmake.rs @@ -0,0 +1,25 @@ +// 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 +// instead of showing an error if the invalid `mod` statement had been passed +// through standard input. This test checks that this bug does not make a resurgence. +// See https://github.com/rust-lang/rust/issues/65601 + +// NOTE: This is not a UI test, because the bug which this test +// is checking for is specifically tied to passing +// `mod unknown;` through standard input. + +use run_make_support::{diff, rustc}; + +fn main() { + let out = rustc().crate_type("rlib").stdin(b"mod unknown;").arg("-").run_fail(); + diff() + .actual_text("actual-stdout", out.stdout_utf8()) + .expected_file("unknown-mod.stdout") + .run(); + diff() + .actual_text("actual-stderr", out.stderr_utf8()) + .expected_file("unknown-mod.stderr") + .normalize(r#"\\"#, "/") + .run(); +} From e4c9a8cf9b2e2a17c589dadcaffae0b9e6b62cbc Mon Sep 17 00:00:00 2001 From: Oli Scherer Date: Wed, 19 Jun 2024 08:25:58 +0000 Subject: [PATCH 14/23] Const generic parameters aren't bounds, even if we end up erroring because of the bound that binds the parameter's type --- .../src/traits/error_reporting/suggestions.rs | 188 ++++++++++-------- .../defaults/doesnt_infer.stderr | 8 +- .../defaults/rp_impl_trait_fail.stderr | 4 +- .../generic_arg_infer/issue-91614.stderr | 4 +- .../issue-62504.full.stderr | 8 +- .../issue-62504.min.stderr | 8 +- .../object-safety-ok-infer-err.stderr | 4 +- .../infer/cannot-infer-const-args.stderr | 4 +- .../const-generics/infer/issue-77092.stderr | 4 +- .../const-generics/infer/method-chain.stderr | 4 +- .../infer/one-param-uninferred.stderr | 4 +- .../infer/uninferred-consts.stderr | 8 +- ...ent_generics_of_encoding_impl_trait.stderr | 4 +- tests/ui/const-generics/type_mismatch.stderr | 4 +- .../unify_with_nested_expr.stderr | 4 +- tests/ui/inference/issue-83606.stderr | 4 +- tests/ui/issues/issue-98299.stderr | 4 +- ...oj-ty-as-type-of-const-issue-125757.stderr | 4 +- .../ui/transmutability/issue-101739-1.stderr | 2 +- 19 files changed, 146 insertions(+), 128 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 f632f1ad4f260..8f8ef4b7acbd8 100644 --- a/compiler/rustc_trait_selection/src/traits/error_reporting/suggestions.rs +++ b/compiler/rustc_trait_selection/src/traits/error_reporting/suggestions.rs @@ -2776,97 +2776,115 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> { let mut this = "this bound"; let mut note = None; let mut help = None; - if let ty::PredicateKind::Clause(clause) = predicate.kind().skip_binder() - && let ty::ClauseKind::Trait(trait_pred) = clause - { - let def_id = trait_pred.def_id(); - let visible_item = if let Some(local) = def_id.as_local() { - // Check for local traits being reachable. - let vis = &tcx.resolutions(()).effective_visibilities; - // Account for non-`pub` traits in the root of the local crate. - let is_locally_reachable = tcx.parent(def_id).is_crate_root(); - vis.is_reachable(local) || is_locally_reachable - } else { - // Check for foreign traits being reachable. - tcx.visible_parent_map(()).get(&def_id).is_some() - }; - if tcx.is_lang_item(def_id, LangItem::Sized) { - // Check if this is an implicit bound, even in foreign crates. - if tcx - .generics_of(item_def_id) - .own_params - .iter() - .any(|param| tcx.def_span(param.def_id) == span) - { - a = "an implicit `Sized`"; - this = "the implicit `Sized` requirement on this type parameter"; - } - if let Some(hir::Node::TraitItem(hir::TraitItem { - generics, - kind: hir::TraitItemKind::Type(bounds, None), - .. - })) = tcx.hir().get_if_local(item_def_id) - // Do not suggest relaxing if there is an explicit `Sized` obligation. - && !bounds.iter() - .filter_map(|bound| bound.trait_ref()) - .any(|tr| tr.trait_def_id() == tcx.lang_items().sized_trait()) - { - let (span, separator) = if let [.., last] = bounds { - (last.span().shrink_to_hi(), " +") + if let ty::PredicateKind::Clause(clause) = predicate.kind().skip_binder() { + match clause { + ty::ClauseKind::Trait(trait_pred) => { + let def_id = trait_pred.def_id(); + let visible_item = if let Some(local) = def_id.as_local() { + // Check for local traits being reachable. + let vis = &tcx.resolutions(()).effective_visibilities; + // Account for non-`pub` traits in the root of the local crate. + let is_locally_reachable = tcx.parent(def_id).is_crate_root(); + vis.is_reachable(local) || is_locally_reachable } else { - (generics.span.shrink_to_hi(), ":") + // Check for foreign traits being reachable. + tcx.visible_parent_map(()).get(&def_id).is_some() }; - err.span_suggestion_verbose( - span, - "consider relaxing the implicit `Sized` restriction", - format!("{separator} ?Sized"), - Applicability::MachineApplicable, - ); + if tcx.is_lang_item(def_id, LangItem::Sized) { + // Check if this is an implicit bound, even in foreign crates. + if tcx + .generics_of(item_def_id) + .own_params + .iter() + .any(|param| tcx.def_span(param.def_id) == span) + { + a = "an implicit `Sized`"; + this = + "the implicit `Sized` requirement on this type parameter"; + } + if let Some(hir::Node::TraitItem(hir::TraitItem { + generics, + kind: hir::TraitItemKind::Type(bounds, None), + .. + })) = tcx.hir().get_if_local(item_def_id) + // Do not suggest relaxing if there is an explicit `Sized` obligation. + && !bounds.iter() + .filter_map(|bound| bound.trait_ref()) + .any(|tr| tr.trait_def_id() == tcx.lang_items().sized_trait()) + { + let (span, separator) = if let [.., last] = bounds { + (last.span().shrink_to_hi(), " +") + } else { + (generics.span.shrink_to_hi(), ":") + }; + err.span_suggestion_verbose( + span, + "consider relaxing the implicit `Sized` restriction", + format!("{separator} ?Sized"), + Applicability::MachineApplicable, + ); + } + } + if let DefKind::Trait = tcx.def_kind(item_def_id) + && !visible_item + { + note = Some(format!( + "`{short_item_name}` is a \"sealed trait\", because to implement it \ + you also need to implement `{}`, which is not accessible; this is \ + usually done to force you to use one of the provided types that \ + already implement it", + with_no_trimmed_paths!(tcx.def_path_str(def_id)), + )); + let impls_of = tcx.trait_impls_of(def_id); + let impls = impls_of + .non_blanket_impls() + .values() + .flatten() + .chain(impls_of.blanket_impls().iter()) + .collect::>(); + if !impls.is_empty() { + let len = impls.len(); + let mut types = impls + .iter() + .map(|t| { + with_no_trimmed_paths!(format!( + " {}", + tcx.type_of(*t).instantiate_identity(), + )) + }) + .collect::>(); + let post = if types.len() > 9 { + types.truncate(8); + format!("\nand {} others", len - 8) + } else { + String::new() + }; + help = Some(format!( + "the following type{} implement{} the trait:\n{}{post}", + pluralize!(len), + if len == 1 { "s" } else { "" }, + types.join("\n"), + )); + } + } } - } - if let DefKind::Trait = tcx.def_kind(item_def_id) - && !visible_item - { - note = Some(format!( - "`{short_item_name}` is a \"sealed trait\", because to implement it \ - you also need to implement `{}`, which is not accessible; this is \ - usually done to force you to use one of the provided types that \ - already implement it", - with_no_trimmed_paths!(tcx.def_path_str(def_id)), - )); - let impls_of = tcx.trait_impls_of(def_id); - let impls = impls_of - .non_blanket_impls() - .values() - .flatten() - .chain(impls_of.blanket_impls().iter()) - .collect::>(); - if !impls.is_empty() { - let len = impls.len(); - let mut types = impls - .iter() - .map(|t| { - with_no_trimmed_paths!(format!( - " {}", - tcx.type_of(*t).instantiate_identity(), - )) - }) - .collect::>(); - let post = if types.len() > 9 { - types.truncate(8); - format!("\nand {} others", len - 8) + ty::ClauseKind::ConstArgHasType(..) => { + let descr = + format!("required by a const generic parameter in `{item_name}`"); + if span.is_visible(sm) { + let msg = format!( + "required by this const generic parameter in `{short_item_name}`" + ); + multispan.push_span_label(span, msg); + err.span_note(multispan, descr); } else { - String::new() - }; - help = Some(format!( - "the following type{} implement{} the trait:\n{}{post}", - pluralize!(len), - if len == 1 { "s" } else { "" }, - types.join("\n"), - )); + err.span_note(tcx.def_span(item_def_id), descr); + } + return; } + _ => (), } - }; + } let descr = format!("required by {a} bound in `{item_name}`"); if span.is_visible(sm) { let msg = format!("required by {this} in `{short_item_name}`"); diff --git a/tests/ui/const-generics/defaults/doesnt_infer.stderr b/tests/ui/const-generics/defaults/doesnt_infer.stderr index e099289827e93..c17f57f36bc5f 100644 --- a/tests/ui/const-generics/defaults/doesnt_infer.stderr +++ b/tests/ui/const-generics/defaults/doesnt_infer.stderr @@ -4,11 +4,11 @@ error[E0284]: type annotations needed for `Foo<_>` LL | let foo = Foo::foo(); | ^^^ ---------- type must be known at this point | -note: required by a bound in `Foo::::foo` +note: required by a const generic parameter in `Foo::::foo` --> $DIR/doesnt_infer.rs:5:6 | LL | impl Foo { - | ^^^^^^^^^^^^ required by this bound in `Foo::::foo` + | ^^^^^^^^^^^^ required by this const generic parameter in `Foo::::foo` LL | fn foo() -> Self { | --- required by a bound in this associated function help: consider giving `foo` an explicit type, where the value of const parameter `N` is specified @@ -22,11 +22,11 @@ error[E0284]: type annotations needed for `Foo<_>` LL | let foo = Foo::foo(); | ^^^ --- type must be known at this point | -note: required by a bound in `Foo` +note: required by a const generic parameter in `Foo` --> $DIR/doesnt_infer.rs:3:12 | LL | struct Foo; - | ^^^^^^^^^^^^^^^^ required by this bound in `Foo` + | ^^^^^^^^^^^^^^^^ required by this const generic parameter in `Foo` help: consider giving `foo` an explicit type, where the value of const parameter `N` is specified | LL | let foo: Foo = Foo::foo(); diff --git a/tests/ui/const-generics/defaults/rp_impl_trait_fail.stderr b/tests/ui/const-generics/defaults/rp_impl_trait_fail.stderr index d91e717b3ebe5..45be3126e3b3f 100644 --- a/tests/ui/const-generics/defaults/rp_impl_trait_fail.stderr +++ b/tests/ui/const-generics/defaults/rp_impl_trait_fail.stderr @@ -37,11 +37,11 @@ error[E0284]: type annotations needed LL | uwu(); | ^^^ cannot infer the value of the const parameter `N` declared on the function `uwu` | -note: required by a bound in `uwu` +note: required by a const generic parameter in `uwu` --> $DIR/rp_impl_trait_fail.rs:16:8 | LL | fn uwu() -> impl Traitor { - | ^^^^^^^^^^^ required by this bound in `uwu` + | ^^^^^^^^^^^ required by this const generic parameter in `uwu` help: consider specifying the generic argument | LL | uwu::(); diff --git a/tests/ui/const-generics/generic_arg_infer/issue-91614.stderr b/tests/ui/const-generics/generic_arg_infer/issue-91614.stderr index b6982e05b8895..217f609459eed 100644 --- a/tests/ui/const-generics/generic_arg_infer/issue-91614.stderr +++ b/tests/ui/const-generics/generic_arg_infer/issue-91614.stderr @@ -4,7 +4,7 @@ error[E0284]: type annotations needed for `Mask<_, _>` LL | let y = Mask::<_, _>::splat(false); | ^ -------------------------- type must be known at this point | -note: required by a bound in `Mask::::splat` +note: required by a const generic parameter in `Mask::::splat` --> $SRC_DIR/core/src/../../portable-simd/crates/core_simd/src/masks.rs:LL:COL help: consider giving `y` an explicit type, where the value of const parameter `N` is specified | @@ -17,7 +17,7 @@ error[E0284]: type annotations needed for `Mask<_, _>` LL | let y = Mask::<_, _>::splat(false); | ^ ------------ type must be known at this point | -note: required by a bound in `Mask` +note: required by a const generic parameter in `Mask` --> $SRC_DIR/core/src/../../portable-simd/crates/core_simd/src/masks.rs:LL:COL help: consider giving `y` an explicit type, where the value of const parameter `N` is specified | diff --git a/tests/ui/const-generics/generic_const_exprs/issue-62504.full.stderr b/tests/ui/const-generics/generic_const_exprs/issue-62504.full.stderr index 27411646cb72e..3739637c27951 100644 --- a/tests/ui/const-generics/generic_const_exprs/issue-62504.full.stderr +++ b/tests/ui/const-generics/generic_const_exprs/issue-62504.full.stderr @@ -24,11 +24,11 @@ error[E0284]: type annotations needed for `ArrayHolder<_>` LL | let mut array = ArrayHolder::new(); | ^^^^^^^^^ ------------------ type must be known at this point | -note: required by a bound in `ArrayHolder::::new` +note: required by a const generic parameter in `ArrayHolder::::new` --> $DIR/issue-62504.rs:16:6 | LL | impl ArrayHolder { - | ^^^^^^^^^^^^^^ required by this bound in `ArrayHolder::::new` + | ^^^^^^^^^^^^^^ required by this const generic parameter in `ArrayHolder::::new` LL | pub const fn new() -> Self { | --- required by a bound in this associated function help: consider giving `array` an explicit type, where the value of const parameter `X` is specified @@ -42,11 +42,11 @@ error[E0284]: type annotations needed for `ArrayHolder<_>` LL | let mut array = ArrayHolder::new(); | ^^^^^^^^^ ----------- type must be known at this point | -note: required by a bound in `ArrayHolder` +note: required by a const generic parameter in `ArrayHolder` --> $DIR/issue-62504.rs:14:20 | LL | struct ArrayHolder([u32; X]); - | ^^^^^^^^^^^^^^ required by this bound in `ArrayHolder` + | ^^^^^^^^^^^^^^ required by this const generic parameter in `ArrayHolder` help: consider giving `array` an explicit type, where the value of const parameter `X` is specified | LL | let mut array: ArrayHolder = ArrayHolder::new(); diff --git a/tests/ui/const-generics/generic_const_exprs/issue-62504.min.stderr b/tests/ui/const-generics/generic_const_exprs/issue-62504.min.stderr index 036b9001c03db..14c67e2528a73 100644 --- a/tests/ui/const-generics/generic_const_exprs/issue-62504.min.stderr +++ b/tests/ui/const-generics/generic_const_exprs/issue-62504.min.stderr @@ -28,11 +28,11 @@ error[E0284]: type annotations needed for `ArrayHolder<_>` LL | let mut array = ArrayHolder::new(); | ^^^^^^^^^ ------------------ type must be known at this point | -note: required by a bound in `ArrayHolder::::new` +note: required by a const generic parameter in `ArrayHolder::::new` --> $DIR/issue-62504.rs:16:6 | LL | impl ArrayHolder { - | ^^^^^^^^^^^^^^ required by this bound in `ArrayHolder::::new` + | ^^^^^^^^^^^^^^ required by this const generic parameter in `ArrayHolder::::new` LL | pub const fn new() -> Self { | --- required by a bound in this associated function help: consider giving `array` an explicit type, where the value of const parameter `X` is specified @@ -46,11 +46,11 @@ error[E0284]: type annotations needed for `ArrayHolder<_>` LL | let mut array = ArrayHolder::new(); | ^^^^^^^^^ ----------- type must be known at this point | -note: required by a bound in `ArrayHolder` +note: required by a const generic parameter in `ArrayHolder` --> $DIR/issue-62504.rs:14:20 | LL | struct ArrayHolder([u32; X]); - | ^^^^^^^^^^^^^^ required by this bound in `ArrayHolder` + | ^^^^^^^^^^^^^^ required by this const generic parameter in `ArrayHolder` help: consider giving `array` an explicit type, where the value of const parameter `X` is specified | LL | let mut array: ArrayHolder = ArrayHolder::new(); diff --git a/tests/ui/const-generics/generic_const_exprs/object-safety-ok-infer-err.stderr b/tests/ui/const-generics/generic_const_exprs/object-safety-ok-infer-err.stderr index 0c290448fc5a8..d1e1c976da664 100644 --- a/tests/ui/const-generics/generic_const_exprs/object-safety-ok-infer-err.stderr +++ b/tests/ui/const-generics/generic_const_exprs/object-safety-ok-infer-err.stderr @@ -4,11 +4,11 @@ error[E0284]: type annotations needed LL | use_dyn(&()); | ^^^^^^^ cannot infer the value of the const parameter `N` declared on the function `use_dyn` | -note: required by a bound in `use_dyn` +note: required by a const generic parameter in `use_dyn` --> $DIR/object-safety-ok-infer-err.rs:14:12 | LL | fn use_dyn(v: &dyn Foo) where [u8; N + 1]: Sized { - | ^^^^^^^^^^^^^^ required by this bound in `use_dyn` + | ^^^^^^^^^^^^^^ required by this const generic parameter in `use_dyn` help: consider specifying the generic argument | LL | use_dyn::(&()); diff --git a/tests/ui/const-generics/infer/cannot-infer-const-args.stderr b/tests/ui/const-generics/infer/cannot-infer-const-args.stderr index 2180ba2f80954..c349a50a83ffb 100644 --- a/tests/ui/const-generics/infer/cannot-infer-const-args.stderr +++ b/tests/ui/const-generics/infer/cannot-infer-const-args.stderr @@ -4,11 +4,11 @@ error[E0284]: type annotations needed LL | foo(); | ^^^ cannot infer the value of the const parameter `X` declared on the function `foo` | -note: required by a bound in `foo` +note: required by a const generic parameter in `foo` --> $DIR/cannot-infer-const-args.rs:1:8 | LL | fn foo() -> usize { - | ^^^^^^^^^^^^^^ required by this bound in `foo` + | ^^^^^^^^^^^^^^ required by this const generic parameter in `foo` help: consider specifying the generic argument | LL | foo::(); diff --git a/tests/ui/const-generics/infer/issue-77092.stderr b/tests/ui/const-generics/infer/issue-77092.stderr index 1579d217c2d47..9a6374a2adcbe 100644 --- a/tests/ui/const-generics/infer/issue-77092.stderr +++ b/tests/ui/const-generics/infer/issue-77092.stderr @@ -4,11 +4,11 @@ error[E0284]: type annotations needed LL | println!("{:?}", take_array_from_mut(&mut arr, i)); | ^^^^^^^^^^^^^^^^^^^ cannot infer the value of the const parameter `N` declared on the function `take_array_from_mut` | -note: required by a bound in `take_array_from_mut` +note: required by a const generic parameter in `take_array_from_mut` --> $DIR/issue-77092.rs:3:27 | LL | fn take_array_from_mut(data: &mut [T], start: usize) -> &mut [T; N] { - | ^^^^^^^^^^^^^^ required by this bound in `take_array_from_mut` + | ^^^^^^^^^^^^^^ required by this const generic parameter in `take_array_from_mut` help: consider specifying the generic arguments | LL | println!("{:?}", take_array_from_mut::(&mut arr, i)); diff --git a/tests/ui/const-generics/infer/method-chain.stderr b/tests/ui/const-generics/infer/method-chain.stderr index 08c664e82f7e9..95044bb5203b3 100644 --- a/tests/ui/const-generics/infer/method-chain.stderr +++ b/tests/ui/const-generics/infer/method-chain.stderr @@ -4,11 +4,11 @@ error[E0284]: type annotations needed LL | Foo.bar().bar().bar().bar().baz(); | ^^^ cannot infer the value of the const parameter `N` declared on the method `baz` | -note: required by a bound in `Foo::baz` +note: required by a const generic parameter in `Foo::baz` --> $DIR/method-chain.rs:8:12 | LL | fn baz(self) -> Foo { - | ^^^^^^^^^^^^^^ required by this bound in `Foo::baz` + | ^^^^^^^^^^^^^^ required by this const generic parameter in `Foo::baz` help: consider specifying the generic argument | LL | Foo.bar().bar().bar().bar().baz::(); diff --git a/tests/ui/const-generics/infer/one-param-uninferred.stderr b/tests/ui/const-generics/infer/one-param-uninferred.stderr index 68bec93e82626..f3aa7973e67d1 100644 --- a/tests/ui/const-generics/infer/one-param-uninferred.stderr +++ b/tests/ui/const-generics/infer/one-param-uninferred.stderr @@ -4,11 +4,11 @@ error[E0284]: type annotations needed LL | let _: [u8; 17] = foo(); | ^^^ cannot infer the value of the const parameter `M` declared on the function `foo` | -note: required by a bound in `foo` +note: required by a const generic parameter in `foo` --> $DIR/one-param-uninferred.rs:2:24 | LL | fn foo() -> [u8; N] { - | ^^^^^^^^^^^^^^ required by this bound in `foo` + | ^^^^^^^^^^^^^^ required by this const generic parameter in `foo` help: consider specifying the generic arguments | LL | let _: [u8; 17] = foo::<17, M>(); diff --git a/tests/ui/const-generics/infer/uninferred-consts.stderr b/tests/ui/const-generics/infer/uninferred-consts.stderr index e8ad336af70cb..839fb25c4e1e6 100644 --- a/tests/ui/const-generics/infer/uninferred-consts.stderr +++ b/tests/ui/const-generics/infer/uninferred-consts.stderr @@ -4,11 +4,11 @@ error[E0284]: type annotations needed LL | Foo.foo(); | ^^^ cannot infer the value of the const parameter `A` declared on the method `foo` | -note: required by a bound in `Foo::foo` +note: required by a const generic parameter in `Foo::foo` --> $DIR/uninferred-consts.rs:6:12 | LL | fn foo(self) {} - | ^^^^^^^^^^^^^^ required by this bound in `Foo::foo` + | ^^^^^^^^^^^^^^ required by this const generic parameter in `Foo::foo` help: consider specifying the generic arguments | LL | Foo.foo::(); @@ -20,11 +20,11 @@ error[E0284]: type annotations needed LL | Foo.foo(); | ^^^ cannot infer the value of the const parameter `B` declared on the method `foo` | -note: required by a bound in `Foo::foo` +note: required by a const generic parameter in `Foo::foo` --> $DIR/uninferred-consts.rs:6:28 | LL | fn foo(self) {} - | ^^^^^^^^^^^^^^ required by this bound in `Foo::foo` + | ^^^^^^^^^^^^^^ required by this const generic parameter in `Foo::foo` help: consider specifying the generic arguments | LL | Foo.foo::(); diff --git a/tests/ui/const-generics/parent_generics_of_encoding_impl_trait.stderr b/tests/ui/const-generics/parent_generics_of_encoding_impl_trait.stderr index cb8f56c6bb089..4809f7d37dd31 100644 --- a/tests/ui/const-generics/parent_generics_of_encoding_impl_trait.stderr +++ b/tests/ui/const-generics/parent_generics_of_encoding_impl_trait.stderr @@ -4,11 +4,11 @@ error[E0284]: type annotations needed LL | generics_of_parent_impl_trait::foo([()]); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ cannot infer the value of const parameter `N` declared on the function `foo` | -note: required by a bound in `foo` +note: required by a const generic parameter in `foo` --> $DIR/auxiliary/generics_of_parent_impl_trait.rs:5:12 | LL | pub fn foo(foo: impl Into<[(); N + 1]>) { - | ^^^^^^^^^^^^^^ required by this bound in `foo` + | ^^^^^^^^^^^^^^ required by this const generic parameter in `foo` error: aborting due to 1 previous error diff --git a/tests/ui/const-generics/type_mismatch.stderr b/tests/ui/const-generics/type_mismatch.stderr index 07476ae76c65e..026999827c0e0 100644 --- a/tests/ui/const-generics/type_mismatch.stderr +++ b/tests/ui/const-generics/type_mismatch.stderr @@ -4,11 +4,11 @@ error: the constant `N` is not of type `u8` LL | bar::() | ^ expected `u8`, found `usize` | -note: required by a bound in `bar` +note: required by a const generic parameter in `bar` --> $DIR/type_mismatch.rs:6:8 | LL | fn bar() -> [u8; N] {} - | ^^^^^^^^^^^ required by this bound in `bar` + | ^^^^^^^^^^^ required by this const generic parameter in `bar` error[E0308]: mismatched types --> $DIR/type_mismatch.rs:6:26 diff --git a/tests/ui/const-generics/unify_with_nested_expr.stderr b/tests/ui/const-generics/unify_with_nested_expr.stderr index 87610db67ae4c..b1aecdb3cb5a7 100644 --- a/tests/ui/const-generics/unify_with_nested_expr.stderr +++ b/tests/ui/const-generics/unify_with_nested_expr.stderr @@ -4,11 +4,11 @@ error[E0284]: type annotations needed LL | bar(); | ^^^ cannot infer the value of the const parameter `N` declared on the function `bar` | -note: required by a bound in `bar` +note: required by a const generic parameter in `bar` --> $DIR/unify_with_nested_expr.rs:12:8 | LL | fn bar() - | ^^^^^^^^^^^^^^ required by this bound in `bar` + | ^^^^^^^^^^^^^^ required by this const generic parameter in `bar` help: consider specifying the generic argument | LL | bar::(); diff --git a/tests/ui/inference/issue-83606.stderr b/tests/ui/inference/issue-83606.stderr index 2d74024bb2873..69d1d71ef3cc0 100644 --- a/tests/ui/inference/issue-83606.stderr +++ b/tests/ui/inference/issue-83606.stderr @@ -4,11 +4,11 @@ error[E0284]: type annotations needed for `[usize; _]` LL | let _ = foo("foo"); | ^ ---------- type must be known at this point | -note: required by a bound in `foo` +note: required by a const generic parameter in `foo` --> $DIR/issue-83606.rs:3:8 | LL | fn foo(_: impl std::fmt::Display) -> [usize; N] { - | ^^^^^^^^^^^^^^ required by this bound in `foo` + | ^^^^^^^^^^^^^^ required by this const generic parameter in `foo` help: consider giving this pattern a type, where the value of const parameter `N` is specified | LL | let _: [usize; N] = foo("foo"); diff --git a/tests/ui/issues/issue-98299.stderr b/tests/ui/issues/issue-98299.stderr index f4b40cbbd1955..b645267e3b91c 100644 --- a/tests/ui/issues/issue-98299.stderr +++ b/tests/ui/issues/issue-98299.stderr @@ -6,11 +6,11 @@ LL | SmallCString::try_from(p).map(|cstr| cstr); | | | type must be known at this point | -note: required by a bound in `SmallCString` +note: required by a const generic parameter in `SmallCString` --> $DIR/issue-98299.rs:10:25 | LL | pub struct SmallCString {} - | ^^^^^^^^^^^^^^ required by this bound in `SmallCString` + | ^^^^^^^^^^^^^^ required by this const generic parameter in `SmallCString` help: consider giving this closure parameter an explicit type, where the value of const parameter `N` is specified | LL | SmallCString::try_from(p).map(|cstr: SmallCString| cstr); diff --git a/tests/ui/specialization/default-proj-ty-as-type-of-const-issue-125757.stderr b/tests/ui/specialization/default-proj-ty-as-type-of-const-issue-125757.stderr index b4c14c2294e5e..71d4277275fee 100644 --- a/tests/ui/specialization/default-proj-ty-as-type-of-const-issue-125757.stderr +++ b/tests/ui/specialization/default-proj-ty-as-type-of-const-issue-125757.stderr @@ -14,11 +14,11 @@ LL | impl Wrapper {} | = help: consider constraining the associated type `::Type` to `usize` = note: for more information, visit https://doc.rust-lang.org/book/ch19-03-advanced-traits.html -note: required by a bound in `Wrapper` +note: required by a const generic parameter in `Wrapper` --> $DIR/default-proj-ty-as-type-of-const-issue-125757.rs:12:16 | LL | struct Wrapper::Type> {} - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ required by this bound in `Wrapper` + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ required by this const generic parameter in `Wrapper` error[E0308]: mismatched types --> $DIR/default-proj-ty-as-type-of-const-issue-125757.rs:15:30 diff --git a/tests/ui/transmutability/issue-101739-1.stderr b/tests/ui/transmutability/issue-101739-1.stderr index 1df7c3e2f9744..6f79bf7b42468 100644 --- a/tests/ui/transmutability/issue-101739-1.stderr +++ b/tests/ui/transmutability/issue-101739-1.stderr @@ -10,7 +10,7 @@ error: the constant `ASSUME_ALIGNMENT` is not of type `Assume` LL | Dst: BikeshedIntrinsicFrom, | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ expected `Assume`, found `bool` | -note: required by a bound in `BikeshedIntrinsicFrom` +note: required by a const generic parameter in `BikeshedIntrinsicFrom` --> $SRC_DIR/core/src/mem/transmutability.rs:LL:COL error[E0308]: mismatched types From 4226a5029e91d6a574b108be542bbaffa7290a22 Mon Sep 17 00:00:00 2001 From: Oneirical Date: Wed, 19 Jun 2024 11:09:05 -0400 Subject: [PATCH 15/23] rewrite and slightly rename issue-68794-textrel-on-minimal-lib --- .../tidy/src/allowed_run_make_makefiles.txt | 1 - .../Makefile | 18 ----------- .../bar.c | 0 .../foo.rs | 0 .../run-make/textrel-on-minimal-lib/rmake.rs | 30 +++++++++++++++++++ 5 files changed, 30 insertions(+), 19 deletions(-) delete mode 100644 tests/run-make/issue-68794-textrel-on-minimal-lib/Makefile rename tests/run-make/{issue-68794-textrel-on-minimal-lib => textrel-on-minimal-lib}/bar.c (100%) rename tests/run-make/{issue-68794-textrel-on-minimal-lib => textrel-on-minimal-lib}/foo.rs (100%) create mode 100644 tests/run-make/textrel-on-minimal-lib/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 235ea5c5c82b3..35e70ea84855c 100644 --- a/src/tools/tidy/src/allowed_run_make_makefiles.txt +++ b/src/tools/tidy/src/allowed_run_make_makefiles.txt @@ -83,7 +83,6 @@ run-make/issue-37839/Makefile run-make/issue-40535/Makefile run-make/issue-47384/Makefile run-make/issue-47551/Makefile -run-make/issue-68794-textrel-on-minimal-lib/Makefile run-make/issue-69368/Makefile run-make/issue-83045/Makefile run-make/issue-83112-incr-test-moved-file/Makefile diff --git a/tests/run-make/issue-68794-textrel-on-minimal-lib/Makefile b/tests/run-make/issue-68794-textrel-on-minimal-lib/Makefile deleted file mode 100644 index 6140b39c0e2aa..0000000000000 --- a/tests/run-make/issue-68794-textrel-on-minimal-lib/Makefile +++ /dev/null @@ -1,18 +0,0 @@ -# ignore-cross-compile -# Regression test for issue #68794 -# -# Verify that no text relocations are accidentally introduced by linking a -# minimal rust staticlib. -# -# The test links a rust static library into a shared library, and checks that -# the linker doesn't have to flag the resulting file as containing TEXTRELs. - -include ../tools.mk - -# only-linux - -all: - $(RUSTC) foo.rs - $(CC) bar.c $(call STATICLIB,foo) -fPIC -shared -o $(call DYLIB,bar) \ - $(EXTRACFLAGS) $(EXTRACXXFLAGS) - readelf -d $(call DYLIB,bar) | grep TEXTREL; test $$? -eq 1 diff --git a/tests/run-make/issue-68794-textrel-on-minimal-lib/bar.c b/tests/run-make/textrel-on-minimal-lib/bar.c similarity index 100% rename from tests/run-make/issue-68794-textrel-on-minimal-lib/bar.c rename to tests/run-make/textrel-on-minimal-lib/bar.c diff --git a/tests/run-make/issue-68794-textrel-on-minimal-lib/foo.rs b/tests/run-make/textrel-on-minimal-lib/foo.rs similarity index 100% rename from tests/run-make/issue-68794-textrel-on-minimal-lib/foo.rs rename to tests/run-make/textrel-on-minimal-lib/foo.rs diff --git a/tests/run-make/textrel-on-minimal-lib/rmake.rs b/tests/run-make/textrel-on-minimal-lib/rmake.rs new file mode 100644 index 0000000000000..4c27295591595 --- /dev/null +++ b/tests/run-make/textrel-on-minimal-lib/rmake.rs @@ -0,0 +1,30 @@ +// Verify that no text relocations are accidentally introduced by linking a +// minimal rust staticlib. +// The test links a rust static library into a shared library, and checks that +// the linker doesn't have to flag the resulting file as containing TEXTRELs. +// This bug otherwise breaks Android builds, which forbid TEXTRELs. +// See https://github.com/rust-lang/rust/issues/68794 + +//@ ignore-cross-compile +//FIXME(Oneirical): check that it works on more than just only-linux + +use run_make_support::{ + cc, dynamic_lib_name, extra_c_flags, extra_cxx_flags, llvm_readobj, rustc, static_lib_name, +}; + +fn main() { + rustc().input("foo.rs").run(); + cc().input("bar.c") + .input(static_lib_name("foo")) + .out_exe(&dynamic_lib_name("bar")) + .arg("-fPIC") + .arg("-shared") + .args(&extra_c_flags()) + .args(&extra_cxx_flags()) + .run(); + llvm_readobj() + .input(dynamic_lib_name("bar")) + .arg("--dynamic") + .run() + .assert_stdout_not_contains("TEXTREL"); +} From e64e326f6f04604f171957bc5154baf1f660e1c8 Mon Sep 17 00:00:00 2001 From: Oneirical Date: Wed, 19 Jun 2024 11:31:13 -0400 Subject: [PATCH 16/23] rewrite raw-dylib-cross-compilation to rmake --- .../tidy/src/allowed_run_make_makefiles.txt | 1 - .../raw-dylib-cross-compilation/Makefile | 20 --------- .../raw-dylib-cross-compilation/rmake.rs | 41 +++++++++++++++++++ 3 files changed, 41 insertions(+), 21 deletions(-) delete mode 100644 tests/run-make/raw-dylib-cross-compilation/Makefile create mode 100644 tests/run-make/raw-dylib-cross-compilation/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 35e70ea84855c..0fcd1f4c85df2 100644 --- a/src/tools/tidy/src/allowed_run_make_makefiles.txt +++ b/src/tools/tidy/src/allowed_run_make_makefiles.txt @@ -157,7 +157,6 @@ run-make/profile/Makefile run-make/prune-link-args/Makefile run-make/raw-dylib-alt-calling-convention/Makefile run-make/raw-dylib-c/Makefile -run-make/raw-dylib-cross-compilation/Makefile run-make/raw-dylib-custom-dlltool/Makefile run-make/raw-dylib-import-name-type/Makefile run-make/raw-dylib-inline-cross-dylib/Makefile diff --git a/tests/run-make/raw-dylib-cross-compilation/Makefile b/tests/run-make/raw-dylib-cross-compilation/Makefile deleted file mode 100644 index 2524f8500e154..0000000000000 --- a/tests/run-make/raw-dylib-cross-compilation/Makefile +++ /dev/null @@ -1,20 +0,0 @@ -# Tests that raw-dylib cross compilation works correctly - -# needs-dlltool - -# i686 dlltool.exe can't product x64 binaries. -# ignore-i686-pc-windows-gnu - -include ../tools.mk - -all: - # Build as x86 and make sure that we have x86 objects only. - $(RUSTC) --crate-type lib --crate-name i686_raw_dylib_test --target i686-pc-windows-gnu lib.rs - "$(LLVM_BIN_DIR)"/llvm-objdump -a $(TMPDIR)/libi686_raw_dylib_test.rlib > $(TMPDIR)/i686.objdump.txt - $(CGREP) "file format coff-i386" < $(TMPDIR)/i686.objdump.txt - $(CGREP) -v "file format coff-x86-64" < $(TMPDIR)/i686.objdump.txt - # Build as x64 and make sure that we have x64 objects only. - $(RUSTC) --crate-type lib --crate-name x64_raw_dylib_test --target x86_64-pc-windows-gnu lib.rs - "$(LLVM_BIN_DIR)"/llvm-objdump -a $(TMPDIR)/libx64_raw_dylib_test.rlib > $(TMPDIR)/x64.objdump.txt - $(CGREP) "file format coff-x86-64" < $(TMPDIR)/x64.objdump.txt - $(CGREP) -v "file format coff-i386" < $(TMPDIR)/x64.objdump.txt diff --git a/tests/run-make/raw-dylib-cross-compilation/rmake.rs b/tests/run-make/raw-dylib-cross-compilation/rmake.rs new file mode 100644 index 0000000000000..994345a197c40 --- /dev/null +++ b/tests/run-make/raw-dylib-cross-compilation/rmake.rs @@ -0,0 +1,41 @@ +// When cross-compiling using `raw-dylib`, rustc would try to fetch some +// very specific `dlltool` to complete the cross-compilation (such as `i686-w64-mingw32-dlltool`) +// when Windows only calls it `dlltool`. This test performs some cross-compilation in a +// way that previously failed due to this bug, and checks that it succeeds. +// See https://github.com/rust-lang/rust/pull/108355 + +//@ ignore-i686-pc-windows-msvc +// Reason: dlltool on this distribution is unable to produce x64 binaries +//@ needs-dlltool +// Reason: this is the utility being checked by this test + +use run_make_support::{llvm_objdump, rust_lib_name, rustc}; + +fn main() { + // Build as x86 and make sure that we have x86 objects only. + rustc() + .crate_type("lib") + .crate_name("i686_raw_dylib_test") + .target("i686-pc-windows-gnu") + .input("lib.rs") + .run(); + llvm_objdump() + .arg("-a") + .input(rust_lib_name("i686_raw_dylib_test")) + .run() + .assert_stdout_contains("file format coff-i386") + .assert_stdout_not_contains("file format coff-x86-64"); + // Build as x64 and make sure that we have x64 objects only. + rustc() + .crate_type("lib") + .crate_name("x64_raw_dylib_test") + .target("x86-64-pc-windows-gnu") + .input("lib.rs") + .run(); + llvm_objdump() + .arg("-a") + .input(rust_lib_name("i686_raw_dylib_test")) + .run() + .assert_stdout_not_contains("file format coff-i386") + .assert_stdout_contains("file format coff-x86-64"); +} From b3c51323b507192521cfa264a6ab129fcdb85b34 Mon Sep 17 00:00:00 2001 From: Oneirical Date: Sun, 9 Jun 2024 16:43:24 -0400 Subject: [PATCH 17/23] make assert_stderr_contains print its contents on panic --- src/doc/book | 2 +- src/tools/cargo | 2 +- src/tools/run-make-support/src/rustc.rs | 12 ------------ tests/run-make/link-args-order/rmake.rs | 19 +++++++++++-------- tests/run-make/lto-readonly-lib/rmake.rs | 16 +++++----------- 5 files changed, 18 insertions(+), 33 deletions(-) diff --git a/src/doc/book b/src/doc/book index 5228bfac8267a..45c1a6d69edfd 160000 --- a/src/doc/book +++ b/src/doc/book @@ -1 +1 @@ -Subproject commit 5228bfac8267ad24659a81b92ec5417976b5edbc +Subproject commit 45c1a6d69edfd1fc91fb7504cb73958dbd09441e diff --git a/src/tools/cargo b/src/tools/cargo index 4dcbca118ab7f..a1f47ec3f7cd0 160000 --- a/src/tools/cargo +++ b/src/tools/cargo @@ -1 +1 @@ -Subproject commit 4dcbca118ab7f9ffac4728004c983754bc6a04ff +Subproject commit a1f47ec3f7cd076986f1bfcd7061f2e8cb1a726e diff --git a/src/tools/run-make-support/src/rustc.rs b/src/tools/run-make-support/src/rustc.rs index 7e5a637e20e15..289d847a5728c 100644 --- a/src/tools/run-make-support/src/rustc.rs +++ b/src/tools/run-make-support/src/rustc.rs @@ -236,18 +236,6 @@ impl Rustc { self } - /// Add an extra argument to prepend the linker invocation, via `-Zpre-link-arg`. - pub fn pre_link_arg(&mut self, link_arg: &str) -> &mut Self { - self.cmd.arg(format!("-Zpre-link-arg={link_arg}")); - self - } - - /// Add multiple extra arguments to the linker invocation, via `-Zpre-link-args`. - pub fn pre_link_args(&mut self, link_args: &str) -> &mut Self { - self.cmd.arg(format!("-Zpre-link-args={link_args}")); - self - } - /// Specify a stdin input pub fn stdin>(&mut self, input: I) -> &mut Self { self.cmd.set_stdin(input.as_ref().to_vec().into_boxed_slice()); diff --git a/tests/run-make/link-args-order/rmake.rs b/tests/run-make/link-args-order/rmake.rs index 4530251c7a585..d238ad23f27c7 100644 --- a/tests/run-make/link-args-order/rmake.rs +++ b/tests/run-make/link-args-order/rmake.rs @@ -3,6 +3,9 @@ // checks that linker arguments remain intact and in the order they were originally passed in. // See https://github.com/rust-lang/rust/pull/70665 +//@ ignore-msvc +// Reason: the ld linker does not exist on Windows. + use run_make_support::rustc; fn main() { @@ -10,18 +13,18 @@ fn main() { .input("empty.rs") .linker_flavor("ld") .link_arg("a") - .link_args("\"b c\"") - .link_args("\"d e\"") + .link_args("b c") + .link_args("d e") .link_arg("f") .run_fail() - .assert_stderr_contains("\"a\" \"b\" \"c\" \"d\" \"e\" \"f\""); + .assert_stderr_contains(r#""a" "b" "c" "d" "e" "f""#); rustc() .input("empty.rs") .linker_flavor("ld") - .pre_link_arg("a") - .pre_link_args("\"b c\"") - .pre_link_args("\"d e\"") - .pre_link_arg("f") + .arg("-Zpre-link-arg=a") + .arg("-Zpre-link-args=b c") + .arg("-Zpre-link-args=d e") + .arg("-Zpre-link-arg=f") .run_fail() - .assert_stderr_contains("\"a\" \"b\" \"c\" \"d\" \"e\" \"f\""); + .assert_stderr_contains(r#""a" "b" "c" "d" "e" "f""#); } diff --git a/tests/run-make/lto-readonly-lib/rmake.rs b/tests/run-make/lto-readonly-lib/rmake.rs index bf1dafee697dc..9eb135addd9ec 100644 --- a/tests/run-make/lto-readonly-lib/rmake.rs +++ b/tests/run-make/lto-readonly-lib/rmake.rs @@ -8,18 +8,12 @@ //@ ignore-cross-compile use run_make_support::fs_wrapper; -use run_make_support::{cwd, run, rustc}; +use run_make_support::{run, rust_lib_name, rustc, test_while_readonly}; fn main() { rustc().input("lib.rs").run(); - let entries = fs_wrapper::read_dir(cwd()); - for entry in entries { - if entry.path().extension().and_then(|s| s.to_str()) == Some("rlib") { - let mut perms = fs_wrapper::metadata(entry.path()).permissions(); - perms.set_readonly(true); - fs_wrapper::set_permissions(entry.path(), perms); - } - } - rustc().input("main.rs").arg("-Clto").run(); - run("main"); + test_while_readonly(rust_lib_name("lib"), || { + rustc().input("main.rs").arg("-Clto").run(); + run("main"); + }); } From 95e214d6e5cbacd4bcc12f449674dbcc3f409a02 Mon Sep 17 00:00:00 2001 From: The 8472 Date: Wed, 19 Jun 2024 20:01:32 +0200 Subject: [PATCH 18/23] reword the hint::blackbox non-guarantees People were tripped up by the "precludes", interpreting it that this function must not ever be used in cryptographic contexts rather than the std lib merely making zero promises about it being fit-for-purpose. What remains unchanged is that if someone does try to use it *despite the warnings* then it is on them to pin their compiler versions and verify the assembly of every single binary build they do. --- library/core/src/hint.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/library/core/src/hint.rs b/library/core/src/hint.rs index 6e2d88c6b8337..c3b16c34293ce 100644 --- a/library/core/src/hint.rs +++ b/library/core/src/hint.rs @@ -263,7 +263,7 @@ pub fn spin_loop() { /// extent to which it can block optimisations may vary depending upon the platform and code-gen /// backend used. Programs cannot rely on `black_box` for *correctness*, beyond it behaving as the /// identity function. As such, it **must not be relied upon to control critical program behavior.** -/// This _immediately_ precludes any direct use of this function for cryptographic or security +/// This also means that this function does not offer any guarantees for cryptographic or security /// purposes. /// /// [`std::convert::identity`]: crate::convert::identity From 445eb08450d26fdce7913db9381d0921fc3adb82 Mon Sep 17 00:00:00 2001 From: Oneirical Date: Wed, 19 Jun 2024 11:38:22 -0400 Subject: [PATCH 19/23] rewrite used-cdylib-macos to rmake --- .../tidy/src/allowed_run_make_makefiles.txt | 1 - tests/run-make/textrel-on-minimal-lib/rmake.rs | 3 ++- tests/run-make/used-cdylib-macos/Makefile | 11 ----------- tests/run-make/used-cdylib-macos/rmake.rs | 16 ++++++++++++++++ 4 files changed, 18 insertions(+), 13 deletions(-) delete mode 100644 tests/run-make/used-cdylib-macos/Makefile create mode 100644 tests/run-make/used-cdylib-macos/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 0fcd1f4c85df2..7edfda1dd7773 100644 --- a/src/tools/tidy/src/allowed_run_make_makefiles.txt +++ b/src/tools/tidy/src/allowed_run_make_makefiles.txt @@ -212,7 +212,6 @@ run-make/translation/Makefile run-make/type-mismatch-same-crate-name/Makefile run-make/unstable-flag-required/Makefile run-make/use-suggestions-rust-2018/Makefile -run-make/used-cdylib-macos/Makefile run-make/volatile-intrinsics/Makefile run-make/wasm-exceptions-nostd/Makefile run-make/wasm-override-linker/Makefile diff --git a/tests/run-make/textrel-on-minimal-lib/rmake.rs b/tests/run-make/textrel-on-minimal-lib/rmake.rs index 4c27295591595..eba664479f112 100644 --- a/tests/run-make/textrel-on-minimal-lib/rmake.rs +++ b/tests/run-make/textrel-on-minimal-lib/rmake.rs @@ -6,7 +6,8 @@ // See https://github.com/rust-lang/rust/issues/68794 //@ ignore-cross-compile -//FIXME(Oneirical): check that it works on more than just only-linux +//@ ignore-windows +// Reason: There is no `bar.dll` produced by CC to run readobj on use run_make_support::{ cc, dynamic_lib_name, extra_c_flags, extra_cxx_flags, llvm_readobj, rustc, static_lib_name, diff --git a/tests/run-make/used-cdylib-macos/Makefile b/tests/run-make/used-cdylib-macos/Makefile deleted file mode 100644 index bdf914a1ca950..0000000000000 --- a/tests/run-make/used-cdylib-macos/Makefile +++ /dev/null @@ -1,11 +0,0 @@ -include ../tools.mk - -# only-apple -# -# This checks that `#[used]` passes through to the linker on -# Apple targets. This is subject to change in the future, see -# https://github.com/rust-lang/rust/pull/93718 for discussion - -all: - $(RUSTC) -Copt-level=3 dylib_used.rs - nm $(TMPDIR)/libdylib_used.dylib | $(CGREP) VERY_IMPORTANT_SYMBOL diff --git a/tests/run-make/used-cdylib-macos/rmake.rs b/tests/run-make/used-cdylib-macos/rmake.rs new file mode 100644 index 0000000000000..be6221f1e4253 --- /dev/null +++ b/tests/run-make/used-cdylib-macos/rmake.rs @@ -0,0 +1,16 @@ +// This checks that `#[used]` passes through to the linker on +// Apple targets. This is subject to change in the future. +// See https://github.com/rust-lang/rust/pull/93718 + +//@ only-apple + +use run_make_support::{dynamic_lib_name, llvm_readobj, rustc}; + +fn main() { + rustc().opt_level("3").input("dylib_used.rs").run(); + llvm_readobj() + .input(dynamic_lib_name("dylib_used")) + .arg("--dt") + .run() + .assert_stdout_contains("VERY_IMPORTANT_SYMBOL"); +} From e7ea063622d4a150fb22030b78d21b18f4855481 Mon Sep 17 00:00:00 2001 From: Oneirical Date: Tue, 18 Jun 2024 16:43:52 -0400 Subject: [PATCH 20/23] rewrite forced-unwind-terminate-pof to rmake --- .../tidy/src/allowed_run_make_makefiles.txt | 1 - .../forced-unwind-terminate-pof/Makefile | 9 --------- .../forced-unwind-terminate-pof/rmake.rs | 16 ++++++++++++++++ .../metadata-flag-frobs-symbols/rmake.rs | 1 - 4 files changed, 16 insertions(+), 11 deletions(-) delete mode 100644 tests/run-make/forced-unwind-terminate-pof/Makefile create mode 100644 tests/run-make/forced-unwind-terminate-pof/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 8eee16e87a88e..a5ccb1b784247 100644 --- a/src/tools/tidy/src/allowed_run_make_makefiles.txt +++ b/src/tools/tidy/src/allowed_run_make_makefiles.txt @@ -51,7 +51,6 @@ run-make/extern-multiple-copies/Makefile run-make/extern-multiple-copies2/Makefile run-make/extra-filename-with-temp-outputs/Makefile run-make/fmt-write-bloat/Makefile -run-make/forced-unwind-terminate-pof/Makefile run-make/foreign-double-unwind/Makefile run-make/foreign-exceptions/Makefile run-make/foreign-rust-exceptions/Makefile diff --git a/tests/run-make/forced-unwind-terminate-pof/Makefile b/tests/run-make/forced-unwind-terminate-pof/Makefile deleted file mode 100644 index 871621520b910..0000000000000 --- a/tests/run-make/forced-unwind-terminate-pof/Makefile +++ /dev/null @@ -1,9 +0,0 @@ -# ignore-cross-compile -# only-linux -include ../tools.mk - -all: foo - $(call RUN,foo) | $(CGREP) -v "cannot unwind" - -foo: foo.rs - $(RUSTC) $< diff --git a/tests/run-make/forced-unwind-terminate-pof/rmake.rs b/tests/run-make/forced-unwind-terminate-pof/rmake.rs new file mode 100644 index 0000000000000..320ddb172b6ec --- /dev/null +++ b/tests/run-make/forced-unwind-terminate-pof/rmake.rs @@ -0,0 +1,16 @@ +// During a forced unwind, crossing the non-Plain Old Frame +// would define the forced unwind as undefined behaviour, and +// immediately abort the unwinding process. This test checks +// that the forced unwinding takes precedence. +// See https://github.com/rust-lang/rust/issues/101469 + +//@ ignore-cross-compile +//@ ignore-windows +//Reason: pthread (POSIX threads) is not available on Windows + +use run_make_support::{run, rustc}; + +fn main() { + rustc().input("foo.rs").run(); + run("foo").assert_stdout_not_contains("cannot unwind"); +} diff --git a/tests/run-make/metadata-flag-frobs-symbols/rmake.rs b/tests/run-make/metadata-flag-frobs-symbols/rmake.rs index 12c07f9e3aeec..938886957fb9a 100644 --- a/tests/run-make/metadata-flag-frobs-symbols/rmake.rs +++ b/tests/run-make/metadata-flag-frobs-symbols/rmake.rs @@ -15,7 +15,6 @@ fn main() { .input("bar.rs") .extern_("foo1", rust_lib_name("foo-a")) .extern_("foo2", rust_lib_name("foo-b")) - .print("link-args") .run(); run("bar"); } From 7d9a92ba31122950f2c7f6a71ad6dee49b3e95e4 Mon Sep 17 00:00:00 2001 From: Nicholas Nethercote Date: Thu, 13 Jun 2024 13:40:14 +1000 Subject: [PATCH 21/23] Inline `can_begin_literal_maybe_minus` call into two places. It's clearer this way, because the `Interpolated` cases in `can_begin_const_arg` and `is_pat_range_end_start` are more permissive than the `Interpolated` cases in `can_begin_literal_maybe_minus`. --- compiler/rustc_ast/src/token.rs | 5 +++-- compiler/rustc_parse/src/parser/pat.rs | 3 ++- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/compiler/rustc_ast/src/token.rs b/compiler/rustc_ast/src/token.rs index 109c401bb6a20..4d513797f5fe8 100644 --- a/compiler/rustc_ast/src/token.rs +++ b/compiler/rustc_ast/src/token.rs @@ -558,9 +558,10 @@ impl Token { /// Returns `true` if the token can appear at the start of a const param. pub fn can_begin_const_arg(&self) -> bool { match self.kind { - OpenDelim(Delimiter::Brace) => true, + OpenDelim(Delimiter::Brace) | Literal(..) | BinOp(Minus) => true, + Ident(name, IdentIsRaw::No) if name.is_bool_lit() => true, Interpolated(ref nt) => matches!(&**nt, NtExpr(..) | NtBlock(..) | NtLiteral(..)), - _ => self.can_begin_literal_maybe_minus(), + _ => false, } } diff --git a/compiler/rustc_parse/src/parser/pat.rs b/compiler/rustc_parse/src/parser/pat.rs index 03aea0888d955..6f2b717715945 100644 --- a/compiler/rustc_parse/src/parser/pat.rs +++ b/compiler/rustc_parse/src/parser/pat.rs @@ -939,7 +939,8 @@ impl<'a> Parser<'a> { || self.look_ahead(dist, |t| { t.is_path_start() // e.g. `MY_CONST`; || t.kind == token::Dot // e.g. `.5` for recovery; - || t.can_begin_literal_maybe_minus() // e.g. `42`. + || matches!(t.kind, token::Literal(..) | token::BinOp(token::Minus)) + || t.is_bool_lit() || t.is_whole_expr() || t.is_lifetime() // recover `'a` instead of `'a'` || (self.may_recover() // recover leading `(` From c6f78270b66b2ffc78742006445df76105b7d558 Mon Sep 17 00:00:00 2001 From: Nicholas Nethercote Date: Thu, 13 Jun 2024 13:52:20 +1000 Subject: [PATCH 22/23] Introduce `can_begin_string_literal`. We currently use `can_begin_literal_maybe_minus` in a couple of places where only string literals are allowed. This commit introduces a more specific function, which makes things clearer. It doesn't change behaviour because the two functions affected (`is_unsafe_foreign_mod` and `check_keyword_case`) are always followed by a call to `parse_abi`, which checks again for a string literal. --- compiler/rustc_ast/src/token.rs | 15 +++++++++++++++ compiler/rustc_parse/src/parser/item.rs | 4 ++-- 2 files changed, 17 insertions(+), 2 deletions(-) diff --git a/compiler/rustc_ast/src/token.rs b/compiler/rustc_ast/src/token.rs index 4d513797f5fe8..4dc41a02cb853 100644 --- a/compiler/rustc_ast/src/token.rs +++ b/compiler/rustc_ast/src/token.rs @@ -621,6 +621,21 @@ impl Token { } } + pub fn can_begin_string_literal(&self) -> bool { + match self.uninterpolate().kind { + Literal(..) => true, + Interpolated(ref nt) => match &**nt { + NtLiteral(_) => true, + NtExpr(e) => match &e.kind { + ast::ExprKind::Lit(_) => true, + _ => false, + }, + _ => false, + }, + _ => false, + } + } + /// A convenience function for matching on identifiers during parsing. /// Turns interpolated identifier (`$i: ident`) or lifetime (`$l: lifetime`) token /// into the regular identifier or lifetime token it refers to, diff --git a/compiler/rustc_parse/src/parser/item.rs b/compiler/rustc_parse/src/parser/item.rs index 2db777a9f70c3..3e1ea7b129de0 100644 --- a/compiler/rustc_parse/src/parser/item.rs +++ b/compiler/rustc_parse/src/parser/item.rs @@ -1259,7 +1259,7 @@ impl<'a> Parser<'a> { self.token.is_keyword(kw::Unsafe) && self.is_keyword_ahead(1, &[kw::Extern]) && self.look_ahead( - 2 + self.look_ahead(2, |t| t.can_begin_literal_maybe_minus() as usize), + 2 + self.look_ahead(2, |t| t.can_begin_string_literal() as usize), |t| t.kind == token::OpenDelim(Delimiter::Brace), ) } @@ -2448,7 +2448,7 @@ impl<'a> Parser<'a> { }) // `extern ABI fn` || self.check_keyword_case(kw::Extern, case) - && self.look_ahead(1, |t| t.can_begin_literal_maybe_minus()) + && self.look_ahead(1, |t| t.can_begin_string_literal()) && (self.look_ahead(2, |t| t.is_keyword_case(kw::Fn, case)) || // this branch is only for better diagnostic in later, `pub` is not allowed here (self.may_recover() From f44494cb3ad0a1c599620e9c020cf7e6a54bb774 Mon Sep 17 00:00:00 2001 From: Jerry Wang Date: Sat, 15 Jun 2024 21:47:27 -0400 Subject: [PATCH 23/23] Migrate `run-make/comment-section` to `rmake.rs` --- .../tidy/src/allowed_run_make_makefiles.txt | 1 - tests/run-make/comment-section/Makefile | 18 ------- tests/run-make/comment-section/rmake.rs | 47 +++++++++++++++++++ 3 files changed, 47 insertions(+), 19 deletions(-) delete mode 100644 tests/run-make/comment-section/Makefile create mode 100644 tests/run-make/comment-section/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 2b273b92ec2d8..c4c1ad0334138 100644 --- a/src/tools/tidy/src/allowed_run_make_makefiles.txt +++ b/src/tools/tidy/src/allowed_run_make_makefiles.txt @@ -10,7 +10,6 @@ run-make/c-unwind-abi-catch-panic/Makefile run-make/cat-and-grep-sanity-check/Makefile run-make/cdylib-dylib-linkage/Makefile run-make/cdylib-fewer-symbols/Makefile -run-make/comment-section/Makefile run-make/compiler-lookup-paths-2/Makefile run-make/compiler-lookup-paths/Makefile run-make/compiler-rt-works-on-mingw/Makefile diff --git a/tests/run-make/comment-section/Makefile b/tests/run-make/comment-section/Makefile deleted file mode 100644 index d0b98176ffed9..0000000000000 --- a/tests/run-make/comment-section/Makefile +++ /dev/null @@ -1,18 +0,0 @@ -# Both GCC and Clang write by default a `.comment` section with compiler information. Rustc received a similar .comment section, so this tests checks that this section properly appears. -# See https://github.com/rust-lang/rust/commit/74b8d324eb77a8f337b35dc68ac91b0c2c06debc - -include ../tools.mk - -# only-linux - -all: - echo 'fn main(){}' | $(RUSTC) - --emit=link,obj -Csave-temps --target=$(TARGET) - - # Check linked output has a `.comment` section with the expected content. - readelf -p '.comment' $(TMPDIR)/rust_out | $(CGREP) -F 'rustc version 1.' - - # Check all object files (including temporary outputs) have a `.comment` - # section with the expected content. - set -e; for f in $(TMPDIR)/*.o; do \ - readelf -p '.comment' $$f | $(CGREP) -F 'rustc version 1.'; \ - done diff --git a/tests/run-make/comment-section/rmake.rs b/tests/run-make/comment-section/rmake.rs new file mode 100644 index 0000000000000..41df04da7a578 --- /dev/null +++ b/tests/run-make/comment-section/rmake.rs @@ -0,0 +1,47 @@ +// Both GCC and Clang write by default a `.comment` section with compiler information. +// Rustc received a similar .comment section, so this tests checks that this section +// properly appears. +// See https://github.com/rust-lang/rust/commit/74b8d324eb77a8f337b35dc68ac91b0c2c06debc + +//@ only-linux +// FIXME(jieyouxu): check cross-compile setup +//@ ignore-cross-compile + +use std::path::PathBuf; + +use run_make_support::llvm_readobj; +use run_make_support::rustc; +use run_make_support::{cwd, env_var, read_dir, run_in_tmpdir}; + +fn main() { + let target = env_var("TARGET"); + + rustc() + .arg("-") + .stdin("fn main() {}") + .emit("link,obj") + .arg("-Csave-temps") + .target(&target) + .run(); + + // Check linked output has a `.comment` section with the expected content. + llvm_readobj() + .section(".comment") + .input("rust_out") + .run() + .assert_stdout_contains("rustc version 1."); + + // Check all object files (including temporary outputs) have a `.comment` + // section with the expected content. + read_dir(cwd(), |f| { + if !f.extension().is_some_and(|ext| ext == "o") { + return; + } + + llvm_readobj() + .section(".comment") + .input(&f) + .run() + .assert_stdout_contains("rustc version 1."); + }); +}