Skip to content

Commit b36018e

Browse files
committed
fix: check uncertain subst when unsized coerce
1 parent d048a47 commit b36018e

File tree

3 files changed

+9
-6
lines changed

3 files changed

+9
-6
lines changed

crates/hir-ty/src/infer/coerce.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ use std::iter;
99

1010
use chalk_ir::{BoundVar, Mutability, TyKind, TyVariableKind, cast::Cast};
1111
use hir_def::{hir::ExprId, lang_item::LangItem};
12+
use rustc_next_trait_solver::solve::HasChanged;
1213
use rustc_type_ir::solve::Certainty;
1314
use stdx::always;
1415
use triomphe::Arc;
@@ -716,7 +717,7 @@ impl<'db> InferenceTable<'db> {
716717
let goal: Goal = coerce_unsized_tref.cast(Interner);
717718

718719
self.commit_if_ok(|table| match table.solve_obligation(goal) {
719-
Ok(Certainty::Yes) => Ok(()),
720+
Ok((_, Certainty::Yes) | (HasChanged::Yes, Certainty::Maybe(_))) => Ok(()),
720721
_ => Err(TypeError),
721722
})?;
722723

crates/hir-ty/src/infer/unify.rs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -728,11 +728,13 @@ impl<'a> InferenceTable<'a> {
728728
}
729729

730730
#[tracing::instrument(level = "debug", skip(self))]
731-
pub(crate) fn solve_obligation(&mut self, goal: Goal) -> Result<Certainty, NoSolution> {
731+
pub(crate) fn solve_obligation(
732+
&mut self,
733+
goal: Goal,
734+
) -> Result<(HasChanged, Certainty), NoSolution> {
732735
let goal = InEnvironment::new(&self.trait_env.env, goal);
733736
let goal = goal.to_nextsolver(self.interner);
734-
let result = next_trait_solve_in_ctxt(&self.infer_ctxt, goal);
735-
result.map(|m| m.1)
737+
next_trait_solve_in_ctxt(&self.infer_ctxt, goal)
736738
}
737739

738740
pub(crate) fn register_obligation(&mut self, predicate: Predicate<'a>) {

crates/hir-ty/src/tests/coercion.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -505,8 +505,8 @@ fn test() {
505505
//^ S<i8, i16>
506506
let obj: &dyn Bar<_, i8, i16> = &S;
507507
//^ S<i8, i16>
508-
//let obj: &dyn Foo<i8, _> = &S;
509-
// S<{unknown}, {unknown}>
508+
let obj: &dyn Foo<u8, usize> = &S;
509+
//^ S<u8, {unknown}>
510510
}"#,
511511
);
512512
}

0 commit comments

Comments
 (0)