rust-lang / rust

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

Tracking issue for `main` feature #29634

Closed aturon closed 3 years ago

aturon commented 8 years ago

Tracks stabilzation of the #[main] attribute, which allows an arbitrary function to be tagged as main.

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!

SimonSapin commented 8 years ago

Is there a reason to do this other than cosmetic preference for another name?

nikomatsakis commented 7 years ago

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

rfcbot commented 7 years ago

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.

steveklabnik commented 7 years ago

The only place that comes close to this for me is osdev, and there, you use no_main rather than main, so...

nrc commented 7 years ago

We still have start or whatever for doing this do we?

withoutboats commented 7 years ago

@rfcbot reviewed

nikomatsakis commented 7 years ago

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

alexcrichton commented 7 years ago

Ah yes, we've got three entry points. I.. think this is how they work:

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.

rfcbot commented 7 years ago

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

rfcbot commented 7 years ago

The final comment period is now complete.

nikomatsakis commented 7 years ago

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:

These 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.

cramertj commented 7 years ago

I'd like to take this!

nikomatsakis commented 7 years ago

@cramertj great! =)

cramertj commented 7 years ago

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.

cramertj commented 7 years ago

This is particularly useful when using #[cfg(...)]'d modules like in this intrinsic-alignment test.

cramertj commented 7 years ago

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?

nikomatsakis commented 7 years ago

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.

Ericson2314 commented 7 years ago

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.

nikomatsakis commented 7 years ago

@Ericson2314

are any of the others currently stable?

other whats?

cramertj commented 7 years ago

@nikomatsakis The entry points #[start], #[lang = "start"], and #[main]. I think @Ericson2314 was referencing this comment.

nikomatsakis commented 7 years ago

I see. I don't think any of them are stable, but not sure off the top of my head.

Ericson2314 commented 7 years ago

Thanks. I suppose at least the lang item definitely wouldn't be.

steveklabnik commented 5 years ago

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.

cramertj commented 5 years ago

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?

Cerber-Ursi commented 4 years ago

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.