Skip to content

Commit 2ccafed

Browse files
committed
Auto merge of rust-lang#126024 - oli-obk:candidate_key_caching_is_unsound_yay, r=lcnr
Do not use global caches if opaque types can be defined fixes rust-lang#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 rust-lang#122192 (comment)
2 parents d24930c + 61b5e11 commit 2ccafed

File tree

2 files changed

+11
-2
lines changed

2 files changed

+11
-2
lines changed

compiler/rustc_trait_selection/src/traits/select/mod.rs

+7-1
Original file line numberDiff line numberDiff line change
@@ -1498,7 +1498,7 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
14981498
return false;
14991499
}
15001500

1501-
// Avoid using the master cache during coherence and just rely
1501+
// Avoid using the global cache during coherence and just rely
15021502
// on the local cache. This effectively disables caching
15031503
// during coherence. It is really just a simplification to
15041504
// avoid us having to fear that coherence results "pollute"
@@ -1509,6 +1509,12 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
15091509
return false;
15101510
}
15111511

1512+
// Avoid using the global cache when we're defining opaque types
1513+
// as their hidden type may impact the result of candidate selection.
1514+
if !self.infcx.defining_opaque_types().is_empty() {
1515+
return false;
1516+
}
1517+
15121518
// Otherwise, we can use the global cache.
15131519
true
15141520
}

tests/crashes/119272.rs tests/ui/auto-traits/opaque_type_candidate_selection.rs

+4-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
1-
//@ known-bug: #119272
1+
//! used to ICE: #119272
2+
3+
//@ check-pass
4+
25
#![feature(type_alias_impl_trait)]
36
mod defining_scope {
47
use super::*;

0 commit comments

Comments
 (0)