Skip to content

Appending to a mutable vector in a hashmap doesn't update the vector #2039

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

Closed
jdm opened this issue Mar 21, 2012 · 1 comment
Closed

Appending to a mutable vector in a hashmap doesn't update the vector #2039

jdm opened this issue Mar 21, 2012 · 1 comment

Comments

@jdm
Copy link
Contributor

jdm commented Mar 21, 2012

import std::map;
import std::map::hashmap;
use std;

type mut_elts = {mutable elts: [int]};

fn main() {
    let elts_hash = map::str_hash::();
    elts_hash.insert("foo", {mutable elts: []});
    elts_hash.get("foo").elts += [1];
    #error("%u", vec::len(elts_hash.get("foo").elts));
}

I would expect to see 1 printed, but instead I see 0.

@marijnh
Copy link
Contributor

marijnh commented Mar 21, 2012

Our value semantics are similar to C, not to languages like Lisp or JavaScript. A record is copied when stored in another place, so putting it into the hash table and getting it out again causes it to be repeatedly copied. Store a @-pointer to the record if you want to actually get at a single value.

@marijnh marijnh closed this as completed Mar 21, 2012
celinval added a commit to celinval/rust-dev that referenced this issue Jun 4, 2024
Refactor how we were creating the rlib files in the link stage. We cannot invoke rustc's linker directly for the native types since they will call the native linker that will fail. Instead, we just manually create an rlib file that includes only a metadata file.

I cleaned up our archive builder since we no longer need to conform to rustc's interface.
Kobzol pushed a commit to Kobzol/rust that referenced this issue Dec 30, 2024
* Update LLVM docs

* Apply feedback
bors pushed a commit to rust-lang-ci/rust that referenced this issue Jan 2, 2025
* Update LLVM docs

* Apply feedback
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants