-
Notifications
You must be signed in to change notification settings - Fork 12.7k
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
region/type inference bug with method #5801
Comments
Paging @catamorphism for derived type error. |
Thanks for flagging me! In this case, the derived error message is because of #5658 |
This still occurs now that |
The current protocol is very comparable to Python, where `.__iter__()` returns an iterator object which implements `.__next__()` and throws `StopIteration` on completion. `Option` is much cleaner than using a exceptions as a flow control hack though. It requires that the container is frozen so there's no worry about invalidating them. Advantages over internal iterators, which are functions that are passed closures and directly implement the iteration protocol: * Iteration is stateful, so you can interleave iteration over arbitrary containers. That's needed to implement algorithms like zip, merge, set union, set intersection, set difference and symmetric difference. I already used this internally in the `TreeMap` and `TreeSet` implementations, but regions and traits weren't solid enough to make it generic yet. * They provide a universal, generic interface. The same trait is used for a forward/reverse iterator, an iterator over a range, etc. Internal iterators end up resulting in a trait for each possible way you could iterate. * They can be composed with adaptors like `ZipIterator`, which also implement the same trait themselves. The disadvantage is that they're a pain to write without support from the compiler for compiling something like `yield` to a state machine. :) This can coexist alongside internal iterators since both can use the current `for` protocol. It's easier to write an internal iterator, but external ones are far more powerful/useful so they should probably be provided whenever possible by the standard library. ## Current issues #5801 is somewhat annoying since explicit type hints are required. I just wanted to get the essentials working well, so I haven't put much thought into making the naming concise (free functions vs. static `new` methods, etc.). Making an `Iterable` trait seems like it will have to be a long-term goal, requiring type system extensions. At least without resorting to objects which would probably be unacceptably slow.
pub fn all<T>(predicate: &fn(T) -> bool, iter: &fn(f: &fn(T) -> bool)) -> bool {
for iter |x| {
if !predicate(x) {
return false
}
}
true
}
fn main() {
all(|x: uint| x < 6, |f| std::uint::range(1, 6, f));
} Much simpler test case, but possibly a different bug. |
@thestinger The reduced test case now runs, but I can't get the treemap snippet to compile (because of the snippet itself, not bugs). |
@cmr: the error happens when you remove the type hint on the closure parameter. |
The reduced test case fails due to a known limitation in our type inference without an obvious easy fix. It is bug #912, which was closed. |
No more bugs. I think we should close.
|
This bug seems to be quite out of date, and there don't seem to be any standalone examples to test on today's compiler. Closing as likely fixed or needs an up-to-date example to make progress. |
Update: I can confirm this is definitely related to regions. An iterator without region annotations doesn't run into this problem.
Update two: I've added a much simpler test case in a comment below.
I'll see if I can cut this down to a simpler test case later. For now, here's a snippet I added to
treemap.rs
:and a test case (which compiles and works as it is here):
Removing the type hint from
result
causes this integer literal inference error:So I tried a workaround like this:
which hits what appears to be a borrow checking bug:
I thought this might be related to
==
being broken in some ways, but yet another error happens withmatch
, unless the explicit type hint is used:@nikomatsakis
The text was updated successfully, but these errors were encountered: