-
Notifications
You must be signed in to change notification settings - Fork 12.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Detect cycle errors hidden by opaques during monomorphization #115801
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
38 changes: 38 additions & 0 deletions
38
tests/ui/async-await/in-trait/indirect-recursion-issue-112047.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,38 @@ | ||
// edition: 2021 | ||
// build-fail | ||
//~^^ ERROR overflow evaluating the requirement `<A as Second>::{opaque#0} == _` | ||
|
||
#![feature(async_fn_in_trait)] | ||
|
||
fn main() { | ||
let _ = async { | ||
A.first().await.second().await; | ||
}; | ||
} | ||
|
||
pub trait First { | ||
type Second: Second; | ||
async fn first(self) -> Self::Second; | ||
} | ||
|
||
struct A; | ||
|
||
impl First for A { | ||
type Second = A; | ||
async fn first(self) -> Self::Second { | ||
A | ||
} | ||
} | ||
|
||
pub trait Second { | ||
async fn second(self); | ||
} | ||
|
||
impl<C> Second for C | ||
where | ||
C: First, | ||
{ | ||
async fn second(self) { | ||
self.first().await.second().await; | ||
} | ||
} |
5 changes: 5 additions & 0 deletions
5
tests/ui/async-await/in-trait/indirect-recursion-issue-112047.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,5 @@ | ||
error[E0275]: overflow evaluating the requirement `<A as Second>::{opaque#0} == _` | ||
|
||
error: aborting due to previous error | ||
|
||
For more information about this error, try `rustc --explain E0275`. |
29 changes: 29 additions & 0 deletions
29
tests/ui/type-alias-impl-trait/indirect-recursion-issue-112047.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,29 @@ | ||
// edition: 2021 | ||
// build-fail | ||
//~^^ ERROR overflow evaluating the requirement `<() as Recur>::Recur == _` | ||
|
||
#![feature(impl_trait_in_assoc_type)] | ||
|
||
use core::future::Future; | ||
|
||
trait Recur { | ||
type Recur: Future<Output = ()>; | ||
|
||
fn recur(self) -> Self::Recur; | ||
} | ||
|
||
async fn recur(t: impl Recur) { | ||
t.recur().await; | ||
} | ||
|
||
impl Recur for () { | ||
type Recur = impl Future<Output = ()>; | ||
|
||
fn recur(self) -> Self::Recur { | ||
async move { recur(self).await; } | ||
} | ||
} | ||
|
||
fn main() { | ||
recur(()); | ||
} |
5 changes: 5 additions & 0 deletions
5
tests/ui/type-alias-impl-trait/indirect-recursion-issue-112047.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,5 @@ | ||
error[E0275]: overflow evaluating the requirement `<() as Recur>::Recur == _` | ||
|
||
error: aborting due to previous error | ||
|
||
For more information about this error, try `rustc --explain E0275`. |
40 changes: 40 additions & 0 deletions
40
tests/ui/type-alias-impl-trait/mututally-recursive-overflow.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,40 @@ | ||
// edition: 2021 | ||
// build-fail | ||
//~^^ ERROR overflow evaluating the requirement `<() as B>::Assoc == _` | ||
|
||
#![feature(rustc_attrs)] | ||
#![feature(impl_trait_in_assoc_type)] | ||
|
||
#[rustc_coinductive] | ||
trait A { | ||
type Assoc; | ||
|
||
fn test() -> Self::Assoc; | ||
} | ||
|
||
#[rustc_coinductive] | ||
trait B { | ||
type Assoc; | ||
|
||
fn test() -> Self::Assoc; | ||
} | ||
|
||
impl<T: A> B for T { | ||
type Assoc = impl Sized; | ||
|
||
fn test() -> <Self as B>::Assoc { | ||
<T as A>::test() | ||
} | ||
} | ||
|
||
fn main() { | ||
<() as A>::test(); | ||
} | ||
|
||
impl<T: B> A for T { | ||
type Assoc = impl Sized; | ||
|
||
fn test() -> <Self as A>::Assoc { | ||
<T as B>::test() | ||
} | ||
} |
5 changes: 5 additions & 0 deletions
5
tests/ui/type-alias-impl-trait/mututally-recursive-overflow.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,5 @@ | ||
error[E0275]: overflow evaluating the requirement `<() as B>::Assoc == _` | ||
|
||
error: aborting due to previous error | ||
|
||
For more information about this error, try `rustc --explain E0275`. |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does it do that for code that passes rustc? We are allowed to cause new errors in rustdoc if the code also wouldn't compile in rustc.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ah, that's the issue. hmm.. does rustdoc unwrap something instead of reporting an error? or where is the ICE coming from?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Well, the problem is that we need to do HIR analysis to make sure we don't have things like malformed and overlapping impl blocks too. These are probably not what we want to "fix" in rustdoc, since we compile rustdoc with all features enabled and stuff?
We also would need to check all type aliases as well-formed too, which we don't even do in rustc yet.
The ICE is coming from a failed projection in the
QueryNormalizer
.What happens is that we hit a cycle here:
rust/compiler/rustc_trait_selection/src/traits/project.rs
Lines 1193 to 1196 in 0692db1
Which means we treat the projection as ambiguous and emit a projection goal with an infer var on the RHS. That causes us to hit this assertion with debug assertions enabled:
rust/compiler/rustc_traits/src/normalize_erasing_regions.rs
Line 50 in 0692db1
Or just errors out with
NoSolution
, which causesnormalize_erasing_regions
to ICE.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah... yea that makes sense sadly.
Tho Rustdoc is moving towards doing wf checks in the future, so this will get cleaned up