about summary refs log tree commit diff
diff options
context:
space:
mode:
authorbors <bors@rust-lang.org>2024-04-20 00:02:59 +0000
committerbors <bors@rust-lang.org>2024-04-20 00:02:59 +0000
commitdb701c2aadab9935515e2a6004594860f1933342 (patch)
tree093531cbc39c7d0ed5a752d4425fd897c696caf1
parentf9b16149208c8a8a349c32813312716f6603eb6f (diff)
parentdadece067ec1cfadaa9c2643abfa395e6c6e126b (diff)
Auto merge of #124166 - oli-obk:define_opaque_types11, r=compiler-errors
Let inherent associated types constrain opaque types during projection

r? `@compiler-errors`

The same test ICEs on master: https://play.rust-lang.org/?version=nightly&mode=debug&edition=2021&gist=f4ff62663a5a3a0e16d00953ee7414d5
-rw-r--r--compiler/rustc_trait_selection/src/traits/project.rs2
-rw-r--r--tests/ui/associated-inherent-types/constrain_opaque_types_during_projection.rs18
2 files changed, 19 insertions, 1 deletions
diff --git a/compiler/rustc_trait_selection/src/traits/project.rs b/compiler/rustc_trait_selection/src/traits/project.rs
index 4a8df6c6a5b..67865bfcaa3 100644
--- a/compiler/rustc_trait_selection/src/traits/project.rs
+++ b/compiler/rustc_trait_selection/src/traits/project.rs
@@ -641,7 +641,7 @@ pub fn compute_inherent_assoc_ty_args<'a, 'b, 'tcx>(
         );
     }
 
-    match selcx.infcx.at(&cause, param_env).eq(DefineOpaqueTypes::No, impl_ty, self_ty) {
+    match selcx.infcx.at(&cause, param_env).eq(DefineOpaqueTypes::Yes, impl_ty, self_ty) {
         Ok(mut ok) => obligations.append(&mut ok.obligations),
         Err(_) => {
             tcx.dcx().span_bug(
diff --git a/tests/ui/associated-inherent-types/constrain_opaque_types_during_projection.rs b/tests/ui/associated-inherent-types/constrain_opaque_types_during_projection.rs
new file mode 100644
index 00000000000..292733cd492
--- /dev/null
+++ b/tests/ui/associated-inherent-types/constrain_opaque_types_during_projection.rs
@@ -0,0 +1,18 @@
+//@ check-pass
+
+#![feature(inherent_associated_types, type_alias_impl_trait)]
+#![allow(incomplete_features)]
+
+struct Foo<T>(T);
+
+impl Foo<i32> {
+    type Assoc = u32;
+}
+
+type Tait = impl Sized;
+
+fn bar(_: Tait) {
+    let x: Foo<Tait>::Assoc = 42;
+}
+
+fn main() {}