diff options
author | Mats Jun <mats@jun.codes> | 2024-04-14 12:54:08 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-04-14 12:54:08 +0200 |
commit | 3c15839a7702aa84566114f86695bb295d29ebaf (patch) | |
tree | a97839d7c41088740d3a6aa2be26366487ff748a | |
parent | 4c7d7a4a20fd18505236e155be0381950e3bc286 (diff) | |
download | compiler-explorer-gh-11319.tar.gz compiler-explorer-gh-11319.zip |
Use rustfmt from the latest rust release (#6326)gh-11319
The current Rust formatter on site doesn't support modern rust syntax
like async/await. This is because the formatter in production runs using
Rust 2015. Forcing edition=2018 allows more modern rust code to be
formatted properly.
Rustfmt is also shipped directly as a Rust component now, so we don't
have to install it separately.
For what it's worth, attempting to "Ctrl Shift I" format the code in
this shortlink demonstrates the problem https://godbolt.org/z/aP4669KEW
-rw-r--r-- | etc/config/rust.amazon.properties | 10 | ||||
-rw-r--r-- | lib/formatters/rustfmt.ts | 2 |
2 files changed, 9 insertions, 3 deletions
diff --git a/etc/config/rust.amazon.properties b/etc/config/rust.amazon.properties index cfa427ee6..f08301c80 100644 --- a/etc/config/rust.amazon.properties +++ b/etc/config/rust.amazon.properties @@ -944,10 +944,14 @@ tools.osacatrunk.type=postcompilation tools.osacatrunk.class=osaca-tool tools.osacatrunk.stdinHint=disabled -tools.rustfmt1436.name=rustfmt (1.4.36) -tools.rustfmt1436.exe=/opt/compiler-explorer/rustfmt-1.4.36/rustfmt +# This tool has the "rustfmmt1436" name for legacy reasons. It was initially introduced when Rustfmt was a separate +# component, not distributed with the Rust compiler. The tool is still named "rustfmt1436" to avoid breaking existing +# shortlinks. +tools.rustfmt1436.name=rustfmt (1.77.0) +tools.rustfmt1436.exe=/opt/compiler-explorer/rust-1.77.0/bin/rustfmt tools.rustfmt1436.type=independent tools.rustfmt1436.class=rustfmt-tool tools.rustfmt1436.stdinHint=disabled tools.rustfmt1436.languageId=rust -tools.rustfmt1436.options=--emit stdout +# Force edition 2021 to support most modern syntax features +tools.rustfmt1436.options=--emit stdout --edition 2021 diff --git a/lib/formatters/rustfmt.ts b/lib/formatters/rustfmt.ts index b81eeeef4..1cba03aad 100644 --- a/lib/formatters/rustfmt.ts +++ b/lib/formatters/rustfmt.ts @@ -41,6 +41,8 @@ export class RustFmtFormatter extends BaseFormatter { `hard_tabs=${options.useSpaces ? 'false' : 'true'}`, '--config', `tab_spaces=${options.tabWidth}`, + // Force edition 2021 to support most modern syntax features + '--edition 2021', ]; return await exec.execute(this.formatterInfo.exe, args, {input: source}); } |