Skip to content
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

Merged
merged 3 commits into from
Oct 13, 2015
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
57 changes: 57 additions & 0 deletions text/0000-main-reexport.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
- Feature Name: main_reexport
- Start Date: 2015-08-19
- RFC PR: (leave this empty)
- Rust Issue: (leave this empty)

# Summary

Allow a re-export of a function as entry point `main`.

# Motivation

Functions and re-exports of functions usually behave the same way, but they do
not for the program entry point `main`. This RFC aims to fix this inconsistency.

The above mentioned inconsistency means that e.g. you currently cannot use a
library's exported function as your main function.

Example:

pub mod foo {
pub fn bar() {
println!("Hello world!");
}
}
use foo::bar as main;

Example 2:

extern crate main_functions;
pub use main_functions::rmdir as main;

See also https://github.com/rust-lang/rust/issues/27640 for the corresponding
issue discussion.

The `#[main]` attribute can also be used to change the entry point of the
generated binary. This is largely irrelevant for this RFC as this RFC tries to
fix an inconsistency with re-exports and directly defined functions.
Nevertheless, it can be pointed out that the `#[main]` attribute does not cover
all the above-mentioned use cases.

# Detailed design

Use the symbol `main` at the top-level of a crate that is compiled as a program
(`--crate-type=bin`) – instead of explicitly only accepting directly-defined
functions, also allow (possibly non-`pub`) re-exports.

# Drawbacks

None.

# Alternatives

None.

# Unresolved questions

None.