Skip to content

Commit

Permalink
feat: emit error when shuttle::main is named main (#707)
Browse files Browse the repository at this point in the history
  • Loading branch information
oddgrd authored Mar 14, 2023
1 parent 69819c9 commit 9f80ee8
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 1 deletion.
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`

0 comments on commit 9f80ee8

Please sign in to comment.