mirror of
https://github.com/rust-lang/rust-analyzer.git
synced 2025-09-28 04:44:57 +00:00
Recognize custom main function as binary entrypoint for runnables
This commit is contained in:
parent
7b8330f283
commit
fe398163b6
3 changed files with 72 additions and 23 deletions
|
@ -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()
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue