Skip to content

Commit 8f178d1

Browse files
Don't call predicate_must_hold during fulfillment in intercrate
1 parent bacf5bc commit 8f178d1

File tree

3 files changed

+38
-2
lines changed

3 files changed

+38
-2
lines changed

compiler/rustc_trait_selection/src/traits/fulfill.rs

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

728-
if obligation.predicate.is_global() {
728+
if obligation.predicate.is_global() && !self.selcx.is_intercrate() {
729729
// no type variables present, can use evaluation for better caching.
730730
// FIXME: consider caching errors too.
731731
if self.selcx.infcx.predicate_must_hold_considering_regions(obligation) {
Lines changed: 24 additions & 0 deletions
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() {}
Lines changed: 12 additions & 0 deletions
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)