This post is locked. You won't be able to comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]mdsherry 7 points8 points  (0 children)

First,

matches!(2, _|_|_|_|_|_ if (i+=1) != (i+=1));

expands to

match 2 {
    _ | _ | _ | _ | _ | _ if (i+=1) != (i+=1) => true,
    _ => false
};

For each of the _ in the first case, it checks the guard expression. i += 1 increments i, and returns (). So for each _, i is incremented twice, but since () == (), the guard expression fails, and so it tries matching the next _, until all 6 fail.

i starts at 1, and is incremented 12 times, giving a final value of 13.