-
Notifications
You must be signed in to change notification settings - Fork 13.3k
Rust is overflowing on recursive trait evaluation where it didn't before #34260
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
Comments
It's been over a year, and there's been no reply to this. Some of Diesel's worst error messages result from this issue. It's even become a meme that if you forget an This case has come up again, in a recent Diesel PR. However, we're seeing overflow in cases where it's checking a concrete type, for which the recursive impl should definitively not apply. I've simplified it down to this: https://gist.github.com/sgrif/48bf08a27b3da35a44ac085cada0622c, which should fail to compile with The code today has a comment which says "it is important that overflow never be masked". What's especially frustrating here is that it is masked in places that it's convenient for rustc. If the overflow occurred as a result of checking |
@nikomatsakis If you have some time this week is there any chance I could get you to take a look at this? |
triage: P-medium @sgrif and I are working on this a bit =) |
Triage: no change |
Instead of producing an overflowing trait bound error show a concrete error message what's wrong for certain query combination. This requires to workaround rust-lang/rust#34260 in our single method query dsl implementations: * `GroupByDsl` * `BoxedDsl` * `DistinctDsl` * `DistinctOnDsl` * `LockingDsl`
Triage: @sgrif 's examples in the original post (markdown code + https://is.gd/XSHLG2 + https://is.gd/vrEvFN) do not reproduce on 2021 edition, tested on @sgrif do you know if there still an issue which can be reproduced? |
This can be simplified down to the following:
When compiling that program, rust will overflow when it did not on older versions.. Of course that example is contrived, and attempting to use any concrete type there will always overflow. It is simplified from the slightly more realistic example in https://is.gd/XSHLG2, which is simplified from the real world case where I encountered this, which was trying to pull https://github.com/diesel-rs/diesel/blob/f0a75bb/diesel/src/query_dsl/load_dsl.rs#L23-L29 into a separate trait.
The important distinction is that we're now overflowing in a generic context, in cases where there are some concrete types which are valid. Specifically this causes confusing differing behavior between where clauses on methods and where clauses on trait impls. The above code is fine if the where clause is instead on some trait method, as it's no longer evaluated until there's a concrete type that the method is being called on.
I'd actually think that rustc could always avoid overflow here, and instead detect that it's evaluating the same trait impl def for the same type and answer no. The code implies that was the intention. But that's aside the point, this is about a concrete change in behavior.
The issue was first introduced in nightly-2015-08-15. On nightlies prior to that, https://is.gd/vrEvFN would compile successfully. It manifested as an actual stack overflow until nightly-2015-10-29, where it became a proper error (hilariously giving a warning that this warning would become a hard error due to RFC 1214, when it was already hard erroring). I believe this was an unintentional side effect of implementing RFC 1214, as that was merged in on the nightly that introduced the issue.
The text was updated successfully, but these errors were encountered: