Skip to content

Fix Rust edition argument parser#7652

Merged
mattgodbolt merged 3 commits intocompiler-explorer:mainfrom
narpfel:rust-edition-argument-parser
May 12, 2025
Merged

Fix Rust edition argument parser#7652
mattgodbolt merged 3 commits intocompiler-explorer:mainfrom
narpfel:rust-edition-argument-parser

Conversation

@narpfel
Copy link
Member

@narpfel narpfel commented May 4, 2025

  • For nightly Rust (and 1.88+), the output format of --help was changed in Unify the format of rustc cli flags rust-lang/rust#140152.
    This PR changes the parser to parse the new format, so that edition overrides are selectable for nightly Rust. Note the <>:
            --edition <2015|2018|2021|2024|future>
                            Specify which edition of the compiler to use when
                            compiling code. The default is 2015 and the latest
                            stable edition is 2024.
    
  • Rust <= 1.34 (and >= 1.31) support the 2018 edition, but the help message only includes --edition in verbose mode.

Copy link
Member

@AbrilRBS AbrilRBS left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks!

Looks good to me, and local testing seems to show that it works as expected.

Could you apply this diff to your PR so that we add tests for the new regex? Thanks!

diff --git a/test/compilers/argument-parsers-tests.ts b/test/compilers/argument-parsers-tests.ts
index 77f68597e..ec4be3bae 100644
--- a/test/compilers/argument-parsers-tests.ts
+++ b/test/compilers/argument-parsers-tests.ts
@@ -31,6 +31,7 @@ import {
     GCCParser,
     ICCParser,
     PascalParser,
+    RustParser,
     TableGenParser,
     VCParser,
 } from '../../lib/compilers/argument-parsers.js';
@@ -262,3 +263,39 @@ describe('TableGen argument parser', () => {
         ]);
     });
 });
+
+
+describe('Rust editions parser', () => {
+    it('Should extract new format editions', async () => {
+        // From Rust 1.88 output
+        const lines = [
+            'USAGE: rustc [OPTIONS]',
+            '',
+            'OPTIONS:',
+            '',
+            '        --edition <2015|2018|2021|2024|future>',
+            '                        Specify which edition of the compiler to use when',
+            '                        compiling code. The default is 2015 and the latest',
+            '                        stable edition is 2024.'
+        ];
+        const compiler = makeCompiler(lines.join('\n'))
+        const editions = await RustParser.getPossibleEditions(compiler)
+        expect(editions).toEqual(['2015', '2018', '2021', '2024', 'future']);
+    });
+
+    it('Should extract old format editions', async () => {
+        // From Rust 1.30 with verbose output
+        const lines = [
+            'USAGE: rustc [OPTIONS]',
+            '',
+            'OPTIONS:',
+            '',
+            '        --edition 2015|2018',
+            '                        Specify which edition of the compiler to use when',
+            '                        compiling code.'
+        ];
+        const compiler = makeCompiler(lines.join('\n'))
+        const editions = await RustParser.getPossibleEditions(compiler)
+        expect(editions).toEqual(['2015', '2018']);
+    });
+})

const result = await compiler.execCompilerCached(compiler.compiler.exe, ['--help']);
const re = /--edition ([\d|]*)/;
const result = await compiler.execCompilerCached(compiler.compiler.exe, ['--help', '-v']);
const re = /--edition <?([\w|]*)>?/;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is the future key new from 1.88 then?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

future is perma-unstable (nightly only) and intended to receive features for a future edition when they’re ready, even if the next edition isn’t named yet (similar to -std=c++2x for GCC/clang), see https://github.com/rust-lang/rust/blob/243c5a35e18b2634892fe7091d5ee888a18f77f5/compiler/rustc_span/src/edition.rs#L26-L35 and rust-lang/rust#137606.

I don’t know if there’s currently any difference to 2024, so including future is currently mostly for completeness’ sake.

Copy link
Member

@junlarsen junlarsen left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seems reasonable to me

@junlarsen junlarsen requested a review from AbrilRBS May 12, 2025 15:35
Copy link
Member

@mattgodbolt mattgodbolt left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Happy to merge and iterate. thanks all

@mattgodbolt mattgodbolt merged commit 703b13a into compiler-explorer:main May 12, 2025
12 checks passed
@mattgodbolt
Copy link
Member

Not sure how to test, but Rust still works in staging

@mattgodbolt
Copy link
Member

Now live

@narpfel narpfel deleted the rust-edition-argument-parser branch May 12, 2025 21:10
mattgodbolt pushed a commit that referenced this pull request Jun 16, 2025
Resolves #7780.

Basically a follow-up to #7652; the output format of `rustc --help` was
changed to include angle brackets `<` and `>`. This PR updates the
regexes used to parse the help output and adds some tests.
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

Successfully merging this pull request may close these issues.

4 participants