-
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
Type Checker getting confused with constraints + ICE #33904
Comments
Looks like this is #30472. |
It's not, it also gets confused if I remove the HRTB and add the lifetime It's definitely related to the Deref and / or lifetimes though. Just requiring IntoIterator makes it work. Also, convex_hull::create has the same signature, with the same constraints, so this isn't about the constraints themselves, as they work perfectly fine in other places. It's about this particular combination that confuses the compiler. Am Freitag, 27. Mai 2016 schrieb Eduard-Mihai Burtescu :
|
@CryZe With associated types under HRTB, the compiler cannot tell that two identical-looking bounds are the same, or that they imply each-other. This has been a problem for as long as HRTB has existed. |
As you can see here, I just removed all HRTB and it still doesn't compile. It still expects Q even though there's no Q on convex_hull::create, just P. At least it correctly named convex_hull::Vec3 as na::Vector3 instead of convex_hull::Vector3 this time :D (actually nvm, na is also a renamed reexport, so it's still kind of wrong). |
The Rust compiler never uses type parameter names from callees in error messages in callers. |
The ICE seems to be caused by the Vec not being able to type infer its type from the constraint. Explicitly giving it a type makes it work. Nvm, it's even more weird. |
Here's the reduced code: https://is.gd/DHxfbu ICE happens on Beta and Nightly. Type Checker problem happens on all. pub fn problem_creator<'a, P>(_: &'a P)
where &'a P: IntoIterator<Item = &'a f64>
{}
pub fn ok() {
let points = Vec::new();
problem_creator(&points)
}
pub fn ok2() {
let points: Vec<f64> = Vec::new();
problem_creator(&points)
}
pub fn ice<'a, Q>(_: &'a Q)
where &'a Q: IntoIterator<Item = &'a f64>
{
let points = Vec::new();
problem_creator(&points)
}
pub fn broken_typechecking<'a, Q>(_: &'a Q)
where &'a Q: IntoIterator<Item = &'a f64>
{
let points: Vec<f64> = Vec::new();
problem_creator(&points)
}
fn main() {} |
Ahh, I see what happens: |
@CryZe As a workaround, |
Yeah, seems to work. Thanks for your help :) |
@arielb1 Is the ICE fixed? |
it looks like the |
I've written the same code in 2 different crates. One compiles perfectly fine, the other doesn't. Apparently the constraints on the function merge(!!) with the constraints of the other function and the type checker is getting really confused and errors out. If you look at the code, the constrained type Q does not come in contact with convex_hull::create in any way, yet it influences it. Removing Q from the function lets convex_hull::create compile just fine.
Also the compiler is complaining about a type called convex_hull::Vector3, which doesn't exist, it's called Vec3. Vec3 is actually a reexport of Vector3 as Vec3, which then got reexported again (and I think again). So maybe somewhere the type checker got confused by that and now thinks it needs to look for a type called Vector3. Not sure if that's related to the problem at all though, just seems like maybe another small bug.
The text was updated successfully, but these errors were encountered: