-
Notifications
You must be signed in to change notification settings - Fork 13.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implement lint against coinductive impl overlap
- Loading branch information
1 parent
2ae4bed
commit 56f5704
Showing
5 changed files
with
183 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
35 changes: 35 additions & 0 deletions
35
tests/ui/coherence/warn-when-cycle-is-error-in-coherence.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
#![deny(coinductive_overlap_in_coherence)] | ||
|
||
use std::borrow::Borrow; | ||
use std::cmp::Ordering; | ||
use std::marker::PhantomData; | ||
|
||
#[derive(PartialEq, Default)] | ||
pub(crate) struct Interval<T>(PhantomData<T>); | ||
|
||
// This impl overlaps with the `derive` unless we reject the nested | ||
// `Interval<?1>: PartialOrd<Interval<?1>>` candidate which results | ||
// in an inductive cycle right now. | ||
impl<T, Q> PartialEq<Q> for Interval<T> | ||
//~^ ERROR impls that are not considered to overlap may be considered to overlap in the future | ||
//~| WARN this was previously accepted by the compiler but is being phased out | ||
where | ||
T: Borrow<Q>, | ||
Q: ?Sized + PartialOrd, | ||
{ | ||
fn eq(&self, _: &Q) -> bool { | ||
true | ||
} | ||
} | ||
|
||
impl<T, Q> PartialOrd<Q> for Interval<T> | ||
where | ||
T: Borrow<Q>, | ||
Q: ?Sized + PartialOrd, | ||
{ | ||
fn partial_cmp(&self, _: &Q) -> Option<Ordering> { | ||
None | ||
} | ||
} | ||
|
||
fn main() {} |
22 changes: 22 additions & 0 deletions
22
tests/ui/coherence/warn-when-cycle-is-error-in-coherence.stderr
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
error: impls that are not considered to overlap may be considered to overlap in the future | ||
--> $DIR/warn-when-cycle-is-error-in-coherence.rs:13:1 | ||
| | ||
LL | #[derive(PartialEq, Default)] | ||
| --------- the second impl is here | ||
... | ||
LL | impl<T, Q> PartialEq<Q> for Interval<T> | ||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ the first impl is here | ||
... | ||
LL | Q: ?Sized + PartialOrd, | ||
| ---------- this where-clause causes a cycle, but it may be treated as possibly holding in the future, causing the impls to overlap | ||
| | ||
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release! | ||
= note: for more information, see issue #114040 <https://github.com/rust-lang/rust/issues/114040> | ||
note: the lint level is defined here | ||
--> $DIR/warn-when-cycle-is-error-in-coherence.rs:1:9 | ||
| | ||
LL | #![deny(coinductive_overlap_in_coherence)] | ||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | ||
|
||
error: aborting due to previous error | ||
|