🔬 introduce a canonical query for evaluate_obligation
#48537
Labels
A-trait-system
Area: Trait system
C-enhancement
Category: An issue proposing an enhancement or a PR with one.
T-compiler
Relevant to the compiler team, which will review and decide on the PR/issue.
WG-traits
Working group: Traits, https://internals.rust-lang.org/t/announcing-traits-working-group/6804
The
evaluate_obligation
method ofSelectionContext
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:
The query would be something like this:
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, likenormalize
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 abool
-- this would allow the same query to be shared forevaluate_obligation_conservatively
. I suggest that we rename theinfcx.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!
The text was updated successfully, but these errors were encountered: