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

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

Closed
catamorphism opened this issue Oct 11, 2012 · 5 comments
Closed

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

catamorphism opened this issue Oct 11, 2012 · 5 comments
Labels
A-lifetimes Area: Lifetimes / regions
Milestone

Comments

@catamorphism
Copy link
Contributor

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.

@nikomatsakis
Copy link
Contributor

I have a plan to address precisely this problem. I was hoping to write a blog post on it today.

@catamorphism
Copy link
Contributor Author

Related: #3490

@nikomatsakis
Copy link
Contributor

@nikomatsakis
Copy link
Contributor

I renamed the issue to describe my proposal and to include the term "RFC".

@graydon
Copy link
Contributor

graydon commented Mar 13, 2013

pure functions are scheduled for removal, so closing WONTFIX

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

3 participants