Closed aturon closed 3 years ago
Is there a reason to do this other than cosmetic preference for another name?
@rfcbot fcp close
I propose that we just remove this feature altogether. I don't see a lot of clamoring for it. =) There are three users according to @brson's survey though -- @brson, was that just a grep that cratesio or what?
Team member @nikomatsakis has proposed to close this. The next step is review by the rest of the tagged teams:
No concerns currently listed.
Once these reviewers reach consensus, this will enter its final comment period. If you spot a major issue that hasn't been raised at any point in this process, please speak up!
See this document for info about what commands tagged team members can give me.
The only place that comes close to this for me is osdev, and there, you use no_main
rather than main
, so...
We still have start
or whatever for doing this do we?
@rfcbot reviewed
@nrc I guess that is slightly different? I think that #[start]
configures at a higher-level than main? Perhaps @alexcrichton or @brson can expound on that.
Ah yes, we've got three entry points. I.. think this is how they work:
#[start]
, the receiver of int argc
and char **argv
. This is literally the symbol main
(or what is called by that symbol generated in the compiler).#[lang = "start"]
. If no #[start]
exists in the crate graph then the compiler generates a main
function that calls this. This functions receives argc/argv along with a third argument that is a function pointer to the #[main]
function (defined below). Importantly, #[lang = "start"]
can be located in a library. For example it's located in the standard library (libstd).#[main]
, the main function for an executable. This is passed no arguments and is called by #[lang = "start"]
(if it decides to). The standard library uses this to initialize itself and then call the Rust program. This, if not specified, defaults to fn main
at the top.So to answer your question, this isn't the same as #[start]
. To answer your other (possibly not yet asked) question, yes we have too many entry points.
:bell: This is now entering its final comment period, as per the review above. :bell:
psst @nikomatsakis, I wasn't able to add the final-comment-period
label, please do so.
The final comment period is now complete.
We have no officially decided to REMOVE the #[main]
feature and would welcome any help from someone who wishes to do it!
Here are the steps to take:
src/libsyntax/feature_gate.rs:136
and add it to the list of removed features found around line 316main
should be removed from the list in BUILTIN_ATTRIBUTES
at src/libsyntax/feature_gate.rs:443
; src/librustc/middle/entry.rs:89
(and mirrored code in src/libsyntax/entry.rs:29
) should be adjusted to remove the case covering else if attr::contains_name(&item.attrs, "main") {
src/libsyntax/feature_gate.rs:1056
can be removedsrc/libsyntax/test.rs:206
that references "main"
can be removed tooThese line numbers may drift over time. :/ For the records, I found them mostly by running ripgrep '"main"'
=)
UPDATE: https://github.com/rust-lang/rust/pull/39282 is a good example of how to do a generic stabilization PR.
I'd like to take this!
@cramertj great! =)
Something that's come up as I've been removing the feature that I don't see discussed here: the #[main]
attribute allows you to specify main
functions that aren't defined at crate-level. I'm not sure how useful/idiomatic this is, but it is used in the existing test harness and a couple other places.
This is particularly useful when using #[cfg(...)]
'd modules like in this intrinsic-alignment test.
Update on this, since it's been a while: I implemented the change, but it broke the test harness, which previously used the #[main]
attribute in order to override the program's existing main
fn. I explored a few other options, such as replacing/renaming the existing main function with the test harness, but it was pretty unwieldy. As I mentioned to @nikomatsakis over email, I think the best way forward is to either keep the #[main]
feature around for internal use only (the easiest solution, but leaves the codebase cluttered with obsolete features), or to implement the test harness using #[start]
(which, if I understand correctly, requires manually running some sort of initialization for std
). What do you all think?
I'm removing the E-easy / E-mentor tags. Based on @cramertj's experience, I don't actually know what's the best way forward at the moment, so i wouldn't consider this easy.
Sorry to hijack a bit, but are any of the others currently stable? I'd like to get a definitive list of what would benefit from a general solution to the "needs provides" problem.
Oh and thanks for the list @alexcrichton. I don't recall all three described side-by-side elsewhere so that was handy.
@Ericson2314
are any of the others currently stable?
other whats?
@nikomatsakis The entry points #[start]
, #[lang = "start"]
, and #[main]
. I think @Ericson2314 was referencing this comment.
I see. I don't think any of them are stable, but not sure off the top of my head.
Thanks. I suppose at least the lang item definitely wouldn't be.
Triage: pretty sure that this is still where it was back in 2017. Since the previous issue was with test harness stuff, I wonder if and when custom test harnesses happen, it will alleviate this or not.
I've been meaning to start more chats about revamping the test harness anyways to work with panic = "abort"
-- perhaps on an internals thread / mini-working-group?
Just run into the issue preparing this playground. Looks like the compiler error E0601 is currently misleading, since it recommends the main
attribute, even on stable where it is unavailable at all. Probably we should drop the corresponding part from the error message at all, as it seems that this attribute is considered to be not for public use anyway.
Tracks stabilzation of the
#[main]
attribute, which allows an arbitrary function to be tagged asmain
.Status Update
Decision was reached to remove this feature and looking for someone to implement; here is a list of instructions, feel free to reach out to @nikomatsakis for more tips!