No need to validate_alias_bound_self_from_param_env in assemble_alias… · rust-lang/rust@6dea155 (original) (raw)
`@@ -5,7 +5,6 @@ use crate::solve::GoalSource;
`
5
5
`use crate::traits::coherence;
`
6
6
`use rustc_hir::def_id::DefId;
`
7
7
`use rustc_infer::traits::query::NoSolution;
`
8
``
`-
use rustc_infer::traits::Reveal;
`
9
8
`use rustc_middle::traits::solve::inspect::ProbeKind;
`
10
9
`use rustc_middle::traits::solve::{
`
11
10
`CandidateSource, CanonicalResponse, Certainty, Goal, QueryResult,
`
`@@ -70,20 +69,6 @@ pub(super) trait GoalKind<'tcx>:
`
70
69
`})
`
71
70
`}
`
72
71
``
73
``
`-
/// Consider a bound originating from the item bounds of an alias. For this we
`
74
``
`-
/// require that the well-formed requirements of the self type of the goal
`
75
``
`-
/// are "satisfied from the param-env".
`
76
``
`` -
/// See [EvalCtxt::validate_alias_bound_self_from_param_env
].
``
77
``
`-
fn consider_alias_bound_candidate(
`
78
``
`-
ecx: &mut EvalCtxt<'_, 'tcx>,
`
79
``
`-
goal: Goal<'tcx, Self>,
`
80
``
`-
assumption: ty::Clause<'tcx>,
`
81
``
`-
) -> QueryResult<'tcx> {
`
82
``
`-
Self::probe_and_match_goal_against_assumption(ecx, goal, assumption, |ecx| {
`
83
``
`-
ecx.validate_alias_bound_self_from_param_env(goal)
`
84
``
`-
})
`
85
``
`-
}
`
86
``
-
87
72
`` /// Consider a clause specifically for a dyn Trait
self type. This requires
``
88
73
`/// additionally checking all of the supertraits and object bounds to hold,
`
89
74
`/// since they're not implied by the well-formedness of the object type.
`
`@@ -557,7 +542,7 @@ impl<'tcx> EvalCtxt<'_, 'tcx> {
`
557
542
`for assumption in
`
558
543
`self.tcx().item_bounds(alias_ty.def_id).instantiate(self.tcx(), alias_ty.args)
`
559
544
`{
`
560
``
`-
match G::consider_alias_bound_candidate(self, goal, assumption) {
`
``
545
`+
match G::consider_implied_clause(self, goal, assumption, []) {
`
561
546
`Ok(result) => {
`
562
547
` candidates.push(Candidate { source: CandidateSource::AliasBound, result })
`
563
548
`}
`
`@@ -566,105 +551,6 @@ impl<'tcx> EvalCtxt<'_, 'tcx> {
`
566
551
`}
`
567
552
`}
`
568
553
``
569
``
`-
/// Check that we are allowed to use an alias bound originating from the self
`
570
``
`-
/// type of this goal. This means something different depending on the self type's
`
571
``
`-
/// alias kind.
`
572
``
`-
///
`
573
``
`` -
/// * Projection: Given a goal with a self type such as <Ty as Trait>::Assoc
,
``
574
``
`` -
/// we require that the bound Ty: Trait
can be proven using either a nested alias
``
575
``
`-
/// bound candidate, or a param-env candidate.
`
576
``
`-
///
`
577
``
`` -
/// * Opaque: The param-env must be in Reveal::UserFacing
mode. Otherwise,
``
578
``
`-
/// the goal should be proven by using the hidden type instead.
`
579
``
`-
#[instrument(level = "debug", skip(self), ret)]
`
580
``
`-
pub(super) fn validate_alias_bound_self_from_param_env<G: GoalKind<'tcx>>(
`
581
``
`-
&mut self,
`
582
``
`-
goal: Goal<'tcx, G>,
`
583
``
`-
) -> QueryResult<'tcx> {
`
584
``
`-
match *goal.predicate.self_ty().kind() {
`
585
``
`-
ty::Alias(ty::Projection, projection_ty) => {
`
586
``
`-
let mut param_env_candidates = vec![];
`
587
``
`-
let self_trait_ref = projection_ty.trait_ref(self.tcx());
`
588
``
-
589
``
`-
if self_trait_ref.self_ty().is_ty_var() {
`
590
``
`-
return self
`
591
``
`-
.evaluate_added_goals_and_make_canonical_response(Certainty::AMBIGUOUS);
`
592
``
`-
}
`
593
``
-
594
``
`-
let trait_goal: Goal<'_, ty::TraitPredicate<'tcx>> = goal.with(
`
595
``
`-
self.tcx(),
`
596
``
`-
ty::TraitPredicate {
`
597
``
`-
trait_ref: self_trait_ref,
`
598
``
`-
polarity: ty::ImplPolarity::Positive,
`
599
``
`-
},
`
600
``
`-
);
`
601
``
-
602
``
`-
self.assemble_param_env_candidates(trait_goal, &mut param_env_candidates);
`
603
``
`-
// FIXME: We probably need some sort of recursion depth check here.
`
604
``
`-
// Can't come up with an example yet, though, and the worst case
`
605
``
`-
// we can have is a compiler stack overflow...
`
606
``
`-
self.assemble_alias_bound_candidates(trait_goal, &mut param_env_candidates);
`
607
``
-
608
``
`-
// FIXME: We must also consider alias-bound candidates for a peculiar
`
609
``
`-
// class of built-in candidates that I'll call "defaulted" built-ins.
`
610
``
`-
//
`
611
``
`` -
// For example, we always know that T: Pointee
is implemented, but
``
612
``
`` -
// we do not always know what <T as Pointee>::Metadata
actually is,
``
613
``
`` -
// similar to if we had a user-defined impl with a default type ...
.
``
614
``
`-
// For these traits, since we're not able to always normalize their
`
615
``
`-
// associated types to a concrete type, we must consider their alias bounds
`
616
``
`` -
// instead, so we can prove bounds such as <T as Pointee>::Metadata: Copy
.
``
617
``
`-
self.assemble_alias_bound_candidates_for_builtin_impl_default_items(
`
618
``
`-
trait_goal,
`
619
``
`-
&mut param_env_candidates,
`
620
``
`-
);
`
621
``
-
622
``
`-
self.merge_candidates(param_env_candidates)
`
623
``
`-
}
`
624
``
`-
ty::Alias(ty::Opaque, _opaque_ty) => match goal.param_env.reveal() {
`
625
``
`-
Reveal::UserFacing => {
`
626
``
`-
self.evaluate_added_goals_and_make_canonical_response(Certainty::Yes)
`
627
``
`-
}
`
628
``
`-
Reveal::All => return Err(NoSolution),
`
629
``
`-
},
`
630
``
`-
_ => bug!("only expected to be called on alias tys"),
`
631
``
`-
}
`
632
``
`-
}
`
633
``
-
634
``
`-
/// Assemble a subset of builtin impl candidates for a class of candidates called
`
635
``
`-
/// "defaulted" built-in traits.
`
636
``
`-
///
`
637
``
`` -
/// For example, we always know that T: Pointee
is implemented, but we do not
``
638
``
`` -
/// always know what <T as Pointee>::Metadata
actually is! See the comment in
``
639
``
`` -
/// [EvalCtxt::validate_alias_bound_self_from_param_env
] for more detail.
``
640
``
`-
#[instrument(level = "debug", skip_all)]
`
641
``
`-
fn assemble_alias_bound_candidates_for_builtin_impl_default_items<G: GoalKind<'tcx>>(
`
642
``
`-
&mut self,
`
643
``
`-
goal: Goal<'tcx, G>,
`
644
``
`-
candidates: &mut Vec<Candidate<'tcx>>,
`
645
``
`-
) {
`
646
``
`-
let lang_items = self.tcx().lang_items();
`
647
``
`-
let trait_def_id = goal.predicate.trait_def_id(self.tcx());
`
648
``
-
649
``
`-
// You probably shouldn't add anything to this list unless you
`
650
``
`-
// know what you're doing.
`
651
``
`-
let result = if lang_items.pointee_trait() == Some(trait_def_id) {
`
652
``
`-
G::consider_builtin_pointee_candidate(self, goal)
`
653
``
`-
} else if lang_items.discriminant_kind_trait() == Some(trait_def_id) {
`
654
``
`-
G::consider_builtin_discriminant_kind_candidate(self, goal)
`
655
``
`-
} else {
`
656
``
`-
Err(NoSolution)
`
657
``
`-
};
`
658
``
-
659
``
`-
match result {
`
660
``
`-
Ok(result) => candidates.push(Candidate {
`
661
``
`-
source: CandidateSource::BuiltinImpl(BuiltinImplSource::Misc),
`
662
``
`-
result,
`
663
``
`-
}),
`
664
``
`-
Err(NoSolution) => (),
`
665
``
`-
}
`
666
``
`-
}
`
667
``
-
668
554
`#[instrument(level = "debug", skip_all)]
`
669
555
`fn assemble_object_bound_candidates<G: GoalKind<'tcx>>(
`
670
556
`&mut self,
`