Skip to content

Commit 0e8e857

Browse files
committed
Auto merge of #113742 - compiler-errors:dont-short-circuit-intercrate-global-preds, r=lcnr
Don't call `predicate_must_hold`-esque functions during fulfillment in intercrate Fixes #113415 Given that this only happens in `translate_substs`, I don't actually think that this is something that you can weaponize, but it's still sketchy regardless. r? `@lcnr`
2 parents c4083fa + 8f178d1 commit 0e8e857

File tree

3 files changed

+38
-2
lines changed

3 files changed

+38
-2
lines changed

compiler/rustc_trait_selection/src/traits/fulfill.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -670,7 +670,7 @@ impl<'a, 'tcx> FulfillProcessor<'a, 'tcx> {
670670
stalled_on: &mut Vec<TyOrConstInferVar<'tcx>>,
671671
) -> ProcessResult<PendingPredicateObligation<'tcx>, FulfillmentErrorCode<'tcx>> {
672672
let infcx = self.selcx.infcx;
673-
if obligation.predicate.is_global() {
673+
if obligation.predicate.is_global() && !self.selcx.is_intercrate() {
674674
// no type variables present, can use evaluation for better caching.
675675
// FIXME: consider caching errors too.
676676
if infcx.predicate_must_hold_considering_regions(obligation) {
@@ -724,7 +724,7 @@ impl<'a, 'tcx> FulfillProcessor<'a, 'tcx> {
724724
) -> ProcessResult<PendingPredicateObligation<'tcx>, FulfillmentErrorCode<'tcx>> {
725725
let tcx = self.selcx.tcx();
726726

727-
if obligation.predicate.is_global() {
727+
if obligation.predicate.is_global() && !self.selcx.is_intercrate() {
728728
// no type variables present, can use evaluation for better caching.
729729
// FIXME: consider caching errors too.
730730
if self.selcx.infcx.predicate_must_hold_considering_regions(obligation) {
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
// check-pass
2+
// issue: 113415
3+
4+
// Makes sure that coherence doesn't call any of the `predicate_may_hold`-esque fns,
5+
// since they are using a different infcx which doesn't preserve the intercrate flag.
6+
7+
#![feature(specialization)]
8+
//~^ WARN the feature `specialization` is incomplete
9+
10+
trait Assoc {
11+
type Output;
12+
}
13+
14+
default impl<T> Assoc for T {
15+
type Output = bool;
16+
}
17+
18+
impl Assoc for u8 {}
19+
20+
trait Foo {}
21+
impl Foo for u32 {}
22+
impl Foo for <u8 as Assoc>::Output {}
23+
24+
fn main() {}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
warning: the feature `specialization` is incomplete and may not be safe to use and/or cause compiler crashes
2+
--> $DIR/coherence-doesnt-use-infcx-evaluate.rs:7:12
3+
|
4+
LL | #![feature(specialization)]
5+
| ^^^^^^^^^^^^^^
6+
|
7+
= note: see issue #31844 <https://github.com/rust-lang/rust/issues/31844> for more information
8+
= help: consider using `min_specialization` instead, which is more stable and complete
9+
= note: `#[warn(incomplete_features)]` on by default
10+
11+
warning: 1 warning emitted
12+

0 commit comments

Comments
 (0)