From 8004413314bf401230f47a4b5c094a6df6cc1614 Mon Sep 17 00:00:00 2001 From: Lioncat2002 Date: Wed, 19 Nov 2025 14:48:50 -0500 Subject: [PATCH 01/13] wip: adds warnings for using deprecated or internal mod main "squashes" work done by Lioncat2002 in pull request #4283 --- CHANGELOG.md | 3 ++ compiler-cli/src/build.rs | 11 +++-- compiler-cli/src/docs.rs | 8 +++- compiler-cli/src/export.rs | 6 +++ compiler-cli/src/lib.rs | 6 ++- compiler-cli/src/publish.rs | 8 +++- compiler-cli/src/run.rs | 48 +++++++++++++++++---- compiler-cli/src/shell.rs | 5 ++- compiler-core/src/build/project_compiler.rs | 10 +++++ compiler-core/src/type_.rs | 2 + compiler-core/src/warning.rs | 29 +++++++++++++ 11 files changed, 119 insertions(+), 17 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 638b38b925b..b09709082a2 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -113,6 +113,9 @@ ``` ([fruno](https://github.com/fruno-bulax/)) +- Gleam will now warn when running a deprecated or internal module main function + ([Lioncat2002](https://github.com/Lioncat2002)) + ### Build tool - The help text displayed by `gleam dev --help`, `gleam test --help`, and diff --git a/compiler-cli/src/build.rs b/compiler-cli/src/build.rs index 6c72ced812c..0d65aaedb11 100644 --- a/compiler-cli/src/build.rs +++ b/compiler-cli/src/build.rs @@ -11,7 +11,7 @@ use gleam_core::{ use crate::{ build_lock::BuildLock, cli, dependencies, - fs::{self, ConsoleWarningEmitter}, + fs::{self}, }; pub fn download_dependencies(paths: &ProjectPaths, telemetry: impl Telemetry) -> Result { @@ -27,8 +27,13 @@ pub fn download_dependencies(paths: &ProjectPaths, telemetry: impl Telemetry) -> ) } -pub fn main(paths: &ProjectPaths, options: Options, manifest: Manifest) -> Result { - main_with_warnings(paths, options, manifest, Rc::new(ConsoleWarningEmitter)) +pub fn main( + paths: &ProjectPaths, + options: Options, + manifest: Manifest, + warnings: Rc, +) -> Result { + main_with_warnings(paths, options, manifest, warnings) } pub(crate) fn main_with_warnings( diff --git a/compiler-cli/src/docs.rs b/compiler-cli/src/docs.rs index 8a4d9d4368d..317b3e13d4c 100644 --- a/compiler-cli/src/docs.rs +++ b/compiler-cli/src/docs.rs @@ -1,12 +1,16 @@ use std::{ collections::HashMap, + rc::Rc, time::{Instant, SystemTime}, }; use camino::{Utf8Path, Utf8PathBuf}; use ecow::EcoString; -use crate::{cli, fs::ProjectIO, http::HttpClient}; +use crate::{cli, + fs::{ConsoleWarningEmitter, ProjectIO}, + http::HttpClient, +}; use gleam_core::{ Result, analyse::TargetSupport, @@ -85,6 +89,7 @@ pub fn build(paths: &ProjectPaths, options: BuildOptions) -> Result<()> { no_print_progress: false, }, manifest, + Rc::new(ConsoleWarningEmitter), )?; let outputs = build_documentation( paths, @@ -207,6 +212,7 @@ pub fn publish(paths: &ProjectPaths) -> Result<()> { no_print_progress: false, }, manifest, + Rc::new(ConsoleWarningEmitter), )?; let outputs = build_documentation( paths, diff --git a/compiler-cli/src/export.rs b/compiler-cli/src/export.rs index 19ae874034e..c57997a51e8 100644 --- a/compiler-cli/src/export.rs +++ b/compiler-cli/src/export.rs @@ -1,3 +1,5 @@ +use std::rc::Rc; + use camino::Utf8PathBuf; use gleam_core::{ Result, @@ -6,6 +8,8 @@ use gleam_core::{ paths::ProjectPaths, }; +use crate::fs::ConsoleWarningEmitter; + static ENTRYPOINT_FILENAME_POWERSHELL: &str = "entrypoint.ps1"; static ENTRYPOINT_FILENAME_POSIX_SHELL: &str = "entrypoint.sh"; @@ -50,6 +54,7 @@ pub(crate) fn erlang_shipment(paths: &ProjectPaths) -> Result<()> { no_print_progress: false, }, crate::build::download_dependencies(paths, crate::cli::Reporter::new())?, + Rc::new(ConsoleWarningEmitter), )?; for entry in crate::fs::read_dir(&build)?.filter_map(Result::ok) { @@ -156,6 +161,7 @@ pub fn package_interface(paths: &ProjectPaths, out: Utf8PathBuf) -> Result<()> { no_print_progress: false, }, crate::build::download_dependencies(paths, crate::cli::Reporter::new())?, + Rc::new(ConsoleWarningEmitter), )?; built.root_package.attach_doc_and_module_comments(); diff --git a/compiler-cli/src/lib.rs b/compiler-cli/src/lib.rs index e2605bf0548..a7dbdd3fd2d 100644 --- a/compiler-cli/src/lib.rs +++ b/compiler-cli/src/lib.rs @@ -77,7 +77,7 @@ mod shell; mod text_layout; use config::root_config; -use fs::{get_current_directory, get_project_root}; +use fs::{ConsoleWarningEmitter, get_current_directory, get_project_root}; pub use gleam_core::error::{Error, Result}; use gleam_core::{ @@ -87,7 +87,7 @@ use gleam_core::{ paths::ProjectPaths, version::COMPILER_VERSION, }; -use std::str::FromStr; +use std::{rc::Rc, str::FromStr}; use camino::Utf8PathBuf; @@ -755,6 +755,7 @@ fn command_check(paths: &ProjectPaths, target: Option) -> Result<()> { no_print_progress: false, }, build::download_dependencies(paths, cli::Reporter::new())?, + Rc::new(ConsoleWarningEmitter) )?; Ok(()) } @@ -782,6 +783,7 @@ fn command_build( no_print_progress, }, manifest, + Rc::new(ConsoleWarningEmitter) )?; Ok(()) } diff --git a/compiler-cli/src/publish.rs b/compiler-cli/src/publish.rs index ea96c2f3abd..7f46e1b367d 100644 --- a/compiler-cli/src/publish.rs +++ b/compiler-cli/src/publish.rs @@ -18,9 +18,12 @@ use gleam_core::{ use hexpm::version::{Range, Version}; use itertools::Itertools; use sha2::Digest; -use std::{collections::HashMap, io::Write, path::PathBuf, time::Instant}; +use std::{collections::HashMap, io::Write, path::PathBuf, rc::Rc, time::Instant}; -use crate::{build, cli, docs, fs, http::HttpClient}; +use crate::{build, cli, docs, + fs::{self, ConsoleWarningEmitter}, + http::HttpClient, +}; const CORE_TEAM_PUBLISH_PASSWORD: &str = "Trans rights are human rights"; @@ -383,6 +386,7 @@ fn do_build_hex_tarball(paths: &ProjectPaths, config: &mut PackageConfig) -> Res no_print_progress: false, }, manifest, + Rc::new(ConsoleWarningEmitter) )?; let minimum_required_version = built.minimum_required_version(); diff --git a/compiler-cli/src/run.rs b/compiler-cli/src/run.rs index 46f7e3ff1ca..5d6bc67d5c0 100644 --- a/compiler-cli/src/run.rs +++ b/compiler-cli/src/run.rs @@ -1,8 +1,9 @@ -use std::sync::OnceLock; +use std::{rc::Rc, sync::OnceLock}; use camino::Utf8PathBuf; use ecow::EcoString; use gleam_core::{ + Warning, analyse::TargetSupport, build::{Built, Codegen, Compile, Mode, NullTelemetry, Options, Runtime, Target, Telemetry}, config::{DenoFlag, PackageConfig}, @@ -10,9 +11,12 @@ use gleam_core::{ io::{Command, CommandExecutor, Stdio}, paths::ProjectPaths, type_::ModuleFunction, + warning::WarningEmitter }; -use crate::{config::PackageKind, fs::ProjectIO}; +use crate::{ + config::PackageKind, + fs::{ConsoleWarningEmitter, ProjectIO}; #[derive(Debug, Clone, Copy)] pub enum Which { @@ -91,11 +95,13 @@ pub fn setup( let root_config = crate::config::root_config(paths)?; // Determine which module to run - let module = module.unwrap_or(match which { - Which::Src => root_config.name.to_string(), - Which::Test => format!("{}_test", &root_config.name), - Which::Dev => format!("{}_dev", &root_config.name), - }); + let module: EcoString = module + .unwrap_or(match which { + Which::Src => root_config.name.to_string(), + Which::Test => format!("{}_test", &root_config.name), + Which::Dev => format!("{}_dev", &root_config.name), + }) + .into(); let target = target.unwrap_or(mod_config.target); @@ -122,11 +128,37 @@ pub fn setup( no_print_progress, }; - let built = crate::build::main(paths, options, manifest)?; + // Warn incase the module being run has been as internal + let warnings = Rc::new(ConsoleWarningEmitter); + let warning_emitter = WarningEmitter::new(warnings.clone()); + + let built = crate::build::main(paths, options, manifest, warnings)?; + + // Warn incase the module being run has been as internal + let internal_module = built.is_internal(&module).unwrap(); + if internal_module { + let warning = Warning::InternalMain { + module: module.clone(), + }; + warning_emitter.emit(warning); + } // A module can not be run if it does not exist or does not have a public main function. let main_function = get_or_suggest_main_function(built, &module, target)?; + // Warn incase the main function being run has been deprecated + + match main_function.deprecation { + gleam_core::type_::Deprecation::Deprecated { message } => { + let warning = Warning::DeprecatedMain { message }; + warning_emitter.emit(warning); + } + gleam_core::type_::Deprecation::NotDeprecated => {} + } + + // Don't exit on ctrl+c as it is used by child erlang shell + ctrlc::set_handler(move || {}).expect("Error setting Ctrl-C handler"); + telemetry.running(&format!("{module}.main")); // Get the command to run the project. diff --git a/compiler-cli/src/shell.rs b/compiler-cli/src/shell.rs index 55047635721..231bf0642b1 100644 --- a/compiler-cli/src/shell.rs +++ b/compiler-cli/src/shell.rs @@ -4,7 +4,9 @@ use gleam_core::{ error::{Error, ShellCommandFailureReason}, paths::ProjectPaths, }; -use std::process::Command; +use std::{process::Command, rc::Rc}; + +use crate::fs::ConsoleWarningEmitter; pub fn command(paths: &ProjectPaths) -> Result<(), Error> { // Build project @@ -20,6 +22,7 @@ pub fn command(paths: &ProjectPaths) -> Result<(), Error> { no_print_progress: false, }, crate::build::download_dependencies(paths, crate::cli::Reporter::new())?, + Rc::new(ConsoleWarningEmitter), )?; // Don't exit on ctrl+c as it is used by child erlang shell diff --git a/compiler-core/src/build/project_compiler.rs b/compiler-core/src/build/project_compiler.rs index c4c0d90e26f..56c416b0d9a 100644 --- a/compiler-core/src/build/project_compiler.rs +++ b/compiler-core/src/build/project_compiler.rs @@ -96,6 +96,16 @@ impl Built { .map(|minimum_required_version| minimum_required_version.clone()) .unwrap_or(Version::new(0, 1, 0)) } + + pub fn is_internal(&self, module: &EcoString) -> Result { + match self.module_interfaces.get(module) { + Some(module_data) => Ok(module_data.is_internal), + None => Err(Error::ModuleDoesNotExist { + module: module.clone(), + suggestion: None, + }), + } + } } #[derive(Debug)] diff --git a/compiler-core/src/type_.rs b/compiler-core/src/type_.rs index 82c123d4cdf..fbb00161573 100644 --- a/compiler-core/src/type_.rs +++ b/compiler-core/src/type_.rs @@ -983,6 +983,7 @@ impl ModuleValueConstructor { #[derive(Debug, Clone)] pub struct ModuleFunction { pub package: EcoString, + pub deprecation: Deprecation, } #[derive(Debug, Clone, PartialEq, Eq)] @@ -1134,6 +1135,7 @@ impl ModuleInterface { Ok(ModuleFunction { package: self.package.clone(), + deprecation: value.deprecation.clone(), }) } diff --git a/compiler-core/src/warning.rs b/compiler-core/src/warning.rs index e133cd1b73c..5327057ec5d 100644 --- a/compiler-core/src/warning.rs +++ b/compiler-core/src/warning.rs @@ -180,6 +180,12 @@ pub enum Warning { src: EcoString, location: SrcSpan, }, + InternalMain { + module: EcoString, + }, + DeprecatedMain { + message: EcoString, + }, } #[derive(Debug, Clone, Eq, PartialEq, Copy)] @@ -275,6 +281,28 @@ pub enum DeprecatedSyntaxWarning { impl Warning { pub fn to_diagnostic(&self) -> Diagnostic { match self { + Warning::DeprecatedMain { message } => Diagnostic { + title: "Deprecated main function".into(), + text: message.into(), + level: diagnostic::Level::Warning, + location: None, + hint: None, + }, + Warning::InternalMain { module } => { + let message = format!( + "The module {} has been marked internal.\ +It is intended for use within the library\ +and is not recommended for public use", + module + ); + Diagnostic { + title: "Internal main function".into(), + text: wrap(message.as_str()), + level: diagnostic::Level::Warning, + location: None, + hint: None, + } + }, Warning::InvalidSource { path } => Diagnostic { title: "Invalid module name".into(), text: "\ @@ -1201,6 +1229,7 @@ Your code will crash before reaching this point." "This function call is unreachable because its last argument always panics. \ Your code will crash before reaching this point." } + PanicPosition::EchoExpression => { "This `echo` won't print anything because the expression it \ should be printing always panics." From 9f553aba4727bb8a1480c05180429210861947a4 Mon Sep 17 00:00:00 2001 From: Kevin Chen Date: Wed, 19 Nov 2025 15:13:13 -0500 Subject: [PATCH 02/13] refactor: undoes refactoring of main, use main_with_warnings instead --- compiler-cli/src/build.rs | 11 +++-------- compiler-cli/src/docs.rs | 8 +------- compiler-cli/src/export.rs | 6 ------ compiler-cli/src/lib.rs | 6 ++---- compiler-cli/src/publish.rs | 8 ++------ compiler-cli/src/run.rs | 2 +- compiler-cli/src/shell.rs | 5 +---- 7 files changed, 10 insertions(+), 36 deletions(-) diff --git a/compiler-cli/src/build.rs b/compiler-cli/src/build.rs index 0d65aaedb11..6c72ced812c 100644 --- a/compiler-cli/src/build.rs +++ b/compiler-cli/src/build.rs @@ -11,7 +11,7 @@ use gleam_core::{ use crate::{ build_lock::BuildLock, cli, dependencies, - fs::{self}, + fs::{self, ConsoleWarningEmitter}, }; pub fn download_dependencies(paths: &ProjectPaths, telemetry: impl Telemetry) -> Result { @@ -27,13 +27,8 @@ pub fn download_dependencies(paths: &ProjectPaths, telemetry: impl Telemetry) -> ) } -pub fn main( - paths: &ProjectPaths, - options: Options, - manifest: Manifest, - warnings: Rc, -) -> Result { - main_with_warnings(paths, options, manifest, warnings) +pub fn main(paths: &ProjectPaths, options: Options, manifest: Manifest) -> Result { + main_with_warnings(paths, options, manifest, Rc::new(ConsoleWarningEmitter)) } pub(crate) fn main_with_warnings( diff --git a/compiler-cli/src/docs.rs b/compiler-cli/src/docs.rs index 317b3e13d4c..8a4d9d4368d 100644 --- a/compiler-cli/src/docs.rs +++ b/compiler-cli/src/docs.rs @@ -1,16 +1,12 @@ use std::{ collections::HashMap, - rc::Rc, time::{Instant, SystemTime}, }; use camino::{Utf8Path, Utf8PathBuf}; use ecow::EcoString; -use crate::{cli, - fs::{ConsoleWarningEmitter, ProjectIO}, - http::HttpClient, -}; +use crate::{cli, fs::ProjectIO, http::HttpClient}; use gleam_core::{ Result, analyse::TargetSupport, @@ -89,7 +85,6 @@ pub fn build(paths: &ProjectPaths, options: BuildOptions) -> Result<()> { no_print_progress: false, }, manifest, - Rc::new(ConsoleWarningEmitter), )?; let outputs = build_documentation( paths, @@ -212,7 +207,6 @@ pub fn publish(paths: &ProjectPaths) -> Result<()> { no_print_progress: false, }, manifest, - Rc::new(ConsoleWarningEmitter), )?; let outputs = build_documentation( paths, diff --git a/compiler-cli/src/export.rs b/compiler-cli/src/export.rs index c57997a51e8..19ae874034e 100644 --- a/compiler-cli/src/export.rs +++ b/compiler-cli/src/export.rs @@ -1,5 +1,3 @@ -use std::rc::Rc; - use camino::Utf8PathBuf; use gleam_core::{ Result, @@ -8,8 +6,6 @@ use gleam_core::{ paths::ProjectPaths, }; -use crate::fs::ConsoleWarningEmitter; - static ENTRYPOINT_FILENAME_POWERSHELL: &str = "entrypoint.ps1"; static ENTRYPOINT_FILENAME_POSIX_SHELL: &str = "entrypoint.sh"; @@ -54,7 +50,6 @@ pub(crate) fn erlang_shipment(paths: &ProjectPaths) -> Result<()> { no_print_progress: false, }, crate::build::download_dependencies(paths, crate::cli::Reporter::new())?, - Rc::new(ConsoleWarningEmitter), )?; for entry in crate::fs::read_dir(&build)?.filter_map(Result::ok) { @@ -161,7 +156,6 @@ pub fn package_interface(paths: &ProjectPaths, out: Utf8PathBuf) -> Result<()> { no_print_progress: false, }, crate::build::download_dependencies(paths, crate::cli::Reporter::new())?, - Rc::new(ConsoleWarningEmitter), )?; built.root_package.attach_doc_and_module_comments(); diff --git a/compiler-cli/src/lib.rs b/compiler-cli/src/lib.rs index a7dbdd3fd2d..e2605bf0548 100644 --- a/compiler-cli/src/lib.rs +++ b/compiler-cli/src/lib.rs @@ -77,7 +77,7 @@ mod shell; mod text_layout; use config::root_config; -use fs::{ConsoleWarningEmitter, get_current_directory, get_project_root}; +use fs::{get_current_directory, get_project_root}; pub use gleam_core::error::{Error, Result}; use gleam_core::{ @@ -87,7 +87,7 @@ use gleam_core::{ paths::ProjectPaths, version::COMPILER_VERSION, }; -use std::{rc::Rc, str::FromStr}; +use std::str::FromStr; use camino::Utf8PathBuf; @@ -755,7 +755,6 @@ fn command_check(paths: &ProjectPaths, target: Option) -> Result<()> { no_print_progress: false, }, build::download_dependencies(paths, cli::Reporter::new())?, - Rc::new(ConsoleWarningEmitter) )?; Ok(()) } @@ -783,7 +782,6 @@ fn command_build( no_print_progress, }, manifest, - Rc::new(ConsoleWarningEmitter) )?; Ok(()) } diff --git a/compiler-cli/src/publish.rs b/compiler-cli/src/publish.rs index 7f46e1b367d..ea96c2f3abd 100644 --- a/compiler-cli/src/publish.rs +++ b/compiler-cli/src/publish.rs @@ -18,12 +18,9 @@ use gleam_core::{ use hexpm::version::{Range, Version}; use itertools::Itertools; use sha2::Digest; -use std::{collections::HashMap, io::Write, path::PathBuf, rc::Rc, time::Instant}; +use std::{collections::HashMap, io::Write, path::PathBuf, time::Instant}; -use crate::{build, cli, docs, - fs::{self, ConsoleWarningEmitter}, - http::HttpClient, -}; +use crate::{build, cli, docs, fs, http::HttpClient}; const CORE_TEAM_PUBLISH_PASSWORD: &str = "Trans rights are human rights"; @@ -386,7 +383,6 @@ fn do_build_hex_tarball(paths: &ProjectPaths, config: &mut PackageConfig) -> Res no_print_progress: false, }, manifest, - Rc::new(ConsoleWarningEmitter) )?; let minimum_required_version = built.minimum_required_version(); diff --git a/compiler-cli/src/run.rs b/compiler-cli/src/run.rs index 5d6bc67d5c0..8b452545961 100644 --- a/compiler-cli/src/run.rs +++ b/compiler-cli/src/run.rs @@ -132,7 +132,7 @@ pub fn setup( let warnings = Rc::new(ConsoleWarningEmitter); let warning_emitter = WarningEmitter::new(warnings.clone()); - let built = crate::build::main(paths, options, manifest, warnings)?; + let built = crate::build::main_with_warnings(paths, options, manifest, warnings)?; // Warn incase the module being run has been as internal let internal_module = built.is_internal(&module).unwrap(); diff --git a/compiler-cli/src/shell.rs b/compiler-cli/src/shell.rs index 231bf0642b1..55047635721 100644 --- a/compiler-cli/src/shell.rs +++ b/compiler-cli/src/shell.rs @@ -4,9 +4,7 @@ use gleam_core::{ error::{Error, ShellCommandFailureReason}, paths::ProjectPaths, }; -use std::{process::Command, rc::Rc}; - -use crate::fs::ConsoleWarningEmitter; +use std::process::Command; pub fn command(paths: &ProjectPaths) -> Result<(), Error> { // Build project @@ -22,7 +20,6 @@ pub fn command(paths: &ProjectPaths) -> Result<(), Error> { no_print_progress: false, }, crate::build::download_dependencies(paths, crate::cli::Reporter::new())?, - Rc::new(ConsoleWarningEmitter), )?; // Don't exit on ctrl+c as it is used by child erlang shell From c3ff0ec38463ecff89e8f7e4879e10fa619c412f Mon Sep 17 00:00:00 2001 From: Kevin Chen Date: Wed, 19 Nov 2025 15:17:57 -0500 Subject: [PATCH 03/13] fix: remove copypasta for ctrlc from run.rs, overzealous } deletion --- compiler-cli/src/run.rs | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/compiler-cli/src/run.rs b/compiler-cli/src/run.rs index 8b452545961..43d06997763 100644 --- a/compiler-cli/src/run.rs +++ b/compiler-cli/src/run.rs @@ -16,7 +16,8 @@ use gleam_core::{ use crate::{ config::PackageKind, - fs::{ConsoleWarningEmitter, ProjectIO}; + fs::{ConsoleWarningEmitter, ProjectIO} +}; #[derive(Debug, Clone, Copy)] pub enum Which { @@ -156,9 +157,6 @@ pub fn setup( gleam_core::type_::Deprecation::NotDeprecated => {} } - // Don't exit on ctrl+c as it is used by child erlang shell - ctrlc::set_handler(move || {}).expect("Error setting Ctrl-C handler"); - telemetry.running(&format!("{module}.main")); // Get the command to run the project. From 09ae190638cab45080f2db5caf5d2661994c6f44 Mon Sep 17 00:00:00 2001 From: Kevin Chen Date: Wed, 19 Nov 2025 17:25:37 -0500 Subject: [PATCH 04/13] fix: stops emitting internal module warning for root package, clarifies warning msgs --- compiler-cli/src/run.rs | 20 +++++++++++--------- compiler-core/src/warning.rs | 5 ++--- 2 files changed, 13 insertions(+), 12 deletions(-) diff --git a/compiler-cli/src/run.rs b/compiler-cli/src/run.rs index 43d06997763..8ce345e66cb 100644 --- a/compiler-cli/src/run.rs +++ b/compiler-cli/src/run.rs @@ -83,7 +83,7 @@ pub fn setup( }; // Get the config for the module that is being run to check the target. - // Also get the kind of the package the module belongs to: wether the module + // Also get the kind of the package the module belongs to: whether the module // belongs to a dependency or to the root package. let (mod_config, package_kind) = match &module { Some(mod_path) => { @@ -129,26 +129,28 @@ pub fn setup( no_print_progress, }; - // Warn incase the module being run has been as internal let warnings = Rc::new(ConsoleWarningEmitter); let warning_emitter = WarningEmitter::new(warnings.clone()); - let built = crate::build::main_with_warnings(paths, options, manifest, warnings)?; // Warn incase the module being run has been as internal let internal_module = built.is_internal(&module).unwrap(); if internal_module { - let warning = Warning::InternalMain { - module: module.clone(), - }; - warning_emitter.emit(warning); + match package_kind { + PackageKind::Root => {} + _ => { + let warning = Warning::InternalMain { + module: module.clone(), + }; + warning_emitter.emit(warning); + } + } } // A module can not be run if it does not exist or does not have a public main function. let main_function = get_or_suggest_main_function(built, &module, target)?; - // Warn incase the main function being run has been deprecated - + // Warn if the main function being run has been deprecated match main_function.deprecation { gleam_core::type_::Deprecation::Deprecated { message } => { let warning = Warning::DeprecatedMain { message }; diff --git a/compiler-core/src/warning.rs b/compiler-core/src/warning.rs index 5327057ec5d..d3981bd4d3a 100644 --- a/compiler-core/src/warning.rs +++ b/compiler-core/src/warning.rs @@ -290,9 +290,8 @@ impl Warning { }, Warning::InternalMain { module } => { let message = format!( - "The module {} has been marked internal.\ -It is intended for use within the library\ -and is not recommended for public use", + "The main function's module {} has been marked internal.\ ++It is not recommended for public use.", module ); Diagnostic { From ff9833edac29586c9ecfba0f014225f95619acf0 Mon Sep 17 00:00:00 2001 From: Kevin Chen Date: Wed, 19 Nov 2025 17:45:07 -0500 Subject: [PATCH 05/13] fix: surfaces module not found error from call to is_internal --- compiler-cli/src/run.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/compiler-cli/src/run.rs b/compiler-cli/src/run.rs index 8ce345e66cb..e8ec28441a2 100644 --- a/compiler-cli/src/run.rs +++ b/compiler-cli/src/run.rs @@ -134,7 +134,7 @@ pub fn setup( let built = crate::build::main_with_warnings(paths, options, manifest, warnings)?; // Warn incase the module being run has been as internal - let internal_module = built.is_internal(&module).unwrap(); + let internal_module = built.is_internal(&module)?; if internal_module { match package_kind { PackageKind::Root => {} From 73964a55b06c0c691b4cb88447fd66102a2a80eb Mon Sep 17 00:00:00 2001 From: Kevin Chen Date: Wed, 19 Nov 2025 23:59:28 -0500 Subject: [PATCH 06/13] refactor: uses package config for detecting whether module is internal --- compiler-cli/src/run.rs | 5 ++--- compiler-core/src/build/project_compiler.rs | 10 ---------- 2 files changed, 2 insertions(+), 13 deletions(-) diff --git a/compiler-cli/src/run.rs b/compiler-cli/src/run.rs index e8ec28441a2..468c1a44457 100644 --- a/compiler-cli/src/run.rs +++ b/compiler-cli/src/run.rs @@ -133,9 +133,8 @@ pub fn setup( let warning_emitter = WarningEmitter::new(warnings.clone()); let built = crate::build::main_with_warnings(paths, options, manifest, warnings)?; - // Warn incase the module being run has been as internal - let internal_module = built.is_internal(&module)?; - if internal_module { + // Warn if the module being run is internal and NOT in the root package + if mod_config.is_internal_module(&module) { match package_kind { PackageKind::Root => {} _ => { diff --git a/compiler-core/src/build/project_compiler.rs b/compiler-core/src/build/project_compiler.rs index 56c416b0d9a..c4c0d90e26f 100644 --- a/compiler-core/src/build/project_compiler.rs +++ b/compiler-core/src/build/project_compiler.rs @@ -96,16 +96,6 @@ impl Built { .map(|minimum_required_version| minimum_required_version.clone()) .unwrap_or(Version::new(0, 1, 0)) } - - pub fn is_internal(&self, module: &EcoString) -> Result { - match self.module_interfaces.get(module) { - Some(module_data) => Ok(module_data.is_internal), - None => Err(Error::ModuleDoesNotExist { - module: module.clone(), - suggestion: None, - }), - } - } } #[derive(Debug)] From a57e7086481f9e207eb6dbd8c4f3b91ebadb2497 Mon Sep 17 00:00:00 2001 From: Kevin Chen Date: Thu, 20 Nov 2025 00:27:07 -0500 Subject: [PATCH 07/13] feat: refines names and text of deprecated main / internal module --- compiler-cli/src/run.rs | 7 +++++-- compiler-core/src/warning.rs | 36 +++++++++++++++++++----------------- 2 files changed, 24 insertions(+), 19 deletions(-) diff --git a/compiler-cli/src/run.rs b/compiler-cli/src/run.rs index 468c1a44457..b6b6af11dbb 100644 --- a/compiler-cli/src/run.rs +++ b/compiler-cli/src/run.rs @@ -138,7 +138,7 @@ pub fn setup( match package_kind { PackageKind::Root => {} _ => { - let warning = Warning::InternalMain { + let warning = Warning::InternalModuleMainFunction { module: module.clone(), }; warning_emitter.emit(warning); @@ -152,7 +152,10 @@ pub fn setup( // Warn if the main function being run has been deprecated match main_function.deprecation { gleam_core::type_::Deprecation::Deprecated { message } => { - let warning = Warning::DeprecatedMain { message }; + let warning = Warning::DeprecatedMainFunction { + module: module.clone(), + message, + }; warning_emitter.emit(warning); } gleam_core::type_::Deprecation::NotDeprecated => {} diff --git a/compiler-core/src/warning.rs b/compiler-core/src/warning.rs index d3981bd4d3a..c18af1a45c5 100644 --- a/compiler-core/src/warning.rs +++ b/compiler-core/src/warning.rs @@ -180,10 +180,11 @@ pub enum Warning { src: EcoString, location: SrcSpan, }, - InternalMain { + InternalModuleMainFunction { module: EcoString, }, - DeprecatedMain { + DeprecatedMainFunction { + module: EcoString, message: EcoString, }, } @@ -281,22 +282,24 @@ pub enum DeprecatedSyntaxWarning { impl Warning { pub fn to_diagnostic(&self) -> Diagnostic { match self { - Warning::DeprecatedMain { message } => Diagnostic { - title: "Deprecated main function".into(), - text: message.into(), - level: diagnostic::Level::Warning, - location: None, - hint: None, + Warning::DeprecatedMainFunction { module, message } => { + let text = wrap(&format!("The main function in module `{module}`\ +was deprecated with this message: {message}")); + Diagnostic { + title: "Deprecated main function".into(), + text, + level: diagnostic::Level::Warning, + location: None, + hint: None, + } }, - Warning::InternalMain { module } => { - let message = format!( - "The main function's module {} has been marked internal.\ -+It is not recommended for public use.", - module - ); + Warning::InternalModuleMainFunction { module } => { + let text = wrap(&format!( + "The main function in module `{module}` has been marked internal.\ +It is not recommended for public use.")); Diagnostic { - title: "Internal main function".into(), - text: wrap(message.as_str()), + title: "Main function in internal module".into(), + text, level: diagnostic::Level::Warning, location: None, hint: None, @@ -1228,7 +1231,6 @@ Your code will crash before reaching this point." "This function call is unreachable because its last argument always panics. \ Your code will crash before reaching this point." } - PanicPosition::EchoExpression => { "This `echo` won't print anything because the expression it \ should be printing always panics." From 535d01d72293388828a986bf98c9a5a75c1de254 Mon Sep 17 00:00:00 2001 From: Kevin Chen Date: Thu, 20 Nov 2025 01:36:46 -0500 Subject: [PATCH 08/13] test: added snapshot tests for new warnings --- ...rning_deprecated_main_function_pretty.snap | 8 +++++ ..._internal_module_main_function_pretty.snap | 8 +++++ compiler-core/src/warning.rs | 29 +++++++++++++++++-- 3 files changed, 43 insertions(+), 2 deletions(-) create mode 100644 compiler-core/src/snapshots/gleam_core__warning__warning_deprecated_main_function_pretty.snap create mode 100644 compiler-core/src/snapshots/gleam_core__warning__warning_internal_module_main_function_pretty.snap diff --git a/compiler-core/src/snapshots/gleam_core__warning__warning_deprecated_main_function_pretty.snap b/compiler-core/src/snapshots/gleam_core__warning__warning_deprecated_main_function_pretty.snap new file mode 100644 index 00000000000..50a89b94cde --- /dev/null +++ b/compiler-core/src/snapshots/gleam_core__warning__warning_deprecated_main_function_pretty.snap @@ -0,0 +1,8 @@ +--- +source: compiler-core/src/warning.rs +expression: warning.to_pretty_string() +--- +warning: Deprecated main function + +The main function in module `apple` was deprecated with this message: Use +some other method please! diff --git a/compiler-core/src/snapshots/gleam_core__warning__warning_internal_module_main_function_pretty.snap b/compiler-core/src/snapshots/gleam_core__warning__warning_internal_module_main_function_pretty.snap new file mode 100644 index 00000000000..0f638a4abd1 --- /dev/null +++ b/compiler-core/src/snapshots/gleam_core__warning__warning_internal_module_main_function_pretty.snap @@ -0,0 +1,8 @@ +--- +source: compiler-core/src/warning.rs +expression: warning.to_pretty_string() +--- +warning: Main function in internal module + +The main function is in internal module `internal/picking`. It is not +recommended for public use. diff --git a/compiler-core/src/warning.rs b/compiler-core/src/warning.rs index c18af1a45c5..f283feccf82 100644 --- a/compiler-core/src/warning.rs +++ b/compiler-core/src/warning.rs @@ -283,7 +283,7 @@ impl Warning { pub fn to_diagnostic(&self) -> Diagnostic { match self { Warning::DeprecatedMainFunction { module, message } => { - let text = wrap(&format!("The main function in module `{module}`\ + let text = wrap(&format!("The main function in module `{module}` \ was deprecated with this message: {message}")); Diagnostic { title: "Deprecated main function".into(), @@ -295,7 +295,7 @@ was deprecated with this message: {message}")); }, Warning::InternalModuleMainFunction { module } => { let text = wrap(&format!( - "The main function in module `{module}` has been marked internal.\ + "The main function is in internal module `{module}`. \ It is not recommended for public use.")); Diagnostic { title: "Main function in internal module".into(), @@ -1607,3 +1607,28 @@ fn pluralise(string: String, quantity: i64) -> String { format!("{string}s") } } + +#[test] +fn warning_deprecated_main_function_pretty() { + let warning = Warning::DeprecatedMainFunction { + module: "apple".into(), + message: "Use some other method please!".into() + }; + + insta::assert_snapshot!( + insta::internals::AutoName, + warning.to_pretty_string() + ); +} + +#[test] +fn warning_internal_module_main_function_pretty() { + let warning: Warning = Warning::InternalModuleMainFunction { + module: "internal/picking".into(), + }; + + insta::assert_snapshot!( + insta::internals::AutoName, + warning.to_pretty_string() + ); +} From bc967673ec4c34285859b1895b256f1ce071ce8e Mon Sep 17 00:00:00 2001 From: Kevin Chen Date: Thu, 20 Nov 2025 02:10:43 -0500 Subject: [PATCH 09/13] fix: uses correct warning emitter for new warnings --- compiler-cli/src/build.rs | 10 ++++++---- compiler-cli/src/fix.rs | 4 ++-- compiler-cli/src/run.rs | 20 +++++++++++++------- compiler-core/src/build/project_compiler.rs | 17 +++++++++++++++-- 4 files changed, 36 insertions(+), 15 deletions(-) diff --git a/compiler-cli/src/build.rs b/compiler-cli/src/build.rs index 6c72ced812c..5650a91e74e 100644 --- a/compiler-cli/src/build.rs +++ b/compiler-cli/src/build.rs @@ -5,7 +5,7 @@ use gleam_core::{ build::{Built, Codegen, NullTelemetry, Options, ProjectCompiler, Telemetry}, manifest::Manifest, paths::ProjectPaths, - warning::WarningEmitterIO, + warning::WarningEmitter, }; use crate::{ @@ -28,14 +28,16 @@ pub fn download_dependencies(paths: &ProjectPaths, telemetry: impl Telemetry) -> } pub fn main(paths: &ProjectPaths, options: Options, manifest: Manifest) -> Result { - main_with_warnings(paths, options, manifest, Rc::new(ConsoleWarningEmitter)) + let console_warning_emitter = Rc::new(ConsoleWarningEmitter); + let warnings = Rc::new(WarningEmitter::new(console_warning_emitter)); + main_with_warnings(paths, options, manifest, warnings) } pub(crate) fn main_with_warnings( paths: &ProjectPaths, options: Options, manifest: Manifest, - warnings: Rc, + warnings: Rc, ) -> Result { let perform_codegen = options.codegen; let root_config = crate::config::root_config(paths)?; @@ -55,7 +57,7 @@ pub(crate) fn main_with_warnings( tracing::info!("Compiling packages"); let result = { let _guard = lock.lock(telemetry); - let compiler = ProjectCompiler::new( + let compiler = ProjectCompiler::new_with_warning_emitter( root_config, options, manifest.packages, diff --git a/compiler-cli/src/fix.rs b/compiler-cli/src/fix.rs index 51cc5a3e266..fbbaa717498 100644 --- a/compiler-cli/src/fix.rs +++ b/compiler-cli/src/fix.rs @@ -7,7 +7,7 @@ use gleam_core::{ error::{FileIoAction, FileKind}, paths::ProjectPaths, type_, - warning::VectorWarningEmitterIO, + warning::{WarningEmitter, VectorWarningEmitterIO}, }; use hexpm::version::Version; @@ -30,7 +30,7 @@ pub fn run(paths: &ProjectPaths) -> Result<()> { no_print_progress: false, }, build::download_dependencies(paths, cli::Reporter::new())?, - warnings.clone(), + Rc::new(WarningEmitter::new(warnings.clone())), )?; let warnings = warnings.take(); diff --git a/compiler-cli/src/run.rs b/compiler-cli/src/run.rs index b6b6af11dbb..b9475a06366 100644 --- a/compiler-cli/src/run.rs +++ b/compiler-cli/src/run.rs @@ -11,7 +11,7 @@ use gleam_core::{ io::{Command, CommandExecutor, Stdio}, paths::ProjectPaths, type_::ModuleFunction, - warning::WarningEmitter + warning::{WarningEmitter, WarningEmitterIO} }; use crate::{ @@ -129,19 +129,19 @@ pub fn setup( no_print_progress, }; - let warnings = Rc::new(ConsoleWarningEmitter); - let warning_emitter = WarningEmitter::new(warnings.clone()); - let built = crate::build::main_with_warnings(paths, options, manifest, warnings)?; + let console_warning_emitter = Rc::new(ConsoleWarningEmitter); + let warning_emitter_with_counter = Rc::new(WarningEmitter::new(console_warning_emitter.clone())); + let built = crate::build::main_with_warnings(paths, options, manifest, warning_emitter_with_counter.clone())?; // Warn if the module being run is internal and NOT in the root package if mod_config.is_internal_module(&module) { match package_kind { PackageKind::Root => {} - _ => { + PackageKind::Dependency => { let warning = Warning::InternalModuleMainFunction { module: module.clone(), }; - warning_emitter.emit(warning); + console_warning_emitter.emit_warning(warning); } } } @@ -156,7 +156,13 @@ pub fn setup( module: module.clone(), message, }; - warning_emitter.emit(warning); + // warning_emitter.emit also increments a counter. However, we only want to + // increment that counter for root package warnings. For dependencies, + // we just print the warning directly to console. + match package_kind { + PackageKind::Root => warning_emitter_with_counter.emit(warning), + PackageKind::Dependency => console_warning_emitter.emit_warning(warning) + } } gleam_core::type_::Deprecation::NotDeprecated => {} } diff --git a/compiler-core/src/build/project_compiler.rs b/compiler-core/src/build/project_compiler.rs index c4c0d90e26f..2f0e7151daf 100644 --- a/compiler-core/src/build/project_compiler.rs +++ b/compiler-core/src/build/project_compiler.rs @@ -109,7 +109,7 @@ pub struct ProjectCompiler { /// The set of modules that have had partial compilation done since the last /// successful compilation. incomplete_modules: HashSet, - warnings: WarningEmitter, + warnings: Rc, telemetry: &'static dyn Telemetry, options: Options, paths: ProjectPaths, @@ -136,6 +136,19 @@ where paths: ProjectPaths, io: IO, ) -> Self { + Self::new_with_warning_emitter(config, options, packages, telemetry, + Rc::new(WarningEmitter::new(warning_emitter)), paths, io) + } + + pub fn new_with_warning_emitter( + config: PackageConfig, + options: Options, + packages: Vec, + telemetry: &'static dyn Telemetry, + warning_emitter: Rc, + paths: ProjectPaths, + io: IO, + ) -> Self { let packages = packages .into_iter() .map(|p| (p.name.to_string(), p)) @@ -147,7 +160,7 @@ where stale_modules: StaleTracker::default(), incomplete_modules: HashSet::new(), ids: UniqueIdGenerator::new(), - warnings: WarningEmitter::new(warning_emitter), + warnings: warning_emitter, subprocess_stdio: Stdio::Inherit, telemetry, packages, From 6a2132e331d64fdde33b93320047fc00db28e151 Mon Sep 17 00:00:00 2001 From: Kevin Chen Date: Thu, 20 Nov 2025 02:12:38 -0500 Subject: [PATCH 10/13] docs: add myself to changelog --- CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index b09709082a2..db87404c57e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -114,7 +114,7 @@ ([fruno](https://github.com/fruno-bulax/)) - Gleam will now warn when running a deprecated or internal module main function - ([Lioncat2002](https://github.com/Lioncat2002)) + ([Kevin Chen](https://github.com/kfc35) & [Lioncat2002](https://github.com/Lioncat2002)) ### Build tool From 62ce100d2838dfdbf885e0582a3ee8f4aa0e2978 Mon Sep 17 00:00:00 2001 From: Kevin Chen Date: Thu, 20 Nov 2025 02:24:27 -0500 Subject: [PATCH 11/13] refactor: shortens test names --- ...gleam_core__warning__deprecated_main_function_pretty.snap} | 0 ..._core__warning__internal_module_main_function_pretty.snap} | 0 compiler-core/src/warning.rs | 4 ++-- 3 files changed, 2 insertions(+), 2 deletions(-) rename compiler-core/src/snapshots/{gleam_core__warning__warning_deprecated_main_function_pretty.snap => gleam_core__warning__deprecated_main_function_pretty.snap} (100%) rename compiler-core/src/snapshots/{gleam_core__warning__warning_internal_module_main_function_pretty.snap => gleam_core__warning__internal_module_main_function_pretty.snap} (100%) diff --git a/compiler-core/src/snapshots/gleam_core__warning__warning_deprecated_main_function_pretty.snap b/compiler-core/src/snapshots/gleam_core__warning__deprecated_main_function_pretty.snap similarity index 100% rename from compiler-core/src/snapshots/gleam_core__warning__warning_deprecated_main_function_pretty.snap rename to compiler-core/src/snapshots/gleam_core__warning__deprecated_main_function_pretty.snap diff --git a/compiler-core/src/snapshots/gleam_core__warning__warning_internal_module_main_function_pretty.snap b/compiler-core/src/snapshots/gleam_core__warning__internal_module_main_function_pretty.snap similarity index 100% rename from compiler-core/src/snapshots/gleam_core__warning__warning_internal_module_main_function_pretty.snap rename to compiler-core/src/snapshots/gleam_core__warning__internal_module_main_function_pretty.snap diff --git a/compiler-core/src/warning.rs b/compiler-core/src/warning.rs index f283feccf82..8a4d07d0359 100644 --- a/compiler-core/src/warning.rs +++ b/compiler-core/src/warning.rs @@ -1609,7 +1609,7 @@ fn pluralise(string: String, quantity: i64) -> String { } #[test] -fn warning_deprecated_main_function_pretty() { +fn deprecated_main_function_pretty() { let warning = Warning::DeprecatedMainFunction { module: "apple".into(), message: "Use some other method please!".into() @@ -1622,7 +1622,7 @@ fn warning_deprecated_main_function_pretty() { } #[test] -fn warning_internal_module_main_function_pretty() { +fn internal_module_main_function_pretty() { let warning: Warning = Warning::InternalModuleMainFunction { module: "internal/picking".into(), }; From 3b754918497057fe8f11ded4617b011001e8757d Mon Sep 17 00:00:00 2001 From: Kevin Chen Date: Thu, 20 Nov 2025 02:31:23 -0500 Subject: [PATCH 12/13] fix: reverse condition checking for internal module main --- compiler-cli/src/run.rs | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/compiler-cli/src/run.rs b/compiler-cli/src/run.rs index b9475a06366..0788fa5dff9 100644 --- a/compiler-cli/src/run.rs +++ b/compiler-cli/src/run.rs @@ -134,10 +134,10 @@ pub fn setup( let built = crate::build::main_with_warnings(paths, options, manifest, warning_emitter_with_counter.clone())?; // Warn if the module being run is internal and NOT in the root package - if mod_config.is_internal_module(&module) { - match package_kind { - PackageKind::Root => {} - PackageKind::Dependency => { + match package_kind { + PackageKind::Root => {} + PackageKind::Dependency => { + if mod_config.is_internal_module(&module) { let warning = Warning::InternalModuleMainFunction { module: module.clone(), }; From bbbc8ba550f34e93325320ef9dec9513f21c2c58 Mon Sep 17 00:00:00 2001 From: Kevin Chen Date: Thu, 20 Nov 2025 10:05:56 -0500 Subject: [PATCH 13/13] style: applies rustfmt --- compiler-cli/src/fix.rs | 2 +- compiler-cli/src/run.rs | 20 +++++++++++------ compiler-core/src/build/project_compiler.rs | 13 ++++++++--- compiler-core/src/warning.rs | 25 +++++++++------------ 4 files changed, 35 insertions(+), 25 deletions(-) diff --git a/compiler-cli/src/fix.rs b/compiler-cli/src/fix.rs index fbbaa717498..acc3f392e3f 100644 --- a/compiler-cli/src/fix.rs +++ b/compiler-cli/src/fix.rs @@ -7,7 +7,7 @@ use gleam_core::{ error::{FileIoAction, FileKind}, paths::ProjectPaths, type_, - warning::{WarningEmitter, VectorWarningEmitterIO}, + warning::{VectorWarningEmitterIO, WarningEmitter}, }; use hexpm::version::Version; diff --git a/compiler-cli/src/run.rs b/compiler-cli/src/run.rs index 0788fa5dff9..60a00bd216e 100644 --- a/compiler-cli/src/run.rs +++ b/compiler-cli/src/run.rs @@ -11,12 +11,12 @@ use gleam_core::{ io::{Command, CommandExecutor, Stdio}, paths::ProjectPaths, type_::ModuleFunction, - warning::{WarningEmitter, WarningEmitterIO} + warning::{WarningEmitter, WarningEmitterIO}, }; use crate::{ - config::PackageKind, - fs::{ConsoleWarningEmitter, ProjectIO} + config::PackageKind, + fs::{ConsoleWarningEmitter, ProjectIO}, }; #[derive(Debug, Clone, Copy)] @@ -130,8 +130,14 @@ pub fn setup( }; let console_warning_emitter = Rc::new(ConsoleWarningEmitter); - let warning_emitter_with_counter = Rc::new(WarningEmitter::new(console_warning_emitter.clone())); - let built = crate::build::main_with_warnings(paths, options, manifest, warning_emitter_with_counter.clone())?; + let warning_emitter_with_counter = + Rc::new(WarningEmitter::new(console_warning_emitter.clone())); + let built = crate::build::main_with_warnings( + paths, + options, + manifest, + warning_emitter_with_counter.clone(), + )?; // Warn if the module being run is internal and NOT in the root package match package_kind { @@ -152,7 +158,7 @@ pub fn setup( // Warn if the main function being run has been deprecated match main_function.deprecation { gleam_core::type_::Deprecation::Deprecated { message } => { - let warning = Warning::DeprecatedMainFunction { + let warning = Warning::DeprecatedMainFunction { module: module.clone(), message, }; @@ -161,7 +167,7 @@ pub fn setup( // we just print the warning directly to console. match package_kind { PackageKind::Root => warning_emitter_with_counter.emit(warning), - PackageKind::Dependency => console_warning_emitter.emit_warning(warning) + PackageKind::Dependency => console_warning_emitter.emit_warning(warning), } } gleam_core::type_::Deprecation::NotDeprecated => {} diff --git a/compiler-core/src/build/project_compiler.rs b/compiler-core/src/build/project_compiler.rs index 2f0e7151daf..f5da0105f12 100644 --- a/compiler-core/src/build/project_compiler.rs +++ b/compiler-core/src/build/project_compiler.rs @@ -136,8 +136,15 @@ where paths: ProjectPaths, io: IO, ) -> Self { - Self::new_with_warning_emitter(config, options, packages, telemetry, - Rc::new(WarningEmitter::new(warning_emitter)), paths, io) + Self::new_with_warning_emitter( + config, + options, + packages, + telemetry, + Rc::new(WarningEmitter::new(warning_emitter)), + paths, + io, + ) } pub fn new_with_warning_emitter( @@ -148,7 +155,7 @@ where warning_emitter: Rc, paths: ProjectPaths, io: IO, - ) -> Self { + ) -> Self { let packages = packages .into_iter() .map(|p| (p.name.to_string(), p)) diff --git a/compiler-core/src/warning.rs b/compiler-core/src/warning.rs index 8a4d07d0359..2688a3261a3 100644 --- a/compiler-core/src/warning.rs +++ b/compiler-core/src/warning.rs @@ -283,8 +283,10 @@ impl Warning { pub fn to_diagnostic(&self) -> Diagnostic { match self { Warning::DeprecatedMainFunction { module, message } => { - let text = wrap(&format!("The main function in module `{module}` \ -was deprecated with this message: {message}")); + let text = wrap(&format!( + "The main function in module `{module}` \ +was deprecated with this message: {message}" + )); Diagnostic { title: "Deprecated main function".into(), text, @@ -292,11 +294,12 @@ was deprecated with this message: {message}")); location: None, hint: None, } - }, + } Warning::InternalModuleMainFunction { module } => { let text = wrap(&format!( "The main function is in internal module `{module}`. \ -It is not recommended for public use.")); +It is not recommended for public use." + )); Diagnostic { title: "Main function in internal module".into(), text, @@ -304,7 +307,7 @@ It is not recommended for public use.")); location: None, hint: None, } - }, + } Warning::InvalidSource { path } => Diagnostic { title: "Invalid module name".into(), text: "\ @@ -1612,13 +1615,10 @@ fn pluralise(string: String, quantity: i64) -> String { fn deprecated_main_function_pretty() { let warning = Warning::DeprecatedMainFunction { module: "apple".into(), - message: "Use some other method please!".into() + message: "Use some other method please!".into(), }; - insta::assert_snapshot!( - insta::internals::AutoName, - warning.to_pretty_string() - ); + insta::assert_snapshot!(insta::internals::AutoName, warning.to_pretty_string()); } #[test] @@ -1627,8 +1627,5 @@ fn internal_module_main_function_pretty() { module: "internal/picking".into(), }; - insta::assert_snapshot!( - insta::internals::AutoName, - warning.to_pretty_string() - ); + insta::assert_snapshot!(insta::internals::AutoName, warning.to_pretty_string()); }