SE-0345: `if let` shorthand for shadowing an existing optional variable

fwiw case let foo as Bar (very similar to potential future direction) is already valid pattern matching syntax:

struct Bar { }
let foo: Any = Bar()

switch foo {
  case let foo as Bar:
    // foo is `Bar`
  default:
    // ...
}

One of the reasons I mentioned this potential direction in the proposal is that it shows how if let foo likely composes better with other language features compared to if let foo?:

// as an extension to `if let foo`
if let foo as? Bar { ... }

// as an extension to `if let foo?`
if let foo? as? Bar { ... }

If the extra ? is too much of a departure from existing pattern matching syntax, we could consider spelling a future feature like this as:

if let foo as Bar { ... }

(which, honestly, I rather like!)


The behavior of if ref foo { ... } seems approximately as clear as:

if ref foo = foo { ... }

which I assume would become part of the language if/when we add these borrow introducers.

Also, keep in mind that the exact spelling for these potential borrow introducers is yet to be determined and I'm sure it would be subject to pretty extensive bikeshedding before a final proposal.