Skip to content

broken interaction between marker traits, lifetimes, and caching #102360

Description

@lcnr

let cache_fresh_trait_pred = self.infcx.freshen(stack.obligation.predicate);

erases all lifetimes for caching, including 'static.

freshener: infcx.freshener_keep_static(),

let fresh_trait_pred = obligation.predicate.fold_with(&mut self.freshener);

// If we erased any lifetimes, then we want to use
// `EvaluatedToOkModuloRegions` instead of `EvaluatedToOk`
// as your final result. The result will be cached using
// the freshened trait predicate as a key, so we need
// our result to be correct by *any* choice of original lifetimes,
// not just the lifetime choice for this particular (non-erased)
// predicate.
// See issue #80691
if stack.fresh_trait_pred.has_erased_regions() {
result = result.max(EvaluatedToOkModuloRegions);
}

changes the evaluation result depending on whether there are any erased regions in the predicate, excluding 'static.

if other.evaluation.must_apply_considering_regions() {

selection only drops allowed-to-overlap candidate if the other resulted in EvaluatedToOk.

This means that depending on the order of evaluation, marker traits can either succeed or result in ambiguity

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-trait-systemArea: Trait systemC-bugCategory: This is a bug.T-typesRelevant to the types team, which will review and decide on the PR/issue.

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions