-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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
RFC: Allow a re-export for main
#1260
Conversation
As requested by @steveklabnik in rust-lang/rust#27640 (comment). |
bb665a8
to
d41ee16
Compare
I think that this RFC probably wants to be expanded at least a little bit more, for example it may wish to consider the |
@alexcrichton Nothing really changes, everything behaves as would be consistent with other behavior: Re-exports behave the same as if the function was declared in that place. To expand on that: The attribute Can you clarify what you think is missing? |
@tbu- there are no concrete examples given in the RFC. The phrase " |
(the RFC text probably would also have benefited from referencing the rust-lang/rust#27640 ) |
I agree with @pnkfelix that a bit more detail would be nice -- I found it a bit hard to figure out what this RFC was even requesting. IIUC, this RFC is basically saying "you should be able to do Do you have an implementation of this? Or was it merely that you opened an issue because it seemed surprising and wrong, but didn't actually plan to fix it in the short term? (I have no objection to the latter, to be clear, just want to understand the state here.) I'm trying to imagine what complications might arise from being more general? I don't know enough about linkers etc to know if there is somehow a problem where ultimately the compiler would have to synthesize the main function you didn't write? For example, if an UPDATE: tweaked wording. |
9148a3b
to
89c91f6
Compare
89c91f6
to
2ac3284
Compare
+1. Seems completely reasonable. |
Forgot to click the 'comment' button: I'm sorry that I rushed this RFC in this way, updated it with examples and a link to the issue discussion, thanks for the hints. @steveklabnik I don't have an implementation of this, this was merely ment as a bug report, "it seemed surprising to me, I didn't plan to fix it in the sort term". I totally see why this is low-priority, because you can work around very easily and without much typing. |
I was going to post something here about this potentially breaking certain workflows with debuggers (along the lines about whether one could assume that certain functions named But then while making a concrete example of the point, I realized that the @tbu- Here are some updates I suggest:
|
Note: I'm still not sure why this even warrants an RFC. Re-exports and functions do not behave differently in other places. |
@tbu- part of the reason for the RFC process is to vet changes to the language and have them go through a review process that is independent of the implementation of the change. I can understand your view that this perhaps could have been categorized as "just a bug" to be fixed, and not a "change to the language per se." But then again, the question about whether the re-exported In this case the change is relatively small and seems pretty straight-forward (in terms of its specification -- I am not considering difficulty of implementation here). I assume there won't be any hurdles for acceptance, assuming no one points out any critical flaws during the FCP. |
I'm confused, I thought Also doesn't main normally need to be public? |
|
Wat. Why on earth do we allow that? Can't declare main to be static in C (https://goo.gl/L6D1gB). I think my first point still stands however: http://is.gd/8Vt2Cq. Now arguably there should be such a notion of a private re-export, so things like that can work, but as it stands the language doesn't have one. |
In my humble opinion non- So any private use would be a re-export for all module below it. (See also #1289) |
@Ericson2314 For what its worth, I meant to write "re-naming import" when I originally wrote "re-export." |
@pnkfelix ah, ok. @Kimundi, I was going to ask would this cause an explosion of extra symbols, but then I remembered (I think correctly) that items' names match the original location they are defined in, and that their aren't extra symbols for each re-export.
I see these options:
|
In the case of On Sun, Oct 4, 2015 at 12:11 PM, John Ericson notifications@github.com
|
@nikomatsakis You are correct that there is a generated stub ( The mangled name for a normal main is roughly tl;dr, generated name or no generated name, still worthwhile to think about symbol names. |
This RFC has been merged. The lang team discussed this RFC, and while no one felt strongly that it was important to tackle, it's a relatively minor detail that we would accept a PR to change. |
It seems like this was not an actual merge? 411daab is the relevant commit. This PR should not be open anymore? |
@jethrogb Fixed, thanks. |
On Thu, Oct 08, 2015 at 07:34:54PM -0700, John Ericson wrote:
I think my point was us that the symbol name of interest is probably |
We discussed this in the @rust-lang/lang meeting. We are generally "fine" with stabilizing this, but we would like to know whether it's in use. Can anybody identify a crate that is using it, or vouch that they would like to use it and have tried it, but are blocked on it not being stable? |
I have tried to write code using functionality like this in the past. Intuitively I expected fn main() {
#[cfg(test)] // harness=false test runner
tests::main();
#[cfg(not(test))]
app::main();
} kinda thing. I imagine anybody doing something like this would be surprised to find out |
I don't remember my use case anymore. I think I remember that I created the issue because I wanted to use it (and expected it to work), not specifically only because I found it inconsistent. |
I think @nagisa identified the use case -- and yes, I imagine the argument in favor of this is basically 'it would be nice if the model is just "we call |
(rendered)