Having "fun" with `let` bindings

let accepts any irrefutable pattern.

a @ b @ c @ ref mut d is an irrefutable pattern that says:

  • matches a mutable, copyable place
  • copy the value to variables a, b, c
  • put a mutable reference to the place in variable d

Since you're not actually matching the pattern, those 4 variables are uninitialized.

This is a pattern that says:

  • matches a mutable, copyable place
  • copy the value to variables a, b
  • put a mutable reference to the place in variables c, d

Since creating two mutable reference to the same place would be invalid, such a pattern is just declared invalid upfront.

The fact that you aren't matching the pattern is irrelevant because the pattern itself is declared invalid.

Here is another interesting example:

let 0u8..=255u8;
7 Likes