Skip to content

Commit

Permalink
Structurallyresolve adts and tuples expectations too
Browse files Browse the repository at this point in the history
  • Loading branch information
compiler-errors committed Oct 10, 2024
1 parent a1eceec commit 2a8f080
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 2 deletions.
4 changes: 2 additions & 2 deletions compiler/rustc_hir_typeck/src/expr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1783,7 +1783,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
expr: &'tcx hir::Expr<'tcx>,
) -> Ty<'tcx> {
let flds = expected.only_has_type(self).and_then(|ty| {
let ty = self.resolve_vars_with_obligations(ty);
let ty = self.try_structurally_resolve_type(expr.span, ty);
match ty.kind() {
ty::Tuple(flds) => Some(&flds[..]),
_ => None,
Expand Down Expand Up @@ -1861,7 +1861,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
) {
let tcx = self.tcx;

let adt_ty = self.resolve_vars_with_obligations(adt_ty);
let adt_ty = self.try_structurally_resolve_type(span, adt_ty);
let adt_ty_hint = expected.only_has_type(self).and_then(|expected| {
self.fudge_inference_if_ok(|| {
let ocx = ObligationCtxt::new(self);
Expand Down
32 changes: 32 additions & 0 deletions tests/ui/traits/next-solver/typeck/guide-ctors.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
//@ compile-flags: -Znext-solver
//@ check-pass

// Makes sure we structurally normalize before trying to use expectation to guide
// coercion in adt and tuples.

use std::any::Any;

trait Coerce {
type Assoc;
}

struct TupleGuidance;
impl Coerce for TupleGuidance {
type Assoc = (&'static dyn Any,);
}

struct AdtGuidance;
impl Coerce for AdtGuidance {
type Assoc = Adt<&'static dyn Any>;
}

struct Adt<T> {
f: T,
}

fn foo<'a, T: Coerce>(_: T::Assoc) {}

fn main() {
foo::<TupleGuidance>((&0u32,));
foo::<AdtGuidance>(Adt { f: &0u32 });
}

0 comments on commit 2a8f080

Please sign in to comment.