Fix Rust edition argument parser#7652
Conversation
AbrilRBS
left a comment
There was a problem hiding this comment.
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|]*)>?/; |
There was a problem hiding this comment.
Is the future key new from 1.88 then?
There was a problem hiding this comment.
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.
mattgodbolt
left a comment
There was a problem hiding this comment.
Happy to merge and iterate. thanks all
|
Not sure how to test, but Rust still works in staging |
|
Now live |
nightlyRust (and 1.88+), the output format of--helpwas 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
nightlyRust. Note the<>:--editionin verbose mode.