From d41ee16dd86ce3bd8ef7c5df594dc22bc883a96b Mon Sep 17 00:00:00 2001 From: Tobias Bucher Date: Wed, 19 Aug 2015 17:17:20 +0200 Subject: [PATCH 1/3] RFC: Allow a re-export for `main` --- text/0000-main-reexport.md | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) create mode 100644 text/0000-main-reexport.md diff --git a/text/0000-main-reexport.md b/text/0000-main-reexport.md new file mode 100644 index 00000000000..64cba1c7ead --- /dev/null +++ b/text/0000-main-reexport.md @@ -0,0 +1,34 @@ +- 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. + +# 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 re-exports. + +# Drawbacks + +None. + +# Alternatives + +None. + +# Unresolved questions + +None. From 2ac3284d209a9d6e000915f8af3035e525a04db7 Mon Sep 17 00:00:00 2001 From: Tobias Bucher Date: Fri, 21 Aug 2015 12:08:43 +0200 Subject: [PATCH 2/3] Add some examples and refer to the issue that led to the RFC --- text/0000-main-reexport.md | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/text/0000-main-reexport.md b/text/0000-main-reexport.md index 64cba1c7ead..0f1007cc5bf 100644 --- a/text/0000-main-reexport.md +++ b/text/0000-main-reexport.md @@ -15,6 +15,23 @@ 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!"); + } + } + pub 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. + # Detailed design Use the symbol `main` at the top-level of a crate that is compiled as a program From aa533f93904f22a807204b53c0e43b470d22e128 Mon Sep 17 00:00:00 2001 From: Tobias Bucher Date: Fri, 2 Oct 2015 21:44:13 +0100 Subject: [PATCH 3/3] Add @pnkfelix's suggestions --- text/0000-main-reexport.md | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/text/0000-main-reexport.md b/text/0000-main-reexport.md index 0f1007cc5bf..08f48185fd5 100644 --- a/text/0000-main-reexport.md +++ b/text/0000-main-reexport.md @@ -22,7 +22,7 @@ Example: println!("Hello world!"); } } - pub use foo::bar as main; + use foo::bar as main; Example 2: @@ -32,11 +32,17 @@ Example 2: 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 re-exports. +functions, also allow (possibly non-`pub`) re-exports. # Drawbacks