Skip to main content

rustc_next_trait_solver/solve/normalizes_to/
anon_const.rs

1use rustc_type_ir::{self as ty, Interner, TypingMode};
2use tracing::instrument;
3
4use crate::delegate::SolverDelegate;
5use crate::solve::{Certainty, EvalCtxt, Goal, QueryResult};
6
7impl<D, I> EvalCtxt<'_, D>
8where
9    D: SolverDelegate<Interner = I>,
10    I: Interner,
11{
12    x;#[instrument(level = "trace", skip(self), ret)]
13    pub(super) fn normalize_anon_const(
14        &mut self,
15        goal: Goal<I, ty::NormalizesTo<I>>,
16    ) -> QueryResult<I> {
17        if self.typing_mode() == TypingMode::Coherence
18            && self.cx().anon_const_kind(goal.predicate.alias.def_id) == ty::AnonConstKind::OGCA
19        {
20            // During coherence, OGCA consts should be normalized ambiguously
21            // because they are opaque but eventually resolved to a real value.
22            // We don't want two OGCAs that have the same value to be treated
23            // as distinct for coherence purposes. (Just like opaque types.)
24            //
25            // We can't rely on evaluate_const below because that particular wrapper
26            // treats too-generic consts as a successful evaluation.
27            self.evaluate_added_goals_and_make_canonical_response(Certainty::AMBIGUOUS)
28        } else if let Some(normalized_const) = self.evaluate_const(
29            goal.param_env,
30            ty::UnevaluatedConst::new(
31                goal.predicate.alias.def_id.try_into().unwrap(),
32                goal.predicate.alias.args,
33            ),
34        ) {
35            self.instantiate_normalizes_to_term(goal, normalized_const.into());
36            self.evaluate_added_goals_and_make_canonical_response(Certainty::Yes)
37        } else {
38            self.evaluate_added_goals_and_make_canonical_response(Certainty::AMBIGUOUS)
39        }
40    }
41}