rust/compiler/rustc_middle/src/traits
bors ec667fbcfc Auto merge of #95031 - compiler-errors:param-env-cache, r=Aaron1011
Do not use `ParamEnv::and` when building a cache key from a param-env and trait eval candidate

Do not use `ParamEnv::and` to cache a param-env with a selection/evaluation candidate.

This is because if the param-env is `RevealAll` mode, and the candidate looks global (i.e. it has erased regions, which can show up when we normalize a projection type under a binder<sup>1</sup>), then when we use `ParamEnv::and` to pair the candidate and the param-env for use as a cache key, we will throw away the param-env's caller bounds, and we'll end up caching a candidate that we inferred from the param-env with a empty param-env, which may cause cache-hit later when we have an empty param-env, and possibly mess with normalization like we see in the referenced issue during codegen.

Not sure how to trigger this with a more structured test, but changing `check-pass` to `build-pass` triggers the case that https://github.com/rust-lang/rust/issues/94903 detected.

<sup>1.</sup> That is, we will replace the late-bound region with a placeholder, which gets canonicalized and turned into an infererence variable, which gets erased during region freshening right before we cache the result. Sorry, it's quite a few steps.

Fixes #94903
r? `@Aaron1011` (or reassign as you see fit)
2022-04-04 04:48:36 +00:00
..
chalk.rs Improve AdtDef interning. 2022-03-11 13:31:24 +11:00
mod.rs update comment 2022-04-01 13:47:01 +02:00
query.rs Swap DtorckConstraint to DropckConstraint 2022-03-24 20:35:35 +01:00
select.rs Do not use ParamEnv::and to cache param-env with candidate 2022-03-26 21:11:06 -07:00
specialization_graph.rs rustc_error: make ErrorReported impossible to construct 2022-03-16 10:35:24 -05:00
structural_impls.rs Rename ~const Drop to ~const Destruct 2022-03-21 17:04:03 +11:00
util.rs Spellchecking compiler comments 2022-03-30 15:14:15 -04:00