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 42cc1d2
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 18 deletions.
24 changes: 6 additions & 18 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,30 +424,16 @@ 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);
// 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)),
);
return ecx
.evaluate_added_goals_and_make_canonical_response(Certainty::Yes);
Some(tail_def) => {
let tail_ty = tail_def.ty(tcx, args);
Ty::new_projection(tcx, metadata_def_id, [tail_ty])
}
},
ty::Adt(_, _) => tcx.types.unit,

ty::Tuple(elements) => match elements.last() {
None => tcx.types.unit,
Some(&self_ty) => {
// 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)),
);
return ecx
.evaluate_added_goals_and_make_canonical_response(Certainty::Yes);
}
Some(&tail_ty) => Ty::new_projection(tcx, metadata_def_id, [tail_ty]),
},

ty::Infer(
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 42cc1d2

Please sign in to comment.