Skip to content

Commit 2d336fb

Browse files
Rollup merge of rust-lang#117992 - compiler-errors:sound-but-not-complete, r=lcnr
Don't require intercrate mode for negative coherence Negative coherence needs to be *sound*, but does not need to be *complete*, since it's looking for the *existence* of a negative goal, not the non-existence of a positive goal. This removes some trivial and annoying ambiguities when a negative impl has region constraints. r? lcnr idk if this needs an fcp but if it does, pls kick it off
2 parents 4c4e671 + ae62ebe commit 2d336fb

7 files changed

+8
-44
lines changed

compiler/rustc_trait_selection/src/traits/coherence.rs

+5-1
Original file line numberDiff line numberDiff line change
@@ -397,7 +397,11 @@ fn impl_intersection_has_negative_obligation(
397397
) -> bool {
398398
debug!("negative_impl(impl1_def_id={:?}, impl2_def_id={:?})", impl1_def_id, impl2_def_id);
399399

400-
let ref infcx = tcx.infer_ctxt().intercrate(true).with_next_trait_solver(true).build();
400+
// N.B. We don't need to use intercrate mode here because we're trying to prove
401+
// the *existence* of a negative goal, not the non-existence of a positive goal.
402+
// Without this, we over-eagerly register coherence ambiguity candidates when
403+
// impl candidates do exist.
404+
let ref infcx = tcx.infer_ctxt().with_next_trait_solver(true).build();
401405
let universe = infcx.universe();
402406

403407
let impl1_header = fresh_impl_header(infcx, impl1_def_id);

tests/ui/coherence/coherence-negative-outlives-lifetimes.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
// revisions: stock with_negative_coherence
2-
//[with_negative_coherence] known-bug: unknown
2+
//[with_negative_coherence] check-pass
33

44
#![feature(negative_impls)]
55
#![cfg_attr(with_negative_coherence, feature(with_negative_coherence))]

tests/ui/coherence/coherence-negative-outlives-lifetimes.with_negative_coherence.stderr

-11
This file was deleted.

tests/ui/coherence/coherence-overlap-with-regions.rs

+1-7
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,4 @@
1-
// known-bug: unknown
2-
3-
// This fails because we currently perform negative coherence in coherence mode.
4-
// This means that when looking for a negative predicate, we also assemble a
5-
// coherence-unknowable predicate. Since confirming the negative impl has region
6-
// obligations, we don't prefer the impl over the unknowable predicate
7-
// unconditionally and instead flounder.
1+
// check-pass
82

93
#![feature(negative_impls)]
104
#![feature(rustc_attrs)]

tests/ui/coherence/coherence-overlap-with-regions.stderr

-11
This file was deleted.

tests/ui/coherence/negative-coherence-considering-regions.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
// revisions: any_lt static_lt
2-
//[static_lt] known-bug: unknown
2+
//[static_lt] check-pass
33

44
// This fails because we currently perform negative coherence in coherence mode.
55
// This means that when looking for a negative predicate, we also assemble a

tests/ui/coherence/negative-coherence-considering-regions.static_lt.stderr

-12
This file was deleted.

0 commit comments

Comments
 (0)