about summary refs log tree commit diff
diff options
context:
space:
mode:
authorMichael Goulet <michael@errs.io>2024-10-10 00:20:37 -0400
committerMichael Goulet <michael@errs.io>2024-10-10 00:34:06 -0400
commit2a8f08083f32ed64fb367282b4896ee792f0c4a8 (patch)
tree453c8aec88d5509af1c08e7591e41be5ce615383
parenta1eceec00b2684f947481696ae2322e20d59db60 (diff)
downloadrust-2a8f08083f32ed64fb367282b4896ee792f0c4a8.tar.gz
rust-2a8f08083f32ed64fb367282b4896ee792f0c4a8.zip
Structurallyresolve adts and tuples expectations too
-rw-r--r--compiler/rustc_hir_typeck/src/expr.rs4
-rw-r--r--tests/ui/traits/next-solver/typeck/guide-ctors.rs32
2 files changed, 34 insertions, 2 deletions
diff --git a/compiler/rustc_hir_typeck/src/expr.rs b/compiler/rustc_hir_typeck/src/expr.rs
index 95ca3e66472..c5b7fc1eabd 100644
--- a/compiler/rustc_hir_typeck/src/expr.rs
+++ b/compiler/rustc_hir_typeck/src/expr.rs
@@ -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,
@@ -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);
diff --git a/tests/ui/traits/next-solver/typeck/guide-ctors.rs b/tests/ui/traits/next-solver/typeck/guide-ctors.rs
new file mode 100644
index 00000000000..7432ea78a56
--- /dev/null
+++ b/tests/ui/traits/next-solver/typeck/guide-ctors.rs
@@ -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 });
+}