ITADN

Add a format symbol macro instead of calling closure directly

#305Closedtahadostifam 创建于 2026-01-03
T
tahadostifamcommented
Already there are plenty of helper functions that facilitate formatting symbols, but in practice rust-fmt converts it into multi-line code which leads to redundant lines of code in sourcebase. let expected = format_sema_ty( return_type.get_const_inner().clone(), &(self.symbol_formatter)(Some(scope_id)), ); So consider to fix it with an small macro like: ```rust macro_rules! format_symbol { // Single argument: creates the formatted symbol ($self:ident) => { &($self.symbol_formatter)(Some(scope_id)) }; // Two arguments: creates formatted symbol for specific scope ($self:ident, $scope:expr) => { &($self.symbol_formatter)($scope) }; // Format type with symbol formatter ($self:ident, format_ty: $ty:expr) => {{ format_sema_ty( $ty.get_const_inner().clone(), &($self.symbol_formatter)(Some(scope_id)) ) }}; // Format type with explicit scope ($self:ident, format_ty: $ty:expr, $scope:expr) => {{ format_sema_ty( $ty.get_const_inner().clone(), &($self.symbol_formatter)($scope) ) }}; } ``` usage: ```rust format_symbol!(self, Some(scope_id)) format_symbol!(self, None) ```
关闭于 2026-01-23 1 条评论