From 08fc5e8acd1bc41fbf5b8a4b5c96a42c16bab158 Mon Sep 17 00:00:00 2001 From: Oli Scherer Date: Wed, 10 Jan 2024 16:03:05 +0000 Subject: [PATCH 1/2] Define hidden types in confirmation --- .../src/traits/project.rs | 2 +- .../nested_inference_failure.rs | 26 +++++++++++++++++++ 2 files changed, 27 insertions(+), 1 deletion(-) create mode 100644 tests/ui/type-alias-impl-trait/nested_inference_failure.rs diff --git a/compiler/rustc_trait_selection/src/traits/project.rs b/compiler/rustc_trait_selection/src/traits/project.rs index dd4e69efe379e..abbc2066eac16 100644 --- a/compiler/rustc_trait_selection/src/traits/project.rs +++ b/compiler/rustc_trait_selection/src/traits/project.rs @@ -2466,7 +2466,7 @@ fn confirm_param_env_candidate<'cx, 'tcx>( debug!(?cache_projection, ?obligation_projection); match infcx.at(cause, param_env).eq( - DefineOpaqueTypes::No, + DefineOpaqueTypes::Yes, cache_projection, obligation_projection, ) { diff --git a/tests/ui/type-alias-impl-trait/nested_inference_failure.rs b/tests/ui/type-alias-impl-trait/nested_inference_failure.rs new file mode 100644 index 0000000000000..16b78f18aa347 --- /dev/null +++ b/tests/ui/type-alias-impl-trait/nested_inference_failure.rs @@ -0,0 +1,26 @@ +// check-pass + +//! This test checks that we can successfully infer +//! the hidden type of `FooImpl` to be `Foo` +//! and `ImplT` to be `i32`. This test used to fail, because +//! we were unable to make the connection that the closure +//! argument is the same as the first argument of `Foo`. + +#![feature(type_alias_impl_trait)] + +use std::fmt::Debug; +use std::marker::PhantomData; + +struct Foo { + f: F, + _phantom: PhantomData, +} + +type ImplT = impl Debug; +type FooImpl = Foo; + +fn bar() -> FooImpl { + Foo:: { f: |_| (), _phantom: PhantomData } +} + +fn main() {} From 0ae00444dc075c814dd061aa1cfdc5c461c1f608 Mon Sep 17 00:00:00 2001 From: Oli Scherer Date: Wed, 10 Jan 2024 16:05:24 +0000 Subject: [PATCH 2/2] Make sure the new solver agrees --- tests/ui/type-alias-impl-trait/nested_inference_failure.rs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/tests/ui/type-alias-impl-trait/nested_inference_failure.rs b/tests/ui/type-alias-impl-trait/nested_inference_failure.rs index 16b78f18aa347..d2091ca96ea01 100644 --- a/tests/ui/type-alias-impl-trait/nested_inference_failure.rs +++ b/tests/ui/type-alias-impl-trait/nested_inference_failure.rs @@ -1,4 +1,6 @@ // check-pass +// revisions: new old +//[new] compile-flags: -Znext-solver //! This test checks that we can successfully infer //! the hidden type of `FooImpl` to be `Foo`