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

Feature: emit error when shuttle::main function is named main #707

Merged
Show file tree
Hide file tree
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
12 changes: 11 additions & 1 deletion codegen/src/shuttle_main/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,16 @@ impl Parse for BuilderOption {

impl Loader {
pub(crate) fn from_item_fn(item_fn: &mut ItemFn) -> Option<Self> {
let fn_ident = item_fn.sig.ident.clone();

if fn_ident.clone().to_string() == "main".to_string() {
emit_error!(
fn_ident,
"shuttle_runtime::main functions cannot be named `main`"
);
return None;
}

let inputs: Vec<_> = item_fn
.sig
.inputs
Expand Down Expand Up @@ -119,7 +129,7 @@ impl Loader {

if let Some(type_path) = check_return_type(item_fn.sig.clone()) {
Some(Self {
fn_ident: item_fn.sig.ident.clone(),
fn_ident: fn_ident.clone(),
fn_inputs: inputs,
fn_return: type_path,
})
Expand Down
2 changes: 2 additions & 0 deletions codegen/tests/ui/main/duplicate-main-fn.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
#[shuttle_codegen::main]
async fn main() -> ShuttleRocket {}
11 changes: 11 additions & 0 deletions codegen/tests/ui/main/duplicate-main-fn.stderr
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
error: shuttle_runtime::main functions cannot be named `main`
--> tests/ui/main/duplicate-main-fn.rs:2:10
|
2 | async fn main() -> ShuttleRocket {}
| ^^^^

error[E0601]: `main` function not found in crate `$CRATE`
--> tests/ui/main/duplicate-main-fn.rs:2:36
|
2 | async fn main() -> ShuttleRocket {}
| ^ consider adding a `main` function to `$DIR/tests/ui/main/duplicate-main-fn.rs`