-
Notifications
You must be signed in to change notification settings - Fork 12.9k
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
ICE with probably recursive opaque types and closures #99073
Comments
This regressed in #94081 |
I was able to "weaponize" this into a transmute, lol: use std::fmt::Display;
fn main() {
test("hi", true);
}
fn test<T: Display>(t: T, recurse: bool) -> impl Display {
let f = || { let i: u32 = test::<i32>(-1, false); println!("{i}"); };
if recurse { f(); }
t
} So the issue here is that, at least in the case of RPITs, we are not checking for opaque type mismatches in closures correctly. The closure, in this example, is able to incorrectly constrain I think I have a fix, though. |
WG-prioritization assigning priority (Zulip discussion). @rustbot label -I-prioritize +P-critical |
…r=oli-obk Do not allow typeck children items to constrain outer RPITs Fixes rust-lang#99073 in a simpler and more conservative way than rust-lang#99079. Simply raise a mismatched types error if we try to constrain an RPIT in an item that isn't the RPIT's parent. r? `@oli-obk`
Check that RPITs constrained by a recursive call in a closure are compatible Fixes rust-lang#99073 Adapts a similar visitor pattern to `find_opaque_ty_constraints` (that we use to check TAITs), but with some changes: 0. Only walk the "OnlyBody" children, instead of all items in the RPIT's defining scope 1. Only walk through the body's children if we found a constraining usage 2. Don't actually do any inference, just do a comparison and error if they're mismatched ---- r? `@oli-obk` -- you know all this impl-trait stuff best... is this the right approach? I can explain the underlying issue better if you'd like, in case that might reveal a better solution. Not sure if it's possible to gather up the closure's defining usages of the RPIT while borrowck'ing the outer function, that might be a better place to put this check...
Messing around with a Haskell-like implementation of
fix
, I encountered two presumably similar ICEs(would think they're the same, but the error messages are obviously different). The other one is here.
I'm pretty sure this should be an error, based on the reasoning that
fix
returns an opaque type, so, while the output offix
might beG
, it also might not (and in this case, isn't), and sincef
only acceptsG
s,f(fix(anything))
should be an error.Code
Note that this
fix
implementation throws the ICE even without the main method, but I'm leaving it there for contrast to the other ICE.Meta
rustc --version --verbose
:Same ICE on nightly:
Error output
Backtrace
The text was updated successfully, but these errors were encountered: