Stop rustfmt versioning from overriding rust-analyzer versioning. (#2553)

There is a bug/typo in `rust_register_toolchains` where
`rustfmt_version` would always override `rust_analyzer_version` (default
or otherwise specified). This causes problems related to mismatched ABIs
when rust-analyzer tries to expand proc macros if one were to use an
older-than-default nightly toolchain without specifying a specific
`rustfmt_version`. This is because `rust-analyzer` will be set to use
the default `rustfmt_version` which is `nightly/2024-02-08`:
https://github.com/bazelbuild/rules_rust/blob/8b977b5f7020fc3a3b3bbc318e414269014f126a/rust/private/common.bzl#L36

As a very basic example of what I mean:
```
rust_register_toolchains(
    edition = "2021",
    versions = [
        "nightly/2024-01-31",
    ],
    extra_exec_rustc_flags = ["-A", "async_fn_in_trait"],
)
```
Will result in rust-analyzer complaining with:
```
proc macro `Deserialize` not expanded: Cannot create expander for /private/var/tmp/_bazel_a/a03e1cfb3989a3cda645602bbe0ee892/execroot/_main/bazel-out/darwin_arm64-opt-exec-ST-13d3ddad9198/bin/external/crate_index__serde_derive-1.0.195/libserde_derive-1365269244.dylib: mismatched ABI expected: `rustc 1.78.0-nightly (8ace7ea1f 2024-02-07)`, got `rustc 1.77.0-nightly (11f32b73e 2024-01-31)`rust-analyzer[unresolved-proc-macro](https://rust-analyzer.github.io/manual.html#unresolved-proc-macro)
```
Using a workaround of setting `rustfmt_version` causes the ABI mismatch
to be resolved:
```
rust_register_toolchains(
    edition = "2021",
    versions = [
        "nightly/2024-01-31",
    ],
    rustfmt_version = "nightly/2024-01-31",
    extra_exec_rustc_flags = ["-A", "async_fn_in_trait"],
)
```
This PR fixes the issue so that rust-analyzer version selection actually
works.

Co-authored-by: UebelAndre <github@uebelandre.com>
1 file changed
tree: f21fbae6677d6f3f76b0c51d432b89239de7622e
  1. .bazelci/
  2. .bcr/
  3. .github/
  4. bindgen/
  5. cargo/
  6. crate_universe/
  7. docs/
  8. examples/
  9. ffi/
  10. nix/
  11. proto/
  12. rust/
  13. test/
  14. tools/
  15. util/
  16. wasm_bindgen/
  17. .bazelignore
  18. .bazelrc
  19. .clang-format
  20. .envrc
  21. .gitattributes
  22. .gitignore
  23. .prettierrc.toml
  24. .rustfmt.toml
  25. ARCHITECTURE.md
  26. AUTHORS
  27. BUILD.bazel
  28. CODEOWNERS
  29. COMPATIBILITY.md
  30. CONTRIBUTING.md
  31. CONTRIBUTORS
  32. LICENSE.txt
  33. MODULE.bazel
  34. README.md
  35. version.bzl
  36. WORKSPACE.bazel
README.md

Rust Rules

  • Postsubmit Build status

Overview

This repository provides rules for building Rust projects with Bazel.

Community

General discussions and announcements take place in the GitHub Discussions, but there are additional places where community members gather to discuss rules_rust.

Documentation

Please refer to the full documentation.