Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix Self type retrieval from ProjectionTy #778

Merged
merged 2 commits into from
Oct 11, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 0 additions & 11 deletions chalk-ir/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1643,17 +1643,6 @@ pub struct ProjectionTy<I: Interner> {

impl<I: Interner> Copy for ProjectionTy<I> where I::InternedSubstitution: Copy {}

impl<I: Interner> ProjectionTy<I> {
/// Gets the type parameters of the `Self` type in this alias type.
pub fn self_type_parameter(&self, interner: I) -> Ty<I> {
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<I: Interner> {
Expand Down
14 changes: 8 additions & 6 deletions chalk-solve/src/clauses.rs
Original file line number Diff line number Diff line change
Expand Up @@ -603,11 +603,12 @@ pub fn program_clauses_that_could_match<I: Interner>(
// ```
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");
}
Expand Down Expand Up @@ -804,10 +805,11 @@ fn push_alias_alias_eq_clause<I: Interner>(
alias: AliasTy<I>,
) {
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));
Expand Down
3 changes: 2 additions & 1 deletion chalk-solve/src/rust_ir.rs
Original file line number Diff line number Diff line change
Expand Up @@ -214,10 +214,11 @@ pub struct FnDefDatumBound<I: Interner> {
}

#[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<T>
Expand Down
27 changes: 27 additions & 0 deletions tests/test/projection.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<T>: Deref;
}
}

goal {
forall<T> {
forall<U> {
if (T: PointerFamily) {
<T as PointerFamily>::Pointer<U>: Deref
}
}
}
} yields {
expect![[r#"Unique"#]]
}
}
}

#[test]
fn normalize_under_binder() {
test! {
Expand Down