Recognize custom main function as binary entrypoint for runnables

This commit is contained in:
Lukas Wirth 2023-10-04 12:04:37 +02:00
parent 7b8330f283
commit fe398163b6
3 changed files with 72 additions and 23 deletions

View file

@ -1971,6 +1971,17 @@ impl Function {
db.function_data(self.id).attrs.is_test()
}
/// is this a `fn main` or a function with an `export_name` of `main`?
pub fn is_main(self, db: &dyn HirDatabase) -> bool {
if !self.module(db).is_crate_root() {
return false;
}
let data = db.function_data(self.id);
data.name.to_smol_str() == "main"
|| data.attrs.export_name().map(core::ops::Deref::deref) == Some("main")
}
/// Does this function have the ignore attribute?
pub fn is_ignore(self, db: &dyn HirDatabase) -> bool {
db.function_data(self.id).attrs.is_ignore()