@@ -113,7 +113,7 @@ fn generate_code_inner<'db>(
113113 db : & ' db dyn Database ,
114114 with_newline : bool ,
115115) -> InlinePluginResult < ' db > {
116- let info = match FormattingInfo :: extract ( db, syntax) {
116+ let info = match FormattingInfo :: extract ( db, syntax, with_newline ) {
117117 Ok ( info) => info,
118118 Err ( diagnostics) => return InlinePluginResult { code : None , diagnostics } ,
119119 } ;
@@ -163,6 +163,7 @@ impl<'db> FormattingInfo<'db> {
163163 fn extract (
164164 db : & ' db dyn Database ,
165165 syntax : & ast:: ExprInlineMacro < ' db > ,
166+ with_newline : bool ,
166167 ) -> Result < FormattingInfo < ' db > , Vec < PluginDiagnostic < ' db > > > {
167168 let Some ( legacy_inline_macro) = syntax. as_legacy_inline_macro ( db) else {
168169 return Err ( vec ! [ not_legacy_macro_diagnostic( syntax. as_syntax_node( ) . stable_ptr( db) ) ] ) ;
@@ -206,10 +207,23 @@ impl<'db> FormattingInfo<'db> {
206207 ) ] ) ;
207208 }
208209 let Some ( format_string_arg) = args_iter. next ( ) else {
209- return Err ( vec ! [ error_with_inner_span(
210- arguments. lparen( db) . as_syntax_node( ) ,
211- "Macro expected format string argument." ,
212- ) ] ) ;
210+ // `writeln!(f)` (no format string) writes just a newline; `write!(f)` still errors.
211+ // There is no format string, so the arg node is unused here — reuse the formatter's.
212+ return if with_newline {
213+ Ok ( FormattingInfo {
214+ formatter_arg_node : RewriteNode :: from_ast_trimmed ( & formatter_arg) ,
215+ format_string_arg : formatter_arg. clone ( ) ,
216+ format_string : String :: new ( ) ,
217+ format_string_source : "" ,
218+ args : vec ! [ ] ,
219+ macro_ast : syntax. clone ( ) ,
220+ } )
221+ } else {
222+ Err ( vec ! [ error_with_inner_span(
223+ arguments. lparen( db) . as_syntax_node( ) ,
224+ "Macro expected format string argument." ,
225+ ) ] )
226+ } ;
213227 } ;
214228 let Some ( format_string_expr) = try_extract_unnamed_arg ( db, & format_string_arg) else {
215229 return Err ( vec ! [ error_with_inner_span(
0 commit comments