rust-lang / rust

Empowering everyone to build reliable and efficient software.
https://www.rust-lang.org
Other
95.32k stars 12.28k forks source link

keyword-idents-2024 unable to migrate loop labels or lifetimes #125986

Open ehuss opened 1 month ago

ehuss commented 1 month ago

The keyword-idents-2024 lint is not able to catch the use of 'gen used as a lifetime or a label. I believe this is because there is no raw syntax available for lifetimes or labels, and thus no way to make it work on both editions (without choosing a new name). I do not see any discussion of this in https://github.com/rust-lang/rfcs/pull/2151 which introduced raw identifiers.

pub fn label() {
    'gen: loop {
        break 'gen;
    }
}

pub fn lifetime<'gen>() {}

I'm not sure what our options are here. It could just pick some different name. Another option is to punt on automatic migration and just document this limitation.

Preliminary crater found in the following:

fauxgen@0.1.4
juniper_codegen@0.16.0
lrp@0.1.0
coasys_juniper_codegen@0.16.0
darling_core@0.20.9
juniper_codegen_puff@0.16.0-dev

cc #123904 @compiler-errors

Meta

rustc --version --verbose:

rustc 1.80.0-nightly (7c52d2db6 2024-06-03)
binary: rustc
commit-hash: 7c52d2db6348b038276198e88a835125849f322e
commit-date: 2024-06-03
host: aarch64-apple-darwin
release: 1.80.0-nightly
LLVM version: 18.1.6

Tracking issue:

Related:

ehuss commented 1 month ago

As a secondary concern, it is also unable to migrate proc-macro attributes or derives. For example:

#[my_proc_macro::gen]
struct S;

// or

#[derive(my_proc_macro::gen)]
struct S;

Here the path is not getting updated with the r#gen syntax.

There were no crater hits on this, but this does seem like something that could be supported.

traviscross commented 1 month ago

@rustbot labels -I-edition-nominated

We discussed this today in the edition call. We're OK accepting this for the edition. We'll use this issue to track that we add appropriate documentation here.

Two other alternatives that are worth exploring:

cc @compiler-errors @oli-obk

mattheww commented 1 month ago

One other alternative that might be worth considering: say that in Rust 2024 'gen is still permitted as a lifetime and as a label.