Skip to content

RFC: Allow pure functions to mutate their &mut arguments #3722

Closed
@catamorphism

Description

@catamorphism

Suppose I want to write something like:

pure fn mk_str() -> ~str {
  let mut s = ~"";
  str::push_char(&mut s, 'c');
  s
}

This doesn't work because push_char isn't pure. Morally, it seems like it should work, though, because although push_char does modify memory it doesn't own, mk_str owns the memory and should be allowed to call a function that modifies it.

I'm sure this question has come up before, but I don't know if there's an issue on it. If we do keep purity in the language, it seems like it's worth thinking about.

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-lifetimesArea: Lifetimes / regions

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions