-
Notifications
You must be signed in to change notification settings - Fork 12.7k
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
Complete removal of #[main] attribute from compiler #93753
Conversation
Thanks for the pull request, and welcome! The Rust team is excited to review your changes, and you should hear from @Mark-Simulacrum (or someone else) soon. Please see the contribution instructions for more information. |
Looks like I just missed that |
If I understand correctly, the main effect of this PR is to make code start erroring that is using the previously-built-in no-op I don't think I would beta backport this without at least a crater run, since we don't know how many crates out there might be using It also looks like something that would be nearly trivial to put through a future-incompatibility warning cycle (which I know is essentially the opposite direction from a beta backport, but the nature of this problem seems like it deserves that treatment: i.e. its not an urgent matter to fix this). The only argument I can see against a warning cycle is that its just extra tech debt hanging around in the compiler. Versus this PR, which immediately eliminates that tech debt. So this is sort of a microcosm of an ongoing prioritization question: should we prioritize the needs of an unknown but likely small set of Rust users over the needs of rustc contributors... |
I suggest backporting it sooner so it gets into the beta crater run, and reverting later if there are any regressions in non-nightly crates. If there's no time for that, then land it on nightly and wait for the next beta crater run. |
@bors r+ rollup |
📌 Commit 475e4ee has been approved by |
…henkov Complete removal of #[main] attribute from compiler resolves rust-lang#93786 --- The `#[main]` attribute was mostly removed from the language in rust-lang#84217, but not completely. It is still recognized as a builtin attribute by the compiler, but it has no effect. However, this no-op attribute is no longer gated by `#[feature(main)]` (which no longer exists), so it's possible to include it in code *on stable* without any errors, which seems unintentional. For example, the following code is accepted ([playground link](https://play.rust-lang.org/?version=stable&mode=debug&edition=2021&code=%23%5Bmain%5D%0Afn%20main()%20%7B%0A%20%20%20%20println!(%22hello%20world%22)%3B%0A%7D%0A)). ```rust #[main] fn main() { println!("hello world"); } ``` Aside from that oddity, the existence of this attribute causes code like the following to fail ([playground link](https://play.rust-lang.org/?version=stable&mode=debug&edition=2021&code=use%20tokio%3A%3Amain%3B%0A%0A%23%5Bmain%5D%0Afn%20main()%20%7B%0A%20%20%20%20println!(%22hello%20world%22)%3B%0A%7D%0A)). According rust-lang#84062 (comment), the removal of `#[main]` was expected to eliminate this conflict (previously reported as rust-lang#62127). ```rust use tokio::main; #[main] fn main() { println!("hello world"); } ``` ``` error[E0659]: `main` is ambiguous --> src/main.rs:3:3 | 3 | #[main] | ^^^^ ambiguous name | = note: ambiguous because of a name conflict with a builtin attribute = note: `main` could refer to a built-in attribute ``` [This error message can be confusing](https://stackoverflow.com/q/71024443/1114), as the mostly-removed `#[main]` attribute is not mentioned in any documentation. Since the current availability of `#[main]` on stable seems unintentional, and to needlessly block use of the `main` identifier in the attribute namespace, this PR finishes removing the `#[main]` attribute as described in rust-lang#29634 (comment) by deleting it from `builtin_attrs.rs`, and adds two test cases to ensure that the attribute is no longer accepted and no longer conflicts with other attributes imported as `main`.
…askrgr Rollup of 6 pull requests Successful merges: - rust-lang#91443 (Better suggestions when user tries to collect into an unsized `[_]`) - rust-lang#91504 (`#[used(linker)]` attribute) - rust-lang#93503 (debuginfo: Fix DW_AT_containing_type vtable debuginfo regression) - rust-lang#93753 (Complete removal of #[main] attribute from compiler) - rust-lang#93799 (Fix typo in `std::fmt` docs) - rust-lang#93813 (Make a few cleanup MIR passes public) Failed merges: r? `@ghost` `@rustbot` modify labels: rollup
…ulacrum [beta] backports This backports: * Complete removal of #[main] attribute from compiler rust-lang#93753 * Resolve lifetimes for const generic defaults rust-lang#93669 * backport llvm fix for issue 91671. rust-lang#93426 * Fix invalid special casing of the unreachable! macro rust-lang#93179 * Fix hashing for windows paths containing a CurDir component rust-lang#93697 r? `@Mark-Simulacrum`
resolves #93786
The
#[main]
attribute was mostly removed from the language in #84217, but not completely. It is still recognized as a builtin attribute by the compiler, but it has no effect. However, this no-op attribute is no longer gated by#[feature(main)]
(which no longer exists), so it's possible to include it in code on stable without any errors, which seems unintentional. For example, the following code is accepted (playground link).Aside from that oddity, the existence of this attribute causes code like the following to fail (playground link). According #84062 (comment), the removal of
#[main]
was expected to eliminate this conflict (previously reported as #62127).This error message can be confusing, as the mostly-removed
#[main]
attribute is not mentioned in any documentation.Since the current availability of
#[main]
on stable seems unintentional, and to needlessly block use of themain
identifier in the attribute namespace, this PR finishes removing the#[main]
attribute as described in #29634 (comment) by deleting it frombuiltin_attrs.rs
, and adds two test cases to ensure that the attribute is no longer accepted and no longer conflicts with other attributes imported asmain
.