Skip to content

Commit

Permalink
Process alias-relate obligations in CoerceUnsized loop
Browse files Browse the repository at this point in the history
  • Loading branch information
compiler-errors committed Feb 27, 2024
1 parent 8790c3c commit cc584ba
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 0 deletions.
14 changes: 14 additions & 0 deletions compiler/rustc_hir_typeck/src/coercion.rs
Original file line number Diff line number Diff line change
Expand Up @@ -636,6 +636,20 @@ impl<'f, 'tcx> Coerce<'f, 'tcx> {
{
self.resolve_vars_if_possible(trait_pred)
}
// Eagerly process alias-relate obligations in new trait solver,
// since these can be emitted in the process of solving trait goals,
// but we need to constrain vars before processing goals mentioning
// them.
Some(ty::PredicateKind::AliasRelate(..)) => {
let mut fulfill_cx = <dyn TraitEngine<'tcx>>::new(self);
fulfill_cx.register_predicate_obligation(self, obligation);
let errs = fulfill_cx.select_where_possible(self);
if !errs.is_empty() {
return Err(TypeError::Mismatch);
}
coercion.obligations.extend(fulfill_cx.pending_obligations());
continue;
}
_ => {
coercion.obligations.push(obligation);
continue;
Expand Down
18 changes: 18 additions & 0 deletions tests/ui/traits/next-solver/constrain-alias-goals-in-unsize.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
//@ compile-flags: -Znext-solver
//@ check-pass

use std::mem::ManuallyDrop;

trait Foo {}

struct Guard<T> {
value: ManuallyDrop<T>,
}

impl<T: Foo> Guard<T> {
fn uwu(&self) {
let x: &dyn Foo = &*self.value;
}
}

fn main() {}

0 comments on commit cc584ba

Please sign in to comment.