Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
ehuss opened this issue Jun 4, 2024 · 4 comments
Closed

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

ehuss opened this issue Jun 4, 2024 · 4 comments
Labels
A-edition-2024 Area: The 2024 edition C-bug Category: This is a bug.

Comments

@ehuss
Copy link
Contributor

ehuss commented Jun 4, 2024

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 rust-lang/rfcs#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 ehuss added C-bug Category: This is a bug. A-edition-2024 Area: The 2024 edition labels Jun 4, 2024
@rustbot rustbot added the needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. label Jun 4, 2024
@ehuss
Copy link
Contributor Author

ehuss commented Jun 4, 2024

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 traviscross added I-edition-nominated Nominated for discussion during an edition team meeting. and removed needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. labels Jun 4, 2024
@traviscross
Copy link
Contributor

traviscross commented Jun 11, 2024

@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:

  • We could warn about this without providing a machine-applicable fix. We'll be doing something similar to this for the lifetime capture rules when APIT is used.
  • We could explore allowing r# syntax in lifetimes and loop labels, though this is a broader language change that would need to be proposed.

cc @compiler-errors @oli-obk

@rustbot rustbot removed the I-edition-nominated Nominated for discussion during an edition team meeting. label Jun 11, 2024
@mattheww
Copy link
Contributor

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

@traviscross
Copy link
Contributor

With the merge of #126335, this now works:

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

pub fn lifetime<'r#gen>() {}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-edition-2024 Area: The 2024 edition C-bug Category: This is a bug.
Projects
None yet
Development

No branches or pull requests

4 participants