[rust-dev] minor things that annoy you about Rust?

Niko Matsakis niko at alum.mit.edu
Sat Dec 24 05:52:14 PST 2011


Now that I sent the mail, I'm already second guessing this suggestion.  It
introduces an asymmetry in that new variable names can be introduced in an
`alt` block without a `let` prefix, but not in a normal assignment (in a
normal assignment).  And I'm sure Dave will point out that much better
solutions exist to avoid having macros capture outside names.



On Sat, Dec 24, 2011 at 5:45 AM, Niko Matsakis <niko at alum.mit.edu> wrote:

> What about "disallow shadowing unless you use the `let` keyword"?
> Sometimes shadowing is nice and sometimes (think macros) you want to use a
> name and know its meaning without regard to existing exterior bindings.
>
> So you could write:
>
>     let a = ...;
>     let b = ...;
>     alt foo {
>         bar(a, let b) { ... }
>     }
>
> this would match a `bar` whose first argument is equal to `a` and with any
> second argument.
>
> We could also allow the `let` to be used at different levels:
>
>     alt foo {
>         let bar(a, b) { ... }
>     }
>
> This would also allow `let x = y;` to continue shadowing bindings.  We
> could also then permit things like:
>
>     (a, let b) = ...;
>
> which I think Marijn was asking for a while back.  After having hacked
> trans for a while, I can see why!  I'm always writing:
>
>     let foo = trans_this_or_that();
>     bcx = foo.bcx;
>
> and it would be nicer to write:
>
>     (bcx, let val) = trans_this_or_that();
>
>
> Niko
>
>
> On Fri, Dec 23, 2011 at 12:00 PM, Marijn Haverbeke <marijnh at gmail.com>wrote:
>
>> > Yeah. One thing that concerns me about that is that it means we lose the
>> > ability to write rebind-the-variable functional-style code:
>>
>> Oh. You'd make this apply to irrevocable patterns as well? Or do you
>> intend to get rid of the restriction that let patterns are
>> irrevocable?
>>
>> In the second case, I think I'd prefer a 'you can shadow anything,
>> except consts and tag variants' rule to a blanket 'no shadowing' one.
>> _______________________________________________
>> Rust-dev mailing list
>> Rust-dev at mozilla.org
>> https://mail.mozilla.org/listinfo/rust-dev
>>
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.mozilla.org/pipermail/rust-dev/attachments/20111224/fde9ff9c/attachment.html>


More information about the Rust-dev mailing list