Skip to content

Commit

Permalink
Rollup merge of rust-lang#117992 - compiler-errors:sound-but-not-comp…
Browse files Browse the repository at this point in the history
…lete, 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
  • Loading branch information
matthiaskrgr committed Nov 17, 2023
2 parents 95010db + ae62ebe commit 09b964a
Show file tree
Hide file tree
Showing 7 changed files with 8 additions and 44 deletions.
6 changes: 5 additions & 1 deletion compiler/rustc_trait_selection/src/traits/coherence.rs
Original file line number Diff line number Diff line change
Expand Up @@ -397,7 +397,11 @@ fn impl_intersection_has_negative_obligation(
) -> bool {
debug!("negative_impl(impl1_def_id={:?}, impl2_def_id={:?})", impl1_def_id, impl2_def_id);

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

let impl1_header = fresh_impl_header(infcx, impl1_def_id);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// revisions: stock with_negative_coherence
//[with_negative_coherence] known-bug: unknown
//[with_negative_coherence] check-pass

#![feature(negative_impls)]
#![cfg_attr(with_negative_coherence, feature(with_negative_coherence))]
Expand Down

This file was deleted.

8 changes: 1 addition & 7 deletions tests/ui/coherence/coherence-overlap-with-regions.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,4 @@
// known-bug: unknown

// This fails because we currently perform negative coherence in coherence mode.
// This means that when looking for a negative predicate, we also assemble a
// coherence-unknowable predicate. Since confirming the negative impl has region
// obligations, we don't prefer the impl over the unknowable predicate
// unconditionally and instead flounder.
// check-pass

#![feature(negative_impls)]
#![feature(rustc_attrs)]
Expand Down
11 changes: 0 additions & 11 deletions tests/ui/coherence/coherence-overlap-with-regions.stderr

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// revisions: any_lt static_lt
//[static_lt] known-bug: unknown
//[static_lt] check-pass

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

This file was deleted.

0 comments on commit 09b964a

Please sign in to comment.