Skip to content

Commit

Permalink
new solver: improve normalization of Pointee::Metadata
Browse files Browse the repository at this point in the history
  • Loading branch information
Lukas Markeffsky committed Feb 5, 2024
1 parent 0c1f401 commit c32e2ec
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 11 deletions.
4 changes: 4 additions & 0 deletions compiler/rustc_middle/src/ty/predicate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -814,6 +814,10 @@ impl<'tcx> NormalizesTo<'tcx> {
pub fn def_id(self) -> DefId {
self.alias.def_id
}

pub fn as_projection(self) -> ProjectionPredicate<'tcx> {
ProjectionPredicate { projection_ty: self.alias, term: self.term }
}
}

pub trait ToPolyTraitRef<'tcx> {
Expand Down
20 changes: 9 additions & 11 deletions compiler/rustc_trait_selection/src/solve/normalizes_to/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -378,6 +378,8 @@ impl<'tcx> assembly::GoalKind<'tcx> for NormalizesTo<'tcx> {
goal: Goal<'tcx, Self>,
) -> QueryResult<'tcx> {
let tcx = ecx.tcx();
let metadata_def_id = tcx.require_lang_item(LangItem::Metadata, None);
assert_eq!(metadata_def_id, goal.predicate.def_id());
ecx.probe_misc_candidate("builtin pointee").enter(|ecx| {
let metadata_ty = match goal.predicate.self_ty().kind() {
ty::Bool
Expand Down Expand Up @@ -422,13 +424,11 @@ impl<'tcx> assembly::GoalKind<'tcx> for NormalizesTo<'tcx> {

ty::Adt(def, args) if def.is_struct() => match def.non_enum_variant().tail_opt() {
None => tcx.types.unit,
Some(field_def) => {
let self_ty = field_def.ty(tcx, args);
Some(tail_def) => {
let tail_ty = tail_def.ty(tcx, args);
let predicate = goal.predicate.with_self_ty(tcx, tail_ty).as_projection();
// FIXME(-Znext-solver=coinductive): Should this be `GoalSource::ImplWhereBound`?
ecx.add_goal(
GoalSource::Misc,
goal.with(tcx, goal.predicate.with_self_ty(tcx, self_ty)),
);
ecx.add_goal(GoalSource::Misc, goal.with(tcx, predicate));
return ecx
.evaluate_added_goals_and_make_canonical_response(Certainty::Yes);
}
Expand All @@ -437,12 +437,10 @@ impl<'tcx> assembly::GoalKind<'tcx> for NormalizesTo<'tcx> {

ty::Tuple(elements) => match elements.last() {
None => tcx.types.unit,
Some(&self_ty) => {
Some(&tail_ty) => {
let predicate = goal.predicate.with_self_ty(tcx, tail_ty).as_projection();
// FIXME(-Znext-solver=coinductive): Should this be `GoalSource::ImplWhereBound`?
ecx.add_goal(
GoalSource::Misc,
goal.with(tcx, goal.predicate.with_self_ty(tcx, self_ty)),
);
ecx.add_goal(GoalSource::Misc, goal.with(tcx, predicate));
return ecx
.evaluate_added_goals_and_make_canonical_response(Certainty::Yes);
}
Expand Down
2 changes: 2 additions & 0 deletions tests/ui/traits/pointee-normalize-equate.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
// check-pass
// revisions: old next
//[next] compile-flags: -Znext-solver

#![feature(ptr_metadata)]

Expand Down

0 comments on commit c32e2ec

Please sign in to comment.