Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

More flexible initialization for vectors #12680

Closed
kvanbere opened this issue Mar 4, 2014 · 2 comments
Closed

More flexible initialization for vectors #12680

kvanbere opened this issue Mar 4, 2014 · 2 comments

Comments

@kvanbere
Copy link

kvanbere commented Mar 4, 2014

In one of my projects which I'd like to port to rust in the long term, there is some C99 compliant array initializer like so;

  static const void *dispatch[255] = {
    [opcode_addk] = &&opc_addk,
    [opcode_addr] = &&opc_addr,
    [opcode_addvk] = &&opc_addvk,
    [opcode_addvr] = &&opc_addvr,
    [opcode_inc] = &&opc_inc,
    [opcode_subk] = &&opc_subk,
    [opcode_subr] = &&opc_subr,
    [opcode_subvk] = &&opc_subvk,
    [opcode_subvr] = &&opc_subvr,
    [opcode_dec] = &&opc_dec,
    &&opc_unident,
  };

Here opc_unident fills the parts of the array not specified, and each [index] = val pair puts val at the respective index. This cuts down the boilerplate for some tasks a LOT (In rust, I would have to write out all 255 entries for it to be quickly "maintainable").

I propose some syntax is added for complex initialization of vectors in a similar way.

@lifthrasiir
Copy link
Contributor

#11936 is a sub-issue of this issue. (It does not mention about how to fill the unspecified elements.)

@alexcrichton
Copy link
Member

Closing as a dupe of #11936. Filling in unspecified elements is required for soundness regardless of syntax/implementation.

bors added a commit to rust-lang-ci/rust that referenced this issue Jul 25, 2022
fix regressions on assignment expressions

This is a follow-up PR on rust-lang#12428. I'm not sure if this is everything I overlooked, so if there are more things that are not right, we may want to revert rust-lang#12428.

This should also fix the increase of the type mismatches and the unknown types in diesel in the [metrics](https://rust-analyzer.github.io/metrics/?start=2022-06-23&end=2022-07-01) introduced by rust-lang#12428.

The regressions are:

- some coercions don't work in the ordinary (i.e. non-destructuring) assignments

    In order for coercions on ADT fields instantiations to work, lhs type has to be known before inferring rhs. rust-lang#12428 changed the inference order, making rhs inferred before lhs, breaking the coercion, so I restored the original inference mechanism for the ordinary assignments.

    Note that this kind of coercion doesn't happen in destructuring assigments, because when they are desugared, the struct expression is first assigned to a temporary, which is then assigned to the assignee, which is not coercion site anymore.

- type mismatches on individual identifiers are not reported
flip1995 pushed a commit to flip1995/rust that referenced this issue Apr 18, 2024
…r=llogiq

Add `cargo dev setup toolchain`

Adds a `cargo dev setup toolchain` subcommand that creates a rustup toolchain with symlinks to the local `cargo-clippy` and `clippy-driver`. Allows you to then do `cargo +clippy clippy` in other projects to run the locally built Clippy

Sometimes more convenient when you're testing changes on a separate project than `cd`ing back & forth to use `cargo dev lint [project]`

changelog: none
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants