Skip to content

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

Closed
@moxian

Description

@moxian

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    New ContentMissing features or aspects of language not currently documented.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions