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

Document function argument evaluation order (or lack thereof) #332

Closed
moxian opened this issue May 11, 2018 · 4 comments
Closed

Document function argument evaluation order (or lack thereof) #332

moxian opened this issue May 11, 2018 · 4 comments
Labels
New Content Missing features or aspects of language not currently documented.

Comments

@moxian
Copy link

moxian commented May 11, 2018

A question I stumbled upon today, and couldn't find the answer in the reference.

Consider the following program:

struct Counter {
    v : i32
}
impl Counter {
    fn next(&mut self) -> i32 {
        self.v += 1;
        self.v
    }
}

fn show(first: i32, second: i32) {
    println!("{} {}", first, second);
}

fn main(){
    let mut x = Counter{v: 0};
    show(x.next(), x.next());
}

In my experience it always prints 1 2 but I want to know whether this is guaranteed, or if it is (like, e.g., in C++) explicitly undefined.
The most obvious place to put the answer is https://doc.rust-lang.org/reference/expressions/call-expr.html (or just https://doc.rust-lang.org/reference/expressions.html)

Same question for order of evaluation of tuple elements.

@Havvy Havvy added the New Content Missing features or aspects of language not currently documented. label May 22, 2018
@Havvy
Copy link
Contributor

Havvy commented May 24, 2018

I was told, but without a source of truth, that the order of evaluation of expressions is the order they are written in at the call site. So for function arguments and tuples they will always be left to right. For struct expressions, it's the order in which the field names are written.

@alercah
Copy link
Contributor

alercah commented May 24, 2018 via email

@ehuss
Copy link
Contributor

ehuss commented Jan 18, 2021

@Havvy Does #888 resolve this?

@Havvy
Copy link
Contributor

Havvy commented Jan 19, 2021

Yes.

@Havvy Havvy closed this as completed Jan 19, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
New Content Missing features or aspects of language not currently documented.
Projects
None yet
Development

No branches or pull requests

4 participants