Skip to content

Commit d688b86

Browse files
Ignore but do not assume region obligations from unifying headers in negative coherence
1 parent 0ea7ddc commit d688b86

File tree

3 files changed

+50
-6
lines changed

3 files changed

+50
-6
lines changed

compiler/rustc_trait_selection/src/traits/coherence.rs

+6-6
Original file line numberDiff line numberDiff line change
@@ -542,14 +542,14 @@ fn try_prove_negated_where_clause<'tcx>(
542542
};
543543

544544
// FIXME(with_negative_coherence): the infcx has region contraints from equating
545-
// the impl headers as requirements. Given that the only region constraints we
546-
// get are involving inference regions in the root, it shouldn't matter, but
547-
// still sus.
545+
// the impl headers as requirements.
548546
//
549-
// We probably should just throw away the region obligations registered up until
550-
// now, or ideally use them as assumptions when proving the region obligations
551-
// that we get from proving the negative predicate below.
547+
// We ideally should use these region constraints as assumptions when proving
548+
// the region obligations that we get from proving the negative predicate below.
552549
let ref infcx = root_infcx.fork();
550+
let _ = infcx.take_registered_region_obligations();
551+
let _ = infcx.take_and_reset_region_constraints();
552+
553553
let ocx = ObligationCtxt::new(infcx);
554554

555555
ocx.register_obligation(Obligation::new(
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
error: conflicting implementations of trait `FnMarker` for type `fn(&_)`
2+
--> $DIR/negative-coherence-placeholder-region-constraints-on-unification.rs:21:1
3+
|
4+
LL | impl<T: ?Sized + Marker> FnMarker for fn(T) {}
5+
| ------------------------------------------- first implementation here
6+
LL | impl<T: ?Sized> FnMarker for fn(&T) {}
7+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ conflicting implementation for `fn(&_)`
8+
|
9+
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
10+
= note: for more information, see issue #56105 <https://github.com/rust-lang/rust/issues/56105>
11+
= note: this behavior recently changed as a result of a bug fix; see rust-lang/rust#56105 for details
12+
note: the lint level is defined here
13+
--> $DIR/negative-coherence-placeholder-region-constraints-on-unification.rs:4:11
14+
|
15+
LL | #![forbid(coherence_leak_check)]
16+
| ^^^^^^^^^^^^^^^^^^^^
17+
18+
error: aborting due to previous error
19+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
// revisions: explicit implicit
2+
//[implicit] check-pass
3+
4+
#![forbid(coherence_leak_check)]
5+
#![feature(negative_impls, with_negative_coherence)]
6+
7+
pub trait Marker {}
8+
9+
#[cfg(implicit)]
10+
impl<T: ?Sized> !Marker for &T {}
11+
12+
#[cfg(explicit)]
13+
impl<'a, T: ?Sized + 'a> !Marker for &'a T {}
14+
15+
trait FnMarker {}
16+
17+
// Unifying these two impls below results in a `T: '!0` obligation
18+
// that we shouldn't need to care about. Ideally, we'd treat that
19+
// as an assumption when proving `&'!0 T: Marker`...
20+
impl<T: ?Sized + Marker> FnMarker for fn(T) {}
21+
impl<T: ?Sized> FnMarker for fn(&T) {}
22+
//[explicit]~^ ERROR conflicting implementations of trait `FnMarker` for type `fn(&_)`
23+
//[explicit]~| WARN this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
24+
25+
fn main() {}

0 commit comments

Comments
 (0)