forked from rust-lang/rust
-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Auto merge of rust-lang#122791 - compiler-errors:make-coinductive-alw…
…ays, r=lcnr Make inductive cycles always ambiguous This makes inductive cycles always result in ambiguity rather than be treated like a stack-dependent error. This has some interactions with specialization, and so breaks a few UI tests that I don't agree should've ever worked in the first place, and also breaks a handful of crates in a way that I don't believe is a problem. On the bright side, it puts us in a better spot when it comes to eventually enabling coinduction everywhere. ## Results This was cratered in rust-lang#116494 (comment), which boils down to two regressions: * `lu_packets` - This code should have never compiled in the first place. More below. * **ALL** other regressions are due to `[email protected]` (edit: and `[email protected]`) - This actually seems to be fixed in version `0.11.0-beta.5`, which is the *most* up to date version, but it's still prerelease on crates.io so I don't think cargo ends up picking `beta.5` when building dependent crates. ### `lu_packets` Firstly, this crate uses specialization, so I think it's automatically worth breaking. However, I've minimized [the regression](https://crater-reports.s3.amazonaws.com/pr-116494-3/try%23d614ed876e31a5f3ad1d0fbf848fcdab3a29d1d8/gh/lcdr.lu_packets/log.txt) to: ```rust // Upstream crate pub trait Serialize {} impl Serialize for &() {} impl<S> Serialize for &[S] where for<'a> &'a S: Serialize {} // ----------------------------------------------------------------------- // // Downstream crate #![feature(specialization)] #![allow(incomplete_features, unused)] use upstream::Serialize; trait Replica { fn serialize(); } impl<T> Replica for T { default fn serialize() {} } impl<T> Replica for Option<T> where for<'a> &'a T: Serialize, { fn serialize() {} } ``` Specifically this fails when computing the specialization graph for the `downstream` crate. The code ends up cycling on `&[?0]: Serialize` when we equate `&?0 = &[?1]` during impl matching, which ends up needing to prove `&[?1]: Serialize`, which since cycles are treated like ambiguity, ends up in a **fatal overflow**. For some reason this requires two crates, squashing them into one crate doesn't work. Side-note: This code is subtly order dependent. When minimizing, I ended up having the code start failing on `nightly` very easily after removing and reordering impls. This seems to me all the more reason to remove this behavior altogether. ## Side-note: Item Bounds (edit: this was fixed independently in rust-lang#121123) Due to the changes in rust-lang#120584 where we now consider an alias's item bounds *and* all the item bounds of the alias's nested self type aliases, I've had to add e6b64c6 which is a hack to make sure we're not eagerly normalizing bounds that have nothing to do with the predicate we're trying to solve, and which result in. This is fixed in a more principled way in rust-lang#121123. --- r? lcnr for an initial review
- Loading branch information
Showing
12 changed files
with
104 additions
and
117 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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,27 @@ | ||
error[E0283]: type annotations needed: cannot satisfy `&str: A` | ||
--> $DIR/unsound-overlap.rs:10:12 | ||
| | ||
LL | impl A for &str {} | ||
| ^^^^ | ||
| | ||
note: multiple `impl`s satisfying `&str: A` found | ||
--> $DIR/unsound-overlap.rs:9:1 | ||
| | ||
LL | impl<T: B> A for T {} | ||
| ^^^^^^^^^^^^^^^^^^ | ||
LL | impl A for &str {} | ||
| ^^^^^^^^^^^^^^^ | ||
|
||
error[E0119]: conflicting implementations of trait `TraitWithAssoc` for type `((&str,),)` | ||
--> $DIR/unsound-overlap.rs:20:1 | ||
--> $DIR/unsound-overlap.rs:21:1 | ||
| | ||
LL | impl<T: A> TraitWithAssoc for T { | ||
| ------------------------------- first implementation here | ||
... | ||
LL | impl TraitWithAssoc for ((&str,),) { | ||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ conflicting implementation for `((&str,),)` | ||
|
||
error: aborting due to 1 previous error | ||
error: aborting due to 2 previous errors | ||
|
||
For more information about this error, try `rustc --explain E0119`. | ||
Some errors have detailed explanations: E0119, E0283. | ||
For more information about an error, try `rustc --explain E0119`. |
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
//@ check-pass | ||
// Regression test for <https://github.com/rust-lang/rust/issues/123303>. | ||
// This time EXCEPT without `dyn` builtin bounds :^) | ||
|
||
pub trait Trait: Supertrait {} | ||
|
||
trait Impossible {} | ||
impl<F: ?Sized + Impossible> Trait for F {} | ||
|
||
pub trait Supertrait {} | ||
|
||
impl<T: ?Sized + Trait + Impossible> Supertrait for T {} | ||
|
||
fn needs_supertrait<T: ?Sized + Supertrait>() {} | ||
fn needs_trait<T: ?Sized + Trait>() {} | ||
|
||
struct A; | ||
impl Trait for A where A: Supertrait {} | ||
impl Supertrait for A {} | ||
|
||
fn main() { | ||
needs_supertrait::<A>(); | ||
needs_trait::<A>(); | ||
} |
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,19 @@ | ||
//@ check-pass | ||
// Regression test for <https://github.com/rust-lang/rust/issues/123303>. | ||
|
||
pub trait Trait: Supertrait {} | ||
|
||
trait Impossible {} | ||
impl<F: ?Sized + Impossible> Trait for F {} | ||
|
||
pub trait Supertrait {} | ||
|
||
impl<T: ?Sized + Trait + Impossible> Supertrait for T {} | ||
|
||
fn needs_supertrait<T: ?Sized + Supertrait>() {} | ||
fn needs_trait<T: ?Sized + Trait>() {} | ||
|
||
fn main() { | ||
needs_supertrait::<dyn Trait>(); | ||
needs_trait::<dyn Trait>(); | ||
} |