Skip to content
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

Borrow check error with hash maps #6021

Closed
catamorphism opened this issue Apr 23, 2013 · 2 comments
Closed

Borrow check error with hash maps #6021

catamorphism opened this issue Apr 23, 2013 · 2 comments
Labels
A-lifetimes Area: Lifetimes / regions

Comments

@catamorphism
Copy link
Contributor

In trans::reachable, there is the following code:

fn traverse_public_item(cx: &ctx, item: @item) {
    let rmap: &mut HashSet<node_id> = cx.rmap;
    if cx.rmap.contains(&item.id) { return; }
    rmap.insert(item.id);
//...
}

A comment says that naming rmap and giving it an explicit type should not be necessary, but with incoming, it still is. The error if I inline rmap is:

/Users/tjc/rust2/src/librustc/middle/trans/reachable.rs:98:7: 98:14 error: illegal borrow unless pure: creating immutable alias to dereference of mutable & pointer
/Users/tjc/rust2/src/librustc/middle/trans/reachable.rs:98     if cx.rmap.contains(&item.id) { return; }
                                                                  ^~~~~~~
/Users/tjc/rust2/src/librustc/middle/trans/reachable.rs:98:7: 98:35 note: impure due to access to impure function
/Users/tjc/rust2/src/librustc/middle/trans/reachable.rs:98     if cx.rmap.contains(&item.id) { return; }

This confuses me since I thought we removed purity. Anyway, this was an XXX and I figured I would make it into a proper issue. (@nikomatsakis may know more.)

@nikomatsakis
Copy link
Contributor

This is a bug in the existing borrow checker (and the error messages were not updated to reflect the absence of purity). Both problems are addressed in my branch.

This was referenced May 6, 2013
bors added a commit that referenced this issue May 7, 2013
…omatsakis

This rather sprawling branch refactors the borrow checker and much of the region code, addressing a number of outstanding issues. I will close them manually after validating that there are test cases for each one, but here is a (probably partial) list:

  - #4903: Flow sensitivity
  - #3387: Moves in overloaded operators
  - #3850: Region granularity
  - #4666: Odd loaning errors
  - #6021: borrow check errors with hashmaps
  - #5910: @mut broken

cc #5047

(take 5)
@nikomatsakis
Copy link
Contributor

This precise code no longer exists, but I believe the situation to be resolved (modulo #6269)

flip1995 pushed a commit to flip1995/rust that referenced this issue Sep 24, 2020
…r=flip1995

Treat refs to arrays the same as owned arrays in `indexing_slicing` and `out_of_bounds_indexing`

Fixes rust-lang#6021

...and remove `walk_ptrs_ty` in favour of `peel_refs`, which came in 2019.

---

changelog: Fix a false positive in `indexing_slicing` and `out_of_bounds_indexing` where references to arrays weren't treated as arrays.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-lifetimes Area: Lifetimes / regions
Projects
None yet
Development

No branches or pull requests

2 participants