diff --git a/compiler-cli/src/add.rs b/compiler-cli/src/add.rs index 7c0390771..b97bf1eae 100644 --- a/compiler-cli/src/add.rs +++ b/compiler-cli/src/add.rs @@ -114,11 +114,12 @@ fn read_toml_edit(name: &Utf8Path) -> Result { fn version_to_string(version: &Version) -> String { let mut text = String::new(); - let _ = write!( + write!( text, "{}.{}.{}", version.major, version.minor, version.patch - ); + ) + .expect("write to a string"); if !version.pre.is_empty() { text.push('-'); @@ -133,7 +134,8 @@ fn version_to_string(version: &Version) -> String { } } if let Some(build) = version.build.as_ref() { - let _ = write!(text, "+{build}"); + text.push('+'); + text.push_str(build); } text } diff --git a/compiler-core/src/derivation_tree.rs b/compiler-core/src/derivation_tree.rs index 7305317ae..75ebe3225 100644 --- a/compiler-core/src/derivation_tree.rs +++ b/compiler-core/src/derivation_tree.rs @@ -13,7 +13,6 @@ use petgraph::prelude::StableGraph; use pubgrub::External; use pubgrub::{DerivationTree, Derived, Ranges}; use std::collections::HashMap; -use std::fmt::Write as _; use std::hash::RandomState; use std::ops::Bound::{Excluded, Included, Unbounded}; use std::sync::Arc; @@ -172,11 +171,13 @@ impl DerivationTreePrinter { .ranges_between(previous, next) .expect("path edge is in the graph"); - let _ = write!( - message, - "\n - {previous_name} requires {next_name} {}", - pretty_range(next_range) - ); + message.push_str("\n - "); + message.push_str(previous_name); + message.push_str(" requires "); + message.push_str(next_name); + message.push(' '); + message.push_str(&pretty_range(next_range)); + previous = next; } message diff --git a/compiler-core/src/docs/tests.rs b/compiler-core/src/docs/tests.rs index b2d8440a7..06cd66f4b 100644 --- a/compiler-core/src/docs/tests.rs +++ b/compiler-core/src/docs/tests.rs @@ -3,7 +3,6 @@ use std::{ collections::{HashMap, HashSet}, - fmt::Write as _, time::SystemTime, }; @@ -201,7 +200,11 @@ fn compile_documentation( output.push_str("---- SOURCE CODE\n"); for (_package, name, src) in modules { - let _ = write!(output, "-- {name}.gleam\n{src}\n\n"); + output.push_str("-- "); + output.push_str(name); + output.push_str(".gleam\n"); + output.push_str(src); + output.push_str("\n\n"); } output.push_str("-- "); output.push_str(module_name); diff --git a/compiler-core/src/error.rs b/compiler-core/src/error.rs index f8c2fb7bd..268abc0c4 100644 --- a/compiler-core/src/error.rs +++ b/compiler-core/src/error.rs @@ -7,7 +7,6 @@ use crate::bit_array::UnsupportedOption; use crate::build::{Origin, Outcome, Runtime, Target}; use crate::dependency::{PackageFetcher, ResolutionError}; use crate::diagnostic::{Diagnostic, ExtraLabel, Label, Location}; -use std::fmt::Write as _; use crate::derivation_tree::DerivationTreePrinter; use crate::parse::error::ParseErrorDetails; @@ -3536,7 +3535,11 @@ but no type in scope with that name." }; text.push_str(message); for module_name in possible_modules { - let _ = writeln!(text, " - {module_name}.{name}"); + text.push_str(" - "); + text.push_str(module_name); + text.push('.'); + text.push_str(name); + text.push('\n'); } } @@ -4649,11 +4652,9 @@ here takes {expected_string}.\n" the `use` callback function.\n", ); } else { - let _ = writeln!( - text, - "You supplied {supplied_arguments_string} \ -and the final one is the `use` callback function." - ); + text.push_str("You supplied "); + text.push_str(&supplied_arguments_string); + text.push_str(" and the final one is the `use` callback function.\n"); } } else { text.push_str( diff --git a/compiler-core/src/javascript/tests.rs b/compiler-core/src/javascript/tests.rs index f1d5214d6..72c7c8359 100644 --- a/compiler-core/src/javascript/tests.rs +++ b/compiler-core/src/javascript/tests.rs @@ -47,14 +47,21 @@ pub static CURRENT_PACKAGE: &str = "thepackage"; #[macro_export] macro_rules! assert_js { ($(($name:literal, $module_src:literal)),+, $src:literal $(,)?) => { - use std::fmt::Write as _; let compiled = $crate::javascript::tests::compile_js($src, vec![$(($crate::javascript::tests::CURRENT_PACKAGE, $name, $module_src)),*]); let mut output = String::from("----- SOURCE CODE\n"); for (name, src) in [$(($name, $module_src)),*] { - let _ = write!(output, "-- {name}.gleam\n{src}\n\n"); + output.push_str("-- "); + output.push_str(name); + output.push_str(".gleam\n"); + output.push_str(src); + output.push_str("\n\n"); } - let _ = write!(output, "-- main.gleam\n{}\n\n----- COMPILED JAVASCRIPT\n{compiled}", $src); + output.push_str("-- main.gleam\n"); + output.push_str($src); + output.push_str("\n\n----- COMPILED JAVASCRIPT\n"); + output.push_str(&compiled); + insta::assert_snapshot!(insta::internals::AutoName, output, $src); }; diff --git a/compiler-core/src/type_/tests.rs b/compiler-core/src/type_/tests.rs index 13ad6ca70..1e1375dda 100644 --- a/compiler-core/src/type_/tests.rs +++ b/compiler-core/src/type_/tests.rs @@ -90,8 +90,6 @@ macro_rules! assert_module_error { }; ($(($name:expr, $module_src:literal)),+, $src:literal $(,)?) => { - use std::fmt::Write as _; - let error = $crate::type_::tests::module_error( $src, vec![ @@ -101,15 +99,20 @@ macro_rules! assert_module_error { let mut output = String::from("----- SOURCE CODE\n"); for (name, src) in [$(($name, $module_src)),*] { - let _ = write!(output, "-- {name}.gleam\n{src}\n\n"); + output.push_str("-- "); + output.push_str(name); + output.push_str(".gleam\n"); + output.push_str(src); + output.push_str("\n\n"); } - let _ = write!(output, "-- main.gleam\n{}\n\n----- ERROR\n{error}", $src); + output.push_str("-- main.gleam\n"); + output.push_str($src); + output.push_str("\n\n----- ERROR\n"); + output.push_str(&error); insta::assert_snapshot!(insta::internals::AutoName, output, $src); }; ($(($package:literal, $name:expr, $module_src:literal)),+, $src:literal $(,)?) => { - use std::fmt::Write as _; - let error = $crate::type_::tests::module_error( $src, vec![ @@ -119,9 +122,16 @@ macro_rules! assert_module_error { let mut output = String::from("----- SOURCE CODE\n"); for (name, src) in [$(($name, $module_src)),*] { - let _ = write!(output, "-- {name}.gleam\n{src}\n\n"); + output.push_str("-- "); + output.push_str(name); + output.push_str(".gleam\n"); + output.push_str(src); + output.push_str("\n\n"); } - let _ = write!(output, "-- main.gleam\n{}\n\n----- ERROR\n{error}", $src); + output.push_str("-- main.gleam\n"); + output.push_str($src); + output.push_str("\n\n----- ERROR\n"); + output.push_str(&error); insta::assert_snapshot!(insta::internals::AutoName, output, $src); }; } @@ -235,8 +245,6 @@ macro_rules! assert_warning { }; ($(($name:expr, $module_src:literal)),+, $src:literal $(,)?) => { - use std::fmt::Write as _; - let warning = $crate::type_::tests::get_printed_warnings( $src, vec![ @@ -249,15 +257,21 @@ macro_rules! assert_warning { let mut output = String::from("----- SOURCE CODE\n"); for (name, src) in [$(($name, $module_src)),*] { - let _ = write!(output, "-- {name}.gleam\n{src}\n\n"); + output.push_str("-- "); + output.push_str(name); + output.push_str(".gleam\n"); + output.push_str(src); + output.push_str("\n\n"); } - let _ = write!(output, "-- main.gleam\n{}\n\n----- WARNING\n{warning}", $src); + + output.push_str("-- main.gleam\n"); + output.push_str($src); + output.push_str("\n\n----- WARNING\n"); + output.push_str(&warning); insta::assert_snapshot!(insta::internals::AutoName, output, $src); }; ($(($package:expr, $name:expr, $module_src:literal)),+, $src:expr) => { - use std::fmt::Write as _; - let warning = $crate::type_::tests::get_printed_warnings( $src, vec![$(($package, $name, $module_src)),*], @@ -268,9 +282,17 @@ macro_rules! assert_warning { let mut output = String::from("----- SOURCE CODE\n"); for (name, src) in [$(($name, $module_src)),*] { - let _ = write!(output, "-- {name}.gleam\n{src}\n\n"); + output.push_str("-- "); + output.push_str(name); + output.push_str(".gleam\n"); + output.push_str(src); + output.push_str("\n\n"); } - let _ = write!(output, "-- main.gleam\n{}\n\n----- WARNING\n{warning}", $src); + + output.push_str("-- main.gleam\n"); + output.push_str($src); + output.push_str("\n\n----- WARNING\n"); + output.push_str(&warning); insta::assert_snapshot!(insta::internals::AutoName, output, $src); }; } diff --git a/compiler-core/src/warning.rs b/compiler-core/src/warning.rs index 01863f8f3..af2732688 100644 --- a/compiler-core/src/warning.rs +++ b/compiler-core/src/warning.rs @@ -22,7 +22,6 @@ use debug_ignore::DebugIgnore; use ecow::EcoString; use itertools::Itertools; use std::{ - fmt::Write as _, io::Write, sync::{Arc, atomic::Ordering}, }; @@ -1102,10 +1101,11 @@ Either change the pattern or use `panic` to unconditionally fail.", let mut text = format!("`{name}` is not a function"); match arguments { 0 => { - let _ = write!( - text, - ", you can just write `{name}` instead of `{name}()`." - ); + text.push_str(", you can just write `"); + text.push_str(name); + text.push_str("` instead of `"); + text.push_str(name); + text.push_str("()`."); } 1 => text.push_str( " and will crash before it can do anything with this argument.", diff --git a/language-server/src/tests/action.rs b/language-server/src/tests/action.rs index 4527122c4..c8765342f 100644 --- a/language-server/src/tests/action.rs +++ b/language-server/src/tests/action.rs @@ -6,7 +6,6 @@ use lsp_types::{ CodeActionContext, CodeActionParams, DocumentChange, PartialResultParams, Position, Uri as Url, WorkDoneProgressParams, }; -use std::fmt::Write as _; use super::*; use crate::path; @@ -249,7 +248,8 @@ macro_rules! assert_code_action { ); if !file_operations.is_empty() { - let _ = write!(output, "\n----- FILE OPERATIONS -----\n{file_operations}"); + output.push_str("\n----- FILE OPERATIONS -----\n"); + output.push_str(&file_operations); } insta::assert_snapshot!(insta::internals::AutoName, output, src); diff --git a/language-server/src/tests/document_highlight.rs b/language-server/src/tests/document_highlight.rs index 3d5590438..73418f0bb 100644 --- a/language-server/src/tests/document_highlight.rs +++ b/language-server/src/tests/document_highlight.rs @@ -86,8 +86,6 @@ macro_rules! assert_highlights { }; ($project:expr, $position:expr $(,)?) => { - use std::fmt::Write as _; - let project = $project; let src = project.src; let position = $position.find_position(src); @@ -101,22 +99,24 @@ macro_rules! assert_highlights { } else { &Vec::new() }; - let _ = write!( - output, - "-- {name}.gleam\n{}\n\n", - show_highlights(src, None, highlights_in_module) - ); + + output.push_str("-- "); + output.push_str(name); + output.push_str(".gleam\n"); + output.push_str(&show_highlights(src, None, highlights_in_module)); + output.push_str("\n\n"); } let highlights_in_app_module = if module_name == "app" { &result } else { &Vec::new() }; - let _ = write!( - output, - "-- app.gleam\n{}", - show_highlights(src, Some(position), highlights_in_app_module) - ); + output.push_str("-- app.gleam\n"); + output.push_str(&show_highlights( + src, + Some(position), + highlights_in_app_module, + )); insta::assert_snapshot!(insta::internals::AutoName, output, src); }; diff --git a/language-server/src/tests/reference.rs b/language-server/src/tests/reference.rs index 3cac0cfb7..6bf23c396 100644 --- a/language-server/src/tests/reference.rs +++ b/language-server/src/tests/reference.rs @@ -94,8 +94,6 @@ macro_rules! assert_references { }; ($project:expr, $position:expr $(,)?) => { - use std::fmt::Write as _; - let project = $project; let src = project.src; let position = $position.find_position(src); @@ -103,21 +101,22 @@ macro_rules! assert_references { let mut output = String::new(); for (name, src) in project.root_package_modules.iter() { - let _ = write!( - output, - "-- {name}.gleam\n{}\n\n", - show_references(src, None, result.get(*name).unwrap_or(&Vec::new())) - ); - } - let _ = write!( - output, - "-- app.gleam\n{}", - show_references( + output.push_str("-- "); + output.push_str(name); + output.push_str(".gleam\n"); + output.push_str(&show_references( src, - Some(position), - result.get("app").unwrap_or(&Vec::new()) - ) - ); + None, + result.get(*name).unwrap_or(&Vec::new()), + )); + output.push_str("\n\n"); + } + output.push_str("-- app.gleam\n"); + output.push_str(&show_references( + src, + Some(position), + result.get("app").unwrap_or(&Vec::new()), + )); insta::assert_snapshot!(insta::internals::AutoName, output, src); }; diff --git a/language-server/src/tests/rename.rs b/language-server/src/tests/rename.rs index 853beaf29..5277df479 100644 --- a/language-server/src/tests/rename.rs +++ b/language-server/src/tests/rename.rs @@ -2,7 +2,6 @@ // SPDX-FileCopyrightText: 2025 The Gleam contributors use std::collections::HashMap; -use std::fmt::Write as _; use lsp_types::{ Position, PrepareRenameParams, PrepareRenamePlaceholder, Range, RenameParams, @@ -120,7 +119,11 @@ fn display_result( ) -> String { let mut output = String::from("----- BEFORE RENAME\n"); for (name, src) in project.root_package_modules.iter() { - let _ = write!(output, "-- {name}.gleam\n{src}\n\n"); + output.push_str("-- "); + output.push_str(name); + output.push_str(".gleam\n"); + output.push_str(src); + output.push_str("\n\n"); } let src = project.src; @@ -129,10 +132,9 @@ fn display_result( } else { src.to_string() }; - let _ = write!( - output, - "-- app.gleam\n{app_src_before}\n\n----- AFTER RENAME\n", - ); + output.push_str("-- app.gleam\n"); + output.push_str(&app_src_before); + output.push_str("\n\n----- AFTER RENAME\n"); for &(name, src) in project.root_package_modules.iter() { let used_name = if let Some(new_name) = renamed_modules.get(name) { @@ -140,22 +142,24 @@ fn display_result( } else { name }; - let _ = write!( - output, - "-- {used_name}.gleam\n{}\n\n", + + output.push_str("-- "); + output.push_str(used_name); + output.push_str(".gleam\n"); + output.push_str( modules .get(name) .map(|string| string.as_str()) - .unwrap_or(src) + .unwrap_or(src), ); + output.push_str("\n\n"); } - let _ = write!( - output, - "-- app.gleam\n{}", + output.push_str("-- app.gleam\n"); + output.push_str( modules .get("app") .map(|string| string.as_str()) - .unwrap_or(src) + .unwrap_or(src), ); output } diff --git a/test-package-compiler/build.rs b/test-package-compiler/build.rs index 633f50e46..4877071ab 100644 --- a/test-package-compiler/build.rs +++ b/test-package-compiler/build.rs @@ -1,7 +1,6 @@ // SPDX-License-Identifier: Apache-2.0 // SPDX-FileCopyrightText: 2022 The Gleam contributors -use std::fmt::Write as _; use std::path::PathBuf; pub fn main() { @@ -26,20 +25,33 @@ pub fn main() { for name in names { let path = cases.join(&name); let path = path.to_str().unwrap().replace('\\', "/"); - let _ = write!( - module, - r#" + module.push_str( + " #[rustfmt::skip] #[test] -fn {name}() {{ - let output = crate::prepare("{path}"); +fn ", + ); + module.push_str(&name); + module.push_str("() {\n"); + module.push_str(" let output = crate::prepare(\""); + module.push_str(&path); + module.push_str( + "\"); insta::assert_snapshot!( - "{name}", + \"", + ); + module.push_str(&name); + module.push_str( + "\", output, - "{path}", + \"", + ); + module.push_str(&path); + module.push_str( + "\", ); -}} -"# +} +", ); }