From ced1a29e11a5fb28576953cf9a17c945413ecbf7 Mon Sep 17 00:00:00 2001 From: Ryo Yoshida Date: Tue, 11 Oct 2022 19:31:37 +0900 Subject: [PATCH 1/2] Fix `Self` type retrieval from `ProjectionTy` --- chalk-ir/src/lib.rs | 11 ----------- chalk-solve/src/clauses.rs | 14 ++++++++------ tests/test/projection.rs | 27 +++++++++++++++++++++++++++ 3 files changed, 35 insertions(+), 17 deletions(-) diff --git a/chalk-ir/src/lib.rs b/chalk-ir/src/lib.rs index b40ac3f5259..b67f8667866 100644 --- a/chalk-ir/src/lib.rs +++ b/chalk-ir/src/lib.rs @@ -1643,17 +1643,6 @@ pub struct ProjectionTy { impl Copy for ProjectionTy where I::InternedSubstitution: Copy {} -impl ProjectionTy { - /// Gets the type parameters of the `Self` type in this alias type. - pub fn self_type_parameter(&self, interner: I) -> Ty { - self.substitution - .iter(interner) - .find_map(move |p| p.ty(interner)) - .unwrap() - .clone() - } -} - /// An opaque type `opaque type T<..>: Trait = HiddenTy`. #[derive(Clone, PartialEq, Eq, Hash, TypeFoldable, TypeVisitable, HasInterner)] pub struct OpaqueTy { diff --git a/chalk-solve/src/clauses.rs b/chalk-solve/src/clauses.rs index bb96de4fbe2..e3fdd351b7a 100644 --- a/chalk-solve/src/clauses.rs +++ b/chalk-solve/src/clauses.rs @@ -603,11 +603,12 @@ pub fn program_clauses_that_could_match( // ``` let associated_ty_datum = db.associated_ty_data(proj.associated_ty_id); let trait_id = associated_ty_datum.trait_id; - let trait_parameters = db.trait_parameters_from_projection(proj); + let trait_ref = db.trait_ref_from_projection(proj); + let trait_parameters = trait_ref.substitution.as_parameters(interner); let trait_datum = db.trait_datum(trait_id); - let self_ty = proj.self_type_parameter(interner); + let self_ty = trait_ref.self_type_parameter(interner); if let TyKind::InferenceVar(_, _) = self_ty.kind(interner) { panic!("Inference vars not allowed when getting program clauses"); } @@ -804,10 +805,11 @@ fn push_alias_alias_eq_clause( alias: AliasTy, ) { let interner = builder.interner(); - assert_eq!( - *projection_ty.self_type_parameter(interner).kind(interner), - TyKind::Alias(alias.clone()) - ); + let self_ty = builder + .db + .trait_ref_from_projection(&projection_ty) + .self_type_parameter(interner); + assert_eq!(*self_ty.kind(interner), TyKind::Alias(alias.clone())); // TODO: instead generate clauses without reference to the specific type parameters of the goal? let generalized = generalize::Generalize::apply(interner, (projection_ty, ty, alias)); diff --git a/tests/test/projection.rs b/tests/test/projection.rs index aaddd17ffa8..a98a660dfed 100644 --- a/tests/test/projection.rs +++ b/tests/test/projection.rs @@ -687,6 +687,33 @@ fn forall_projection_gat() { } } +#[test] +fn gat_in_non_enumerable_trait() { + test! { + program { + #[non_enumerable] + trait Deref { } + + #[non_enumerable] + trait PointerFamily { + type Pointer: Deref; + } + } + + goal { + forall { + forall { + if (T: PointerFamily) { + ::Pointer: Deref + } + } + } + } yields { + expect![[r#"Unique"#]] + } + } +} + #[test] fn normalize_under_binder() { test! { From 7bc0c591a3f592955ea6a2fbe7928c8a52f61e6a Mon Sep 17 00:00:00 2001 From: Ryo Yoshida Date: Wed, 12 Oct 2022 00:40:37 +0900 Subject: [PATCH 2/2] Ignore doctest for GATs --- chalk-solve/src/rust_ir.rs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/chalk-solve/src/rust_ir.rs b/chalk-solve/src/rust_ir.rs index aa9f06ece8e..f68d6b97e3e 100644 --- a/chalk-solve/src/rust_ir.rs +++ b/chalk-solve/src/rust_ir.rs @@ -214,10 +214,11 @@ pub struct FnDefDatumBound { } #[derive(Clone, Debug, PartialEq, Eq, Hash)] +// FIXME: unignore the doctest below when GATs hit stable. /// A rust intermediate representation (rust_ir) of a Trait Definition. For /// example, given the following rust code: /// -/// ```compile_fail +/// ```ignore /// use std::fmt::Debug; /// /// trait Foo