diff options
| author | bors <bors@rust-lang.org> | 2024-07-24 11:59:10 +0000 |
|---|---|---|
| committer | bors <bors@rust-lang.org> | 2024-07-24 11:59:10 +0000 |
| commit | 2ccafed862f6906707a390caf180449dd64cad2e (patch) | |
| tree | fd325c746df969d4ce22fa28d9cec00ac6285f42 | |
| parent | d24930ceb473b7b361d108d573308e3529cb5ef7 (diff) | |
| parent | 61b5e11c47c452ed987295b147783e8bd8e16434 (diff) | |
| download | rust-2ccafed862f6906707a390caf180449dd64cad2e.tar.gz rust-2ccafed862f6906707a390caf180449dd64cad2e.zip | |
Auto merge of #126024 - oli-obk:candidate_key_caching_is_unsound_yay, r=lcnr
Do not use global caches if opaque types can be defined fixes #119272 r? `@lcnr` This is certainly a crude way to make the cache sound wrt opaque types, but since perf lets us get away with this, let's do it in the old solver and let the new solver fix this correctly once and for all. cc https://github.com/rust-lang/rust/pull/122192#issuecomment-2149252655
| -rw-r--r-- | compiler/rustc_trait_selection/src/traits/select/mod.rs | 8 | ||||
| -rw-r--r-- | tests/ui/auto-traits/opaque_type_candidate_selection.rs (renamed from tests/crashes/119272.rs) | 5 |
2 files changed, 11 insertions, 2 deletions
diff --git a/compiler/rustc_trait_selection/src/traits/select/mod.rs b/compiler/rustc_trait_selection/src/traits/select/mod.rs index d6590322caa..02ad361f9f5 100644 --- a/compiler/rustc_trait_selection/src/traits/select/mod.rs +++ b/compiler/rustc_trait_selection/src/traits/select/mod.rs @@ -1498,7 +1498,7 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> { return false; } - // Avoid using the master cache during coherence and just rely + // Avoid using the global cache during coherence and just rely // on the local cache. This effectively disables caching // during coherence. It is really just a simplification to // avoid us having to fear that coherence results "pollute" @@ -1509,6 +1509,12 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> { return false; } + // Avoid using the global cache when we're defining opaque types + // as their hidden type may impact the result of candidate selection. + if !self.infcx.defining_opaque_types().is_empty() { + return false; + } + // Otherwise, we can use the global cache. true } diff --git a/tests/crashes/119272.rs b/tests/ui/auto-traits/opaque_type_candidate_selection.rs index 02e2cfd09e2..d6973b76a6e 100644 --- a/tests/crashes/119272.rs +++ b/tests/ui/auto-traits/opaque_type_candidate_selection.rs @@ -1,4 +1,7 @@ -//@ known-bug: #119272 +//! used to ICE: #119272 + +//@ check-pass + #![feature(type_alias_impl_trait)] mod defining_scope { use super::*; |
