Description
The evaluate_obligation
method of SelectionContext
has the job of determining whether a given predicate may hold:
rust/src/librustc/traits/select.rs
Lines 622 to 625 in 322d7f7
Building on the work in #48411, this seems like a clean place to introduce a canonical trait query. The argument to this query would be canonicalized predicate, combined with an environment:
type CanonicalPredicateGoal<'tcx> = &'tcx Canonical<ParamEnvAnd<'tcx, Predicate<'tcx>>>
The query would be something like this:
[] fn evaluate_obligation(CanonicalPredicateGoal<'tcx>) -> traits::EvaluationResult
I expect this would follow the pattern introduced in #48411, where the query is not invoked directly by end-users. Rather, they invoke a wrapper method defined on the At
type, like normalize
here. This method would canonicalize and invoke the underlying query.
Note that I defined the query to return a EvaluationResult
, where the current method returns a bool
-- this would allow the same query to be shared for evaluate_obligation_conservatively
. I suggest that we rename the infcx.at().foo()
methods, actually, to be something like this:
infcx.at(...).predicate_may_hold(predicate)
(what is todayevaluate_obligation
)infcx.at(...).predicate_must_hold(predicate)
(what is todayevaluate_obligation_conservatively
)
Both of these would return a boolean.
Anyway, I will try to write up more comprehensive guidelines in the rustc-guide describing the pattern for trait queries, and link to them from here.
If you are interesting in this task, please feel free to ping me on gitter for more info!