-
Notifications
You must be signed in to change notification settings - Fork 12.8k
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
Remove #[main] attribute and add #[rustc_main] attribute. #84062
Conversation
Some changes occurred in diagnostic error codes Some changes occured to rustc_codegen_cranelift cc @bjorn3 |
c4eea4d
to
9d2aa48
Compare
This comment has been minimized.
This comment has been minimized.
9d2aa48
to
3f0aa33
Compare
This comment has been minimized.
This comment has been minimized.
3f0aa33
to
ce354cd
Compare
This comment has been minimized.
This comment has been minimized.
ce354cd
to
10e3c43
Compare
This comment has been minimized.
This comment has been minimized.
10e3c43
to
8491450
Compare
This comment has been minimized.
This comment has been minimized.
8491450
to
4b64990
Compare
This comment has been minimized.
This comment has been minimized.
4b64990
to
3f144fe
Compare
@@ -421,6 +421,7 @@ pub const BUILTIN_ATTRIBUTES: &[BuiltinAttribute] = &[ | |||
"the `#[profiler_runtime]` attribute is used to identify the `profiler_builtins` crate \ | |||
which contains the profiler runtime and will never be stable", | |||
), | |||
gated!(rustc_main, AssumedUsed, template!(List: "path"), experimental!(rustc_main)), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If this attribute is not going to be stabilized, then it doesn't need a separate feature and a tracking issue.
It can use feature(rustc_attrs)
instead, see the attributes defined with rustc_attr!
below.
@@ -1,5 +1,4 @@ | |||
// Test that `#[rustc_*]` attributes are gated by `rustc_attrs` feature gate. | |||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nit: unnecessary change causing an stderr diff.
@crlf0710 |
This PR does too many orthogonal things in general, and it's hard to track the motivation. RFC 1260 requires resolving In this PR the code is rearranged to switch from |
@petrochenkov Thank you for your review. Task A: Removing
This PR in its current form resolves all these issues by: Task B: Implement RFC 1260: If 1 & 2 is still satisfied, i have to write all these generated data as path to be resolved. I wonder if you could give me some implementation advice on this... Maybe by setting up a middle ground so i can split this pr into two. reason i didn't re-use the existing For the resolution implementation, i just didn't know much about late resolution. I'll try to work it out if that's a better candidate. |
I guess the next steps here will be giving resolution of Any mentoring notes are welcome! |
status update: skimmed through |
First in After some thought the alternative with adding |
Why? The result of resolving |
status update: i've implemented the changes we discussed above. But it seems it's necessary to avoid the |
The easiest way to do that is to call Also the resolution should happen before |
Second part extracted to #84401 . |
Will this "solve" #62127 ? Where a proc-macro named |
…enkov Implement RFC 1260 with feature_name `imported_main`. This is the second extraction part of rust-lang#84062 plus additional adjustments. This (mostly) implements RFC 1260. However there's still one test case failure in the extern crate case. Maybe `LocalDefId` doesn't work here? I'm not sure. cc rust-lang#28937 r? `@petrochenkov`
…enkov Implement RFC 1260 with feature_name `imported_main`. This is the second extraction part of rust-lang#84062 plus additional adjustments. This (mostly) implements RFC 1260. However there's still one test case failure in the extern crate case. Maybe `LocalDefId` doesn't work here? I'm not sure. cc rust-lang#28937 r? `@petrochenkov`
…per, r=nagisa Add primary marker on codegen unit and generate main wrapper on primary codegen. This is the codegen part of changes extracted from rust-lang#84062. This add a marker called `primary` on each codegen units, where exactly one codegen unit will be `primary = true` at a time. This specific codegen unit will take charge of generating `main` wrapper when `main` is imported from a foreign crate after the implementation of RFC 1260. cc rust-lang#28937 I'm not sure who should i ask for review for codegen changes, so feel free to reassign. r? `@nagisa`
…r, r=nagisa Add primary marker on codegen unit and generate main wrapper on primary codegen. This is the codegen part of changes extracted from rust-lang#84062. This add a marker called `primary` on each codegen units, where exactly one codegen unit will be `primary = true` at a time. This specific codegen unit will take charge of generating `main` wrapper when `main` is imported from a foreign crate after the implementation of RFC 1260. cc rust-lang#28937 I'm not sure who should i ask for review for codegen changes, so feel free to reassign. r? `@nagisa`
…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`.
…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`.
This removes the
#[main]
attribute support from the compiler according to the decisions within #29634. For existing use cases within test harness generation, replaced it with a newly-introduced resolution based crate-level attribute#[rustc_main]
, which will later be used to implement RFC 1260.Future vision: If we agree to migrate and merge the functionality of
#[start]
attribute into this#[rustc_main]
attribute and make it also resolution-based like RFC 1260, theentry
pass withinrustc_passes
crate will be able to be removed entirely, and whole entry function determination mechanism can happen at the ast lowering stage.Closes #29634.
cc #28937
cc #84060
r? @petrochenkov cc @nikomatsakis