-
Notifications
You must be signed in to change notification settings - Fork 13.3k
Iterator invalidation not caught by borrow-checker #20232
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
(1) I can replicate the same issue (at least, I'm pretty sure it's the same issue) in Rust 0.12. (2) No unsafe code need be involved. (3) It appears to be a combined problem with the interaction of Code below (the #![feature(if_let)]
struct Foo<T> { x: T }
impl<T> Index<uint,T> for Foo<T> {
fn index(&self, _: &uint) -> &T {
&self.x
}
}
struct Bar<T> { x: T }
impl<T> Deref<T> for Bar<T> {
fn deref(&self) -> &T {
&self.x
}
}
struct Baz<T> { x: T }
impl<T> Baz<T> {
fn foo(&self) -> &T {
&self.x
}
}
fn main() {
let u = 1u8;
let mut v = Foo { x: Bar { x: Baz { x: Some(&u) } } };
let i = v[0].foo();
if let Some(ref i) = *i {
v.x.x.x = None;
println!("i = {}", i);
}
} |
I'll check it out (if @eddyb doens't figure it out first!) |
What's very interesting is that |
This may be a bug in the for loop handling code. When I do various transforms to the code, such as storing the iterator in a local, I get the expected error messages. |
@nikomatsakis I found some of those a long while ago (#17068), guess there's more? |
@nikomatsakis It's not related to |
… implicit deref that is associated with an overloaded index, we should not consult the method lookup table. This deref is *always* a deref of an `&T` and hence is never overloaded (and is also not present in the tables; it has no "id" or other associated key).
Fix pending. |
See PR #20751 |
Issue rust-lang#20232. Fun. r? @eddyb you prob know this system best
Fixed in #20751 |
In the following reduced code the call to
do_bad_thing
invalidates the iterator inmain
.Running this locally produces (without optimizations):
On playpen this does not give wrong results, but it does compile (which is the actual problem).
I'm running rustc on Windows:
The text was updated successfully, but these errors were encountered: