From a8b3046eca631ea7eb053fabdfe2fce97c5279f2 Mon Sep 17 00:00:00 2001 From: austaras Date: Thu, 4 Sep 2025 18:24:01 +0800 Subject: [PATCH] fix: check uncertain subst when unsized coerce --- crates/hir-ty/src/infer/coerce.rs | 3 ++- crates/hir-ty/src/infer/unify.rs | 8 +++++--- crates/hir-ty/src/tests/coercion.rs | 4 ++-- 3 files changed, 9 insertions(+), 6 deletions(-) diff --git a/crates/hir-ty/src/infer/coerce.rs b/crates/hir-ty/src/infer/coerce.rs index df516662bfd3..824caca64155 100644 --- a/crates/hir-ty/src/infer/coerce.rs +++ b/crates/hir-ty/src/infer/coerce.rs @@ -9,6 +9,7 @@ use std::iter; use chalk_ir::{BoundVar, Mutability, TyKind, TyVariableKind, cast::Cast}; use hir_def::{hir::ExprId, lang_item::LangItem}; +use rustc_next_trait_solver::solve::HasChanged; use rustc_type_ir::solve::Certainty; use stdx::always; use triomphe::Arc; @@ -716,7 +717,7 @@ impl<'db> InferenceTable<'db> { let goal: Goal = coerce_unsized_tref.cast(Interner); self.commit_if_ok(|table| match table.solve_obligation(goal) { - Ok(Certainty::Yes) => Ok(()), + Ok((_, Certainty::Yes) | (HasChanged::Yes, Certainty::Maybe(_))) => Ok(()), _ => Err(TypeError), })?; diff --git a/crates/hir-ty/src/infer/unify.rs b/crates/hir-ty/src/infer/unify.rs index 19b83d3c212d..50191e89d30b 100644 --- a/crates/hir-ty/src/infer/unify.rs +++ b/crates/hir-ty/src/infer/unify.rs @@ -728,11 +728,13 @@ impl<'a> InferenceTable<'a> { } #[tracing::instrument(level = "debug", skip(self))] - pub(crate) fn solve_obligation(&mut self, goal: Goal) -> Result { + pub(crate) fn solve_obligation( + &mut self, + goal: Goal, + ) -> Result<(HasChanged, Certainty), NoSolution> { let goal = InEnvironment::new(&self.trait_env.env, goal); let goal = goal.to_nextsolver(self.interner); - let result = next_trait_solve_in_ctxt(&self.infer_ctxt, goal); - result.map(|m| m.1) + next_trait_solve_in_ctxt(&self.infer_ctxt, goal) } pub(crate) fn register_obligation(&mut self, predicate: Predicate<'a>) { diff --git a/crates/hir-ty/src/tests/coercion.rs b/crates/hir-ty/src/tests/coercion.rs index 7ec5231a7341..bf4098cfbd6b 100644 --- a/crates/hir-ty/src/tests/coercion.rs +++ b/crates/hir-ty/src/tests/coercion.rs @@ -505,8 +505,8 @@ fn test() { //^ S let obj: &dyn Bar<_, i8, i16> = &S; //^ S - //let obj: &dyn Foo = &S; - // S<{unknown}, {unknown}> + let obj: &dyn Foo = &S; + //^ S }"#, ); }