From dadece067ec1cfadaa9c2643abfa395e6c6e126b Mon Sep 17 00:00:00 2001 From: Oli Scherer Date: Fri, 19 Apr 2024 16:12:54 +0000 Subject: [PATCH] Let inherent associated types constrain opaque types during projection --- .../src/traits/project.rs | 2 +- ...constrain_opaque_types_during_projection.rs | 18 ++++++++++++++++++ 2 files changed, 19 insertions(+), 1 deletion(-) create mode 100644 tests/ui/associated-inherent-types/constrain_opaque_types_during_projection.rs 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); + +impl Foo { + type Assoc = u32; +} + +type Tait = impl Sized; + +fn bar(_: Tait) { + let x: Foo::Assoc = 42; +} + +fn main() {}