Skip to content

Commit 88e7405

Browse files
committed
Document adding unstable compiler flags
1 parent ebd7a5b commit 88e7405

1 file changed

Lines changed: 36 additions & 0 deletions

File tree

src/implementing-new-features.md

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -228,6 +228,42 @@ The below steps needs to be followed in order to implement a new unstable featur
228228
[tracking issue]: #tracking-issues
229229
[add-feature-gate]: ./feature-gates.md#adding-a-feature-gate
230230

231+
## Adding unstable compiler flags
232+
233+
For compiler-internal experiments, diagnostics, debugging aids, and temporary implementation
234+
controls, a `-Z` flag can be more appropriate than a language feature gate.
235+
Feature gates should still be preferred for user-facing language features,
236+
especially when crates need to opt in from source code.
237+
238+
When adding a new `-Z` flag:
239+
240+
1. Add the option to `UnstableOptions` in
241+
`compiler/rustc_session/src/options.rs`.
242+
The option name is written as snake_case in the struct and is exposed as
243+
kebab-case on the command line.
244+
Choose the parser, default value, and dependency tracking marker carefully.
245+
Use `[UNTRACKED]` for flags that only affect diagnostics or debugging output,
246+
and use `[TRACKED]` when changing the flag can change compilation results.
247+
248+
1. Update the option tests in `compiler/rustc_interface/src/tests.rs`.
249+
`options.rs` also has a short checklist near the `UnstableOptions` list for
250+
files that need to stay in sync.
251+
252+
1. Use the option through `sess.opts.unstable_opts.$flag_name` or
253+
`tcx.sess.opts.unstable_opts.$flag_name`.
254+
If bootstrap or rustdoc needs to pass the flag internally,
255+
thread it through the relevant command construction code as part of the same
256+
change.
257+
258+
1. Add focused tests for the behavior controlled by the flag.
259+
For example, UI tests can use `//@ compile-flags: -Zyour-flag`,
260+
while rustdoc behavior usually belongs in `tests/rustdoc`.
261+
262+
1. If the flag is meant for users of nightly rustc or rustdoc,
263+
document it in the unstable book under `src/doc/unstable-book/src/compiler-flags`.
264+
265+
Before opening the PR, run `./x test tidy` and the narrow test suite that exercises the new flag.
266+
231267
## Call for testing
232268

233269
Once the implementation is complete,

0 commit comments

Comments
 (0)