Implement forced keywords (k#) - #161775
Conversation
|
@bors try @rust-timer queue |
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
Implement forced keywords (`k#`)
This comment has been minimized.
This comment has been minimized.
| match pnr { | ||
| ParseNtResult::Ident(nt_ident, is_raw) => { | ||
| if let IdentIsRaw::Yes = is_raw { | ||
| if let IdentKind::Raw = is_raw { |
There was a problem hiding this comment.
sussy, needs re-audit
| _, | ||
| )) => { | ||
| if let IdentIsRaw::Yes = is_raw { | ||
| if let IdentKind::Raw = is_raw { |
There was a problem hiding this comment.
| /// Traits for function pointers and items | ||
| (unstable, fn_static, "CURRENT_RUSTC_VERSION", Some(148768)), | ||
| /// Allows using forced keywords `k#fn`. | ||
| (unstable, forced_keywords, "CURRENT_RUSTC_VERSION", Some(153839)), |
There was a problem hiding this comment.
I've intentionally not marked it internal even though this feature is only backed by a T-compiler MCP and not by a T-lang RFC or in-tree experiment:
I would find it a bit weird if we (in a hypothetical future) told the users to "please try out" "k#only bounds" or "&k#own" types & exprs where the corresponding feature will obviously be non-internal.
However, I'm fine with switching it to internal (or incomplete).
| @@ -103,6 +104,26 @@ impl ToInternal<tk::LitKind> for LitKind { | |||
| } | |||
| } | |||
|
|
|||
There was a problem hiding this comment.
We can't test the roundtripping in the current form of this PR because I haven't added any k#-exclusive weak keywords where it'd be observable if we accidentally dropped k# during encoding&decoding.
I have however tested locally that it works by introducing a new dummy keyword. A hypothetical UI test would have a setup like
use proc_macro::TokenStream;
#[proc_macro]
pub fn perform(_: TokenStream) -> TokenStream {
let stream: TokenStream = "const _: Option<k#never> = None;").parse().unwrap(); // positive
//let stream: TokenStream = "fn k#branded() {}").parse().unwrap(); // negative
stream.into_iter().collect() // forces encoding+decoding
}
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
|
Finished benchmarking commit (4eb8eac): comparison URL. Overall result: ✅ improvements - no action neededBenchmarking means the PR may be perf-sensitive. Consider adding rollup=never if this change is not fit for rolling up. @rustbot label: -S-waiting-on-perf -perf-regression Instruction countOur most reliable metric. Used to determine the overall result above. However, even this metric can be noisy.
Max RSS (memory usage)Results (primary -3.0%, secondary 1.1%)A less reliable metric. May be of interest, but not used to determine the overall result above.
CyclesResults (primary 2.1%, secondary -1.4%)A less reliable metric. May be of interest, but not used to determine the overall result above.
Binary sizeResults (primary 0.0%, secondary -0.0%)A less reliable metric. May be of interest, but not used to determine the overall result above.
Bootstrap: 477.576s -> 469.017s (-1.79%) |
|
☔ The latest upstream changes (presumably #161801) made this pull request unmergeable. Please resolve the merge conflicts by rebasing. |
Part of #153839. CC @dianne
Re. draft status: Needs one final self-review pass.
What won't be done in this PR:
'k#static)builtin # $ident($($tt)*)/ introducingk#-exclusive (weak) keywordsgenanyway IINM)proc_macro::IdentAPI to allow users to programmatically create forced keywords (might never be added)(No LLM was or will be used by me during the entire creation process of this PR)