Add gen modifier to functions

We don't yet lower or maybe even parse them, but blocks already have `gen`, so why not.
This commit is contained in:
Chayim Refael Friedman 2024-08-22 14:27:35 +03:00
parent 506b9663bf
commit cc07652be5
9 changed files with 38 additions and 4 deletions

View file

@ -484,6 +484,8 @@ impl Fn {
#[inline]
pub fn fn_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![fn]) }
#[inline]
pub fn gen_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![gen]) }
#[inline]
pub fn unsafe_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![unsafe]) }
}

View file

@ -1035,6 +1035,7 @@ pub fn fn_(
is_async: bool,
is_const: bool,
is_unsafe: bool,
is_gen: bool,
) -> ast::Fn {
let type_params = match type_params {
Some(type_params) => format!("{type_params}"),
@ -1056,9 +1057,10 @@ pub fn fn_(
let async_literal = if is_async { "async " } else { "" };
let const_literal = if is_const { "const " } else { "" };
let unsafe_literal = if is_unsafe { "unsafe " } else { "" };
let gen_literal = if is_gen { "gen " } else { "" };
ast_from_text(&format!(
"{visibility}{async_literal}{const_literal}{unsafe_literal}fn {fn_name}{type_params}{params} {ret_type}{where_clause}{body}",
"{visibility}{const_literal}{async_literal}{gen_literal}{unsafe_literal}fn {fn_name}{type_params}{params} {ret_type}{where_clause}{body}",
))
}
pub fn struct_(