From 2c31c550206ae0f5d88db5f3d46e0957b669dfc9 Mon Sep 17 00:00:00 2001 From: Michael Goulet Date: Wed, 25 Dec 2024 01:27:21 +0000 Subject: [PATCH 1/4] Use PostBorrowckAnalysis in check_coroutine_obligations --- .../rustc_hir_analysis/src/check/check.rs | 23 ++++++++++++------- tests/ui/coroutine/issue-52304.rs | 2 ++ 2 files changed, 17 insertions(+), 8 deletions(-) diff --git a/compiler/rustc_hir_analysis/src/check/check.rs b/compiler/rustc_hir_analysis/src/check/check.rs index 5548a6a6ef797..8c6059d49a840 100644 --- a/compiler/rustc_hir_analysis/src/check/check.rs +++ b/compiler/rustc_hir_analysis/src/check/check.rs @@ -1845,13 +1845,18 @@ pub(super) fn check_coroutine_obligations( debug!(?typeck_results.coroutine_stalled_predicates); + let mode = if tcx.next_trait_solver_globally() { + TypingMode::post_borrowck_analysis(tcx, def_id) + } else { + TypingMode::analysis_in_body(tcx, def_id) + }; + let infcx = tcx .infer_ctxt() // typeck writeback gives us predicates with their regions erased. // As borrowck already has checked lifetimes, we do not need to do it again. .ignoring_regions() - // FIXME(#132279): This should eventually use the already defined hidden types. - .build(TypingMode::analysis_in_body(tcx, def_id)); + .build(mode); let ocx = ObligationCtxt::new_with_diagnostics(&infcx); for (predicate, cause) in &typeck_results.coroutine_stalled_predicates { @@ -1864,12 +1869,14 @@ pub(super) fn check_coroutine_obligations( return Err(infcx.err_ctxt().report_fulfillment_errors(errors)); } - // Check that any hidden types found when checking these stalled coroutine obligations - // are valid. - for (key, ty) in infcx.take_opaque_types() { - let hidden_type = infcx.resolve_vars_if_possible(ty.hidden_type); - let key = infcx.resolve_vars_if_possible(key); - sanity_check_found_hidden_type(tcx, key, hidden_type)?; + if !tcx.next_trait_solver_globally() { + // Check that any hidden types found when checking these stalled coroutine obligations + // are valid. + for (key, ty) in infcx.take_opaque_types() { + let hidden_type = infcx.resolve_vars_if_possible(ty.hidden_type); + let key = infcx.resolve_vars_if_possible(key); + sanity_check_found_hidden_type(tcx, key, hidden_type)?; + } } Ok(()) diff --git a/tests/ui/coroutine/issue-52304.rs b/tests/ui/coroutine/issue-52304.rs index 552bc0028ee04..77dfe8391956f 100644 --- a/tests/ui/coroutine/issue-52304.rs +++ b/tests/ui/coroutine/issue-52304.rs @@ -1,4 +1,6 @@ //@ check-pass +//@ revisions: current next +//@ ignore-compare-mode-next-solver (explicit revisions) #![feature(coroutines, coroutine_trait)] From 592259930b27525789f14f07396f02b254d4dfc9 Mon Sep 17 00:00:00 2001 From: Michael Goulet Date: Wed, 25 Dec 2024 20:14:43 +0000 Subject: [PATCH 2/4] Report correct SelectionError for ConstArgHasType in new solver fulfill --- .../src/solve/fulfill.rs | 19 ++++++++++++++++++- ...nst-in-impl-fn-return-type.current.stderr} | 4 ++-- .../const-in-impl-fn-return-type.next.stderr | 15 +++++++++++++++ .../const-in-impl-fn-return-type.rs | 5 +++++ 4 files changed, 40 insertions(+), 3 deletions(-) rename tests/ui/typeck/issue-114918/{const-in-impl-fn-return-type.stderr => const-in-impl-fn-return-type.current.stderr} (81%) create mode 100644 tests/ui/typeck/issue-114918/const-in-impl-fn-return-type.next.stderr diff --git a/compiler/rustc_trait_selection/src/solve/fulfill.rs b/compiler/rustc_trait_selection/src/solve/fulfill.rs index 2b2623a050ec9..c79a8abca2049 100644 --- a/compiler/rustc_trait_selection/src/solve/fulfill.rs +++ b/compiler/rustc_trait_selection/src/solve/fulfill.rs @@ -10,9 +10,9 @@ use rustc_infer::traits::{ self, FromSolverError, MismatchedProjectionTypes, Obligation, ObligationCause, ObligationCauseCode, PredicateObligation, PredicateObligations, SelectionError, TraitEngine, }; -use rustc_middle::bug; use rustc_middle::ty::error::{ExpectedFound, TypeError}; use rustc_middle::ty::{self, TyCtxt}; +use rustc_middle::{bug, span_bug}; use rustc_next_trait_solver::solve::{GenerateProofTree, HasChanged, SolverDelegateEvalExt as _}; use tracing::{instrument, trace}; @@ -258,6 +258,23 @@ fn fulfillment_error_for_no_solution<'tcx>( MismatchedProjectionTypes { err: TypeError::Mismatch }, ) } + ty::PredicateKind::Clause(ty::ClauseKind::ConstArgHasType(ct, expected_ty)) => { + let ct_ty = match ct.kind() { + ty::ConstKind::Unevaluated(uv) => { + infcx.tcx.type_of(uv.def).instantiate(infcx.tcx, uv.args) + } + ty::ConstKind::Param(param_ct) => param_ct.find_ty_from_env(obligation.param_env), + _ => span_bug!( + obligation.cause.span, + "ConstArgHasWrongType failed but we don't know how to compute type" + ), + }; + FulfillmentErrorCode::Select(SelectionError::ConstArgHasWrongType { + ct, + ct_ty, + expected_ty, + }) + } ty::PredicateKind::NormalizesTo(..) => { FulfillmentErrorCode::Project(MismatchedProjectionTypes { err: TypeError::Mismatch }) } diff --git a/tests/ui/typeck/issue-114918/const-in-impl-fn-return-type.stderr b/tests/ui/typeck/issue-114918/const-in-impl-fn-return-type.current.stderr similarity index 81% rename from tests/ui/typeck/issue-114918/const-in-impl-fn-return-type.stderr rename to tests/ui/typeck/issue-114918/const-in-impl-fn-return-type.current.stderr index 8017e5446cc71..1bcc0dbaf6726 100644 --- a/tests/ui/typeck/issue-114918/const-in-impl-fn-return-type.stderr +++ b/tests/ui/typeck/issue-114918/const-in-impl-fn-return-type.current.stderr @@ -1,11 +1,11 @@ error[E0308]: mismatched types - --> $DIR/const-in-impl-fn-return-type.rs:15:39 + --> $DIR/const-in-impl-fn-return-type.rs:20:39 | LL | fn func() -> [(); { () }] { | ^^ expected `usize`, found `()` error: the constant `N` is not of type `usize` - --> $DIR/const-in-impl-fn-return-type.rs:7:32 + --> $DIR/const-in-impl-fn-return-type.rs:12:32 | LL | fn func() -> [(); N]; | ^^^^^^^ expected `usize`, found `u32` diff --git a/tests/ui/typeck/issue-114918/const-in-impl-fn-return-type.next.stderr b/tests/ui/typeck/issue-114918/const-in-impl-fn-return-type.next.stderr new file mode 100644 index 0000000000000..1bcc0dbaf6726 --- /dev/null +++ b/tests/ui/typeck/issue-114918/const-in-impl-fn-return-type.next.stderr @@ -0,0 +1,15 @@ +error[E0308]: mismatched types + --> $DIR/const-in-impl-fn-return-type.rs:20:39 + | +LL | fn func() -> [(); { () }] { + | ^^ expected `usize`, found `()` + +error: the constant `N` is not of type `usize` + --> $DIR/const-in-impl-fn-return-type.rs:12:32 + | +LL | fn func() -> [(); N]; + | ^^^^^^^ expected `usize`, found `u32` + +error: aborting due to 2 previous errors + +For more information about this error, try `rustc --explain E0308`. diff --git a/tests/ui/typeck/issue-114918/const-in-impl-fn-return-type.rs b/tests/ui/typeck/issue-114918/const-in-impl-fn-return-type.rs index 5eef268872113..6bbac9d45bbe5 100644 --- a/tests/ui/typeck/issue-114918/const-in-impl-fn-return-type.rs +++ b/tests/ui/typeck/issue-114918/const-in-impl-fn-return-type.rs @@ -1,4 +1,9 @@ +//@ revisions: current next +//@[next] compile-flags: -Znext-solver +//@ ignore-compare-mode-next-solver (explicit revisions) + // Regression test for #114918 + // Test that a const generic enclosed in a block within the return type // of an impl fn produces a type mismatch error instead of triggering // a const eval cycle From 85e0d42a776cc0fc655b39cb9e085d36caec071b Mon Sep 17 00:00:00 2001 From: Zalathar Date: Mon, 6 Jan 2025 12:50:10 +1100 Subject: [PATCH 3/4] Don't enable anyhow's `backtrace` feature in opt-dist As of the stabilization of `std::backtrace` in Rust 1.65, this package flag has no effect other than to enable an unused dependency on the `backtrace` crate. --- Cargo.lock | 3 --- src/tools/opt-dist/Cargo.toml | 2 +- 2 files changed, 1 insertion(+), 4 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 62541eb9d479c..0b38cb92e2b88 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -185,9 +185,6 @@ name = "anyhow" version = "1.0.95" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "34ac096ce696dc2fcabef30516bb13c0a68a11d30131d3df6f04711467681b04" -dependencies = [ - "backtrace", -] [[package]] name = "ar_archive_writer" diff --git a/src/tools/opt-dist/Cargo.toml b/src/tools/opt-dist/Cargo.toml index d0413911014f4..cea234cc74cb2 100644 --- a/src/tools/opt-dist/Cargo.toml +++ b/src/tools/opt-dist/Cargo.toml @@ -7,7 +7,7 @@ edition = "2021" build_helper = { path = "../../build_helper" } env_logger = "0.11" log = "0.4" -anyhow = { version = "1", features = ["backtrace"] } +anyhow = "1" humantime = "2" humansize = "2" sysinfo = { version = "0.31.2", default-features = false, features = ["disk"] } From 591bf634394867c44cfc5cdaf391f948e6c3d11a Mon Sep 17 00:00:00 2001 From: crystalstall Date: Mon, 6 Jan 2025 15:47:49 +0800 Subject: [PATCH 4/4] chore: remove redundant words in comment Signed-off-by: crystalstall --- library/std/src/ffi/os_str.rs | 2 +- library/std/src/pipe.rs | 2 +- library/std/src/sync/poison/mutex.rs | 2 +- .../patches/gcc/8.5.0/0002-hidden-jump-target.patch | 2 +- tests/ui/duplicate/multiple-types-with-same-name-and-derive.rs | 2 +- 5 files changed, 5 insertions(+), 5 deletions(-) diff --git a/library/std/src/ffi/os_str.rs b/library/std/src/ffi/os_str.rs index fff140f1564fa..7fb57d410431e 100644 --- a/library/std/src/ffi/os_str.rs +++ b/library/std/src/ffi/os_str.rs @@ -550,7 +550,7 @@ impl OsString { OsStr::from_inner_mut(self.inner.leak()) } - /// Truncate the the `OsString` to the specified length. + /// Truncate the `OsString` to the specified length. /// /// # Panics /// Panics if `len` does not lie on a valid `OsStr` boundary diff --git a/library/std/src/pipe.rs b/library/std/src/pipe.rs index 06f3fd9fdffe8..913c22588a76c 100644 --- a/library/std/src/pipe.rs +++ b/library/std/src/pipe.rs @@ -97,7 +97,7 @@ impl PipeReader { /// let mut jobs = vec![]; /// let (reader, mut writer) = std::pipe::pipe()?; /// - /// // Write NUM_SLOT characters the the pipe. + /// // Write NUM_SLOT characters the pipe. /// writer.write_all(&[b'|'; NUM_SLOT as usize])?; /// /// // Spawn several processes that read a character from the pipe, do some work, then diff --git a/library/std/src/sync/poison/mutex.rs b/library/std/src/sync/poison/mutex.rs index e28c2090afed7..01ef71a187fec 100644 --- a/library/std/src/sync/poison/mutex.rs +++ b/library/std/src/sync/poison/mutex.rs @@ -534,7 +534,7 @@ impl Mutex { /// # Errors /// /// If another user of this mutex panicked while holding the mutex, then - /// this call will return an error containing the the underlying data + /// this call will return an error containing the underlying data /// instead. /// /// # Examples diff --git a/src/ci/docker/host-x86_64/dist-riscv64-linux/patches/gcc/8.5.0/0002-hidden-jump-target.patch b/src/ci/docker/host-x86_64/dist-riscv64-linux/patches/gcc/8.5.0/0002-hidden-jump-target.patch index 7ae4469428b13..1ae0ecf6cb5ea 100644 --- a/src/ci/docker/host-x86_64/dist-riscv64-linux/patches/gcc/8.5.0/0002-hidden-jump-target.patch +++ b/src/ci/docker/host-x86_64/dist-riscv64-linux/patches/gcc/8.5.0/0002-hidden-jump-target.patch @@ -10,7 +10,7 @@ https://sourceware.org/bugzilla/show_bug.cgi?id=28509 And this is the first version of the proposed binutils patch, https://sourceware.org/pipermail/binutils/2021-November/118398.html -After applying the binutils patch, I get the the unexpected error when +After applying the binutils patch, I get the unexpected error when building libgcc, /scratch/nelsonc/riscv-gnu-toolchain/riscv-gcc/libgcc/config/riscv/div.S:42: diff --git a/tests/ui/duplicate/multiple-types-with-same-name-and-derive.rs b/tests/ui/duplicate/multiple-types-with-same-name-and-derive.rs index 72375eb0b3e83..f3bf299aa65f4 100644 --- a/tests/ui/duplicate/multiple-types-with-same-name-and-derive.rs +++ b/tests/ui/duplicate/multiple-types-with-same-name-and-derive.rs @@ -1,5 +1,5 @@ // Here, there are two types with the same name. One of these has a `derive` annotation, but in the -// expansion these `impl`s are associated to the the *other* type. There is a suggestion to remove +// expansion these `impl`s are associated to the *other* type. There is a suggestion to remove // unneeded type parameters, but because we're now point at a type with no type parameters, the // suggestion would suggest removing code from an empty span, which would ICE in nightly. //