Skip to content

Commit c32e2ec

Browse files
author
Lukas Markeffsky
committed
new solver: improve normalization of Pointee::Metadata
1 parent 0c1f401 commit c32e2ec

File tree

3 files changed

+15
-11
lines changed

3 files changed

+15
-11
lines changed

compiler/rustc_middle/src/ty/predicate.rs

+4
Original file line numberDiff line numberDiff line change
@@ -814,6 +814,10 @@ impl<'tcx> NormalizesTo<'tcx> {
814814
pub fn def_id(self) -> DefId {
815815
self.alias.def_id
816816
}
817+
818+
pub fn as_projection(self) -> ProjectionPredicate<'tcx> {
819+
ProjectionPredicate { projection_ty: self.alias, term: self.term }
820+
}
817821
}
818822

819823
pub trait ToPolyTraitRef<'tcx> {

compiler/rustc_trait_selection/src/solve/normalizes_to/mod.rs

+9-11
Original file line numberDiff line numberDiff line change
@@ -378,6 +378,8 @@ impl<'tcx> assembly::GoalKind<'tcx> for NormalizesTo<'tcx> {
378378
goal: Goal<'tcx, Self>,
379379
) -> QueryResult<'tcx> {
380380
let tcx = ecx.tcx();
381+
let metadata_def_id = tcx.require_lang_item(LangItem::Metadata, None);
382+
assert_eq!(metadata_def_id, goal.predicate.def_id());
381383
ecx.probe_misc_candidate("builtin pointee").enter(|ecx| {
382384
let metadata_ty = match goal.predicate.self_ty().kind() {
383385
ty::Bool
@@ -422,13 +424,11 @@ impl<'tcx> assembly::GoalKind<'tcx> for NormalizesTo<'tcx> {
422424

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

438438
ty::Tuple(elements) => match elements.last() {
439439
None => tcx.types.unit,
440-
Some(&self_ty) => {
440+
Some(&tail_ty) => {
441+
let predicate = goal.predicate.with_self_ty(tcx, tail_ty).as_projection();
441442
// FIXME(-Znext-solver=coinductive): Should this be `GoalSource::ImplWhereBound`?
442-
ecx.add_goal(
443-
GoalSource::Misc,
444-
goal.with(tcx, goal.predicate.with_self_ty(tcx, self_ty)),
445-
);
443+
ecx.add_goal(GoalSource::Misc, goal.with(tcx, predicate));
446444
return ecx
447445
.evaluate_added_goals_and_make_canonical_response(Certainty::Yes);
448446
}

tests/ui/traits/pointee-normalize-equate.rs

+2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
// check-pass
2+
// revisions: old next
3+
//[next] compile-flags: -Znext-solver
24

35
#![feature(ptr_metadata)]
46

0 commit comments

Comments
 (0)