From 0609b999681f9c807554bffe838288bda7efa3f1 Mon Sep 17 00:00:00 2001
From: Michael Goulet <michael@errs.io>
Date: Thu, 28 Nov 2024 00:58:05 +0000
Subject: [PATCH] Structurally resolve in probe_adt

---
 compiler/rustc_hir_typeck/src/fn_ctxt/mod.rs      |  6 +++++-
 tests/crashes/132320.rs                           | 15 ---------------
 .../typeck/structurally-resolve-in-probe_adt.rs   | 15 +++++++++++++++
 3 files changed, 20 insertions(+), 16 deletions(-)
 delete mode 100644 tests/crashes/132320.rs
 create mode 100644 tests/ui/traits/next-solver/typeck/structurally-resolve-in-probe_adt.rs

diff --git a/compiler/rustc_hir_typeck/src/fn_ctxt/mod.rs b/compiler/rustc_hir_typeck/src/fn_ctxt/mod.rs
index 3940d138deb..aacdcf027b6 100644
--- a/compiler/rustc_hir_typeck/src/fn_ctxt/mod.rs
+++ b/compiler/rustc_hir_typeck/src/fn_ctxt/mod.rs
@@ -307,7 +307,11 @@ impl<'tcx> HirTyLowerer<'tcx> for FnCtxt<'_, 'tcx> {
             ty::Alias(ty::Projection | ty::Inherent | ty::Weak, _)
                 if !ty.has_escaping_bound_vars() =>
             {
-                self.normalize(span, ty).ty_adt_def()
+                if self.next_trait_solver() {
+                    self.try_structurally_resolve_type(span, ty).ty_adt_def()
+                } else {
+                    self.normalize(span, ty).ty_adt_def()
+                }
             }
             _ => None,
         }
diff --git a/tests/crashes/132320.rs b/tests/crashes/132320.rs
deleted file mode 100644
index 79181c3a2c5..00000000000
--- a/tests/crashes/132320.rs
+++ /dev/null
@@ -1,15 +0,0 @@
-//@ known-bug: #132320
-//@ compile-flags: -Znext-solver=globally
-
-trait Foo {
-    type Item;
-    fn foo(&mut self);
-}
-
-impl Foo for () {
-    type Item = Option<()>;
-
-    fn foo(&mut self) {
-        let _ = Self::Item::None;
-    }
-}
diff --git a/tests/ui/traits/next-solver/typeck/structurally-resolve-in-probe_adt.rs b/tests/ui/traits/next-solver/typeck/structurally-resolve-in-probe_adt.rs
new file mode 100644
index 00000000000..23915808279
--- /dev/null
+++ b/tests/ui/traits/next-solver/typeck/structurally-resolve-in-probe_adt.rs
@@ -0,0 +1,15 @@
+//@ check-pass
+//@ compile-flags: -Znext-solver
+
+trait Mirror {
+    type Assoc;
+}
+impl<T> Mirror for T {
+    type Assoc = T;
+}
+
+type Foo<T> = <Option<T> as Mirror>::Assoc;
+
+fn main() {
+    let x = Foo::<i32>::None;
+}