Skip to content

Commit

Permalink
Auto merge of #800 - HKalbasi:discriminant-kind, r=jackh726
Browse files Browse the repository at this point in the history
Push DiscriminantKind implementation fact unconditionally

This makes r-a infer the output type of `discriminant_value` intrinsic as `<T as DiscriminantKind>::Discriminant` instead of unknown.
  • Loading branch information
bors committed Aug 7, 2023
2 parents e366ab7 + c40c29f commit db55a04
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 10 deletions.
17 changes: 9 additions & 8 deletions chalk-solve/src/clauses/builtin_traits/discriminant_kind.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,25 +39,27 @@ pub fn add_discriminant_clauses<I: Interner>(
| TyKind::InferenceVar(..) => false,
};

if !can_determine_discriminant {
return Err(Floundered);
}

let disc_ty = db.discriminant_type(self_ty.clone());

let trait_id = db
.well_known_trait_id(WellKnownTrait::DiscriminantKind)
.unwrap();
let trait_datum = db.trait_datum(trait_id);

let associated_ty_id = trait_datum.associated_ty_ids[0];
let substitution = Substitution::from1(interner, self_ty);
let substitution = Substitution::from1(interner, self_ty.clone());

let trait_ref = TraitRef {
trait_id,
substitution: substitution.clone(),
};

builder.push_fact(trait_ref);

if !can_determine_discriminant {
return Ok(());
}

let disc_ty = db.discriminant_type(self_ty);

let normalize = Normalize {
alias: AliasTy::Projection(ProjectionTy {
associated_ty_id,
Expand All @@ -66,7 +68,6 @@ pub fn add_discriminant_clauses<I: Interner>(
ty: disc_ty,
};

builder.push_fact(trait_ref);
builder.push_fact(normalize);

Ok(())
Expand Down
4 changes: 2 additions & 2 deletions tests/test/discriminant_kind.rs
Original file line number Diff line number Diff line change
Expand Up @@ -156,11 +156,11 @@ fn discriminant_kind_assoc() {
goal {
forall<T> {
exists<U> {
Normalize(<T as DiscriminantKind>::Discriminant -> U)
<T as DiscriminantKind>::Discriminant = U
}
}
} yields {
expect![["Ambiguous; no inference guidance"]]
expect![["Unique; substitution [?0 := (DiscriminantKind::Discriminant)<!1_0>]"]]
}
}
}
Expand Down

0 comments on commit db55a04

Please sign in to comment.