diff --git a/compiler-cli/Cargo.toml b/compiler-cli/Cargo.toml index 3bd976d5a2a..252cadcd42b 100644 --- a/compiler-cli/Cargo.toml +++ b/compiler-cli/Cargo.toml @@ -2,7 +2,7 @@ name = "gleam" version = "1.8.1" authors = ["Louis Pilfold "] -edition = "2021" +edition = "2024" license-file = "LICENCE" [dependencies] diff --git a/compiler-cli/src/add.rs b/compiler-cli/src/add.rs index 4bb2c45ca15..c817f8d2ea4 100644 --- a/compiler-cli/src/add.rs +++ b/compiler-cli/src/add.rs @@ -1,14 +1,14 @@ use camino::{Utf8Path, Utf8PathBuf}; use gleam_core::{ + Error, Result, error::{FileIoAction, FileKind}, paths::ProjectPaths, - Error, Result, }; use crate::{ cli, - dependencies::{parse_gleam_add_specifier, UseManifest}, + dependencies::{UseManifest, parse_gleam_add_specifier}, fs, }; diff --git a/compiler-cli/src/beam_compiler.rs b/compiler-cli/src/beam_compiler.rs index fd07b6fafe5..db81ce14e90 100644 --- a/compiler-cli/src/beam_compiler.rs +++ b/compiler-cli/src/beam_compiler.rs @@ -1,7 +1,8 @@ use gleam_core::{ + Result, error::{Error, ShellCommandFailureReason}, io::{FileSystemWriter, Stdio}, - paths, Result, + paths, }; use crate::fs::get_os; @@ -37,13 +38,10 @@ impl BeamCompiler { stdio: Stdio, ) -> Result, Error> { let inner = match self.inner { - Some(ref mut inner) => { - if let Ok(None) = inner.process.try_wait() { - inner - } else { - self.inner.insert(self.spawn(io, out)?) - } - } + Some(ref mut inner) => match inner.process.try_wait() { + Ok(None) => inner, + _ => self.inner.insert(self.spawn(io, out)?), + }, None => self.inner.insert(self.spawn(io, out)?), }; @@ -77,7 +75,7 @@ impl BeamCompiler { return Err(Error::ShellCommand { program: "escript".into(), reason: ShellCommandFailureReason::Unknown, - }) + }); } s if s.starts_with("gleam-compile-module:") => { if let Some(module_content) = s.strip_prefix("gleam-compile-module:") { diff --git a/compiler-cli/src/build.rs b/compiler-cli/src/build.rs index fb49b5889c2..e6361f769a0 100644 --- a/compiler-cli/src/build.rs +++ b/compiler-cli/src/build.rs @@ -1,11 +1,11 @@ use std::{rc::Rc, time::Instant}; use gleam_core::{ + Result, build::{Built, Codegen, NullTelemetry, Options, ProjectCompiler, Telemetry}, manifest::Manifest, paths::ProjectPaths, warning::WarningEmitterIO, - Result, }; use crate::{ diff --git a/compiler-cli/src/build_lock.rs b/compiler-cli/src/build_lock.rs index dc4e712f944..2cb870788f1 100644 --- a/compiler-cli/src/build_lock.rs +++ b/compiler-cli/src/build_lock.rs @@ -1,9 +1,9 @@ use camino::Utf8PathBuf; use gleam_core::{ + Error, Result, build::{Mode, Target, Telemetry}, error::{FileIoAction, FileKind}, paths::ProjectPaths, - Error, Result, }; use strum::IntoEnumIterator; diff --git a/compiler-cli/src/compile_package.rs b/compiler-cli/src/compile_package.rs index f183f976da6..e63ad62069d 100644 --- a/compiler-cli/src/compile_package.rs +++ b/compiler-cli/src/compile_package.rs @@ -1,11 +1,11 @@ use crate::{ - config, + CompilePackage, config, fs::{self, ConsoleWarningEmitter, ProjectIO}, - CompilePackage, }; use camino::Utf8Path; use ecow::EcoString; use gleam_core::{ + Error, Result, build::{ Mode, NullTelemetry, PackageCompiler, StaleTracker, Target, TargetCodegenConfiguration, }, @@ -14,7 +14,6 @@ use gleam_core::{ type_::ModuleInterface, uid::UniqueIdGenerator, warning::WarningEmitter, - Error, Result, }; use std::{collections::HashSet, rc::Rc}; diff --git a/compiler-cli/src/dependencies.rs b/compiler-cli/src/dependencies.rs index e3d5d81b6ef..ac2ebd90871 100644 --- a/compiler-cli/src/dependencies.rs +++ b/compiler-cli/src/dependencies.rs @@ -5,10 +5,11 @@ use std::{ }; use camino::{Utf8Path, Utf8PathBuf}; -use ecow::{eco_format, EcoString}; +use ecow::{EcoString, eco_format}; use flate2::read::GzDecoder; use futures::future; use gleam_core::{ + Error, Result, build::{Mode, Target, Telemetry}, config::PackageConfig, dependency, @@ -18,7 +19,6 @@ use gleam_core::{ manifest::{Base16Checksum, Manifest, ManifestPackage, ManifestPackageSource}, paths::ProjectPaths, requirement::Requirement, - Error, Result, }; use hexpm::version::Version; use itertools::Itertools; @@ -29,11 +29,11 @@ use strum::IntoEnumIterator; mod tests; use crate::{ + TreeOptions, build_lock::BuildLock, cli, fs::{self, ProjectIO}, http::HttpClient, - TreeOptions, }; struct Symbols { @@ -336,7 +336,7 @@ pub fn parse_gleam_add_specifier(package: &str) -> Result<(EcoString, Requiremen error: format!( "Expected up to 3 numbers in version specifier (MAJOR.MINOR.PATCH), found {n}" ), - }) + }); } }; diff --git a/compiler-cli/src/dependencies/tests.rs b/compiler-cli/src/dependencies/tests.rs index 1d1bf8fa9aa..8295b042873 100644 --- a/compiler-cli/src/dependencies/tests.rs +++ b/compiler-cli/src/dependencies/tests.rs @@ -6,11 +6,11 @@ use hexpm::version::Version; use pretty_assertions::assert_eq; use gleam_core::{ + Error, build::Runtime, config::{DenoConfig, DenoFlag, Docs, ErlangConfig, JavaScriptConfig, Repository}, manifest::{Base16Checksum, Manifest, ManifestPackage, ManifestPackageSource}, requirement::Requirement, - Error, }; use crate::dependencies::*; @@ -507,14 +507,16 @@ fn provide_wrong_package() { &mut provided, &mut vec!["root".into(), "subpackage".into()], ); - if let Err(Error::WrongDependencyProvided { - expected, found, .. - }) = result - { - assert_eq!(expected, "wrong_name"); - assert_eq!(found, "hello_world"); - } else { - panic!("Expected WrongDependencyProvided error") + match result { + Err(Error::WrongDependencyProvided { + expected, found, .. + }) => { + assert_eq!(expected, "wrong_name"); + assert_eq!(found, "hello_world"); + } + _ => { + panic!("Expected WrongDependencyProvided error") + } } } @@ -568,10 +570,13 @@ fn provide_conflicting_package() { &mut provided, &mut vec!["root".into(), "subpackage".into()], ); - if let Err(Error::ProvidedDependencyConflict { package, .. }) = result { - assert_eq!(package, "hello_world"); - } else { - panic!("Expected ProvidedDependencyConflict error") + match result { + Err(Error::ProvidedDependencyConflict { package, .. }) => { + assert_eq!(package, "hello_world"); + } + _ => { + panic!("Expected ProvidedDependencyConflict error") + } } } @@ -589,10 +594,13 @@ fn provided_is_absolute() { ); assert_eq!(result, Ok(hexpm::version::Range::new("== 0.1.0".into()))); let package = provided.get("hello_world").unwrap().clone(); - if let ProvidedPackageSource::Local { path } = package.source { - assert!(path.is_absolute()) - } else { - panic!("Provide_local_package provided a package that is not local!") + match package.source { + ProvidedPackageSource::Local { path } => { + assert!(path.is_absolute()) + } + _ => { + panic!("Provide_local_package provided a package that is not local!") + } } } diff --git a/compiler-cli/src/docs.rs b/compiler-cli/src/docs.rs index 656da267dda..a09429f3038 100644 --- a/compiler-cli/src/docs.rs +++ b/compiler-cli/src/docs.rs @@ -4,6 +4,7 @@ use camino::{Utf8Path, Utf8PathBuf}; use crate::{cli, fs::ProjectIO, http::HttpClient}; use gleam_core::{ + Result, analyse::TargetSupport, build::{Codegen, Compile, Mode, Options, Package, Target}, config::{DocsPage, PackageConfig}, @@ -12,7 +13,6 @@ use gleam_core::{ hex, io::HttpClient as _, paths::ProjectPaths, - Result, }; pub fn remove(package: String, version: String) -> Result<()> { diff --git a/compiler-cli/src/export.rs b/compiler-cli/src/export.rs index c9715af60c5..84afed68b7f 100644 --- a/compiler-cli/src/export.rs +++ b/compiler-cli/src/export.rs @@ -1,9 +1,9 @@ use camino::Utf8PathBuf; use gleam_core::{ + Result, analyse::TargetSupport, build::{Codegen, Compile, Mode, Options, Target}, paths::ProjectPaths, - Result, }; #[cfg(target_os = "windows")] diff --git a/compiler-cli/src/fix.rs b/compiler-cli/src/fix.rs index b4376cee657..51cc5a3e266 100644 --- a/compiler-cli/src/fix.rs +++ b/compiler-cli/src/fix.rs @@ -1,13 +1,13 @@ use std::rc::Rc; use gleam_core::{ + Error, Result, Warning, analyse::TargetSupport, build::{Codegen, Compile, Mode, Options}, error::{FileIoAction, FileKind}, paths::ProjectPaths, type_, warning::VectorWarningEmitterIO, - Error, Result, Warning, }; use hexpm::version::Version; diff --git a/compiler-cli/src/fs.rs b/compiler-cli/src/fs.rs index 39034ab8c39..4f042a33dae 100644 --- a/compiler-cli/src/fs.rs +++ b/compiler-cli/src/fs.rs @@ -1,6 +1,7 @@ use gleam_core::{ + Result, Warning, build::{NullTelemetry, Target}, - error::{parse_os, Error, FileIoAction, FileKind, ShellCommandFailureReason, OS}, + error::{Error, FileIoAction, FileKind, OS, ShellCommandFailureReason, parse_os}, io::{ BeamCompiler, Command, CommandExecutor, Content, DirEntry, FileSystemReader, FileSystemWriter, OutputFile, ReadDir, Stdio, WrappedReader, @@ -9,7 +10,6 @@ use gleam_core::{ manifest::Manifest, paths::ProjectPaths, warning::WarningEmitterIO, - Result, Warning, }; use std::{ collections::HashSet, diff --git a/compiler-cli/src/hex.rs b/compiler-cli/src/hex.rs index 4ca354e6080..a5ceaa142b6 100644 --- a/compiler-cli/src/hex.rs +++ b/compiler-cli/src/hex.rs @@ -2,10 +2,10 @@ mod auth; use crate::{cli, http::HttpClient}; use gleam_core::{ + Error, Result, hex::{self, RetirementReason}, io::HttpClient as _, paths::ProjectPaths, - Error, Result, }; pub use auth::HexAuthentication; diff --git a/compiler-cli/src/hex/auth.rs b/compiler-cli/src/hex/auth.rs index d1d91d2b082..0405932d319 100644 --- a/compiler-cli/src/hex/auth.rs +++ b/compiler-cli/src/hex/auth.rs @@ -1,5 +1,5 @@ use crate::{cli, http::HttpClient}; -use gleam_core::{encryption, hex, paths::global_hexpm_credentials_path, Error, Result}; +use gleam_core::{Error, Result, encryption, hex, paths::global_hexpm_credentials_path}; use std::time::SystemTime; pub const USER_PROMPT: &str = "https://hex.pm username"; diff --git a/compiler-cli/src/http.rs b/compiler-cli/src/http.rs index 5df62d1a68f..6b05e5586fe 100644 --- a/compiler-cli/src/http.rs +++ b/compiler-cli/src/http.rs @@ -4,8 +4,8 @@ use std::sync::OnceLock; use async_trait::async_trait; use camino::Utf8PathBuf; use gleam_core::{ - error::{FileIoAction, FileKind}, Error, Result, + error::{FileIoAction, FileKind}, }; use http::{Request, Response}; use reqwest::{Certificate, Client}; diff --git a/compiler-cli/src/lsp.rs b/compiler-cli/src/lsp.rs index 98eee46e151..1bfc2d96ecb 100644 --- a/compiler-cli/src/lsp.rs +++ b/compiler-cli/src/lsp.rs @@ -1,9 +1,9 @@ use crate::{build_lock::BuildLock, fs::ProjectIO}; use gleam_core::{ + Result, build::{Mode, NullTelemetry, Target}, language_server::{LanguageServer, LockGuard, Locker}, paths::ProjectPaths, - Result, }; pub fn main() -> Result<()> { diff --git a/compiler-cli/src/main.rs b/compiler-cli/src/main.rs index 994cabf2839..a39ea32eedf 100644 --- a/compiler-cli/src/main.rs +++ b/compiler-cli/src/main.rs @@ -88,8 +88,8 @@ use std::str::FromStr; use camino::Utf8PathBuf; use clap::{ - builder::{styling, PossibleValuesParser, Styles, TypedValueParser}, Args, Parser, Subcommand, + builder::{PossibleValuesParser, Styles, TypedValueParser, styling}, }; use strum::VariantNames; diff --git a/compiler-cli/src/new.rs b/compiler-cli/src/new.rs index d51cc0f5098..ff5aec9d762 100644 --- a/compiler-cli/src/new.rs +++ b/compiler-cli/src/new.rs @@ -1,9 +1,9 @@ use camino::{Utf8Path, Utf8PathBuf}; use clap::ValueEnum; use gleam_core::{ - erlang, error, + Result, erlang, error, error::{Error, FileIoAction, FileKind, InvalidProjectNameReason}, - parse, Result, + parse, }; use serde::{Deserialize, Serialize}; use std::fs::File; @@ -13,7 +13,7 @@ use strum::{Display, EnumIter, EnumString, IntoEnumIterator, VariantNames}; #[cfg(test)] mod tests; -use crate::{fs::get_current_directory, NewOptions}; +use crate::{NewOptions, fs::get_current_directory}; const GLEAM_STDLIB_REQUIREMENT: &str = ">= 0.44.0 and < 2.0.0"; const GLEEUNIT_REQUIREMENT: &str = ">= 1.0.0 and < 2.0.0"; @@ -419,7 +419,7 @@ fn get_valid_project_name(name: Option, project_root: &str) -> Result"] -edition = "2021" +edition = "2024" license-file = "LICENCE" [dependencies] diff --git a/compiler-core/src/analyse.rs b/compiler-core/src/analyse.rs index 67d1f86b852..7a1fa119658 100644 --- a/compiler-core/src/analyse.rs +++ b/compiler-core/src/analyse.rs @@ -5,6 +5,7 @@ pub(crate) mod name; mod tests; use crate::{ + GLEAM_CORE_PACKAGE_NAME, ast::{ self, Arg, BitArrayOption, CustomType, Definition, DefinitionLocation, Function, GroupedStatements, Import, ModuleConstant, Publicity, RecordConstructor, @@ -14,26 +15,24 @@ use crate::{ UntypedModule, UntypedModuleConstant, UntypedStatement, UntypedTypeAlias, }, build::{Origin, Outcome, Target}, - call_graph::{into_dependency_order, CallGraphNode}, + call_graph::{CallGraphNode, into_dependency_order}, config::PackageConfig, dep_tree, line_numbers::LineNumbers, parse::SpannedString, type_::{ - self, + self, AccessorsMap, Deprecation, ModuleInterface, PatternConstructor, RecordAccessor, Type, + TypeConstructor, TypeValueConstructor, TypeValueConstructorField, TypeVariantConstructors, + ValueConstructor, ValueConstructorVariant, Warning, environment::*, - error::{convert_unify_error, Error, FeatureKind, MissingAnnotation, Named, Problems}, + error::{Error, FeatureKind, MissingAnnotation, Named, Problems, convert_unify_error}, expression::{ExprTyper, FunctionDefinition, Implementations}, fields::{FieldMap, FieldMapBuilder}, hydrator::Hydrator, prelude::*, - AccessorsMap, Deprecation, ModuleInterface, PatternConstructor, RecordAccessor, Type, - TypeConstructor, TypeValueConstructor, TypeValueConstructorField, TypeVariantConstructors, - ValueConstructor, ValueConstructorVariant, Warning, }, uid::UniqueIdGenerator, warning::TypeWarningEmitter, - GLEAM_CORE_PACKAGE_NAME, }; use camino::Utf8PathBuf; use ecow::EcoString; @@ -847,27 +846,28 @@ impl<'a, A> ModuleAnalyzer<'a, A> { .expect("Could not find preregistered type for function"); let preregistered_type = preregistered_fn.type_.clone(); - let args = - if let Some((args_types, _return_type)) = preregistered_type.fn_types() { - args.into_iter() - .zip(&args_types) - .map(|(argument, t)| { - if let Some((location, label)) = &argument.label { - self.check_name_case(*location, label, Named::Label); - } - - RecordConstructorArg { - label: argument.label, - ast: argument.ast, - location: argument.location, - type_: t.clone(), - doc: argument.doc, - } - }) - .collect() - } else { + let args = match preregistered_type.fn_types() { + Some((args_types, _return_type)) => args + .into_iter() + .zip(&args_types) + .map(|(argument, t)| { + if let Some((location, label)) = &argument.label { + self.check_name_case(*location, label, Named::Label); + } + + RecordConstructorArg { + label: argument.label, + ast: argument.ast, + location: argument.location, + type_: t.clone(), + doc: argument.doc, + } + }) + .collect(), + _ => { vec![] - }; + } + }; RecordConstructor { location, diff --git a/compiler-core/src/analyse/name.rs b/compiler-core/src/analyse/name.rs index 6f8f49b63eb..21ae5add47d 100644 --- a/compiler-core/src/analyse/name.rs +++ b/compiler-core/src/analyse/name.rs @@ -1,6 +1,6 @@ use std::sync::OnceLock; -use ecow::{eco_format, EcoString}; +use ecow::{EcoString, eco_format}; use regex::Regex; use crate::{ diff --git a/compiler-core/src/ast.rs b/compiler-core/src/ast.rs index 47e0cd9bf21..1e2015f2242 100644 --- a/compiler-core/src/ast.rs +++ b/compiler-core/src/ast.rs @@ -1287,15 +1287,16 @@ impl CallArg { .or_else(|| body.iter().find_map(|s| s.find_node(byte_index))), // In all other cases we're happy with the default behaviour. // - _ => { - if let Some(located) = self.value.find_node(byte_index) { - Some(located) - } else if self.location.contains(byte_index) && self.label.is_some() { - Some(Located::Label(self.location, self.value.type_())) - } else { - None + _ => match self.value.find_node(byte_index) { + Some(located) => Some(located), + _ => { + if self.location.contains(byte_index) && self.label.is_some() { + Some(Located::Label(self.location, self.value.type_())) + } else { + None + } } - } + }, } } @@ -1312,7 +1313,7 @@ impl CallArg { pub fn is_capture_hole(&self) -> bool { match &self.value { - TypedExpr::Var { ref name, .. } => name == CAPTURE_VARIABLE, + TypedExpr::Var { name, .. } => name == CAPTURE_VARIABLE, _ => false, } } @@ -1320,12 +1321,15 @@ impl CallArg { impl CallArg { pub fn find_node(&self, byte_index: u32) -> Option> { - if let Some(located) = self.value.find_node(byte_index) { - Some(located) - } else if self.location.contains(byte_index) && self.label.is_some() { - Some(Located::Label(self.location, self.value.type_())) - } else { - None + match self.value.find_node(byte_index) { + Some(located) => Some(located), + _ => { + if self.location.contains(byte_index) && self.label.is_some() { + Some(Located::Label(self.location, self.value.type_())) + } else { + None + } + } } } } @@ -1333,7 +1337,7 @@ impl CallArg { impl CallArg { pub fn is_capture_hole(&self) -> bool { match &self.value { - UntypedExpr::Var { ref name, .. } => name == CAPTURE_VARIABLE, + UntypedExpr::Var { name, .. } => name == CAPTURE_VARIABLE, _ => false, } } diff --git a/compiler-core/src/ast/tests.rs b/compiler-core/src/ast/tests.rs index 496010315d1..da2af8dbabd 100644 --- a/compiler-core/src/ast/tests.rs +++ b/compiler-core/src/ast/tests.rs @@ -8,7 +8,7 @@ use crate::config::PackageConfig; use crate::line_numbers::LineNumbers; use crate::type_::error::VariableOrigin; use crate::type_::expression::FunctionDefinition; -use crate::type_::{Deprecation, Problems, PRELUDE_MODULE_NAME}; +use crate::type_::{Deprecation, PRELUDE_MODULE_NAME, Problems}; use crate::warning::WarningEmitter; use crate::{ ast::{SrcSpan, TypedExpr}, diff --git a/compiler-core/src/ast/typed.rs b/compiler-core/src/ast/typed.rs index c0013d91de4..460d8b4b328 100644 --- a/compiler-core/src/ast/typed.rs +++ b/compiler-core/src/ast/typed.rs @@ -3,7 +3,7 @@ use std::sync::OnceLock; use type_::{FieldMap, TypedCallArg}; use super::*; -use crate::type_::{bool, HasType, Type, ValueConstructorVariant}; +use crate::type_::{HasType, Type, ValueConstructorVariant, bool}; #[derive(Debug, Clone, PartialEq, Eq)] pub enum TypedExpr { diff --git a/compiler-core/src/ast/visit.rs b/compiler-core/src/ast/visit.rs index 1621ee7a37e..a992986dc8d 100644 --- a/compiler-core/src/ast/visit.rs +++ b/compiler-core/src/ast/visit.rs @@ -41,8 +41,8 @@ use crate::{ analyse::Inferred, type_::{ - error::VariableOrigin, ModuleValueConstructor, PatternConstructor, TypedCallArg, - ValueConstructor, + ModuleValueConstructor, PatternConstructor, TypedCallArg, ValueConstructor, + error::VariableOrigin, }, }; use std::sync::Arc; @@ -53,11 +53,12 @@ use vec1::Vec1; use crate::type_::Type; use super::{ - untyped::FunctionLiteralKind, AssignName, BinOp, BitArrayOption, CallArg, Definition, Pattern, - PipelineAssignmentKind, SrcSpan, Statement, TodoKind, TypeAst, TypedArg, TypedAssignment, - TypedClause, TypedClauseGuard, TypedConstant, TypedCustomType, TypedDefinition, TypedExpr, + AssignName, BinOp, BitArrayOption, CallArg, Definition, Pattern, PipelineAssignmentKind, + SrcSpan, Statement, TodoKind, TypeAst, TypedArg, TypedAssignment, TypedClause, + TypedClauseGuard, TypedConstant, TypedCustomType, TypedDefinition, TypedExpr, TypedExprBitArraySegment, TypedFunction, TypedModule, TypedModuleConstant, TypedPattern, TypedPatternBitArraySegment, TypedPipelineAssignment, TypedStatement, TypedUse, + untyped::FunctionLiteralKind, }; pub trait Visit<'ast> { diff --git a/compiler-core/src/build/elixir_libraries.rs b/compiler-core/src/build/elixir_libraries.rs index 75c38dd08c6..a2a14a1113b 100644 --- a/compiler-core/src/build/elixir_libraries.rs +++ b/compiler-core/src/build/elixir_libraries.rs @@ -1,7 +1,7 @@ use crate::{ + Error, error::ShellCommandFailureReason, io::{Command, CommandExecutor, FileSystemReader, FileSystemWriter, Stdio}, - Error, }; use camino::Utf8PathBuf; @@ -79,13 +79,13 @@ where ELIXIR_LIBS.iter().map(|lib| format!(":{}", lib)).collect(); // Use Elixir to find its core lib paths and write the pathfinder file let args = vec![ - "--eval".to_string(), - format!( - ":ok = File.write(~s({}), [{}] |> Stream.map(fn(lib) -> lib |> :code.lib_dir |> Path.expand end) |> Enum.join(~s(\\n)))", - self.paths_cache_filename(), - elixir_atoms.join(", "), - ), - ]; + "--eval".to_string(), + format!( + ":ok = File.write(~s({}), [{}] |> Stream.map(fn(lib) -> lib |> :code.lib_dir |> Path.expand end) |> Enum.join(~s(\\n)))", + self.paths_cache_filename(), + elixir_atoms.join(", "), + ), + ]; tracing::debug!("writing_elixir_paths_to_build"); let status = self.io.exec(Command { program: ELIXIR_EXECUTABLE.into(), diff --git a/compiler-core/src/build/module_loader.rs b/compiler-core/src/build/module_loader.rs index 43ee3bc6977..35f4453b663 100644 --- a/compiler-core/src/build/module_loader.rs +++ b/compiler-core/src/build/module_loader.rs @@ -9,15 +9,15 @@ use ecow::EcoString; use serde::{Deserialize, Serialize}; use super::{ - package_compiler::{module_name, CacheMetadata, CachedModule, Input, UncompiledModule}, - package_loader::CodegenRequired, Mode, Origin, SourceFingerprint, Target, + package_compiler::{CacheMetadata, CachedModule, Input, UncompiledModule, module_name}, + package_loader::CodegenRequired, }; use crate::{ + Error, Result, error::{FileIoAction, FileKind}, io::{CommandExecutor, FileSystemReader, FileSystemWriter}, warning::{TypeWarningEmitter, WarningEmitter}, - Error, Result, }; #[derive(Debug)] diff --git a/compiler-core/src/build/module_loader/tests.rs b/compiler-core/src/build/module_loader/tests.rs index 19b296e2873..c18f710d4ad 100644 --- a/compiler-core/src/build/module_loader/tests.rs +++ b/compiler-core/src/build/module_loader/tests.rs @@ -1,7 +1,7 @@ use super::*; use crate::{ build::SourceFingerprint, - io::{memory::InMemoryFileSystem, FileSystemWriter}, + io::{FileSystemWriter, memory::InMemoryFileSystem}, line_numbers::LineNumbers, }; use std::time::Duration; diff --git a/compiler-core/src/build/native_file_copier.rs b/compiler-core/src/build/native_file_copier.rs index 37cf260fd0f..9ab57556690 100644 --- a/compiler-core/src/build/native_file_copier.rs +++ b/compiler-core/src/build/native_file_copier.rs @@ -4,11 +4,11 @@ mod tests; use std::collections::{HashMap, HashSet}; use camino::{Utf8Path, Utf8PathBuf}; -use ecow::{eco_format, EcoString}; +use ecow::{EcoString, eco_format}; use crate::{ - io::{DirWalker, FileSystemReader, FileSystemWriter}, Error, Result, + io::{DirWalker, FileSystemReader, FileSystemWriter}, }; #[derive(Debug, Clone, PartialEq, Eq)] diff --git a/compiler-core/src/build/native_file_copier/tests.rs b/compiler-core/src/build/native_file_copier/tests.rs index 12eb1ab5772..4d7fffced4d 100644 --- a/compiler-core/src/build/native_file_copier/tests.rs +++ b/compiler-core/src/build/native_file_copier/tests.rs @@ -1,7 +1,7 @@ use super::NativeFileCopier; use crate::{ build::native_file_copier::CopiedNativeFiles, - io::{memory::InMemoryFileSystem, FileSystemWriter}, + io::{FileSystemWriter, memory::InMemoryFileSystem}, }; use std::{ collections::HashMap, diff --git a/compiler-core/src/build/package_compiler.rs b/compiler-core/src/build/package_compiler.rs index 1e824d4681a..68dbbbcc6b0 100644 --- a/compiler-core/src/build/package_compiler.rs +++ b/compiler-core/src/build/package_compiler.rs @@ -2,12 +2,13 @@ use crate::analyse::{ModuleAnalyzerConstructor, TargetSupport}; use crate::line_numbers::{self, LineNumbers}; use crate::type_::PRELUDE_MODULE_NAME; use crate::{ + Error, Result, Warning, ast::{SrcSpan, TypedModule, UntypedModule}, build::{ + Mode, Module, Origin, Outcome, Package, SourceFingerprint, Target, elixir_libraries::ElixirLibraries, native_file_copier::NativeFileCopier, package_loader::{CodegenRequired, PackageLoader, StaleTracker}, - Mode, Module, Origin, Outcome, Package, SourceFingerprint, Target, }, codegen::{Erlang, ErlangApp, JavaScript, TypeScriptDeclarations}, config::PackageConfig, @@ -18,7 +19,6 @@ use crate::{ paths, type_, uid::UniqueIdGenerator, warning::{TypeWarningEmitter, WarningEmitter}, - Error, Result, Warning, }; use askama::Template; use ecow::EcoString; @@ -540,7 +540,7 @@ fn analyse( path: path.clone(), src: code.clone(), errors, - }) + }); } }; } diff --git a/compiler-core/src/build/package_loader.rs b/compiler-core/src/build/package_loader.rs index 511ebc36f23..af22b9cc9f3 100644 --- a/compiler-core/src/build/package_loader.rs +++ b/compiler-core/src/build/package_loader.rs @@ -15,26 +15,26 @@ use itertools::Itertools; use vec1::Vec1; use crate::{ + Error, Result, ast::SrcSpan, - build::{module_loader::ModuleLoader, package_compiler::module_name, Module, Origin}, + build::{Module, Origin, module_loader::ModuleLoader, package_compiler::module_name}, config::PackageConfig, dep_tree, error::{FileIoAction, FileKind, ImportCycleLocationDetails}, io::{ - gleam_cache_files, gleam_source_files, CommandExecutor, FileSystemReader, FileSystemWriter, + CommandExecutor, FileSystemReader, FileSystemWriter, gleam_cache_files, gleam_source_files, }, metadata, type_, uid::UniqueIdGenerator, warning::WarningEmitter, - Error, Result, }; use super::{ + Mode, Target, module_loader::read_source, package_compiler::{ CacheMetadata, CachedModule, CachedWarnings, Input, Loaded, UncompiledModule, }, - Mode, Target, }; #[derive(Debug, Clone, Copy, PartialEq, Eq)] diff --git a/compiler-core/src/build/package_loader/tests.rs b/compiler-core/src/build/package_loader/tests.rs index a94849084fc..f861542ec7d 100644 --- a/compiler-core/src/build/package_loader/tests.rs +++ b/compiler-core/src/build/package_loader/tests.rs @@ -1,14 +1,14 @@ -use ecow::{eco_format, EcoString}; +use ecow::{EcoString, eco_format}; use hexpm::version::Version; use super::*; use crate::{ + Warning, build::SourceFingerprint, - io::{memory::InMemoryFileSystem, FileSystemWriter}, + io::{FileSystemWriter, memory::InMemoryFileSystem}, line_numbers, parse::extra::ModuleExtra, warning::NullWarningEmitterIO, - Warning, }; use std::time::Duration; diff --git a/compiler-core/src/build/project_compiler.rs b/compiler-core/src/build/project_compiler.rs index 7ef36cca4a6..2bbd9575bef 100644 --- a/compiler-core/src/build/project_compiler.rs +++ b/compiler-core/src/build/project_compiler.rs @@ -1,11 +1,12 @@ use crate::{ + Error, Result, Warning, analyse::TargetSupport, build::{ + Mode, Module, Origin, Package, Target, package_compiler::{self, PackageCompiler}, package_loader::StaleTracker, project_compiler, telemetry::Telemetry, - Mode, Module, Origin, Package, Target, }, codegen::{self, ErlangApp}, config::PackageConfig, @@ -19,7 +20,6 @@ use crate::{ uid::UniqueIdGenerator, version::COMPILER_VERSION, warning::{self, WarningEmitter, WarningEmitterIO}, - Error, Result, Warning, }; use ecow::EcoString; use hexpm::version::Version; @@ -36,8 +36,8 @@ use std::{ }; use super::{ - elixir_libraries::ElixirLibraries, package_compiler::CachedWarnings, Codegen, Compile, - ErlangAppCodegenConfiguration, Outcome, + Codegen, Compile, ErlangAppCodegenConfiguration, Outcome, elixir_libraries::ElixirLibraries, + package_compiler::CachedWarnings, }; use camino::{Utf8Path, Utf8PathBuf}; @@ -302,7 +302,7 @@ where return Err(Error::UnsupportedBuildTool { package: package.name.to_string(), build_tools: package.build_tools.clone(), - }) + }); } }; diff --git a/compiler-core/src/build/tests.rs b/compiler-core/src/build/tests.rs index 8f97ae021be..03b48e908f1 100644 --- a/compiler-core/src/build/tests.rs +++ b/compiler-core/src/build/tests.rs @@ -1,6 +1,6 @@ -use crate::{manifest::ManifestPackage, Error}; +use crate::{Error, manifest::ManifestPackage}; -use super::project_compiler::{usable_build_tools, BuildTool}; +use super::project_compiler::{BuildTool, usable_build_tools}; #[test] fn usable_build_tool_unknown() { diff --git a/compiler-core/src/call_graph.rs b/compiler-core/src/call_graph.rs index 535ca7544ef..af09b7ee36a 100644 --- a/compiler-core/src/call_graph.rs +++ b/compiler-core/src/call_graph.rs @@ -5,17 +5,17 @@ mod into_dependency_order_tests; use crate::{ + Result, ast::{ AssignName, BitArrayOption, ClauseGuard, Constant, Pattern, SrcSpan, Statement, UntypedClauseGuard, UntypedExpr, UntypedFunction, UntypedModuleConstant, UntypedPattern, UntypedStatement, }, type_::Error, - Result, }; use itertools::Itertools; use petgraph::stable_graph::NodeIndex; -use petgraph::{stable_graph::StableGraph, Directed}; +use petgraph::{Directed, stable_graph::StableGraph}; #[derive(Debug, Default)] struct CallGraphBuilder<'a> { diff --git a/compiler-core/src/call_graph/into_dependency_order_tests.rs b/compiler-core/src/call_graph/into_dependency_order_tests.rs index 6cd727b1ae2..e3f6bb48306 100644 --- a/compiler-core/src/call_graph/into_dependency_order_tests.rs +++ b/compiler-core/src/call_graph/into_dependency_order_tests.rs @@ -1,7 +1,7 @@ use super::*; use crate::{ ast::{Arg, Function, ModuleConstant, Publicity}, - type_::{expression::Implementations, Deprecation}, + type_::{Deprecation, expression::Implementations}, }; use ecow::EcoString; diff --git a/compiler-core/src/codegen.rs b/compiler-core/src/codegen.rs index ce200040085..e30f14bc926 100644 --- a/compiler-core/src/codegen.rs +++ b/compiler-core/src/codegen.rs @@ -1,4 +1,5 @@ use crate::{ + Result, analyse::TargetSupport, build::{ErlangAppCodegenConfiguration, Module}, config::PackageConfig, @@ -6,7 +7,6 @@ use crate::{ io::FileSystemWriter, javascript, line_numbers::LineNumbers, - Result, }; use ecow::EcoString; use erlang::escape_atom_string; diff --git a/compiler-core/src/config.rs b/compiler-core/src/config.rs index b2c1a23de7a..03d4e2b8838 100644 --- a/compiler-core/src/config.rs +++ b/compiler-core/src/config.rs @@ -790,7 +790,7 @@ pub struct Link { // Note we don't use http-serde since we also want to validate the scheme and host is set. mod uri_serde { use http::uri::InvalidUri; - use serde::{de::Error as _, Deserialize, Deserializer}; + use serde::{Deserialize, Deserializer, de::Error as _}; pub fn deserialize<'de, D>(deserializer: D) -> Result where @@ -824,7 +824,7 @@ mod uri_serde { // This prefixes https as a default in the event no scheme was provided mod uri_serde_default_https { use http::uri::InvalidUri; - use serde::{de::Error as _, Deserialize, Deserializer}; + use serde::{Deserialize, Deserializer, de::Error as _}; pub fn deserialize<'de, D>(deserializer: D) -> Result where diff --git a/compiler-core/src/dep_tree.rs b/compiler-core/src/dep_tree.rs index 5b35e486ce8..1f3c0aa45ca 100644 --- a/compiler-core/src/dep_tree.rs +++ b/compiler-core/src/dep_tree.rs @@ -1,5 +1,5 @@ use ecow::EcoString; -use petgraph::{algo::Cycle, graph::NodeIndex, Direction}; +use petgraph::{Direction, algo::Cycle, graph::NodeIndex}; use std::collections::{HashMap, HashSet}; #[cfg(test)] diff --git a/compiler-core/src/dependency.rs b/compiler-core/src/dependency.rs index 8569464c17d..3d2f810fd4e 100644 --- a/compiler-core/src/dependency.rs +++ b/compiler-core/src/dependency.rs @@ -4,11 +4,11 @@ use crate::{Error, Result}; use ecow::EcoString; use hexpm::{ - version::{Range, ResolutionError, Version}, Dependency, Release, + version::{Range, ResolutionError, Version}, }; use pubgrub::{ - solver::{choose_package_with_fewest_versions, Dependencies}, + solver::{Dependencies, choose_package_with_fewest_versions}, type_aliases::Map, }; @@ -789,11 +789,11 @@ mod tests { .unwrap_err(); match err { - Error::DependencyResolutionFailed(msg) => assert_eq!( - msg, - "An unrecoverable error happened while solving dependencies: gleam_stdlib is specified with the requirement `~> 0.1.0`, but it is locked to 0.2.0, which is incompatible." - ), - _ => panic!("wrong error: {err}"), + Error::DependencyResolutionFailed(msg) => assert_eq!( + msg, + "An unrecoverable error happened while solving dependencies: gleam_stdlib is specified with the requirement `~> 0.1.0`, but it is locked to 0.2.0, which is incompatible." + ), + _ => panic!("wrong error: {err}"), } } diff --git a/compiler-core/src/diagnostic.rs b/compiler-core/src/diagnostic.rs index 93ee447846a..ff30889980d 100644 --- a/compiler-core/src/diagnostic.rs +++ b/compiler-core/src/diagnostic.rs @@ -91,10 +91,9 @@ impl Diagnostic { .extra_labels .iter() .map(|l| { - let (location_src, location_path) = if let Some(info) = &l.src_info { - (info.0.as_str(), info.1.as_str()) - } else { - (main_location_src, main_location_path) + let (location_src, location_path) = match &l.src_info { + Some(info) => (info.0.as_str(), info.1.as_str()), + _ => (main_location_src, main_location_path), }; match file_map.get(location_path) { None => { diff --git a/compiler-core/src/docs/source_links.rs b/compiler-core/src/docs/source_links.rs index aa0d4eab413..8fdc3080633 100644 --- a/compiler-core/src/docs/source_links.rs +++ b/compiler-core/src/docs/source_links.rs @@ -26,10 +26,9 @@ impl SourceLinker { .expect("path is not in root") .with_extension("gleam"); - let path_in_repo = if let Some(repo_path) = project_config.repository.path() { - to_url_path(&Utf8PathBuf::from(repo_path).join(path)) - } else { - to_url_path(&path) + let path_in_repo = match project_config.repository.path() { + Some(repo_path) => to_url_path(&Utf8PathBuf::from(repo_path).join(path)), + _ => to_url_path(&path), } .unwrap_or_default(); diff --git a/compiler-core/src/docs/tests.rs b/compiler-core/src/docs/tests.rs index 5e04616f549..d2e90f6e025 100644 --- a/compiler-core/src/docs/tests.rs +++ b/compiler-core/src/docs/tests.rs @@ -5,7 +5,7 @@ use crate::{ build::{Mode, NullTelemetry, PackageCompiler, StaleTracker, TargetCodegenConfiguration}, config::{DocsPage, PackageConfig, Repository}, docs::DocContext, - io::{memory::InMemoryFileSystem, FileSystemWriter}, + io::{FileSystemWriter, memory::InMemoryFileSystem}, paths::ProjectPaths, uid::UniqueIdGenerator, version::COMPILER_VERSION, @@ -384,8 +384,10 @@ fn source_link_for_github_repository() { }; let modules = vec![("app.gleam", "pub type Wibble = Int")]; - assert!(compile(config, modules) - .contains("https://github.com/wibble/wobble/blob/v0.1.0/src/app.gleam#L1-L1")); + assert!( + compile(config, modules) + .contains("https://github.com/wibble/wobble/blob/v0.1.0/src/app.gleam#L1-L1") + ); } #[test] diff --git a/compiler-core/src/erlang.rs b/compiler-core/src/erlang.rs index 741379f757f..2fd44615fc4 100644 --- a/compiler-core/src/erlang.rs +++ b/compiler-core/src/erlang.rs @@ -10,6 +10,7 @@ use crate::build::Target; use crate::strings::convert_string_escape_chars; use crate::type_::is_prelude_module; use crate::{ + Result, ast::{CustomType, Function, Import, ModuleConstant, TypeAlias, *}, docvec, line_numbers::LineNumbers, @@ -18,10 +19,9 @@ use crate::{ ModuleValueConstructor, PatternConstructor, Type, TypeVar, TypedCallArg, ValueConstructor, ValueConstructorVariant, }, - Result, }; use camino::Utf8Path; -use ecow::{eco_format, EcoString}; +use ecow::{EcoString, eco_format}; use heck::ToSnakeCase; use im::HashSet; use itertools::Itertools; @@ -489,16 +489,19 @@ fn module_function<'a>( // So the doc directive will look like this: `-doc(false).` env.needs_function_docs = true; docvec![attributes, line(), hidden_function_doc()] - } else if let Some((_, documentation)) = &function.documentation { - env.needs_function_docs = true; - let doc_lines = documentation - .trim_end() - .split('\n') - .map(EcoString::from) - .collect_vec(); - docvec![attributes, line(), function_doc(&doc_lines)] } else { - attributes + match &function.documentation { + Some((_, documentation)) => { + env.needs_function_docs = true; + let doc_lines = documentation + .trim_end() + .split('\n') + .map(EcoString::from) + .collect_vec(); + docvec![attributes, line(), function_doc(&doc_lines)] + } + _ => attributes, + } }; Some(( @@ -1275,9 +1278,9 @@ fn var<'a>(name: &'a str, constructor: &'a ValueConstructor, env: &mut Env<'a>) .. } => function_reference(Some(module), name, *arity), - ValueConstructorVariant::ModuleFn { - arity, ref module, .. - } if module == env.module => function_reference(None, name, *arity), + ValueConstructorVariant::ModuleFn { arity, module, .. } if module == env.module => { + function_reference(None, name, *arity) + } ValueConstructorVariant::ModuleFn { arity, @@ -1715,7 +1718,7 @@ fn docs_args_call<'a>( ValueConstructorVariant::ModuleConstant { literal: Constant::Var { - constructor: Some(ref constructor), + constructor: Some(constructor), .. }, .. @@ -1723,18 +1726,18 @@ fn docs_args_call<'a>( .. }, .. - } if constructor.variant.is_module_fn() => { - if let ValueConstructorVariant::ModuleFn { + } if constructor.variant.is_module_fn() => match &constructor.variant { + ValueConstructorVariant::ModuleFn { external_erlang: Some((module, name)), .. } - | ValueConstructorVariant::ModuleFn { module, name, .. } = &constructor.variant - { + | ValueConstructorVariant::ModuleFn { module, name, .. } => { module_fn_with_args(module, name, args, env) - } else { + } + _ => { unreachable!("The above clause guard ensures that this is a module fn") } - } + }, TypedExpr::ModuleSelect { constructor: diff --git a/compiler-core/src/erlang/tests.rs b/compiler-core/src/erlang/tests.rs index 650d2341570..75e205e967a 100644 --- a/compiler-core/src/erlang/tests.rs +++ b/compiler-core/src/erlang/tests.rs @@ -122,7 +122,7 @@ pub fn compile_test_project(src: &str, src_path: &str, dep: Option<(&str, &str, #[macro_export] macro_rules! assert_erl { - (($dep_package:expr, $dep_name:expr, $dep_src:expr), $src:expr $(,)?) => {{ + (($dep_package:expr_2021, $dep_name:expr_2021, $dep_src:expr_2021), $src:expr_2021 $(,)?) => {{ let compiled = $crate::erlang::tests::compile_test_project( $src, "/root/project/test/my/mod.gleam", @@ -135,7 +135,7 @@ macro_rules! assert_erl { insta::assert_snapshot!(insta::internals::AutoName, output, $src); }}; - ($src:expr $(,)?) => {{ + ($src:expr_2021 $(,)?) => {{ let compiled = $crate::erlang::tests::compile_test_project( $src, "/root/project/test/my/mod.gleam", diff --git a/compiler-core/src/error.rs b/compiler-core/src/error.rs index 67d80b2b2f1..0b883301d7c 100644 --- a/compiler-core/src/error.rs +++ b/compiler-core/src/error.rs @@ -7,7 +7,7 @@ use crate::type_::error::{ UnsafeRecordUpdateReason, }; use crate::type_::printer::{Names, Printer}; -use crate::type_::{error::PatternMatchKind, FieldAccessUsage}; +use crate::type_::{FieldAccessUsage, error::PatternMatchKind}; use crate::{ast::BinOp, parse::error::ParseErrorType, type_::Type}; use crate::{bit_array, diagnostic::Level, javascript, type_::UnifyErrorSituation}; use ecow::EcoString; @@ -290,7 +290,9 @@ file_names.iter().map(|x| x.as_str()).join(", "))] #[error("The modules {unfinished:?} contain todo expressions and so cannot be published")] CannotPublishTodo { unfinished: Vec }, - #[error("The modules {unfinished:?} contain internal types in their public API so cannot be published")] + #[error( + "The modules {unfinished:?} contain internal types in their public API so cannot be published" + )] CannotPublishLeakedInternalType { unfinished: Vec }, #[error("Publishing packages to reserve names is not permitted")] @@ -455,13 +457,18 @@ impl Error { let mut conflicting_packages = HashSet::new(); collect_conflicting_packages(&derivation_tree, &mut conflicting_packages); - wrap_format!("Unable to find compatible versions for \ + wrap_format!( + "Unable to find compatible versions for \ the version constraints in your gleam.toml. \ The conflicting packages are: {} ", - conflicting_packages.into_iter().map(|s| format!("- {s}")).join("\n")) + conflicting_packages + .into_iter() + .map(|s| format!("- {s}")) + .join("\n") + ) } ResolutionError::ErrorRetrievingDependencies { @@ -476,9 +483,7 @@ The conflicting packages are: package, version, dependent, - } => format!( - "{package}@{version} has an impossible dependency on {dependent}", - ), + } => format!("{package}@{version} has an impossible dependency on {dependent}",), ResolutionError::SelfDependency { package, version } => { format!("{package}@{version} somehow depends on itself.") @@ -492,9 +497,9 @@ The conflicting packages are: format!("Dependency resolution was cancelled. {err}") } - ResolutionError::Failure(err) => format!( - "An unrecoverable error happened while solving dependencies: {err}" - ), + ResolutionError::Failure(err) => { + format!("An unrecoverable error happened while solving dependencies: {err}") + } }) } diff --git a/compiler-core/src/exhaustiveness.rs b/compiler-core/src/exhaustiveness.rs index eee2988e4d5..c6c48ea8e7c 100644 --- a/compiler-core/src/exhaustiveness.rs +++ b/compiler-core/src/exhaustiveness.rs @@ -38,10 +38,10 @@ use self::pattern::{Constructor, Pattern, PatternId}; use crate::{ ast::AssignName, type_::{ + Environment, Type, TypeValueConstructor, TypeValueConstructorField, TypeVar, collapse_links, error::{UnknownTypeConstructorError, UnreachableCaseClauseReason}, - is_prelude_module, Environment, Type, TypeValueConstructor, TypeValueConstructorField, - TypeVar, + is_prelude_module, }, }; use ecow::EcoString; diff --git a/compiler-core/src/exhaustiveness/missing_patterns.rs b/compiler-core/src/exhaustiveness/missing_patterns.rs index d94af9fc3c6..9114cc7b9ed 100644 --- a/compiler-core/src/exhaustiveness/missing_patterns.rs +++ b/compiler-core/src/exhaustiveness/missing_patterns.rs @@ -1,4 +1,4 @@ -use super::{printer::Printer, Constructor, Decision, Match, Variable}; +use super::{Constructor, Decision, Match, Variable, printer::Printer}; use crate::type_::environment::Environment; use ecow::EcoString; use std::collections::{HashMap, HashSet}; diff --git a/compiler-core/src/exhaustiveness/printer.rs b/compiler-core/src/exhaustiveness/printer.rs index e36ac87208a..9dae82d7a2f 100644 --- a/compiler-core/src/exhaustiveness/printer.rs +++ b/compiler-core/src/exhaustiveness/printer.rs @@ -4,7 +4,7 @@ use ecow::EcoString; use crate::type_::printer::{NameContextInformation, Names}; -use super::{missing_patterns::Term, Variable}; +use super::{Variable, missing_patterns::Term}; #[derive(Debug)] pub struct Printer<'a> { @@ -167,8 +167,8 @@ mod tests { use std::{collections::HashMap, sync::Arc}; use crate::{ - exhaustiveness::{missing_patterns::Term, Variable}, - type_::{printer::Names, Type}, + exhaustiveness::{Variable, missing_patterns::Term}, + type_::{Type, printer::Names}, }; /// Create a variable with a dummy type, for ease of writing tests diff --git a/compiler-core/src/fix.rs b/compiler-core/src/fix.rs index 38142a5eda0..0bc5ac2d076 100644 --- a/compiler-core/src/fix.rs +++ b/compiler-core/src/fix.rs @@ -1,7 +1,7 @@ use crate::{ + Error, Result, format::{Formatter, Intermediate}, warning::WarningEmitter, - Error, Result, }; use camino::Utf8Path; use ecow::EcoString; diff --git a/compiler-core/src/format.rs b/compiler-core/src/format.rs index 107b43aed57..93d9b69e2bc 100644 --- a/compiler-core/src/format.rs +++ b/compiler-core/src/format.rs @@ -2,6 +2,7 @@ mod tests; use crate::{ + Error, Result, ast::{ CustomType, Import, ModuleConstant, TypeAlias, TypeAstConstructor, TypeAstFn, TypeAstHole, TypeAstTuple, TypeAstVar, *, @@ -9,14 +10,13 @@ use crate::{ build::Target, docvec, io::Utf8Writer, - parse::extra::{Comment, ModuleExtra}, parse::SpannedString, + parse::extra::{Comment, ModuleExtra}, pretty::{self, *}, type_::{self, Type}, warning::WarningEmitter, - Error, Result, }; -use ecow::{eco_format, EcoString}; +use ecow::{EcoString, eco_format}; use itertools::Itertools; use std::{cmp::Ordering, sync::Arc}; use vec1::Vec1; @@ -136,7 +136,7 @@ impl<'comments> Formatter<'comments> { fn pop_comments_with_position( &mut self, limit: u32, - ) -> impl Iterator)> { + ) -> impl Iterator)> + use<'comments> { let (popped, rest, empty_lines) = comments_before(self.comments, self.empty_lines, limit, true); self.comments = rest; @@ -146,14 +146,20 @@ impl<'comments> Formatter<'comments> { /// Pop comments that occur before a byte-index in the source, consuming /// and retaining any empty lines contained within. - fn pop_comments(&mut self, limit: u32) -> impl Iterator> { + fn pop_comments( + &mut self, + limit: u32, + ) -> impl Iterator> + use<'comments> { self.pop_comments_with_position(limit) .map(|(_position, comment)| comment) } /// Pop doc comments that occur before a byte-index in the source, consuming /// and dropping any empty lines contained within. - fn pop_doc_comments(&mut self, limit: u32) -> impl Iterator> { + fn pop_doc_comments( + &mut self, + limit: u32, + ) -> impl Iterator> + use<'comments> { let (popped, rest, empty_lines) = comments_before(self.doc_comments, self.empty_lines, limit, false); self.doc_comments = rest; diff --git a/compiler-core/src/format/tests.rs b/compiler-core/src/format/tests.rs index 846af5d446c..b24e95c2142 100644 --- a/compiler-core/src/format/tests.rs +++ b/compiler-core/src/format/tests.rs @@ -19,7 +19,7 @@ mod use_; #[macro_export] macro_rules! assert_format { - ($src:expr $(,)?) => { + ($src:expr_2021 $(,)?) => { let mut writer = String::new(); $crate::format::pretty(&mut writer, &$src.into(), camino::Utf8Path::new("")) .unwrap(); @@ -29,7 +29,7 @@ macro_rules! assert_format { #[macro_export] macro_rules! assert_format_rewrite { - ($src:expr, $expected:expr $(,)?) => { + ($src:expr_2021, $expected:expr_2021 $(,)?) => { let mut writer = String::new(); $crate::format::pretty(&mut writer, &$src.into(), camino::Utf8Path::new("")) .unwrap(); diff --git a/compiler-core/src/graph.rs b/compiler-core/src/graph.rs index fbba0f849d1..89cf7d3fea1 100644 --- a/compiler-core/src/graph.rs +++ b/compiler-core/src/graph.rs @@ -1,6 +1,6 @@ //! General functions for working with graphs. -use petgraph::{prelude::NodeIndex, stable_graph::StableGraph, Direction}; +use petgraph::{Direction, prelude::NodeIndex, stable_graph::StableGraph}; /// Sort a graph into a sequence from the leaves to the roots. /// diff --git a/compiler-core/src/hex.rs b/compiler-core/src/hex.rs index 8c48092cdf2..53b1ae3562b 100644 --- a/compiler-core/src/hex.rs +++ b/compiler-core/src/hex.rs @@ -2,14 +2,14 @@ use camino::Utf8Path; use debug_ignore::DebugIgnore; use flate2::read::GzDecoder; use futures::future; -use hexpm::{version::Version, ApiError}; +use hexpm::{ApiError, version::Version}; use tar::Archive; use crate::{ + Error, Result, io::{FileSystemReader, FileSystemWriter, HttpClient, TarUnpacker}, manifest::{ManifestPackage, ManifestPackageSource}, paths::{self, ProjectPaths}, - Error, Result, }; pub const HEXPM_PUBLIC_KEY: &[u8] = b"-----BEGIN PUBLIC KEY----- @@ -158,11 +158,11 @@ impl Downloader { &self, package: &ManifestPackage, ) -> Result { - let outer_checksum = if let ManifestPackageSource::Hex { outer_checksum } = &package.source - { - outer_checksum - } else { - panic!("Attempt to download non-hex package from hex") + let outer_checksum = match &package.source { + ManifestPackageSource::Hex { outer_checksum } => outer_checksum, + _ => { + panic!("Attempt to download non-hex package from hex") + } }; let tarball_path = paths::global_package_cache_package_tarball( diff --git a/compiler-core/src/io.rs b/compiler-core/src/io.rs index f9226824d50..ad81b27eb77 100644 --- a/compiler-core/src/io.rs +++ b/compiler-core/src/io.rs @@ -402,7 +402,7 @@ impl Reader for WrappedReader { #[async_trait] pub trait HttpClient { async fn send(&self, request: http::Request>) - -> Result>, Error>; + -> Result>, Error>; } pub trait TarUnpacker { diff --git a/compiler-core/src/javascript.rs b/compiler-core/src/javascript.rs index cc0407e68fd..d870b334d6a 100644 --- a/compiler-core/src/javascript.rs +++ b/compiler-core/src/javascript.rs @@ -20,7 +20,7 @@ use crate::{ pretty::*, }; use camino::Utf8Path; -use ecow::{eco_format, EcoString}; +use ecow::{EcoString, eco_format}; use expression::Context; use itertools::Itertools; @@ -530,7 +530,7 @@ impl<'a> Generator<'a> { // and the target support is not enforced. In this case we do not error, instead // returning nothing which will cause no function to be generated. Err(error) if error.is_unsupported() && !self.target_support.is_enforced() => { - return None + return None; } // Some other error case which will be returned to the user. diff --git a/compiler-core/src/javascript/expression.rs b/compiler-core/src/javascript/expression.rs index 979a0aa5943..1221d979b07 100644 --- a/compiler-core/src/javascript/expression.rs +++ b/compiler-core/src/javascript/expression.rs @@ -143,17 +143,19 @@ impl<'module> Generator<'module> { TypedExpr::Int { value, .. } => Ok(int(value)), TypedExpr::Float { value, .. } => Ok(float(value)), - TypedExpr::List { elements, tail, .. } => self.not_in_tail_position(|gen| match tail { - Some(tail) => { - gen.tracker.prepend_used = true; - let tail = gen.wrap_expression(tail)?; - prepend(elements.iter().map(|e| gen.wrap_expression(e)), tail) - } - None => { - gen.tracker.list_used = true; - list(elements.iter().map(|e| gen.wrap_expression(e))) - } - }), + TypedExpr::List { elements, tail, .. } => { + self.not_in_tail_position(|r#gen| match tail { + Some(tail) => { + r#gen.tracker.prepend_used = true; + let tail = r#gen.wrap_expression(tail)?; + prepend(elements.iter().map(|e| r#gen.wrap_expression(e)), tail) + } + None => { + r#gen.tracker.list_used = true; + list(elements.iter().map(|e| r#gen.wrap_expression(e))) + } + }) + } TypedExpr::Tuple { elems, .. } => self.tuple(elems), TypedExpr::TupleIndex { tuple, index, .. } => self.tuple_index(tuple, *index), @@ -223,7 +225,7 @@ impl<'module> Generator<'module> { } fn negate_with<'a>(&mut self, with: &'static str, value: &'a TypedExpr) -> Output<'a> { - self.not_in_tail_position(|gen| Ok(docvec![with, gen.wrap_expression(value)?])) + self.not_in_tail_position(|r#gen| Ok(docvec![with, r#gen.wrap_expression(value)?])) } fn bit_array<'a>(&mut self, segments: &'a [TypedExprBitArraySegment]) -> Output<'a> { @@ -233,7 +235,7 @@ impl<'module> Generator<'module> { // Collect all the values used in segments. let segments_array = array(segments.iter().map(|segment| { - let value = self.not_in_tail_position(|gen| gen.wrap_expression(&segment.value))?; + let value = self.not_in_tail_position(|r#gen| r#gen.wrap_expression(&segment.value))?; if segment.type_ == crate::type_::int() || segment.type_ == crate::type_::float() { let details = self.sized_bit_array_segment_details(segment)?; @@ -373,7 +375,7 @@ impl<'module> Generator<'module> { ( size_value, - self.not_in_tail_position(|gen| gen.wrap_expression(size))?, + self.not_in_tail_position(|r#gen| r#gen.wrap_expression(size))?, ) } _ => { @@ -427,8 +429,8 @@ impl<'module> Generator<'module> { | TypedExpr::Case { .. } | TypedExpr::Pipeline { .. } | TypedExpr::RecordUpdate { .. } => self - .immediately_invoked_function_expression(expression, |gen, expr| { - gen.expression(expr) + .immediately_invoked_function_expression(expression, |r#gen, expr| { + r#gen.expression(expr) }), _ => self.expression(expression), } @@ -515,8 +517,8 @@ impl<'module> Generator<'module> { .chain(assignments.iter().map(|(assignment, _kind)| assignment)); for assignment in all_assignments { - documents.push(self.not_in_tail_position(|gen| { - gen.simple_variable_assignment(&assignment.name, &assignment.value) + documents.push(self.not_in_tail_position(|r#gen| { + r#gen.simple_variable_assignment(&assignment.name, &assignment.value) })?); documents.push(line()); } @@ -548,8 +550,8 @@ impl<'module> Generator<'module> { Statement::Use(use_) => self.child_expression(&use_.call), } } else { - self.immediately_invoked_function_expression(statements, |gen, statements| { - gen.statements(statements) + self.immediately_invoked_function_expression(statements, |r#gen, statements| { + r#gen.statements(statements) }) } } @@ -559,7 +561,7 @@ impl<'module> Generator<'module> { let mut documents = Vec::with_capacity(count * 3); for (i, statement) in statements.iter().enumerate() { if i + 1 < count { - documents.push(self.not_in_tail_position(|gen| gen.statement(statement))?); + documents.push(self.not_in_tail_position(|r#gen| r#gen.statement(statement))?); if requires_semicolon(statement) { documents.push(";".to_doc()); } @@ -581,7 +583,7 @@ impl<'module> Generator<'module> { value: &'a TypedExpr, ) -> Output<'a> { // Subject must be rendered before the variable for variable numbering - let subject = self.not_in_tail_position(|gen| gen.wrap_expression(value))?; + let subject = self.not_in_tail_position(|r#gen| r#gen.wrap_expression(value))?; let js_name = self.next_local_var(name); let assignment = docvec!["let ", js_name.clone(), " = ", subject, ";"]; let assignment = if self.scope_position.is_tail() { @@ -611,7 +613,7 @@ impl<'module> Generator<'module> { // Otherwise we need to compile the patterns let (subject, subject_assignment) = pattern::assign_subject(self, value); // Value needs to be rendered before traversing pattern to have correctly incremented variables. - let value = self.not_in_tail_position(|gen| gen.wrap_expression(value))?; + let value = self.not_in_tail_position(|r#gen| r#gen.wrap_expression(value))?; let mut pattern_generator = pattern::Generator::new(self); pattern_generator.traverse_pattern(&subject, pattern)?; let compiled = pattern_generator.take_compiled(); @@ -649,7 +651,7 @@ impl<'module> Generator<'module> { pattern::assign_subjects(self, subject_values) .into_iter() .unzip(); - let mut gen = pattern::Generator::new(self); + let mut r#gen = pattern::Generator::new(self); let mut doc = nil(); @@ -670,9 +672,10 @@ impl<'module> Generator<'module> { // A clause can have many patterns `pattern, pattern ->...` for multipatterns in multipatterns { - let scope = gen.expression_generator.current_scope_vars.clone(); - let mut compiled = gen.generate(&subjects, multipatterns, clause.guard.as_ref())?; - let consequence = gen + let scope = r#gen.expression_generator.current_scope_vars.clone(); + let mut compiled = + r#gen.generate(&subjects, multipatterns, clause.guard.as_ref())?; + let consequence = r#gen .expression_generator .expression_flattening_blocks(&clause.then)?; @@ -681,11 +684,11 @@ impl<'module> Generator<'module> { // Reset the scope now that this clause has finished, causing the // variables to go out of scope. - gen.expression_generator.current_scope_vars = scope; + r#gen.expression_generator.current_scope_vars = scope; // If the pattern assigns any variables we need to render assignments let body = if compiled.has_assignments() { - let assignments = gen + let assignments = r#gen .expression_generator .pattern_take_assignments_doc(&mut compiled); docvec![assignments, line(), consequence] @@ -719,7 +722,8 @@ impl<'module> Generator<'module> { " else if (" }) .append( - gen.expression_generator + r#gen + .expression_generator .pattern_take_checks_doc(&mut compiled, true), ) .append(") {") @@ -737,7 +741,7 @@ impl<'module> Generator<'module> { .zip(subject_values) .flat_map(|(assignment_name, value)| assignment_name.map(|name| (name, value))) .map(|(name, value)| { - let value = self.not_in_tail_position(|gen| gen.wrap_expression(value))?; + let value = self.not_in_tail_position(|r#gen| r#gen.wrap_expression(value))?; Ok(docvec!["let ", name, " = ", value, ";", line()]) }) .try_collect()?; @@ -752,7 +756,7 @@ impl<'module> Generator<'module> { message: Option<&'a TypedExpr>, ) -> Output<'a> { let message = match message { - Some(m) => self.not_in_tail_position(|gen| gen.expression(m))?, + Some(m) => self.not_in_tail_position(|r#gen| r#gen.expression(m))?, None => string("Pattern match failed, no pattern matched the value."), }; @@ -760,15 +764,19 @@ impl<'module> Generator<'module> { } fn tuple<'a>(&mut self, elements: &'a [TypedExpr]) -> Output<'a> { - self.not_in_tail_position(|gen| { - array(elements.iter().map(|element| gen.wrap_expression(element))) + self.not_in_tail_position(|r#gen| { + array( + elements + .iter() + .map(|element| r#gen.wrap_expression(element)), + ) }) } fn call<'a>(&mut self, fun: &'a TypedExpr, arguments: &'a [TypedCallArg]) -> Output<'a> { let arguments = arguments .iter() - .map(|element| self.not_in_tail_position(|gen| gen.wrap_expression(&element.value))) + .map(|element| self.not_in_tail_position(|r#gen| r#gen.wrap_expression(&element.value))) .try_collect()?; self.call_with_doc_args(fun, arguments) @@ -845,9 +853,9 @@ impl<'module> Generator<'module> { } _ => { - let fun = self.not_in_tail_position(|gen| { + let fun = self.not_in_tail_position(|r#gen| { let is_fn_literal = matches!(fun, TypedExpr::Fn { .. }); - let fun = gen.wrap_expression(fun)?; + let fun = r#gen.wrap_expression(fun)?; if is_fn_literal { Ok(docvec!["(", fun, ")"]) } else { @@ -902,8 +910,8 @@ impl<'module> Generator<'module> { } fn record_access<'a>(&mut self, record: &'a TypedExpr, label: &'a str) -> Output<'a> { - self.not_in_tail_position(|gen| { - let record = gen.wrap_expression(record)?; + self.not_in_tail_position(|r#gen| { + let record = r#gen.wrap_expression(record)?; Ok(docvec![record, ".", maybe_escape_property_doc(label)]) }) } @@ -915,15 +923,15 @@ impl<'module> Generator<'module> { args: &'a [TypedCallArg], ) -> Output<'a> { Ok(docvec![ - self.not_in_tail_position(|gen| gen.assignment(record))?, + self.not_in_tail_position(|r#gen| r#gen.assignment(record))?, line(), self.call(constructor, args)?, ]) } fn tuple_index<'a>(&mut self, tuple: &'a TypedExpr, index: u64) -> Output<'a> { - self.not_in_tail_position(|gen| { - let tuple = gen.wrap_expression(tuple)?; + self.not_in_tail_position(|r#gen| { + let tuple = r#gen.wrap_expression(tuple)?; Ok(docvec![tuple, eco_format!("[{index}]")]) }) } @@ -955,22 +963,22 @@ impl<'module> Generator<'module> { } fn div_int<'a>(&mut self, left: &'a TypedExpr, right: &'a TypedExpr) -> Output<'a> { - let left = self.not_in_tail_position(|gen| gen.child_expression(left))?; - let right = self.not_in_tail_position(|gen| gen.child_expression(right))?; + let left = self.not_in_tail_position(|r#gen| r#gen.child_expression(left))?; + let right = self.not_in_tail_position(|r#gen| r#gen.child_expression(right))?; self.tracker.int_division_used = true; Ok(docvec!["divideInt", wrap_args([left, right])]) } fn remainder_int<'a>(&mut self, left: &'a TypedExpr, right: &'a TypedExpr) -> Output<'a> { - let left = self.not_in_tail_position(|gen| gen.child_expression(left))?; - let right = self.not_in_tail_position(|gen| gen.child_expression(right))?; + let left = self.not_in_tail_position(|r#gen| r#gen.child_expression(left))?; + let right = self.not_in_tail_position(|r#gen| r#gen.child_expression(right))?; self.tracker.int_remainder_used = true; Ok(docvec!["remainderInt", wrap_args([left, right])]) } fn div_float<'a>(&mut self, left: &'a TypedExpr, right: &'a TypedExpr) -> Output<'a> { - let left = self.not_in_tail_position(|gen| gen.child_expression(left))?; - let right = self.not_in_tail_position(|gen| gen.child_expression(right))?; + let left = self.not_in_tail_position(|r#gen| r#gen.child_expression(left))?; + let right = self.not_in_tail_position(|r#gen| r#gen.child_expression(right))?; self.tracker.float_division_used = true; Ok(docvec!["divideFloat", wrap_args([left, right])]) } @@ -983,15 +991,15 @@ impl<'module> Generator<'module> { ) -> Output<'a> { // If it is a simple scalar type then we can use JS' reference identity if is_js_scalar(left.type_()) { - let left_doc = self.not_in_tail_position(|gen| gen.child_expression(left))?; - let right_doc = self.not_in_tail_position(|gen| gen.child_expression(right))?; + let left_doc = self.not_in_tail_position(|r#gen| r#gen.child_expression(left))?; + let right_doc = self.not_in_tail_position(|r#gen| r#gen.child_expression(right))?; let operator = if should_be_equal { " === " } else { " !== " }; return Ok(docvec![left_doc, operator, right_doc]); } // Other types must be compared using structural equality - let left = self.not_in_tail_position(|gen| gen.wrap_expression(left))?; - let right = self.not_in_tail_position(|gen| gen.wrap_expression(right))?; + let left = self.not_in_tail_position(|r#gen| r#gen.wrap_expression(left))?; + let right = self.not_in_tail_position(|r#gen| r#gen.wrap_expression(right))?; Ok(self.prelude_equal_call(should_be_equal, left, right)) } @@ -1019,14 +1027,14 @@ impl<'module> Generator<'module> { right: &'a TypedExpr, op: &'a str, ) -> Output<'a> { - let left = self.not_in_tail_position(|gen| gen.child_expression(left))?; - let right = self.not_in_tail_position(|gen| gen.child_expression(right))?; + let left = self.not_in_tail_position(|r#gen| r#gen.child_expression(left))?; + let right = self.not_in_tail_position(|r#gen| r#gen.child_expression(right))?; Ok(docvec![left, " ", op, " ", right]) } fn todo<'a>(&mut self, message: Option<&'a TypedExpr>, location: &'a SrcSpan) -> Output<'a> { let message = match message { - Some(m) => self.not_in_tail_position(|gen| gen.expression(m))?, + Some(m) => self.not_in_tail_position(|r#gen| r#gen.expression(m))?, None => string("`todo` expression evaluated. This code has not yet been implemented."), }; let doc = self.throw_error("todo", &message, *location, vec![]); @@ -1036,7 +1044,7 @@ impl<'module> Generator<'module> { fn panic<'a>(&mut self, location: &'a SrcSpan, message: Option<&'a TypedExpr>) -> Output<'a> { let message = match message { - Some(m) => self.not_in_tail_position(|gen| gen.expression(m))?, + Some(m) => self.not_in_tail_position(|r#gen| r#gen.expression(m))?, None => string("`panic` expression evaluated."), }; let doc = self.throw_error("panic", &message, *location, vec![]); diff --git a/compiler-core/src/javascript/import.rs b/compiler-core/src/javascript/import.rs index f982d496fdd..354cc2cc609 100644 --- a/compiler-core/src/javascript/import.rs +++ b/compiler-core/src/javascript/import.rs @@ -5,8 +5,8 @@ use itertools::Itertools; use crate::{ docvec, - javascript::{JavaScriptCodegenTarget, INDENT}, - pretty::{break_, concat, join, line, Document, Documentable}, + javascript::{INDENT, JavaScriptCodegenTarget}, + pretty::{Document, Documentable, break_, concat, join, line}, }; /// A collection of JavaScript import statements from Gleam imports and from diff --git a/compiler-core/src/javascript/pattern.rs b/compiler-core/src/javascript/pattern.rs index eb79f6cf7bb..e6a7413bd6e 100644 --- a/compiler-core/src/javascript/pattern.rs +++ b/compiler-core/src/javascript/pattern.rs @@ -418,7 +418,7 @@ impl<'module_ctx, 'expression_gen, 'a> Generator<'module_ctx, 'expression_gen, ' &mut self.assignments, self.expression_generator.tracker, constant, - ) + ); } }) } diff --git a/compiler-core/src/javascript/tests.rs b/compiler-core/src/javascript/tests.rs index a9449072d98..4608e0a63e6 100644 --- a/compiler-core/src/javascript/tests.rs +++ b/compiler-core/src/javascript/tests.rs @@ -51,7 +51,7 @@ macro_rules! assert_js_with_multiple_imports { #[macro_export] macro_rules! assert_js { - (($dep_package:expr, $dep_name:expr, $dep_src:expr), $src:expr $(,)?) => {{ + (($dep_package:expr_2021, $dep_name:expr_2021, $dep_src:expr_2021), $src:expr_2021 $(,)?) => {{ let compiled = $crate::javascript::tests::compile_js($src, vec![($dep_package, $dep_name, $dep_src)]) .expect("compilation failed"); @@ -62,14 +62,14 @@ macro_rules! assert_js { insta::assert_snapshot!(insta::internals::AutoName, output, $src); }}; - (($dep_package:expr, $dep_name:expr, $dep_src:expr), $src:expr, $js:expr $(,)?) => {{ + (($dep_package:expr_2021, $dep_name:expr_2021, $dep_src:expr_2021), $src:expr_2021, $js:expr_2021 $(,)?) => {{ let output = $crate::javascript::tests::compile_js($src, Some(($dep_package, $dep_name, $dep_src))) .expect("compilation failed"); assert_eq!(($src, output), ($src, $js.to_string())); }}; - ($src:expr $(,)?) => {{ + ($src:expr_2021 $(,)?) => {{ let compiled = $crate::javascript::tests::compile_js($src, vec![]).expect("compilation failed"); let output = format!( @@ -79,7 +79,7 @@ macro_rules! assert_js { insta::assert_snapshot!(insta::internals::AutoName, output, $src); }}; - ($src:expr, $js:expr $(,)?) => {{ + ($src:expr_2021, $js:expr_2021 $(,)?) => {{ let output = $crate::javascript::tests::compile_js($src, vec![]).expect("compilation failed"); assert_eq!(($src, output), ($src, $js.to_string())); @@ -88,7 +88,7 @@ macro_rules! assert_js { #[macro_export] macro_rules! assert_js_error { - ($src:expr $(,)?) => {{ + ($src:expr_2021 $(,)?) => {{ let error = $crate::javascript::tests::expect_js_error($src, vec![]); let output = format!("----- SOURCE CODE\n{}\n\n----- ERROR\n{}", $src, error); insta::assert_snapshot!(insta::internals::AutoName, output, $src); @@ -97,7 +97,7 @@ macro_rules! assert_js_error { #[macro_export] macro_rules! assert_ts_def { - (($dep_1_package:expr, $dep_1_name:expr, $dep_1_src:expr), ($dep_2_package:expr, $dep_2_name:expr, $dep_2_src:expr), $src:expr $(,)?) => {{ + (($dep_1_package:expr_2021, $dep_1_name:expr_2021, $dep_1_src:expr_2021), ($dep_2_package:expr_2021, $dep_2_name:expr_2021, $dep_2_src:expr_2021), $src:expr_2021 $(,)?) => {{ let compiled = $crate::javascript::tests::compile_ts( $src, vec![ @@ -113,7 +113,7 @@ macro_rules! assert_ts_def { insta::assert_snapshot!(insta::internals::AutoName, output, $src); }}; - (($dep_package:expr, $dep_name:expr, $dep_src:expr), $src:expr $(,)?) => {{ + (($dep_package:expr_2021, $dep_name:expr_2021, $dep_src:expr_2021), $src:expr_2021 $(,)?) => {{ let compiled = $crate::javascript::tests::compile_ts($src, vec![($dep_package, $dep_name, $dep_src)]) .expect("compilation failed"); @@ -124,7 +124,7 @@ macro_rules! assert_ts_def { insta::assert_snapshot!(insta::internals::AutoName, output, $src); }}; - ($src:expr $(,)?) => {{ + ($src:expr_2021 $(,)?) => {{ let compiled = $crate::javascript::tests::compile_ts($src, vec![]).expect("compilation failed"); let output = format!( diff --git a/compiler-core/src/javascript/typescript.rs b/compiler-core/src/javascript/typescript.rs index ab4a4a709b1..e91e1e16dcb 100644 --- a/compiler-core/src/javascript/typescript.rs +++ b/compiler-core/src/javascript/typescript.rs @@ -12,7 +12,7 @@ //! use crate::ast::{AssignName, Publicity}; -use crate::type_::{is_prelude_module, PRELUDE_MODULE_NAME}; +use crate::type_::{PRELUDE_MODULE_NAME, is_prelude_module}; use crate::{ ast::{ CustomType, Definition, Function, Import, ModuleConstant, TypeAlias, TypedArg, @@ -20,14 +20,14 @@ use crate::{ }, docvec, javascript::JavaScriptCodegenTarget, - pretty::{break_, Document, Documentable}, + pretty::{Document, Documentable, break_}, type_::{Type, TypeVar}, }; -use ecow::{eco_format, EcoString}; +use ecow::{EcoString, eco_format}; use itertools::Itertools; use std::{collections::HashMap, ops::Deref, sync::Arc}; -use super::{import::Imports, join, line, lines, wrap_args, Output, INDENT}; +use super::{INDENT, Output, import::Imports, join, line, lines, wrap_args}; /// When rendering a type variable to an TypeScript type spec we need all type /// variables with the same id to end up with the same name in the generated diff --git a/compiler-core/src/language_server.rs b/compiler-core/src/language_server.rs index abd34284ffb..eda3ebb8e9a 100644 --- a/compiler-core/src/language_server.rs +++ b/compiler-core/src/language_server.rs @@ -18,8 +18,8 @@ mod tests; pub use server::LanguageServer; use crate::{ - ast::SrcSpan, build::Target, line_numbers::LineNumbers, manifest::Manifest, - paths::ProjectPaths, Result, + Result, ast::SrcSpan, build::Target, line_numbers::LineNumbers, manifest::Manifest, + paths::ProjectPaths, }; use camino::Utf8PathBuf; use lsp_types::{Position, Range, TextEdit, Url}; diff --git a/compiler-core/src/language_server/code_action.rs b/compiler-core/src/language_server/code_action.rs index 9826c2fd40d..8262b02c5b0 100644 --- a/compiler-core/src/language_server/code_action.rs +++ b/compiler-core/src/language_server/code_action.rs @@ -1,39 +1,38 @@ use std::{collections::HashSet, iter, sync::Arc}; use crate::{ + Error, STDLIB_PACKAGE_NAME, ast::{ - self, - visit::{visit_typed_call_arg, visit_typed_pattern_call_arg, Visit as _}, - AssignName, AssignmentKind, CallArg, FunctionLiteralKind, ImplicitCallArgOrigin, Pattern, - PipelineAssignmentKind, SrcSpan, TodoKind, TypedArg, TypedAssignment, TypedExpr, + self, AssignName, AssignmentKind, CallArg, FunctionLiteralKind, ImplicitCallArgOrigin, + Pattern, PipelineAssignmentKind, SrcSpan, TodoKind, TypedArg, TypedAssignment, TypedExpr, TypedModuleConstant, TypedPattern, TypedPipelineAssignment, TypedRecordConstructor, TypedStatement, TypedUse, + visit::{Visit as _, visit_typed_call_arg, visit_typed_pattern_call_arg}, }, build::{Located, Module}, io::{BeamCompiler, CommandExecutor, FileSystemReader, FileSystemWriter}, line_numbers::LineNumbers, parse::{extra::ModuleExtra, lexer::str_to_keyword}, type_::{ - self, + self, FieldMap, ModuleValueConstructor, Type, TypeVar, TypedCallArg, ValueConstructor, error::{ModuleSuggestion, VariableOrigin}, printer::{Names, Printer}, - FieldMap, ModuleValueConstructor, Type, TypeVar, TypedCallArg, ValueConstructor, }, - Error, STDLIB_PACKAGE_NAME, }; -use ecow::{eco_format, EcoString}; +use ecow::{EcoString, eco_format}; use heck::ToSnakeCase; use im::HashMap; use itertools::Itertools; use lsp_types::{CodeAction, CodeActionKind, CodeActionParams, Position, Range, TextEdit, Url}; -use vec1::{vec1, Vec1}; +use vec1::{Vec1, vec1}; use super::{ + TextEdits, compiler::LspProjectCompiler, edits::{add_newlines_after_import, get_import_edit, position_of_first_definition_if_import}, engine::{overlaps, within}, rename::find_variable_references, - src_span_to_lsp_range, TextEdits, + src_span_to_lsp_range, }; #[derive(Debug)] @@ -867,10 +866,9 @@ pub fn code_action_import_module( )) }; - let title = if let Some(import) = &suggestion.import { - &format!("Import `{import}`") - } else { - &format!("Did you mean `{}`", suggestion.name) + let title = match &suggestion.import { + Some(import) => &format!("Import `{import}`"), + _ => &format!("Did you mean `{}`", suggestion.name), }; CodeActionBuilder::new(title) @@ -3190,7 +3188,7 @@ impl RecordLabel<'_> { fn variable_name(&self) -> EcoString { match self { RecordLabel::Labeled(label) => (*label).into(), - RecordLabel::Unlabeled(mut index) => { + &RecordLabel::Unlabeled(mut index) => { let mut characters = Vec::new(); let alphabet_length = 26; let alphabet_offset = b'a'; @@ -3231,58 +3229,71 @@ impl<'a> DecoderPrinter<'a> { eco_format!("{module_name}.int") } else if type_.is_string() { eco_format!("{module_name}.string") - } else if let Some(types) = type_.tuple_types() { - let fields = types - .iter() - .enumerate() - .map(|(index, type_)| RecordField { - type_, - label: RecordLabel::Unlabeled(index), - }) - .collect_vec(); - let decoders = fields - .iter() - .map(|field| self.decode_field(field, indent + 2)) - .join("\n"); - let mut field_names = fields.iter().map(|field| field.label.variable_name()); + } else { + match type_.tuple_types() { + Some(types) => { + let fields = types + .iter() + .enumerate() + .map(|(index, type_)| RecordField { + type_, + label: RecordLabel::Unlabeled(index), + }) + .collect_vec(); + let decoders = fields + .iter() + .map(|field| self.decode_field(field, indent + 2)) + .join("\n"); + let mut field_names = fields.iter().map(|field| field.label.variable_name()); - eco_format!( - "{{ + eco_format!( + "{{ {decoders} {indent} {module_name}.success(#({fields})) {indent}}}", - fields = field_names.join(", "), - indent = " ".repeat(indent) - ) - } else { - let type_information = type_.named_type_information(); - let type_information = type_information.as_ref().map(|(module, name, arguments)| { - (module.as_str(), name.as_str(), arguments.as_slice()) - }); - - match type_information { - Some(("gleam/dynamic", "Dynamic", _)) => eco_format!("{module_name}.dynamic"), - Some(("gleam", "List", [element])) => { - eco_format!("{module_name}.list({})", self.decoder_for(element, indent)) - } - Some(("gleam/option", "Option", [some])) => { - eco_format!("{module_name}.optional({})", self.decoder_for(some, indent)) - } - Some(("gleam/dict", "Dict", [key, value])) => { - eco_format!( - "{module_name}.dict({}, {})", - self.decoder_for(key, indent), - self.decoder_for(value, indent) + fields = field_names.join(", "), + indent = " ".repeat(indent) ) } - Some((module, name, _)) if module == self.type_module && name == self.type_name => { - eco_format!("{}_decoder()", name.to_snake_case()) + _ => { + let type_information = type_.named_type_information(); + let type_information = + type_information.as_ref().map(|(module, name, arguments)| { + (module.as_str(), name.as_str(), arguments.as_slice()) + }); + + match type_information { + Some(("gleam/dynamic", "Dynamic", _)) => { + eco_format!("{module_name}.dynamic") + } + Some(("gleam", "List", [element])) => { + eco_format!("{module_name}.list({})", self.decoder_for(element, indent)) + } + Some(("gleam/option", "Option", [some])) => { + eco_format!( + "{module_name}.optional({})", + self.decoder_for(some, indent) + ) + } + Some(("gleam/dict", "Dict", [key, value])) => { + eco_format!( + "{module_name}.dict({}, {})", + self.decoder_for(key, indent), + self.decoder_for(value, indent) + ) + } + Some((module, name, _)) + if module == self.type_module && name == self.type_name => + { + eco_format!("{}_decoder()", name.to_snake_case()) + } + _ => eco_format!( + r#"todo as "Decoder for {}""#, + self.printer.print_type(type_) + ), + } } - _ => eco_format!( - r#"todo as "Decoder for {}""#, - self.printer.print_type(type_) - ), } } } @@ -3508,94 +3519,102 @@ impl<'a> EncoderPrinter<'a> { maybe_capture(eco_format!("{module_name}.int")) } else if type_.is_string() { maybe_capture(eco_format!("{module_name}.string")) - } else if let Some(types) = type_.tuple_types() { - let (tuple, new_indent) = if is_capture { - ("value", indent + 4) - } else { - (encoded_value, indent + 2) - }; + } else { + match type_.tuple_types() { + Some(types) => { + let (tuple, new_indent) = if is_capture { + ("value", indent + 4) + } else { + (encoded_value, indent + 2) + }; - let encoders = types - .iter() - .enumerate() - .map(|(index, type_)| { - self.encoder_for(&format!("{tuple}.{index}"), type_, new_indent) - }) - .collect_vec(); + let encoders = types + .iter() + .enumerate() + .map(|(index, type_)| { + self.encoder_for(&format!("{tuple}.{index}"), type_, new_indent) + }) + .collect_vec(); - if is_capture { - eco_format!( - "fn(value) {{ + if is_capture { + eco_format!( + "fn(value) {{ {indent} {module_name}.preprocessed_array([ {indent} {encoders}, {indent} ]) {indent}}}", - indent = " ".repeat(indent), - encoders = encoders.join(&format!(",\n{}", " ".repeat(new_indent))), - ) - } else { - eco_format!( - "{module_name}.preprocessed_array([ + indent = " ".repeat(indent), + encoders = encoders.join(&format!(",\n{}", " ".repeat(new_indent))), + ) + } else { + eco_format!( + "{module_name}.preprocessed_array([ {indent} {encoders}, {indent}])", - indent = " ".repeat(indent), - encoders = encoders.join(&format!(",\n{}", " ".repeat(new_indent))), - ) - } - } else { - let type_information = type_.named_type_information(); - let type_information: Option<(&str, &str, &[Arc])> = - type_information.as_ref().map(|(module, name, arguments)| { - (module.as_str(), name.as_str(), arguments.as_slice()) - }); - - match type_information { - Some(("gleam", "List", [element])) => { - eco_format!( - "{module_name}.array({encoded_value}, {map_function})", - map_function = self.encoder_for("_", element, indent) - ) + indent = " ".repeat(indent), + encoders = encoders.join(&format!(",\n{}", " ".repeat(new_indent))), + ) + } } - Some(("gleam/option", "Option", [some])) => { - eco_format!( - "case {encoded_value} {{ + _ => { + let type_information = type_.named_type_information(); + let type_information: Option<(&str, &str, &[Arc])> = + type_information.as_ref().map(|(module, name, arguments)| { + (module.as_str(), name.as_str(), arguments.as_slice()) + }); + + match type_information { + Some(("gleam", "List", [element])) => { + eco_format!( + "{module_name}.array({encoded_value}, {map_function})", + map_function = self.encoder_for("_", element, indent) + ) + } + Some(("gleam/option", "Option", [some])) => { + eco_format!( + "case {encoded_value} {{ {indent} {none} -> {module_name}.null() {indent} {some}(value) -> {encoder} {indent}}}", - indent = " ".repeat(indent), - none = self - .printer - .print_constructor(&"gleam/option".into(), &"None".into()), - some = self - .printer - .print_constructor(&"gleam/option".into(), &"Some".into()), - encoder = self.encoder_for("value", some, indent + 2) - ) - } - Some(("gleam/dict", "Dict", [key, value])) => { - let stringify_function = match key.named_type_information().as_ref().map( - |(module, name, arguments)| { - (module.as_str(), name.as_str(), arguments.as_slice()) - }, - ) { - Some(("gleam", "String", [])) => "fn(string) { string }", - _ => &format!( - r#"todo as "Function to stringify {}""#, - self.printer.print_type(key) + indent = " ".repeat(indent), + none = self + .printer + .print_constructor(&"gleam/option".into(), &"None".into()), + some = self + .printer + .print_constructor(&"gleam/option".into(), &"Some".into()), + encoder = self.encoder_for("value", some, indent + 2) + ) + } + Some(("gleam/dict", "Dict", [key, value])) => { + let stringify_function = match key + .named_type_information() + .as_ref() + .map(|(module, name, arguments)| { + (module.as_str(), name.as_str(), arguments.as_slice()) + }) { + Some(("gleam", "String", [])) => "fn(string) { string }", + _ => &format!( + r#"todo as "Function to stringify {}""#, + self.printer.print_type(key) + ), + }; + eco_format!( + "{module_name}.dict({encoded_value}, {stringify_function}, {})", + self.encoder_for("_", value, indent) + ) + } + Some((module, name, _)) + if module == self.type_module && name == self.type_name => + { + maybe_capture(eco_format!("encode_{}", name.to_snake_case())) + } + _ => eco_format!( + r#"todo as "Encoder for {}""#, + self.printer.print_type(type_) ), - }; - eco_format!( - "{module_name}.dict({encoded_value}, {stringify_function}, {})", - self.encoder_for("_", value, indent) - ) - } - Some((module, name, _)) if module == self.type_module && name == self.type_name => { - maybe_capture(eco_format!("encode_{}", name.to_snake_case())) + } } - _ => eco_format!( - r#"todo as "Encoder for {}""#, - self.printer.print_type(type_) - ), } } } diff --git a/compiler-core/src/language_server/compiler.rs b/compiler-core/src/language_server/compiler.rs index 1ce81954f1e..582c8060403 100644 --- a/compiler-core/src/language_server/compiler.rs +++ b/compiler-core/src/language_server/compiler.rs @@ -3,6 +3,7 @@ use ecow::EcoString; use itertools::Itertools; use crate::{ + Error, Result, Warning, analyse::TargetSupport, build::{self, Mode, Module, NullTelemetry, Outcome, ProjectCompiler}, config::PackageConfig, @@ -13,7 +14,6 @@ use crate::{ paths::ProjectPaths, type_::ModuleInterface, warning::VectorWarningEmitterIO, - Error, Result, Warning, }; use std::{collections::HashMap, rc::Rc}; diff --git a/compiler-core/src/language_server/completer.rs b/compiler-core/src/language_server/completer.rs index 9dd9237ac48..4b606411e9b 100644 --- a/compiler-core/src/language_server/completer.rs +++ b/compiler-core/src/language_server/completer.rs @@ -11,6 +11,7 @@ use strum::IntoEnumIterator; use vec1::Vec1; use crate::{ + Result, ast::{ self, Arg, CallArg, Definition, Function, FunctionLiteralKind, Pattern, Publicity, TypedExpr, @@ -19,21 +20,20 @@ use crate::{ io::{BeamCompiler, CommandExecutor, FileSystemReader, FileSystemWriter}, line_numbers::LineNumbers, type_::{ - self, collapse_links, error::VariableOrigin, pretty::Printer, FieldMap, ModuleInterface, - PreludeType, RecordAccessor, Type, TypeConstructor, ValueConstructorVariant, - PRELUDE_MODULE_NAME, + self, FieldMap, ModuleInterface, PRELUDE_MODULE_NAME, PreludeType, RecordAccessor, Type, + TypeConstructor, ValueConstructorVariant, collapse_links, error::VariableOrigin, + pretty::Printer, }, - Result, }; use super::{ + DownloadDependencies, MakeLocker, compiler::LspProjectCompiler, edits::{ - add_newlines_after_import, get_import, get_import_edit, - position_of_first_definition_if_import, Newlines, + Newlines, add_newlines_after_import, get_import, get_import_edit, + position_of_first_definition_if_import, }, files::FileSystemProxy, - DownloadDependencies, MakeLocker, }; // Represents the kind/specificity of completion that is being requested. diff --git a/compiler-core/src/language_server/engine.rs b/compiler-core/src/language_server/engine.rs index f7524d0fa8d..a3e781bae5a 100644 --- a/compiler-core/src/language_server/engine.rs +++ b/compiler-core/src/language_server/engine.rs @@ -1,10 +1,11 @@ use crate::{ + Error, Result, Warning, analyse::name::correct_name_case, ast::{ ArgNames, CustomType, Definition, DefinitionLocation, ModuleConstant, Pattern, SrcSpan, TypedArg, TypedExpr, TypedFunction, TypedModule, TypedPattern, }, - build::{type_constructor_from_modules, Located, Module, UnqualifiedImport}, + build::{Located, Module, UnqualifiedImport, type_constructor_from_modules}, config::PackageConfig, io::{BeamCompiler, CommandExecutor, FileSystemReader, FileSystemWriter}, language_server::{ @@ -13,10 +14,9 @@ use crate::{ line_numbers::LineNumbers, paths::ProjectPaths, type_::{ - self, error::VariableOrigin, printer::Printer, Deprecation, ModuleInterface, Type, - TypeConstructor, ValueConstructor, ValueConstructorVariant, + self, Deprecation, ModuleInterface, Type, TypeConstructor, ValueConstructor, + ValueConstructorVariant, error::VariableOrigin, printer::Printer, }, - Error, Result, Warning, }; use camino::Utf8PathBuf; use ecow::EcoString; @@ -30,18 +30,19 @@ use lsp_types::{ use std::sync::Arc; use super::{ + DownloadDependencies, MakeLocker, code_action::{ + AddAnnotations, CodeActionBuilder, ConvertFromUse, ConvertToFunctionCall, ConvertToPipe, + ConvertToUse, ExpandFunctionCapture, ExtractVariable, FillInMissingLabelledArgs, + GenerateDynamicDecoder, GenerateFunction, GenerateJsonEncoder, InlineVariable, + LetAssertToCase, PatternMatchOnValue, RedundantTupleInCaseSubject, UseLabelShorthandSyntax, code_action_add_missing_patterns, code_action_convert_qualified_constructor_to_unqualified, code_action_convert_unqualified_constructor_to_qualified, code_action_import_module, - code_action_inexhaustive_let_to_case, AddAnnotations, CodeActionBuilder, ConvertFromUse, - ConvertToFunctionCall, ConvertToPipe, ConvertToUse, ExpandFunctionCapture, ExtractVariable, - FillInMissingLabelledArgs, GenerateDynamicDecoder, GenerateFunction, GenerateJsonEncoder, - InlineVariable, LetAssertToCase, PatternMatchOnValue, RedundantTupleInCaseSubject, - UseLabelShorthandSyntax, + code_action_inexhaustive_let_to_case, }, completer::Completer, - rename::{rename_local_variable, VariableRenameKind}, - signature_help, src_span_to_lsp_range, DownloadDependencies, MakeLocker, + rename::{VariableRenameKind, rename_local_variable}, + signature_help, src_span_to_lsp_range, }; #[derive(Debug, PartialEq, Eq)] diff --git a/compiler-core/src/language_server/feedback.rs b/compiler-core/src/language_server/feedback.rs index 8f50b16df59..1f9ba92a256 100644 --- a/compiler-core/src/language_server/feedback.rs +++ b/compiler-core/src/language_server/feedback.rs @@ -1,4 +1,4 @@ -use crate::{diagnostic::Diagnostic, Error, Warning}; +use crate::{Error, Warning, diagnostic::Diagnostic}; use std::collections::{HashMap, HashSet}; use camino::Utf8PathBuf; diff --git a/compiler-core/src/language_server/files.rs b/compiler-core/src/language_server/files.rs index 1aac5061df9..774864bc0ef 100644 --- a/compiler-core/src/language_server/files.rs +++ b/compiler-core/src/language_server/files.rs @@ -4,12 +4,12 @@ use std::time::SystemTime; use debug_ignore::DebugIgnore; use crate::{ + Result, error::Error, io::{ - memory::InMemoryFileSystem, BeamCompiler, Command, CommandExecutor, FileSystemReader, - FileSystemWriter, ReadDir, Stdio, WrappedReader, + BeamCompiler, Command, CommandExecutor, FileSystemReader, FileSystemWriter, ReadDir, Stdio, + WrappedReader, memory::InMemoryFileSystem, }, - Result, }; use camino::{Utf8Path, Utf8PathBuf}; diff --git a/compiler-core/src/language_server/rename.rs b/compiler-core/src/language_server/rename.rs index bbf70096d40..17f5d3537df 100644 --- a/compiler-core/src/language_server/rename.rs +++ b/compiler-core/src/language_server/rename.rs @@ -5,10 +5,10 @@ use lsp_types::{RenameParams, TextEdit, Url, WorkspaceEdit}; use crate::{ analyse::name, - ast::{self, visit::Visit, SrcSpan, TypedModule}, + ast::{self, SrcSpan, TypedModule, visit::Visit}, build::Module, line_numbers::LineNumbers, - type_::{error::Named, ValueConstructor, ValueConstructorVariant}, + type_::{ValueConstructor, ValueConstructorVariant, error::Named}, }; use super::TextEdits; diff --git a/compiler-core/src/language_server/router.rs b/compiler-core/src/language_server/router.rs index 4a2047860df..8cbab2456ae 100644 --- a/compiler-core/src/language_server/router.rs +++ b/compiler-core/src/language_server/router.rs @@ -1,16 +1,16 @@ use crate::{ + Error, Result, build::SourceFingerprint, error::{FileIoAction, FileKind}, io::{BeamCompiler, CommandExecutor, FileSystemReader, FileSystemWriter}, language_server::{ - engine::LanguageServerEngine, files::FileSystemProxy, progress::ProgressReporter, - DownloadDependencies, MakeLocker, + DownloadDependencies, MakeLocker, engine::LanguageServerEngine, files::FileSystemProxy, + progress::ProgressReporter, }, paths::ProjectPaths, - Error, Result, }; use std::{ - collections::{hash_map::Entry, HashMap}, + collections::{HashMap, hash_map::Entry}, time::SystemTime, }; @@ -194,7 +194,7 @@ pub(crate) struct Project { #[cfg(test)] mod find_gleam_project_parent_tests { use super::*; - use crate::io::{memory::InMemoryFileSystem, FileSystemWriter}; + use crate::io::{FileSystemWriter, memory::InMemoryFileSystem}; #[test] fn root() { diff --git a/compiler-core/src/language_server/server.rs b/compiler-core/src/language_server/server.rs index e9e851e8ba4..a2948ab7d64 100644 --- a/compiler-core/src/language_server/server.rs +++ b/compiler-core/src/language_server/server.rs @@ -3,17 +3,18 @@ use super::{ progress::ConnectionProgressReporter, }; use crate::{ + Result, diagnostic::{Diagnostic, Level}, io::{BeamCompiler, CommandExecutor, FileSystemReader, FileSystemWriter}, language_server::{ + DownloadDependencies, MakeLocker, engine::{self, LanguageServerEngine}, feedback::{Feedback, FeedbackBookKeeper}, files::FileSystemProxy, router::Router, - src_span_to_lsp_range, DownloadDependencies, MakeLocker, + src_span_to_lsp_range, }, line_numbers::LineNumbers, - Result, }; use camino::{Utf8Path, Utf8PathBuf}; use debug_ignore::DebugIgnore; @@ -509,17 +510,18 @@ fn diagnostic_to_lsp(diagnostic: Diagnostic) -> Vec { .iter() .map(|extra| { let message = extra.label.text.clone().unwrap_or_default(); - let location = if let Some((src, path)) = &extra.src_info { - let line_numbers = LineNumbers::new(src); - lsp::Location { - uri: path_to_uri(path.clone()), - range: src_span_to_lsp_range(extra.label.span, &line_numbers), + let location = match &extra.src_info { + Some((src, path)) => { + let line_numbers = LineNumbers::new(src); + lsp::Location { + uri: path_to_uri(path.clone()), + range: src_span_to_lsp_range(extra.label.span, &line_numbers), + } } - } else { - lsp::Location { + _ => lsp::Location { uri: path.clone(), range: src_span_to_lsp_range(extra.label.span, &line_numbers), - } + }, }; lsp::DiagnosticRelatedInformation { location, message } }) diff --git a/compiler-core/src/language_server/signature_help.rs b/compiler-core/src/language_server/signature_help.rs index df1e0564771..dfb17d5c090 100644 --- a/compiler-core/src/language_server/signature_help.rs +++ b/compiler-core/src/language_server/signature_help.rs @@ -11,7 +11,7 @@ use lsp_types::{ use crate::{ ast::{CallArg, ImplicitCallArgOrigin, TypedExpr}, - type_::{pretty::Printer, FieldMap, ModuleValueConstructor, Type}, + type_::{FieldMap, ModuleValueConstructor, Type, pretty::Printer}, }; pub fn for_expression(expr: &TypedExpr) -> Option { diff --git a/compiler-core/src/language_server/tests.rs b/compiler-core/src/language_server/tests.rs index e670c03959f..90fd9b1361d 100644 --- a/compiler-core/src/language_server/tests.rs +++ b/compiler-core/src/language_server/tests.rs @@ -21,20 +21,20 @@ use itertools::Itertools; use lsp_types::{Position, TextDocumentIdentifier, TextDocumentPositionParams, Url}; use crate::{ + Result, config::PackageConfig, io::{ - memory::InMemoryFileSystem, BeamCompiler, Command, CommandExecutor, FileSystemReader, - FileSystemWriter, ReadDir, WrappedReader, + BeamCompiler, Command, CommandExecutor, FileSystemReader, FileSystemWriter, ReadDir, + WrappedReader, memory::InMemoryFileSystem, }, language_server::{ - engine::LanguageServerEngine, files::FileSystemProxy, progress::ProgressReporter, - DownloadDependencies, LockGuard, Locker, MakeLocker, + DownloadDependencies, LockGuard, Locker, MakeLocker, engine::LanguageServerEngine, + files::FileSystemProxy, progress::ProgressReporter, }, line_numbers::LineNumbers, manifest::{Base16Checksum, Manifest, ManifestPackage, ManifestPackageSource}, paths::ProjectPaths, requirement::Requirement, - Result, }; pub const LSP_TEST_ROOT_PACKAGE_NAME: &str = "app"; diff --git a/compiler-core/src/language_server/tests/action.rs b/compiler-core/src/language_server/tests/action.rs index 6dd59889585..0d8b1188401 100644 --- a/compiler-core/src/language_server/tests/action.rs +++ b/compiler-core/src/language_server/tests/action.rs @@ -80,12 +80,12 @@ const INLINE_VARIABLE: &str = "Inline variable"; const CONVERT_TO_PIPE: &str = "Convert to pipe"; macro_rules! assert_code_action { - ($title:expr, $code:literal, $range:expr $(,)?) => { + ($title:expr_2021, $code:literal, $range:expr_2021 $(,)?) => { let project = TestProject::for_source($code); assert_code_action!($title, project, $range); }; - ($title:expr, $project:expr, $range:expr $(,)?) => { + ($title:expr_2021, $project:expr_2021, $range:expr_2021 $(,)?) => { let src = $project.src; let range = $range.find_range(src); let result = apply_code_action($title, $project, range); @@ -99,12 +99,12 @@ macro_rules! assert_code_action { } macro_rules! assert_no_code_actions { - ($title:ident $(| $titles:ident)*, $code:literal, $range:expr $(,)?) => { + ($title:ident $(| $titles:ident)*, $code:literal, $range:expr_2021 $(,)?) => { let project = TestProject::for_source($code); assert_no_code_actions!($title $(| $titles)*, project, $range); }; - ($title:ident $(| $titles:ident)*, $project:expr, $range:expr $(,)?) => { + ($title:ident $(| $titles:ident)*, $project:expr_2021, $range:expr_2021 $(,)?) => { let src = $project.src; let range = $range.find_range(src); let all_titles = vec![$title $(, $titles)*]; @@ -4513,8 +4513,8 @@ pub fn main(arg: CannotBeDestructured) { } #[test] -fn pattern_match_on_argument_with_multiple_constructors_is_nicely_formatted_in_function_with_empty_body( -) { +fn pattern_match_on_argument_with_multiple_constructors_is_nicely_formatted_in_function_with_empty_body() + { assert_code_action!( PATTERN_MATCH_ON_ARGUMENT, " diff --git a/compiler-core/src/language_server/tests/completion.rs b/compiler-core/src/language_server/tests/completion.rs index 91aefeb0d25..4cab4e43a21 100644 --- a/compiler-core/src/language_server/tests/completion.rs +++ b/compiler-core/src/language_server/tests/completion.rs @@ -37,7 +37,7 @@ fn apply_conversion(src: &str, completions: Vec, value: &str) -> #[macro_export] macro_rules! assert_apply_completion { - ($project:expr, $name:literal, $position:expr) => { + ($project:expr_2021, $name:literal, $position:expr_2021) => { let src = $project.src; let completions = completion($project, $position); let output = format!( @@ -51,7 +51,7 @@ macro_rules! assert_apply_completion { #[macro_export] macro_rules! assert_completion { - ($project:expr) => { + ($project:expr_2021) => { let src = $project.src; let result = completion_with_prefix($project, ""); let output = format!( @@ -61,7 +61,7 @@ macro_rules! assert_completion { ); insta::assert_snapshot!(insta::internals::AutoName, output, src); }; - ($project:expr, $position:expr) => { + ($project:expr_2021, $position:expr_2021) => { let src = $project.src; let result = completion($project, $position); let output = format!( @@ -75,7 +75,7 @@ macro_rules! assert_completion { #[macro_export] macro_rules! assert_completion_with_prefix { - ($project:expr, $prefix:expr) => { + ($project:expr_2021, $prefix:expr_2021) => { let src = $project.src; let result = completion_with_prefix($project, $prefix); let line = 1 + $prefix.lines().count(); @@ -332,9 +332,11 @@ pub fn wobble() { } "; - assert_completion!(TestProject::for_source(code) - .add_module("dep", dep) - .add_module("dep2", dep2)); + assert_completion!( + TestProject::for_source(code) + .add_module("dep", dep) + .add_module("dep2", dep2) + ); } #[test] @@ -393,9 +395,11 @@ fn importable_adds_extra_new_line_if_import_exists_below_other_definitions() { let dep = "pub fn wobble() {\nNil\n}"; let code = "\nimport dep2\n"; // "code" goes after "fn typing_in_here() {}". - assert_completion!(TestProject::for_source(code) - .add_module("dep", dep) - .add_module("dep2", "")); + assert_completion!( + TestProject::for_source(code) + .add_module("dep", dep) + .add_module("dep2", "") + ); } #[test] diff --git a/compiler-core/src/language_server/tests/definition.rs b/compiler-core/src/language_server/tests/definition.rs index 0acfae5cb0d..59a137d5f42 100644 --- a/compiler-core/src/language_server/tests/definition.rs +++ b/compiler-core/src/language_server/tests/definition.rs @@ -1,5 +1,5 @@ use lsp_types::{ - request::GotoTypeDefinitionParams, GotoDefinitionParams, Location, Position, Range, Url, + GotoDefinitionParams, Location, Position, Range, Url, request::GotoTypeDefinitionParams, }; use super::*; @@ -94,11 +94,11 @@ fn jump_locations_to_string( #[macro_export] macro_rules! assert_goto { - ($src:literal, $position:expr) => { + ($src:literal, $position:expr_2021) => { let project = TestProject::for_source($src); assert_goto!(project, $position); }; - ($project:expr, $position:expr) => { + ($project:expr_2021, $position:expr_2021) => { let output = pretty_definition($project, $position); insta::assert_snapshot!(insta::internals::AutoName, output); }; @@ -106,11 +106,11 @@ macro_rules! assert_goto { #[macro_export] macro_rules! assert_goto_type { - ($src:literal, $position:expr) => { + ($src:literal, $position:expr_2021) => { let project = TestProject::for_source($src); assert_goto_type!(project, $position); }; - ($project:expr, $position:expr) => { + ($project:expr_2021, $position:expr_2021) => { let output = pretty_type_definition($project, $position); insta::assert_snapshot!(insta::internals::AutoName, output); }; diff --git a/compiler-core/src/language_server/tests/hover.rs b/compiler-core/src/language_server/tests/hover.rs index 68634c2c673..b2176be13fb 100644 --- a/compiler-core/src/language_server/tests/hover.rs +++ b/compiler-core/src/language_server/tests/hover.rs @@ -51,12 +51,12 @@ pub fn show_hover(code: &str, range: Range, position: Position) -> String { #[macro_export] macro_rules! assert_hover { - ($code:literal, $position:expr $(,)?) => { + ($code:literal, $position:expr_2021 $(,)?) => { let project = TestProject::for_source($code); assert_hover!(project, $position); }; - ($project:expr, $position:expr $(,)?) => { + ($project:expr_2021, $position:expr_2021 $(,)?) => { let src = $project.src; let position = $position.find_position(src); let result = hover($project, position).expect("no hover produced"); diff --git a/compiler-core/src/language_server/tests/rename.rs b/compiler-core/src/language_server/tests/rename.rs index 09412cd0ac4..3430905f526 100644 --- a/compiler-core/src/language_server/tests/rename.rs +++ b/compiler-core/src/language_server/tests/rename.rs @@ -2,7 +2,7 @@ use std::collections::HashMap; use lsp_types::{Position, RenameParams, TextDocumentPositionParams, Url, WorkDoneProgressParams}; -use crate::language_server::tests::{find_position_of, TestProject}; +use crate::language_server::tests::{TestProject, find_position_of}; use super::hover; @@ -50,12 +50,12 @@ fn apply_code_edit(src: &str, changes: HashMap>) - } macro_rules! assert_rename { - ($code:literal, $new_name:literal, $range:expr $(,)?) => { + ($code:literal, $new_name:literal, $range:expr_2021 $(,)?) => { let project = TestProject::for_source($code); assert_rename!(project, $new_name, $range); }; - ($project:expr, $new_name:literal, $range:expr $(,)?) => { + ($project:expr_2021, $new_name:literal, $range:expr_2021 $(,)?) => { let src = $project.src; let range = $range.find_range(src); let result = apply_rename($project, $new_name, range.start); @@ -69,12 +69,12 @@ macro_rules! assert_rename { } macro_rules! assert_no_rename { - ($code:literal, $new_name:literal, $range:expr $(,)?) => { + ($code:literal, $new_name:literal, $range:expr_2021 $(,)?) => { let project = TestProject::for_source($code); assert_no_rename!(project, $new_name, $range); }; - ($project:expr, $new_name:literal, $range:expr $(,)?) => { + ($project:expr_2021, $new_name:literal, $range:expr_2021 $(,)?) => { let src = $project.src; let range = $range.find_range(src); let result = rename($project, $new_name, range.start); diff --git a/compiler-core/src/language_server/tests/signature_help.rs b/compiler-core/src/language_server/tests/signature_help.rs index b3284e333ac..c2c76b2bbdd 100644 --- a/compiler-core/src/language_server/tests/signature_help.rs +++ b/compiler-core/src/language_server/tests/signature_help.rs @@ -62,12 +62,12 @@ fn pretty_signature_help(signature_help: SignatureHelp) -> String { #[macro_export] macro_rules! assert_signature_help { - ($code:literal, $position:expr $(,)?) => { + ($code:literal, $position:expr_2021 $(,)?) => { let project = TestProject::for_source($code); assert_signature_help!(project, $position); }; - ($project:expr, $position:expr $(,)?) => { + ($project:expr_2021, $position:expr_2021 $(,)?) => { let src = $project.src; let position = $position.find_position(src); let result = signature_help($project, position).expect("no signature help produced"); @@ -96,12 +96,12 @@ macro_rules! assert_signature_help { #[macro_export] macro_rules! assert_no_signature_help { - ($code:literal, $position:expr $(,)?) => { + ($code:literal, $position:expr_2021 $(,)?) => { let project = TestProject::for_source($code); assert_no_signature_help!(project, $position); }; - ($project:expr, $position:expr $(,)?) => { + ($project:expr_2021, $position:expr_2021 $(,)?) => { let src = $project.src; let position = $position.find_position(src); let result = signature_help($project, position); diff --git a/compiler-core/src/manifest.rs b/compiler-core/src/manifest.rs index b44c223c089..fd68b652f39 100644 --- a/compiler-core/src/manifest.rs +++ b/compiler-core/src/manifest.rs @@ -1,8 +1,8 @@ use std::collections::HashMap; +use crate::Result; use crate::io::{make_relative, ordered_map}; use crate::requirement::Requirement; -use crate::Result; use camino::{Utf8Path, Utf8PathBuf}; use ecow::EcoString; use hexpm::version::Version; diff --git a/compiler-core/src/metadata/module_decoder.rs b/compiler-core/src/metadata/module_decoder.rs index 121bf4ea23f..96f85c3d6dd 100755 --- a/compiler-core/src/metadata/module_decoder.rs +++ b/compiler-core/src/metadata/module_decoder.rs @@ -5,6 +5,7 @@ use ecow::EcoString; use itertools::Itertools; use crate::{ + Result, ast::{ BitArrayOption, BitArraySegment, CallArg, Constant, Publicity, SrcSpan, TypedConstant, TypedConstantBitArraySegment, TypedConstantBitArraySegmentOption, @@ -13,17 +14,16 @@ use crate::{ line_numbers::LineNumbers, schema_capnp::{self as schema, *}, type_::{ - self, expression::Implementations, AccessorsMap, Deprecation, FieldMap, ModuleInterface, - RecordAccessor, Type, TypeConstructor, TypeValueConstructor, TypeValueConstructorField, - TypeVariantConstructors, ValueConstructor, ValueConstructorVariant, + self, AccessorsMap, Deprecation, FieldMap, ModuleInterface, RecordAccessor, Type, + TypeConstructor, TypeValueConstructor, TypeValueConstructorField, TypeVariantConstructors, + ValueConstructor, ValueConstructorVariant, expression::Implementations, }, uid::UniqueIdGenerator, - Result, }; use std::{collections::HashMap, io::BufRead, sync::Arc}; macro_rules! read_vec { - ($reader:expr, $self:expr, $method:ident) => {{ + ($reader:expr_2021, $self:expr_2021, $method:ident) => {{ let reader = $reader; let mut vec = Vec::with_capacity(reader.len() as usize); for reader in reader.into_iter() { @@ -35,7 +35,7 @@ macro_rules! read_vec { } macro_rules! read_hashmap { - ($reader:expr, $self:expr, $method:ident) => {{ + ($reader:expr_2021, $self:expr_2021, $method:ident) => {{ let reader = $reader; let mut map = HashMap::with_capacity(reader.len() as usize); for prop in reader.into_iter() { diff --git a/compiler-core/src/metadata/module_encoder.rs b/compiler-core/src/metadata/module_encoder.rs index f104dba894e..98003ecc7d7 100644 --- a/compiler-core/src/metadata/module_encoder.rs +++ b/compiler-core/src/metadata/module_encoder.rs @@ -7,9 +7,9 @@ use crate::{ }, schema_capnp::{self as schema, *}, type_::{ - self, expression::Implementations, AccessorsMap, Deprecation, FieldMap, RecordAccessor, - Type, TypeConstructor, TypeValueConstructor, TypeVar, TypeVariantConstructors, - ValueConstructor, ValueConstructorVariant, + self, AccessorsMap, Deprecation, FieldMap, RecordAccessor, Type, TypeConstructor, + TypeValueConstructor, TypeVar, TypeVariantConstructors, ValueConstructor, + ValueConstructorVariant, expression::Implementations, }, }; use std::{collections::HashMap, ops::Deref, sync::Arc}; diff --git a/compiler-core/src/metadata/tests.rs b/compiler-core/src/metadata/tests.rs index fc597417879..68829023d9c 100644 --- a/compiler-core/src/metadata/tests.rs +++ b/compiler-core/src/metadata/tests.rs @@ -11,9 +11,9 @@ use crate::{ build::Origin, line_numbers::LineNumbers, type_::{ - self, expression::Implementations, Deprecation, ModuleInterface, Type, TypeConstructor, - TypeValueConstructor, TypeValueConstructorField, TypeVariantConstructors, ValueConstructor, - ValueConstructorVariant, + self, Deprecation, ModuleInterface, Type, TypeConstructor, TypeValueConstructor, + TypeValueConstructorField, TypeVariantConstructors, ValueConstructor, + ValueConstructorVariant, expression::Implementations, }, uid::UniqueIdGenerator, }; @@ -697,13 +697,13 @@ fn record_value() { name: "one".into(), module: "themodule".into(), field_map: None, - arity: random.gen(), - variants_count: random.gen(), + arity: random.r#gen(), + variants_count: random.r#gen(), location: SrcSpan { - start: random.gen(), - end: random.gen(), + start: random.r#gen(), + end: random.r#gen(), }, - variant_index: random.gen(), + variant_index: random.r#gen(), }, }, )] @@ -740,15 +740,16 @@ fn record_value_with_field_map() { module: "themodule".into(), name: "one".into(), field_map: Some(FieldMap { - arity: random.gen(), - fields: [("ok".into(), random.gen()), ("ko".into(), random.gen())].into(), + arity: random.r#gen(), + fields: [("ok".into(), random.r#gen()), ("ko".into(), random.r#gen())] + .into(), }), - arity: random.gen(), - variants_count: random.gen(), - variant_index: random.gen(), + arity: random.r#gen(), + variants_count: random.r#gen(), + variant_index: random.r#gen(), location: SrcSpan { - start: random.gen(), - end: random.gen(), + start: random.r#gen(), + end: random.r#gen(), }, }, }, diff --git a/compiler-core/src/package_interface.rs b/compiler-core/src/package_interface.rs index 936902ddb82..b2c9e9e8905 100644 --- a/compiler-core/src/package_interface.rs +++ b/compiler-core/src/package_interface.rs @@ -10,7 +10,7 @@ mod tests; use crate::{ ast::{CustomType, Definition, Function, ModuleConstant, Publicity, TypeAlias}, io::ordered_map, - type_::{expression::Implementations, Deprecation, Type, TypeVar}, + type_::{Deprecation, Type, TypeVar, expression::Implementations}, }; use crate::build::{Module, Package}; diff --git a/compiler-core/src/package_interface/tests.rs b/compiler-core/src/package_interface/tests.rs index 5495a848db9..e2c133bfc05 100644 --- a/compiler-core/src/package_interface/tests.rs +++ b/compiler-core/src/package_interface/tests.rs @@ -19,7 +19,7 @@ use super::PackageInterface; #[macro_export] macro_rules! assert_package_interface_with_name { - ($module_name:expr, $src:expr) => { + ($module_name:expr_2021, $src:expr_2021) => { let output = $crate::package_interface::tests::compile_package(Some($module_name), $src, None); insta::assert_snapshot!(insta::internals::AutoName, output, $src); @@ -28,7 +28,7 @@ macro_rules! assert_package_interface_with_name { #[macro_export] macro_rules! assert_package_interface { - (($dep_package:expr, $dep_name:expr, $dep_src:expr), $src:expr $(,)?) => {{ + (($dep_package:expr_2021, $dep_name:expr_2021, $dep_src:expr_2021), $src:expr_2021 $(,)?) => {{ let output = $crate::package_interface::tests::compile_package( None, $src, @@ -37,7 +37,7 @@ macro_rules! assert_package_interface { insta::assert_snapshot!(insta::internals::AutoName, output, $src); }}; - (($dep_package:expr, $dep_name:expr, $dep_src:expr), $src:expr $(,)?) => {{ + (($dep_package:expr_2021, $dep_name:expr_2021, $dep_src:expr_2021), $src:expr_2021 $(,)?) => {{ let output = $crate::package_interface::tests::compile_package( None, $src, @@ -46,7 +46,7 @@ macro_rules! assert_package_interface { insta::assert_snapshot!(insta::internals::AutoName, output, $src); }}; - ($src:expr) => {{ + ($src:expr_2021) => {{ let output = $crate::package_interface::tests::compile_package(None, $src, None); insta::assert_snapshot!(insta::internals::AutoName, output, $src); }}; @@ -167,9 +167,11 @@ fn package_from_module(module: Module) -> Package { erlang: ErlangConfig::default(), javascript: JavaScriptConfig::default(), target: Target::Erlang, - internal_modules: Some(vec![GlobBuilder::new("internals/*") - .build() - .expect("internals glob")]), + internal_modules: Some(vec![ + GlobBuilder::new("internals/*") + .build() + .expect("internals glob"), + ]), }, modules: vec![module], } diff --git a/compiler-core/src/parse.rs b/compiler-core/src/parse.rs index aaab8fe5555..fe168261888 100644 --- a/compiler-core/src/parse.rs +++ b/compiler-core/src/parse.rs @@ -54,25 +54,25 @@ pub mod extra; pub mod lexer; mod token; +use crate::Warning; use crate::analyse::Inferred; use crate::ast::{ Arg, ArgNames, AssignName, Assignment, AssignmentKind, BinOp, BitArrayOption, BitArraySegment, - CallArg, Clause, ClauseGuard, Constant, CustomType, Definition, Function, FunctionLiteralKind, - HasLocation, Import, Module, ModuleConstant, Pattern, Publicity, RecordBeingUpdated, - RecordConstructor, RecordConstructorArg, SrcSpan, Statement, TargetedDefinition, TodoKind, - TypeAlias, TypeAst, TypeAstConstructor, TypeAstFn, TypeAstHole, TypeAstTuple, TypeAstVar, - UnqualifiedImport, UntypedArg, UntypedClause, UntypedClauseGuard, UntypedConstant, - UntypedDefinition, UntypedExpr, UntypedModule, UntypedPattern, UntypedRecordUpdateArg, - UntypedStatement, UntypedUseAssignment, Use, UseAssignment, CAPTURE_VARIABLE, + CAPTURE_VARIABLE, CallArg, Clause, ClauseGuard, Constant, CustomType, Definition, Function, + FunctionLiteralKind, HasLocation, Import, Module, ModuleConstant, Pattern, Publicity, + RecordBeingUpdated, RecordConstructor, RecordConstructorArg, SrcSpan, Statement, + TargetedDefinition, TodoKind, TypeAlias, TypeAst, TypeAstConstructor, TypeAstFn, TypeAstHole, + TypeAstTuple, TypeAstVar, UnqualifiedImport, UntypedArg, UntypedClause, UntypedClauseGuard, + UntypedConstant, UntypedDefinition, UntypedExpr, UntypedModule, UntypedPattern, + UntypedRecordUpdateArg, UntypedStatement, UntypedUseAssignment, Use, UseAssignment, }; use crate::build::Target; use crate::error::wrap; use crate::parse::extra::ModuleExtra; +use crate::type_::Deprecation; use crate::type_::error::VariableOrigin; use crate::type_::expression::Implementations; -use crate::type_::Deprecation; use crate::warning::{DeprecatedSyntaxWarning, WarningEmitter}; -use crate::Warning; use camino::Utf8PathBuf; use ecow::EcoString; use error::{LexicalError, ParseError, ParseErrorType}; @@ -82,7 +82,7 @@ use std::cmp::Ordering; use std::collections::VecDeque; use std::str::FromStr; use token::Token; -use vec1::{vec1, Vec1}; +use vec1::{Vec1, vec1}; #[cfg(test)] mod tests; @@ -181,10 +181,9 @@ pub fn parse_statement_sequence(src: &str) -> Result, Par let mut parser = Parser::new(lex); let expr = parser.parse_statement_seq(); let expr = parser.ensure_no_errors_or_remaining_input(expr)?; - if let Some((e, _)) = expr { - Ok(e) - } else { - parse_error(ParseErrorType::ExpectedExpr, SrcSpan { start: 0, end: 0 }) + match expr { + Some((e, _)) => Ok(e), + _ => parse_error(ParseErrorType::ExpectedExpr, SrcSpan { start: 0, end: 0 }), } } @@ -197,10 +196,9 @@ pub fn parse_const_value(src: &str) -> Result, ParseError> { let mut parser = Parser::new(lex); let expr = parser.parse_const_value(); let expr = parser.ensure_no_errors_or_remaining_input(expr)?; - if let Some(e) = expr { - Ok(e) - } else { - parse_error(ParseErrorType::ExpectedExpr, SrcSpan { start: 0, end: 0 }) + match expr { + Some(e) => Ok(e), + _ => parse_error(ParseErrorType::ExpectedExpr, SrcSpan { start: 0, end: 0 }), } } @@ -420,25 +418,31 @@ where } } - if let Some((op_s, t, op_e)) = self.tok0.take() { - if let Some(p) = precedence(&t) { - // Is Op - self.advance(); - last_op_start = op_s; - last_op_end = op_e; - let _ = handle_op( - Some(((op_s, t, op_e), p)), - &mut opstack, - &mut estack, - &do_reduce_expression, - ); - } else { - // Is not Op - self.tok0 = Some((op_s, t, op_e)); + match self.tok0.take() { + Some((op_s, t, op_e)) => { + match precedence(&t) { + Some(p) => { + // Is Op + self.advance(); + last_op_start = op_s; + last_op_end = op_e; + let _ = handle_op( + Some(((op_s, t, op_e), p)), + &mut opstack, + &mut estack, + &do_reduce_expression, + ); + } + _ => { + // Is not Op + self.tok0 = Some((op_s, t, op_e)); + break; + } + } + } + _ => { break; } - } else { - break; } } @@ -758,7 +762,7 @@ where return parse_error( ParseErrorType::ExpectedExpr, SrcSpan { start, end: start }, - ) + ); } } } @@ -778,7 +782,7 @@ where return parse_error( ParseErrorType::ExpectedExpr, SrcSpan { start, end: start }, - ) + ); } } } @@ -791,115 +795,126 @@ where // field access and call can stack up loop { - if let Some((dot_start, _)) = self.maybe_one(&Token::Dot) { - let start = expr.location().start; - // field access - match self.tok0.take() { - // tuple access - Some(( - _, - Token::Int { - value, - int_value: _, - }, - end, - )) => { - self.advance(); - let v = value.replace("_", ""); - if let Ok(index) = u64::from_str(&v) { - expr = UntypedExpr::TupleIndex { - location: SrcSpan { start, end }, - index, - tuple: Box::new(expr), + match self.maybe_one(&Token::Dot) { + Some((dot_start, _)) => { + let start = expr.location().start; + // field access + match self.tok0.take() { + // tuple access + Some(( + _, + Token::Int { + value, + int_value: _, + }, + end, + )) => { + self.advance(); + let v = value.replace("_", ""); + match u64::from_str(&v) { + Ok(index) => { + expr = UntypedExpr::TupleIndex { + location: SrcSpan { start, end }, + index, + tuple: Box::new(expr), + } + } + _ => { + return parse_error( + ParseErrorType::InvalidTupleAccess, + SrcSpan { start, end }, + ); + } } - } else { - return parse_error( - ParseErrorType::InvalidTupleAccess, - SrcSpan { start, end }, - ); } - } - Some((label_start, Token::Name { name: label }, end)) => { - self.advance(); - expr = UntypedExpr::FieldAccess { - location: SrcSpan { start, end }, - label_location: SrcSpan { - start: label_start, - end, - }, - label, - container: Box::new(expr), + Some((label_start, Token::Name { name: label }, end)) => { + self.advance(); + expr = UntypedExpr::FieldAccess { + location: SrcSpan { start, end }, + label_location: SrcSpan { + start: label_start, + end, + }, + label, + container: Box::new(expr), + } } - } - Some((label_start, Token::UpName { name: label }, end)) => { - self.advance(); - expr = UntypedExpr::FieldAccess { - location: SrcSpan { start, end }, - label_location: SrcSpan { - start: label_start, - end, - }, - label, - container: Box::new(expr), + Some((label_start, Token::UpName { name: label }, end)) => { + self.advance(); + expr = UntypedExpr::FieldAccess { + location: SrcSpan { start, end }, + label_location: SrcSpan { + start: label_start, + end, + }, + label, + container: Box::new(expr), + } } - } - t0 => { - // parse a field access with no label - self.tok0 = t0; - let end = dot_start + 1; - expr = UntypedExpr::FieldAccess { - location: SrcSpan { start, end }, - label_location: SrcSpan { - start: dot_start, - end, - }, - label: "".into(), - container: Box::new(expr), - }; - return Ok(Some(expr)); + t0 => { + // parse a field access with no label + self.tok0 = t0; + let end = dot_start + 1; + expr = UntypedExpr::FieldAccess { + location: SrcSpan { start, end }, + label_location: SrcSpan { + start: dot_start, + end, + }, + label: "".into(), + container: Box::new(expr), + }; + return Ok(Some(expr)); + } } } - } else if self.maybe_one(&Token::LeftParen).is_some() { - let start = expr.location().start; - if let Some((dot_s, _)) = self.maybe_one(&Token::DotDot) { - // Record update - let base = self.expect_expression()?; - let base_e = base.location().end; - let record = RecordBeingUpdated { - base: Box::new(base), - location: SrcSpan { - start: dot_s, - end: base_e, - }, - }; - let mut args = vec![]; - if self.maybe_one(&Token::Comma).is_some() { - args = Parser::series_of( - self, - &Parser::parse_record_update_arg, - Some(&Token::Comma), - )?; - } - let (_, end) = self.expect_one(&Token::RightParen)?; + _ => { + if self.maybe_one(&Token::LeftParen).is_some() { + let start = expr.location().start; + match self.maybe_one(&Token::DotDot) { + Some((dot_s, _)) => { + // Record update + let base = self.expect_expression()?; + let base_e = base.location().end; + let record = RecordBeingUpdated { + base: Box::new(base), + location: SrcSpan { + start: dot_s, + end: base_e, + }, + }; + let mut args = vec![]; + if self.maybe_one(&Token::Comma).is_some() { + args = Parser::series_of( + self, + &Parser::parse_record_update_arg, + Some(&Token::Comma), + )?; + } + let (_, end) = self.expect_one(&Token::RightParen)?; - expr = UntypedExpr::RecordUpdate { - location: SrcSpan { start, end }, - constructor: Box::new(expr), - record, - arguments: args, - }; - } else { - // Call - let args = self.parse_fn_args()?; - let (_, end) = self.expect_one(&Token::RightParen)?; - expr = make_call(expr, args, start, end)?; + expr = UntypedExpr::RecordUpdate { + location: SrcSpan { start, end }, + constructor: Box::new(expr), + record, + arguments: args, + }; + } + _ => { + // Call + let args = self.parse_fn_args()?; + let (_, end) = self.expect_one(&Token::RightParen)?; + expr = make_call(expr, args, start, end)?; + } + } + } else { + // done + break; + } } - } else { - // done - break; } } @@ -914,10 +929,11 @@ where // use a, b, c <- function(a, b) // use a, b, c, <- function(a, b) fn parse_use(&mut self, start: u32, end: u32) -> Result { - let assignments = if let Some((_, Token::LArrow, _)) = self.tok0 { - vec![] - } else { - Parser::series_of(self, &Parser::parse_use_assignment, Some(&Token::Comma))? + let assignments = match self.tok0 { + Some((_, Token::LArrow, _)) => { + vec![] + } + _ => Parser::series_of(self, &Parser::parse_use_assignment, Some(&Token::Comma))?, }; _ = self.expect_one_following_series(&Token::LArrow, "a use variable assignment")?; @@ -963,20 +979,22 @@ where // An assignment, with `Let` already consumed fn parse_assignment(&mut self, start: u32) -> Result { - let mut kind = if let Some((assert_start, Token::Assert, assert_end)) = self.tok0 { - _ = self.next_tok(); - AssignmentKind::Assert { - location: SrcSpan::new(assert_start, assert_end), - message: None, + let mut kind = match self.tok0 { + Some((assert_start, Token::Assert, assert_end)) => { + _ = self.next_tok(); + AssignmentKind::Assert { + location: SrcSpan::new(assert_start, assert_end), + message: None, + } } - } else { - AssignmentKind::Let + _ => AssignmentKind::Let, }; - let pattern = if let Some(p) = self.parse_pattern()? { - p - } else { - // DUPE: 62884 - return self.next_tok_unexpected(vec!["A pattern".into()])?; + let pattern = match self.parse_pattern()? { + Some(p) => p, + _ => { + // DUPE: 62884 + return self.next_tok_unexpected(vec!["A pattern".into()])?; + } }; let annotation = self.parse_type_annotation(&Token::Colon)?; let (eq_s, eq_e) = self.maybe_one(&Token::Equal).ok_or(ParseError { @@ -1125,7 +1143,7 @@ where return parse_error( ParseErrorType::InvalidModuleTypePattern, SrcSpan { start, end }, - ) + ); } } } else { @@ -1134,7 +1152,7 @@ where return parse_error( ParseErrorType::LowcaseBooleanPattern, SrcSpan { start, end }, - ) + ); } _ => Pattern::Variable { origin: VariableOrigin::Variable(name.clone()), @@ -1304,35 +1322,39 @@ where let mut elements_after_tail = None; let mut dot_dot_location = None; - let tail = if let Some((dot_dot_start, Token::DotDot, dot_dot_end)) = self.tok0 { - dot_dot_location = Some((dot_dot_start, dot_dot_end)); - if !elements.is_empty() && !elements_end_with_comma { - self.warnings - .push(DeprecatedSyntaxWarning::DeprecatedListPattern { - location: SrcSpan { - start: dot_dot_start, - end: dot_dot_end, - }, - }); - } + let tail = match self.tok0 { + Some((dot_dot_start, Token::DotDot, dot_dot_end)) => { + dot_dot_location = Some((dot_dot_start, dot_dot_end)); + if !elements.is_empty() && !elements_end_with_comma { + self.warnings + .push(DeprecatedSyntaxWarning::DeprecatedListPattern { + location: SrcSpan { + start: dot_dot_start, + end: dot_dot_end, + }, + }); + } - self.advance(); - let pat = self.parse_pattern()?; - if self.maybe_one(&Token::Comma).is_some() { - // See if there's a list of items after the tail, - // like `[..wibble, wobble, wabble]` - let elements = - Parser::series_of(self, &Parser::parse_pattern, Some(&Token::Comma)); - match elements { - Err(_) => {} - Ok(elements) => { - elements_after_tail = Some(elements); - } + self.advance(); + let pat = self.parse_pattern()?; + if self.maybe_one(&Token::Comma).is_some() { + // See if there's a list of items after the tail, + // like `[..wibble, wobble, wabble]` + let elements = Parser::series_of( + self, + &Parser::parse_pattern, + Some(&Token::Comma), + ); + match elements { + Err(_) => {} + Ok(elements) => { + elements_after_tail = Some(elements); + } + }; }; - }; - Some(pat) - } else { - None + Some(pat) + } + _ => None, }; let (end, rsqb_e) = @@ -1361,7 +1383,7 @@ where } // There is a tail and but it has no content, implicit discard Some(Some(pat)) => { - return parse_error(ParseErrorType::InvalidTailPattern, pat.location()) + return parse_error(ParseErrorType::InvalidTailPattern, pat.location()); } Some(None) => Some(Pattern::Discard { location: SrcSpan { @@ -1397,16 +1419,17 @@ where } }; - if let Some((_, Token::As, _)) = self.tok0 { - self.advance(); - let (start, name, end) = self.expect_name()?; - Ok(Some(Pattern::Assign { - name, - location: SrcSpan { start, end }, - pattern: Box::new(pattern), - })) - } else { - Ok(Some(pattern)) + match self.tok0 { + Some((_, Token::As, _)) => { + self.advance(); + let (start, name, end) = self.expect_name()?; + Ok(Some(Pattern::Assign { + name, + location: SrcSpan { start, end }, + pattern: Box::new(pattern), + })) + } + _ => Ok(Some(pattern)), } } @@ -1423,46 +1446,46 @@ where // pattern, pattern | pattern, pattern if -> expr fn parse_case_clause(&mut self) -> Result, ParseError> { let patterns = self.parse_patterns()?; - if let Some(lead) = &patterns.first() { - let mut alternative_patterns = vec![]; - loop { - if self.maybe_one(&Token::Vbar).is_none() { - break; - } - alternative_patterns.push(self.parse_patterns()?); - } - let guard = self.parse_case_clause_guard(false)?; - let (arr_s, arr_e) = self - .expect_one(&Token::RArrow) - .map_err(|e| self.add_multi_line_clause_hint(e))?; - let then = self.parse_expression()?; - if let Some(then) = then { - Ok(Some(Clause { - location: SrcSpan { - start: lead.location().start, - end: then.location().end, - }, - pattern: patterns, - alternative_patterns, - guard, - then, - })) - } else { - match self.tok0 { - Some((start, Token::DiscardName { .. }, end)) => { - parse_error(ParseErrorType::IncorrectName, SrcSpan { start, end }) + match &patterns.first() { + Some(lead) => { + let mut alternative_patterns = vec![]; + loop { + if self.maybe_one(&Token::Vbar).is_none() { + break; } - _ => parse_error( - ParseErrorType::ExpectedExpr, - SrcSpan { - start: arr_s, - end: arr_e, + alternative_patterns.push(self.parse_patterns()?); + } + let guard = self.parse_case_clause_guard(false)?; + let (arr_s, arr_e) = self + .expect_one(&Token::RArrow) + .map_err(|e| self.add_multi_line_clause_hint(e))?; + let then = self.parse_expression()?; + match then { + Some(then) => Ok(Some(Clause { + location: SrcSpan { + start: lead.location().start, + end: then.location().end, }, - ), + pattern: patterns, + alternative_patterns, + guard, + then, + })), + _ => match self.tok0 { + Some((start, Token::DiscardName { .. }, end)) => { + parse_error(ParseErrorType::IncorrectName, SrcSpan { start, end }) + } + _ => parse_error( + ParseErrorType::ExpectedExpr, + SrcSpan { + start: arr_s, + end: arr_e, + }, + ), + }, } } - } else { - Ok(None) + _ => Ok(None), } } fn parse_patterns(&mut self) -> Result, ParseError> { @@ -1483,36 +1506,42 @@ where let mut last_op_start = 0; let mut last_op_end = 0; loop { - if let Some(unit) = self.parse_case_clause_guard_unit()? { - estack.push(unit) - } else if estack.is_empty() { - return Ok(None); - } else { - return parse_error( - ParseErrorType::OpNakedRight, - SrcSpan { - start: last_op_start, - end: last_op_end, - }, - ); + match self.parse_case_clause_guard_unit()? { + Some(unit) => estack.push(unit), + _ => { + if estack.is_empty() { + return Ok(None); + } else { + return parse_error( + ParseErrorType::OpNakedRight, + SrcSpan { + start: last_op_start, + end: last_op_end, + }, + ); + } + } } if let Some((op_s, t, op_e)) = self.tok0.take() { - if let Some(p) = t.guard_precedence() { - // Is Op - self.advance(); - last_op_start = op_s; - last_op_end = op_e; - let _ = handle_op( - Some(((op_s, t, op_e), p)), - &mut opstack, - &mut estack, - &do_reduce_clause_guard, - ); - } else { - // Is not Op - self.tok0 = Some((op_s, t, op_e)); - break; + match t.guard_precedence() { + Some(p) => { + // Is Op + self.advance(); + last_op_start = op_s; + last_op_end = op_e; + let _ = handle_op( + Some(((op_s, t, op_e), p)), + &mut opstack, + &mut estack, + &do_reduce_clause_guard, + ); + } + _ => { + // Is not Op + self.tok0 = Some((op_s, t, op_e)); + break; + } } } } @@ -1586,18 +1615,16 @@ where self.parse_function_call_in_clause_guard(start)?; - let mut unit = if let Some(record) = - self.parse_record_in_clause_guard(&name, SrcSpan { start, end })? - { - record - } else { - ClauseGuard::Var { - location: SrcSpan { start, end }, - type_: (), - name, - definition_location: SrcSpan::default(), - } - }; + let mut unit = + match self.parse_record_in_clause_guard(&name, SrcSpan { start, end })? { + Some(record) => record, + _ => ClauseGuard::Var { + location: SrcSpan { start, end }, + type_: (), + name, + definition_location: SrcSpan::default(), + }, + }; loop { let dot_s = match self.maybe_one(&Token::Dot) { @@ -1615,21 +1642,24 @@ where int_e, )) => { let v = value.replace("_", ""); - if let Ok(index) = u64::from_str(&v) { - unit = ClauseGuard::TupleIndex { - location: SrcSpan { - start: dot_s, - end: int_e, - }, - index, - type_: (), - tuple: Box::new(unit), - }; - } else { - return parse_error( - ParseErrorType::InvalidTupleAccess, - SrcSpan { start, end }, - ); + match u64::from_str(&v) { + Ok(index) => { + unit = ClauseGuard::TupleIndex { + location: SrcSpan { + start: dot_s, + end: int_e, + }, + index, + type_: (), + tuple: Box::new(unit), + }; + } + _ => { + return parse_error( + ParseErrorType::InvalidTupleAccess, + SrcSpan { start, end }, + ); + } } } @@ -1652,7 +1682,7 @@ where return parse_error( ParseErrorType::IncorrectName, SrcSpan { start, end }, - ) + ); } _ => return self.next_tok_unexpected(vec!["A positive integer".into()]), @@ -1668,11 +1698,12 @@ where } t0 => { self.tok0 = t0; - if let Some(const_val) = self.parse_const_value()? { - // Constant - Ok(Some(ClauseGuard::Constant(const_val))) - } else { - Ok(None) + match self.parse_const_value()? { + Some(const_val) => { + // Constant + Ok(Some(ClauseGuard::Constant(const_val))) + } + _ => Ok(None), } } } @@ -1697,15 +1728,14 @@ where } }; - if let Some(record) = self.parse_const_record_finish( + match self.parse_const_record_finish( module_location.start, Some((module.clone(), module_location)), name, end, )? { - Ok(Some(ClauseGuard::Constant(record))) - } else { - Ok(None) + Some(record) => Ok(Some(ClauseGuard::Constant(record))), + _ => Ok(None), } } @@ -1776,8 +1806,8 @@ where (Some((start, Token::Name { name }, _)), Some((_, Token::Colon, end))) => { self.advance(); self.advance(); - if let Some(value) = self.parse_pattern()? { - Ok(Some(CallArg { + match self.parse_pattern()? { + Some(value) => Ok(Some(CallArg { implicit: None, location: SrcSpan { start, @@ -1785,35 +1815,35 @@ where }, label: Some(name), value, - })) - } else { - // Argument supplied with a label shorthand. - Ok(Some(CallArg { - implicit: None, - location: SrcSpan { start, end }, - label: Some(name.clone()), - value: UntypedPattern::Variable { - origin: VariableOrigin::LabelShorthand(name.clone()), - name, + })), + _ => { + // Argument supplied with a label shorthand. + Ok(Some(CallArg { + implicit: None, location: SrcSpan { start, end }, - type_: (), - }, - })) + label: Some(name.clone()), + value: UntypedPattern::Variable { + origin: VariableOrigin::LabelShorthand(name.clone()), + name, + location: SrcSpan { start, end }, + type_: (), + }, + })) + } } } // unnamed arg (t0, t1) => { self.tok0 = t0; self.tok1 = t1; - if let Some(value) = self.parse_pattern()? { - Ok(Some(CallArg { + match self.parse_pattern()? { + Some(value) => Ok(Some(CallArg { implicit: None, location: value.location(), label: None, value, - })) - } else { - Ok(None) + })), + _ => Ok(None), } } } @@ -1823,31 +1853,33 @@ where // a: expr // a: fn parse_record_update_arg(&mut self) -> Result, ParseError> { - if let Some((start, label, _)) = self.maybe_name() { - let (_, end) = self.expect_one(&Token::Colon)?; - let value = self.parse_expression()?; - if let Some(value) = value { - Ok(Some(UntypedRecordUpdateArg { - label, - location: SrcSpan { - start, - end: value.location().end, - }, - value, - })) - } else { - // Argument supplied with a label shorthand. - Ok(Some(UntypedRecordUpdateArg { - label: label.clone(), - location: SrcSpan { start, end }, - value: UntypedExpr::Var { - name: label, - location: SrcSpan { start, end }, - }, - })) + match self.maybe_name() { + Some((start, label, _)) => { + let (_, end) = self.expect_one(&Token::Colon)?; + let value = self.parse_expression()?; + match value { + Some(value) => Ok(Some(UntypedRecordUpdateArg { + label, + location: SrcSpan { + start, + end: value.location().end, + }, + value, + })), + _ => { + // Argument supplied with a label shorthand. + Ok(Some(UntypedRecordUpdateArg { + label: label.clone(), + location: SrcSpan { start, end }, + value: UntypedExpr::Var { + name: label, + location: SrcSpan { start, end }, + }, + })) + } + } } - } else { - Ok(None) + _ => Ok(None), } } @@ -2087,11 +2119,12 @@ where return Ok(None); } }; - let annotation = if let Some(a) = self.parse_type_annotation(&Token::Colon)? { - end = a.location().end; - Some(a) - } else { - None + let annotation = match self.parse_type_annotation(&Token::Colon)? { + Some(a) => { + end = a.location().end; + Some(a) + } + _ => None, }; Ok(Some(Arg { location: SrcSpan { start, end }, @@ -2134,69 +2167,78 @@ where } }; - if let Some(value) = self.parse_expression()? { - let arg = if let Some((start, label, _)) = label { - CallArg { - implicit: None, - label: Some(label), - location: SrcSpan { - start, - end: value.location().end, - }, - value, - } - } else { - CallArg { - implicit: None, - label: None, - location: value.location(), - value, - } - }; - Ok(Some(ParserArg::Arg(Box::new(arg)))) - } else if let Some((name_start, name, name_end)) = self.maybe_discard_name() { - let arg = if let Some((label_start, label, _)) = label { - ParserArg::Hole { - label: Some(label), - arg_location: SrcSpan { - start: label_start, - end: name_end, - }, - discard_location: SrcSpan { - start: name_start, - end: name_end, - }, - name, - } - } else { - ParserArg::Hole { - label: None, - arg_location: SrcSpan { - start: name_start, - end: name_end, + match self.parse_expression()? { + Some(value) => { + let arg = match label { + Some((start, label, _)) => CallArg { + implicit: None, + label: Some(label), + location: SrcSpan { + start, + end: value.location().end, + }, + value, }, - discard_location: SrcSpan { - start: name_start, - end: name_end, + _ => CallArg { + implicit: None, + label: None, + location: value.location(), + value, }, - name, + }; + Ok(Some(ParserArg::Arg(Box::new(arg)))) + } + _ => { + match self.maybe_discard_name() { + Some((name_start, name, name_end)) => { + let arg = match label { + Some((label_start, label, _)) => ParserArg::Hole { + label: Some(label), + arg_location: SrcSpan { + start: label_start, + end: name_end, + }, + discard_location: SrcSpan { + start: name_start, + end: name_end, + }, + name, + }, + _ => ParserArg::Hole { + label: None, + arg_location: SrcSpan { + start: name_start, + end: name_end, + }, + discard_location: SrcSpan { + start: name_start, + end: name_end, + }, + name, + }, + }; + + Ok(Some(arg)) + } + _ => { + match label { + Some((start, label, end)) => { + // Argument supplied with a label shorthand. + Ok(Some(ParserArg::Arg(Box::new(CallArg { + implicit: None, + label: Some(label.clone()), + location: SrcSpan { start, end }, + value: UntypedExpr::Var { + name: label, + location: SrcSpan { start, end }, + }, + })))) + } + _ => Ok(None), + } + } } - }; - - Ok(Some(arg)) - } else if let Some((start, label, end)) = label { - // Argument supplied with a label shorthand. - Ok(Some(ParserArg::Arg(Box::new(CallArg { - implicit: None, - label: Some(label.clone()), - location: SrcSpan { start, end }, - value: UntypedExpr::Var { - name: label, - location: SrcSpan { start, end }, - }, - })))) - } else { - Ok(None) + } } } @@ -2242,23 +2284,24 @@ where } } - if let Some((c_s, c_n, c_e)) = Parser::maybe_upname(p) { - let documentation = p.take_documentation(c_s); - let (args, args_e) = Parser::parse_type_constructor_args(p)?; - let end = args_e.max(c_e); - Ok(Some(RecordConstructor { - location: SrcSpan { start: c_s, end }, - name_location: SrcSpan { - start: c_s, - end: c_e, - }, - name: c_n, - arguments: args, - documentation, - deprecation: attributes.deprecated, - })) - } else { - Ok(None) + match Parser::maybe_upname(p) { + Some((c_s, c_n, c_e)) => { + let documentation = p.take_documentation(c_s); + let (args, args_e) = Parser::parse_type_constructor_args(p)?; + let end = args_e.max(c_e); + Ok(Some(RecordConstructor { + location: SrcSpan { start: c_s, end }, + name_location: SrcSpan { + start: c_s, + end: c_e, + }, + name: c_n, + arguments: args, + documentation, + deprecation: attributes.deprecated, + })) + } + _ => Ok(None), } }, // No separator @@ -2266,30 +2309,42 @@ where )?; let (_, close_end) = self.expect_custom_type_close(&name, public, opaque)?; (constructors, close_end) - } else if let Some((eq_s, eq_e)) = self.maybe_one(&Token::Equal) { - // Type Alias - if opaque { - return parse_error(ParseErrorType::OpaqueTypeAlias, SrcSpan { start, end }); - } + } else { + match self.maybe_one(&Token::Equal) { + Some((eq_s, eq_e)) => { + // Type Alias + if opaque { + return parse_error( + ParseErrorType::OpaqueTypeAlias, + SrcSpan { start, end }, + ); + } - if let Some(t) = self.parse_type()? { - let type_end = t.location().end; - return Ok(Some(Definition::TypeAlias(TypeAlias { - documentation, - location: SrcSpan::new(start, type_end), - publicity: self.publicity(public, attributes.internal)?, - alias: name, - name_location, - parameters, - type_ast: t, - type_: (), - deprecation: std::mem::take(&mut attributes.deprecated), - }))); - } else { - return parse_error(ParseErrorType::ExpectedType, SrcSpan::new(eq_s, eq_e)); + match self.parse_type()? { + Some(t) => { + let type_end = t.location().end; + return Ok(Some(Definition::TypeAlias(TypeAlias { + documentation, + location: SrcSpan::new(start, type_end), + publicity: self.publicity(public, attributes.internal)?, + alias: name, + name_location, + parameters, + type_ast: t, + type_: (), + deprecation: std::mem::take(&mut attributes.deprecated), + }))); + } + _ => { + return parse_error( + ParseErrorType::ExpectedType, + SrcSpan::new(eq_s, eq_e), + ); + } + } + } + _ => (vec![], end), } - } else { - (vec![], end) }; Ok(Some(Definition::CustomType(CustomType { @@ -2314,23 +2369,24 @@ where &mut self, ) -> Result<(u32, EcoString, Vec, u32, u32), ParseError> { let (start, upname, end) = self.expect_upname()?; - if let Some((par_s, _)) = self.maybe_one(&Token::LeftParen) { - let args = - Parser::series_of(self, &|p| Ok(Parser::maybe_name(p)), Some(&Token::Comma))?; - let (_, par_e) = self.expect_one_following_series(&Token::RightParen, "a name")?; - if args.is_empty() { - return parse_error( - ParseErrorType::TypeDefinitionNoArguments, - SrcSpan::new(par_s, par_e), - ); + match self.maybe_one(&Token::LeftParen) { + Some((par_s, _)) => { + let args = + Parser::series_of(self, &|p| Ok(Parser::maybe_name(p)), Some(&Token::Comma))?; + let (_, par_e) = self.expect_one_following_series(&Token::RightParen, "a name")?; + if args.is_empty() { + return parse_error( + ParseErrorType::TypeDefinitionNoArguments, + SrcSpan::new(par_s, par_e), + ); + } + let args2 = args + .into_iter() + .map(|(start, name, end)| (SrcSpan { start, end }, name)) + .collect(); + Ok((start, upname, args2, par_e, end)) } - let args2 = args - .into_iter() - .map(|(start, name, end)| (SrcSpan { start, end }, name)) - .collect(); - Ok((start, upname, args2, par_e, end)) - } else { - Ok((start, upname, vec![], end, end)) + _ => Ok((start, upname, vec![], end, end)), } } @@ -2453,23 +2509,22 @@ where let _ = self.expect_one_following_series(&Token::RightParen, "a type")?; let (arr_s, arr_e) = self.expect_one(&Token::RArrow)?; let retrn = self.parse_type()?; - if let Some(retrn) = retrn { - Ok(Some(TypeAst::Fn(TypeAstFn { + match retrn { + Some(retrn) => Ok(Some(TypeAst::Fn(TypeAstFn { location: SrcSpan { start, end: retrn.location().end, }, return_: Box::new(retrn), arguments: args, - }))) - } else { - parse_error( + }))), + _ => parse_error( ParseErrorType::ExpectedType, SrcSpan { start: arr_s, end: arr_e, }, - ) + ), } } @@ -2513,28 +2568,29 @@ where name: EcoString, end: u32, ) -> Result, ParseError> { - if let Some((par_s, _)) = self.maybe_one(&Token::LeftParen) { - let args = self.parse_types()?; - let (_, par_e) = self.expect_one(&Token::RightParen)?; - if args.is_empty() { - return parse_error( - ParseErrorType::TypeConstructorNoArguments, - SrcSpan::new(par_s, par_e), - ); + match self.maybe_one(&Token::LeftParen) { + Some((par_s, _)) => { + let args = self.parse_types()?; + let (_, par_e) = self.expect_one(&Token::RightParen)?; + if args.is_empty() { + return parse_error( + ParseErrorType::TypeConstructorNoArguments, + SrcSpan::new(par_s, par_e), + ); + } + Ok(Some(TypeAst::Constructor(TypeAstConstructor { + location: SrcSpan { start, end: par_e }, + module, + name, + arguments: args, + }))) } - Ok(Some(TypeAst::Constructor(TypeAstConstructor { - location: SrcSpan { start, end: par_e }, - module, - name, - arguments: args, - }))) - } else { - Ok(Some(TypeAst::Constructor(TypeAstConstructor { + _ => Ok(Some(TypeAst::Constructor(TypeAstConstructor { location: SrcSpan { start, end }, module, name, arguments: vec![], - }))) + }))), } } @@ -2720,42 +2776,43 @@ where let annotation = self.parse_type_annotation(&Token::Colon)?; let (eq_s, eq_e) = self.expect_one(&Token::Equal)?; - if let Some(value) = self.parse_const_value()? { - Ok(Some(Definition::ModuleConstant(ModuleConstant { - documentation, - location: SrcSpan { - start, + match self.parse_const_value()? { + Some(value) => { + Ok(Some(Definition::ModuleConstant(ModuleConstant { + documentation, + location: SrcSpan { + start, - // End after the type annotation if it's there, otherwise after the name - end: annotation - .as_ref() - .map(|annotation| annotation.location().end) - .unwrap_or(0) - .max(name_end), - }, - publicity: self.publicity(public, attributes.internal)?, - name, - name_location: SrcSpan::new(name_start, name_end), - annotation, - value: Box::new(value), - type_: (), - deprecation: attributes.deprecated.clone(), - implementations: Implementations { - gleam: true, - can_run_on_erlang: true, - can_run_on_javascript: true, - uses_erlang_externals: false, - uses_javascript_externals: false, - }, - }))) - } else { - parse_error( + // End after the type annotation if it's there, otherwise after the name + end: annotation + .as_ref() + .map(|annotation| annotation.location().end) + .unwrap_or(0) + .max(name_end), + }, + publicity: self.publicity(public, attributes.internal)?, + name, + name_location: SrcSpan::new(name_start, name_end), + annotation, + value: Box::new(value), + type_: (), + deprecation: attributes.deprecated.clone(), + implementations: Implementations { + gleam: true, + can_run_on_erlang: true, + can_run_on_javascript: true, + uses_erlang_externals: false, + uses_javascript_externals: false, + }, + }))) + } + _ => parse_error( ParseErrorType::NoValueAfterEqual, SrcSpan { start: eq_s, end: eq_e, }, - ) + ), } } @@ -2767,10 +2824,9 @@ where // foo <> "bar" fn parse_const_value(&mut self) -> Result, ParseError> { let constant_result = self.parse_const_value_unit(); - if let Ok(Some(constant)) = constant_result { - self.parse_const_maybe_concatenation(constant) - } else { - constant_result + match constant_result { + Ok(Some(constant)) => self.parse_const_maybe_concatenation(constant), + _ => constant_result, } } @@ -2945,23 +3001,22 @@ where Some((op_start, Token::LtGt, op_end)) => { self.advance(); - if let Ok(Some(right_constant_value)) = self.parse_const_value() { - Ok(Some(Constant::StringConcatenation { + match self.parse_const_value() { + Ok(Some(right_constant_value)) => Ok(Some(Constant::StringConcatenation { location: SrcSpan { start: left.location().start, end: right_constant_value.location().end, }, left: Box::new(left), right: Box::new(right_constant_value), - })) - } else { - parse_error( + })), + _ => parse_error( ParseErrorType::OpNakedRight, SrcSpan { start: op_start, end: op_end, }, - ) + ), } } t0 => { @@ -2979,28 +3034,31 @@ where name: EcoString, end: u32, ) -> Result, ParseError> { - if let Some((par_s, _)) = self.maybe_one(&Token::LeftParen) { - let args = - Parser::series_of(self, &Parser::parse_const_record_arg, Some(&Token::Comma))?; - let (_, par_e) = - self.expect_one_following_series(&Token::RightParen, "a constant record argument")?; - if args.is_empty() { - return parse_error( - ParseErrorType::ConstantRecordConstructorNoArguments, - SrcSpan::new(par_s, par_e), - ); + match self.maybe_one(&Token::LeftParen) { + Some((par_s, _)) => { + let args = + Parser::series_of(self, &Parser::parse_const_record_arg, Some(&Token::Comma))?; + let (_, par_e) = self.expect_one_following_series( + &Token::RightParen, + "a constant record argument", + )?; + if args.is_empty() { + return parse_error( + ParseErrorType::ConstantRecordConstructorNoArguments, + SrcSpan::new(par_s, par_e), + ); + } + Ok(Some(Constant::Record { + location: SrcSpan { start, end: par_e }, + module, + name, + args, + tag: (), + type_: (), + field_map: None, + })) } - Ok(Some(Constant::Record { - location: SrcSpan { start, end: par_e }, - module, - name, - args, - tag: (), - type_: (), - field_map: None, - })) - } else { - Ok(Some(Constant::Record { + _ => Ok(Some(Constant::Record { location: SrcSpan { start, end }, module, name, @@ -3008,7 +3066,7 @@ where tag: (), type_: (), field_map: None, - })) + })), } } @@ -3033,9 +3091,9 @@ where } }; - if let Some(value) = self.parse_const_value()? { - if let Some((start, label, _)) = label { - Ok(Some(CallArg { + match self.parse_const_value()? { + Some(value) => match label { + Some((start, label, _)) => Ok(Some(CallArg { implicit: None, location: SrcSpan { start, @@ -3043,31 +3101,34 @@ where }, value, label: Some(label), - })) - } else { - Ok(Some(CallArg { + })), + _ => Ok(Some(CallArg { implicit: None, location: value.location(), value, label: None, - })) + })), + }, + _ => { + match label { + Some((start, label, end)) => { + // Argument supplied with a label shorthand. + Ok(Some(CallArg { + implicit: None, + location: SrcSpan { start, end }, + label: Some(label.clone()), + value: UntypedConstant::Var { + location: SrcSpan { start, end }, + constructor: None, + module: None, + name: label, + type_: (), + }, + })) + } + _ => Ok(None), + } } - } else if let Some((start, label, end)) = label { - // Argument supplied with a label shorthand. - Ok(Some(CallArg { - implicit: None, - location: SrcSpan { start, end }, - label: Some(label.clone()), - value: UntypedConstant::Var { - location: SrcSpan { start, end }, - constructor: None, - module: None, - name: label, - type_: (), - }, - })) - } else { - Ok(None) } } @@ -3088,31 +3149,32 @@ where where A: HasLocation + std::fmt::Debug, { - if let Some(value) = value_parser(self)? { - let options = if self.maybe_one(&Token::Colon).is_some() { - Parser::series_of( - self, - &|s| Parser::parse_bit_array_option(s, &arg_parser, &to_int_segment), - Some(&Token::Minus), - )? - } else { - vec![] - }; - let end = options - .last() - .map(|o| o.location().end) - .unwrap_or_else(|| value.location().end); - Ok(Some(BitArraySegment { - location: SrcSpan { - start: value.location().start, - end, - }, - value: Box::new(value), - type_: (), - options, - })) - } else { - Ok(None) + match value_parser(self)? { + Some(value) => { + let options = if self.maybe_one(&Token::Colon).is_some() { + Parser::series_of( + self, + &|s| Parser::parse_bit_array_option(s, &arg_parser, &to_int_segment), + Some(&Token::Minus), + )? + } else { + vec![] + }; + let end = options + .last() + .map(|o| o.location().end) + .unwrap_or_else(|| value.location().end); + Ok(Some(BitArraySegment { + location: SrcSpan { + start: value.location().start, + end, + }, + value: Box::new(value), + type_: (), + options, + })) + } + _ => Ok(None), } } @@ -3132,9 +3194,8 @@ where if self.maybe_one(&Token::LeftParen).is_some() { // named function segment match name.as_str() { - "unit" => { - if let Some((int_s, Token::Int { value, .. }, int_e)) = self.next_tok() - { + "unit" => match self.next_tok() { + Some((int_s, Token::Int { value, .. }, int_e)) => { let (_, end) = self.expect_one(&Token::RightParen)?; let v = value.replace("_", ""); match u8::from_str(&v) { @@ -3151,10 +3212,9 @@ where }, }), } - } else { - self.next_tok_unexpected(vec!["positive integer".into()]) } - } + _ => self.next_tok_unexpected(vec!["positive integer".into()]), + }, "size" => { let value = arg_parser(self)?; @@ -3222,18 +3282,16 @@ where } fn expect_expression(&mut self) -> Result { - if let Some(e) = self.parse_expression()? { - Ok(e) - } else { - self.next_tok_unexpected(vec!["An expression".into()]) + match self.parse_expression()? { + Some(e) => Ok(e), + _ => self.next_tok_unexpected(vec!["An expression".into()]), } } fn expect_expression_unit(&mut self) -> Result { - if let Some(e) = self.parse_expression_unit()? { - Ok(e) - } else { - self.next_tok_unexpected(vec!["An expression".into()]) + match self.parse_expression_unit()? { + Some(e) => Ok(e), + _ => self.next_tok_unexpected(vec!["An expression".into()]), } } @@ -3360,17 +3418,20 @@ functions are declared separately from types."; fn expect_upname(&mut self) -> Result<(u32, EcoString, u32), ParseError> { let t = self.next_tok(); match t { - Some((start, tok, end)) => { - if let Token::Name { .. } = tok { - parse_error(ParseErrorType::IncorrectUpName, SrcSpan { start, end }) - } else if let Token::UpName { name } = tok { - Ok((start, name, end)) - } else if let Token::DiscardName { .. } = tok { + Some((start, tok, end)) => match tok { + Token::Name { .. } => { parse_error(ParseErrorType::IncorrectUpName, SrcSpan { start, end }) - } else { - parse_error(ParseErrorType::ExpectedUpName, SrcSpan { start, end }) } - } + _ => match tok { + Token::UpName { name } => Ok((start, name, end)), + _ => match tok { + Token::DiscardName { .. } => { + parse_error(ParseErrorType::IncorrectUpName, SrcSpan { start, end }) + } + _ => parse_error(ParseErrorType::ExpectedUpName, SrcSpan { start, end }), + }, + }, + }, None => parse_error(ParseErrorType::UnexpectedEof, SrcSpan { start: 0, end: 0 }), } } @@ -3380,7 +3441,7 @@ functions are declared separately from types."; let (start, t, end) = match self.next_tok() { Some(t) => t, None => { - return parse_error(ParseErrorType::UnexpectedEof, SrcSpan { start: 0, end: 0 }) + return parse_error(ParseErrorType::UnexpectedEof, SrcSpan { start: 0, end: 0 }); } }; match t { @@ -3777,17 +3838,18 @@ fn handle_op( let mut next_op = next_op; loop { match (opstack.pop(), next_op.take()) { - (None, None) => { - if let Some(fin) = estack.pop() { + (None, None) => match estack.pop() { + Some(fin) => { if estack.is_empty() { return Some(fin); } else { panic!("Expression not fully reduced.") } - } else { + } + _ => { return None; } - } + }, (None, Some(op)) => { opstack.push(op); @@ -3873,25 +3935,31 @@ fn do_reduce_clause_guard(op: Spanned, estack: &mut Vec) { fn expr_op_reduction((_, token, _): Spanned, l: UntypedExpr, r: UntypedExpr) -> UntypedExpr { if token == Token::Pipe { - let expressions = if let UntypedExpr::PipeLine { mut expressions } = l { - expressions.push(r); - expressions - } else { - vec1![l, r] + let expressions = match l { + UntypedExpr::PipeLine { mut expressions } => { + expressions.push(r); + expressions + } + _ => { + vec1![l, r] + } }; UntypedExpr::PipeLine { expressions } - } else if let Some(bin_op) = tok_to_binop(&token) { - UntypedExpr::BinOp { - location: SrcSpan { - start: l.location().start, - end: r.location().end, + } else { + match tok_to_binop(&token) { + Some(bin_op) => UntypedExpr::BinOp { + location: SrcSpan { + start: l.location().start, + end: r.location().end, + }, + name: bin_op, + left: Box::new(l), + right: Box::new(r), }, - name: bin_op, - left: Box::new(l), - right: Box::new(r), + _ => { + panic!("Token could not be converted to binop.") + } } - } else { - panic!("Token could not be converted to binop.") } } diff --git a/compiler-core/src/parse/lexer.rs b/compiler-core/src/parse/lexer.rs index 004a71bc48e..c31fe251380 100644 --- a/compiler-core/src/parse/lexer.rs +++ b/compiler-core/src/parse/lexer.rs @@ -477,12 +477,15 @@ where let end_pos = self.get_pos(); - if let Some(tok) = str_to_keyword(&name) { - Ok((start_pos, tok, end_pos)) - } else if name.starts_with('_') { - Ok((start_pos, Token::DiscardName { name: name.into() }, end_pos)) - } else { - Ok((start_pos, Token::Name { name: name.into() }, end_pos)) + match str_to_keyword(&name) { + Some(tok) => Ok((start_pos, tok, end_pos)), + _ => { + if name.starts_with('_') { + Ok((start_pos, Token::DiscardName { name: name.into() }, end_pos)) + } else { + Ok((start_pos, Token::Name { name: name.into() }, end_pos)) + } + } } } // A type name or constructor @@ -496,10 +499,9 @@ where let end_pos = self.get_pos(); - if let Some(tok) = str_to_keyword(&name) { - Ok((start_pos, tok, end_pos)) - } else { - Ok((start_pos, Token::UpName { name: name.into() }, end_pos)) + match str_to_keyword(&name) { + Some(tok) => Ok((start_pos, tok, end_pos)), + _ => Ok((start_pos, Token::UpName { name: name.into() }, end_pos)), } } diff --git a/compiler-core/src/parse/tests.rs b/compiler-core/src/parse/tests.rs index 10538f0d9e6..72c420e5803 100644 --- a/compiler-core/src/parse/tests.rs +++ b/compiler-core/src/parse/tests.rs @@ -12,11 +12,11 @@ use itertools::Itertools; use pretty_assertions::assert_eq; macro_rules! assert_error { - ($src:expr, $error:expr $(,)?) => { + ($src:expr_2021, $error:expr_2021 $(,)?) => { let result = crate::parse::parse_statement_sequence($src).expect_err("should not parse"); assert_eq!(($src, $error), ($src, result),); }; - ($src:expr) => { + ($src:expr_2021) => { let error = $crate::parse::tests::expect_error($src); let output = format!("----- SOURCE CODE\n{}\n\n----- ERROR\n{}", $src, error); insta::assert_snapshot!(insta::internals::AutoName, output, $src); @@ -24,7 +24,7 @@ macro_rules! assert_error { } macro_rules! assert_module_error { - ($src:expr) => { + ($src:expr_2021) => { let error = $crate::parse::tests::expect_module_error($src); let output = format!("----- SOURCE CODE\n{}\n\n----- ERROR\n{}", $src, error); insta::assert_snapshot!(insta::internals::AutoName, output, $src); @@ -32,7 +32,7 @@ macro_rules! assert_module_error { } macro_rules! assert_parse_module { - ($src:expr) => { + ($src:expr_2021) => { let result = crate::parse::parse_module( camino::Utf8PathBuf::from("test/path"), $src, @@ -44,7 +44,7 @@ macro_rules! assert_parse_module { } macro_rules! assert_parse { - ($src:expr) => { + ($src:expr_2021) => { let result = crate::parse::parse_statement_sequence($src).expect("should parse"); insta::assert_snapshot!(insta::internals::AutoName, &format!("{:#?}", result), $src); }; diff --git a/compiler-core/src/paths.rs b/compiler-core/src/paths.rs index 69c741ee52d..e71080e6123 100644 --- a/compiler-core/src/paths.rs +++ b/compiler-core/src/paths.rs @@ -166,6 +166,8 @@ fn paths() { .ends_with("hex/hexpm/packages/gleam_stdlib-0.17.1.tar") ); - assert!(global_package_cache_package_tarball("elli", "1.0.0") - .ends_with("hex/hexpm/packages/elli-1.0.0.tar")); + assert!( + global_package_cache_package_tarball("elli", "1.0.0") + .ends_with("hex/hexpm/packages/elli-1.0.0.tar") + ); } diff --git a/compiler-core/src/pretty.rs b/compiler-core/src/pretty.rs index c4c4ddb0361..20e0525dd2f 100644 --- a/compiler-core/src/pretty.rs +++ b/compiler-core/src/pretty.rs @@ -16,11 +16,11 @@ #[cfg(test)] mod tests; -use ecow::{eco_format, EcoString}; +use ecow::{EcoString, eco_format}; use itertools::Itertools; use unicode_segmentation::UnicodeSegmentation; -use crate::{io::Utf8Writer, Result}; +use crate::{Result, io::Utf8Writer}; #[macro_export] macro_rules! docvec { @@ -28,7 +28,7 @@ macro_rules! docvec { Document::Vec(Vec::new()) }; - ($($x:expr),+ $(,)?) => { + ($($x:expr_2021),+ $(,)?) => { Document::Vec(vec![$($x.to_doc()),+]) }; } diff --git a/compiler-core/src/requirement.rs b/compiler-core/src/requirement.rs index 92d4248229f..ec8f9a24c7f 100644 --- a/compiler-core/src/requirement.rs +++ b/compiler-core/src/requirement.rs @@ -6,9 +6,9 @@ use crate::io::make_relative; use camino::{Utf8Path, Utf8PathBuf}; use ecow::EcoString; use hexpm::version::Range; +use serde::Deserialize; use serde::de::{self, Deserializer, MapAccess, Visitor}; use serde::ser::{Serialize, SerializeMap, Serializer}; -use serde::Deserialize; #[derive(Deserialize, Debug, PartialEq, Eq, Clone)] #[serde(untagged, remote = "Self")] diff --git a/compiler-core/src/type_/environment.rs b/compiler-core/src/type_/environment.rs index 81a67000556..3995bb0e5bd 100644 --- a/compiler-core/src/type_/environment.rs +++ b/compiler-core/src/type_/environment.rs @@ -2,7 +2,7 @@ use pubgrub::range::Range; use crate::{ analyse::TargetSupport, - ast::{Publicity, PIPE_VARIABLE}, + ast::{PIPE_VARIABLE, Publicity}, build::Target, error::edit_distance, uid::UniqueIdGenerator, @@ -540,13 +540,13 @@ impl Environment<'_> { Type::Var { type_ } => { match type_.borrow().deref() { TypeVar::Link { type_ } => { - return self.instantiate(type_.clone(), ids, hydrator) + return self.instantiate(type_.clone(), ids, hydrator); } TypeVar::Unbound { .. } => { return Arc::new(Type::Var { type_: type_.clone(), - }) + }); } TypeVar::Generic { id } => match ids.get(id) { diff --git a/compiler-core/src/type_/error.rs b/compiler-core/src/type_/error.rs index c6136fcf866..68661473bf7 100644 --- a/compiler-core/src/type_/error.rs +++ b/compiler-core/src/type_/error.rs @@ -1,6 +1,6 @@ use super::{ - expression::{ArgumentKind, CallKind}, FieldAccessUsage, + expression::{ArgumentKind, CallKind}, }; use crate::{ ast::{BinOp, Layer, SrcSpan, TodoKind}, diff --git a/compiler-core/src/type_/expression.rs b/compiler-core/src/type_/expression.rs index cdd62431c3f..3bfbdb8cbda 100644 --- a/compiler-core/src/type_/expression.rs +++ b/compiler-core/src/type_/expression.rs @@ -4,12 +4,12 @@ use crate::{ ast::{ Arg, Assignment, AssignmentKind, BinOp, BitArrayOption, BitArraySegment, CallArg, Clause, ClauseGuard, Constant, FunctionLiteralKind, HasLocation, ImplicitCallArgOrigin, Layer, - RecordBeingUpdated, SrcSpan, Statement, TodoKind, TypeAst, TypedArg, TypedAssignment, - TypedClause, TypedClauseGuard, TypedConstant, TypedExpr, TypedMultiPattern, TypedStatement, - UntypedArg, UntypedAssignment, UntypedClause, UntypedClauseGuard, UntypedConstant, - UntypedConstantBitArraySegment, UntypedExpr, UntypedExprBitArraySegment, - UntypedMultiPattern, UntypedStatement, UntypedUse, UntypedUseAssignment, Use, - UseAssignment, RECORD_UPDATE_VARIABLE, USE_ASSIGNMENT_VARIABLE, + RECORD_UPDATE_VARIABLE, RecordBeingUpdated, SrcSpan, Statement, TodoKind, TypeAst, + TypedArg, TypedAssignment, TypedClause, TypedClauseGuard, TypedConstant, TypedExpr, + TypedMultiPattern, TypedStatement, USE_ASSIGNMENT_VARIABLE, UntypedArg, UntypedAssignment, + UntypedClause, UntypedClauseGuard, UntypedConstant, UntypedConstantBitArraySegment, + UntypedExpr, UntypedExprBitArraySegment, UntypedMultiPattern, UntypedStatement, UntypedUse, + UntypedUseAssignment, Use, UseAssignment, }, build::Target, exhaustiveness::{self, Reachability}, @@ -1713,7 +1713,7 @@ impl<'a, 'b> ExprTyper<'a, 'b> { ValueConstructorVariant::ModuleConstant { literal, .. } | ValueConstructorVariant::LocalConstant { literal } => { - return Ok(ClauseGuard::Constant(literal.clone())) + return Ok(ClauseGuard::Constant(literal.clone())); } }; @@ -2569,32 +2569,37 @@ impl<'a, 'b> ExprTyper<'a, 'b> { self.track_feature_usage(FeatureKind::LabelShorthandSyntax, *location); } - if let Some(index) = fields.remove(label) { - unify(variant.arg_type(index), value.type_()) - .map_err(|e| convert_unify_error(e, *location))?; + match fields.remove(label) { + Some(index) => { + unify(variant.arg_type(index), value.type_()) + .map_err(|e| convert_unify_error(e, *location))?; - Ok(( - index, - CallArg { - label: Some(label.clone()), - location: *location, - value, - implicit: None, - }, - )) - } else if variant.has_field(label) { - Err(Error::DuplicateArgument { - location: *location, - label: label.clone(), - }) - } else { - Err(self.unknown_field_error( - variant.field_names(), - record_type.clone(), - *location, - label.clone(), - FieldAccessUsage::RecordUpdate, - )) + Ok(( + index, + CallArg { + label: Some(label.clone()), + location: *location, + value, + implicit: None, + }, + )) + } + _ => { + if variant.has_field(label) { + Err(Error::DuplicateArgument { + location: *location, + label: label.clone(), + }) + } else { + Err(self.unknown_field_error( + variant.field_names(), + record_type.clone(), + *location, + label.clone(), + FieldAccessUsage::RecordUpdate, + )) + } + } } }, ) @@ -2675,7 +2680,7 @@ impl<'a, 'b> ExprTyper<'a, 'b> { _ => { return Err(Error::RecordUpdateInvalidConstructor { location: constructor.location(), - }) + }); } }; @@ -2703,7 +2708,7 @@ impl<'a, 'b> ExprTyper<'a, 'b> { _ => { return Err(Error::RecordUpdateInvalidConstructor { location: constructor.location(), - }) + }); } }; @@ -2985,13 +2990,13 @@ impl<'a, 'b> ExprTyper<'a, 'b> { ValueConstructorVariant::ModuleFn { .. } | ValueConstructorVariant::LocalVariable { .. } => { - return Err(Error::NonLocalClauseGuardVariable { location, name }) + return Err(Error::NonLocalClauseGuardVariable { location, name }); } // TODO: remove this clone. Could use an rc instead ValueConstructorVariant::ModuleConstant { literal, .. } | ValueConstructorVariant::LocalConstant { literal } => { - return Ok(literal.clone()) + return Ok(literal.clone()); } }; @@ -3029,13 +3034,13 @@ impl<'a, 'b> ExprTyper<'a, 'b> { ValueConstructorVariant::ModuleFn { .. } | ValueConstructorVariant::LocalVariable { .. } => { - return Err(Error::NonLocalClauseGuardVariable { location, name }) + return Err(Error::NonLocalClauseGuardVariable { location, name }); } // TODO: remove this clone. Could be an rc instead ValueConstructorVariant::ModuleConstant { literal, .. } | ValueConstructorVariant::LocalConstant { literal } => { - return Ok(literal.clone()) + return Ok(literal.clone()); } }; @@ -3225,16 +3230,17 @@ impl<'a, 'b> ExprTyper<'a, 'b> { // Type annotation and inferred value are valid. Ensure they are unifiable. // NOTE: if the types are not unifiable we use the annotated type. (Some(Ok(const_ann)), Ok(inferred)) => { - if let Err(e) = unify(const_ann.clone(), inferred.type_()) + match unify(const_ann.clone(), inferred.type_()) .map_err(|e| convert_unify_error(e, inferred.location())) { - self.problems.error(e); - Constant::Invalid { - location: loc, - type_: const_ann, + Err(e) => { + self.problems.error(e); + Constant::Invalid { + location: loc, + type_: const_ann, + } } - } else { - inferred + _ => inferred, } } // Type annotation is valid but not the inferred value. Place a placeholder constant with the annotation type. @@ -3427,22 +3433,24 @@ impl<'a, 'b> ExprTyper<'a, 'b> { } }); if let Err(e) = field_map { - if let Error::IncorrectArity { - expected, - given, - labels, - location, - } = e - { - labelled_arity_error = true; - self.problems.error(Error::IncorrectArity { + match e { + Error::IncorrectArity { expected, given, labels, location, - }); - } else { - self.problems.error(e); + } => { + labelled_arity_error = true; + self.problems.error(Error::IncorrectArity { + expected, + given, + labels, + location, + }); + } + _ => { + self.problems.error(e); + } } } diff --git a/compiler-core/src/type_/pattern.rs b/compiler-core/src/type_/pattern.rs index 4b78ee306c0..d7bccbbbae3 100644 --- a/compiler-core/src/type_/pattern.rs +++ b/compiler-core/src/type_/pattern.rs @@ -8,7 +8,7 @@ use num_bigint::BigInt; /// use super::*; use crate::{ - analyse::{name::check_name_case, Inferred}, + analyse::{Inferred, name::check_name_case}, ast::{ AssignName, BitArrayOption, ImplicitCallArgOrigin, Layer, UntypedPatternBitArraySegment, }, @@ -464,16 +464,21 @@ impl<'a, 'b> PatternTyper<'a, 'b> { } // The right hand side may assign a variable, which is the suffix of the string - if let AssignName::Variable(right) = &right_side_assignment { - self.insert_variable( - right.as_ref(), - string(), - right_location, - VariableOrigin::Variable(right.clone()), - ) - .map_err(|e| convert_unify_error(e, location))?; - } else if let AssignName::Discard(right) = &right_side_assignment { - self.check_name_case(right_location, right, Named::Discard); + match &right_side_assignment { + AssignName::Variable(right) => { + self.insert_variable( + right.as_ref(), + string(), + right_location, + VariableOrigin::Variable(right.clone()), + ) + .map_err(|e| convert_unify_error(e, location))?; + } + AssignName::Discard(_) => { + if let AssignName::Discard(right) = &right_side_assignment { + self.check_name_case(right_location, right, Named::Discard); + } + } }; Ok(Pattern::StringPrefix { diff --git a/compiler-core/src/type_/pipe.rs b/compiler-core/src/type_/pipe.rs index e346c68702f..4f8c8ccdb2d 100644 --- a/compiler-core/src/type_/pipe.rs +++ b/compiler-core/src/type_/pipe.rs @@ -2,8 +2,8 @@ use self::expression::CallKind; use super::*; use crate::ast::{ - FunctionLiteralKind, ImplicitCallArgOrigin, PipelineAssignmentKind, Statement, - TypedPipelineAssignment, UntypedExpr, PIPE_VARIABLE, + FunctionLiteralKind, ImplicitCallArgOrigin, PIPE_VARIABLE, PipelineAssignmentKind, Statement, + TypedPipelineAssignment, UntypedExpr, }; use vec1::Vec1; diff --git a/compiler-core/src/type_/pretty.rs b/compiler-core/src/type_/pretty.rs index d0e75e3baab..de6f15d40a0 100644 --- a/compiler-core/src/type_/pretty.rs +++ b/compiler-core/src/type_/pretty.rs @@ -97,7 +97,7 @@ impl Printer { fn type_var_doc<'a>(&mut self, type_: &TypeVar) -> Document<'a> { match type_ { - TypeVar::Link { ref type_, .. } => self.print(type_), + TypeVar::Link { type_, .. } => self.print(type_), TypeVar::Unbound { id, .. } | TypeVar::Generic { id, .. } => self.generic_type_var(*id), } } @@ -246,7 +246,7 @@ fn next_letter_test() { #[test] fn pretty_print_test() { macro_rules! assert_string { - ($src:expr, $type_:expr $(,)?) => { + ($src:expr_2021, $type_:expr_2021 $(,)?) => { let mut printer = Printer::new(); assert_eq!($type_.to_string(), printer.pretty_print(&$src, 0),); }; diff --git a/compiler-core/src/type_/printer.rs b/compiler-core/src/type_/printer.rs index b15a21e4dc8..66685d65999 100644 --- a/compiler-core/src/type_/printer.rs +++ b/compiler-core/src/type_/printer.rs @@ -1,5 +1,5 @@ use bimap::BiMap; -use ecow::{eco_format, EcoString}; +use ecow::{EcoString, eco_format}; use im::HashMap; use std::{collections::HashSet, sync::Arc}; @@ -321,10 +321,9 @@ impl<'a> Printer<'a> { } pub fn print_module(&self, module: &str) -> EcoString { - if let Some(module) = self.names.imported_modules.get(module) { - module.clone() - } else { - module.split("/").last().unwrap_or(module).into() + match self.names.imported_modules.get(module) { + Some(module) => module.clone(), + _ => module.split("/").last().unwrap_or(module).into(), } } diff --git a/compiler-core/src/type_/tests.rs b/compiler-core/src/type_/tests.rs index 76b6b4f7041..b2bf9e749ba 100644 --- a/compiler-core/src/type_/tests.rs +++ b/compiler-core/src/type_/tests.rs @@ -38,7 +38,7 @@ mod warnings; #[macro_export] macro_rules! assert_infer { - ($src:expr, $type_:expr $(,)?) => { + ($src:expr_2021, $type_:expr_2021 $(,)?) => { let t = $crate::type_::tests::infer($src); assert_eq!(($src, t), ($src, $type_.to_string()),); }; @@ -47,9 +47,9 @@ macro_rules! assert_infer { #[macro_export] macro_rules! assert_infer_with_module { ( - ($name1:expr, $module_src1:literal), - ($name2:expr, $module_src2:literal), - $src:expr, $module:expr $(,)? + ($name1:expr_2021, $module_src1:literal), + ($name2:expr_2021, $module_src2:literal), + $src:expr_2021, $module:expr_2021 $(,)? ) => { let constructors = $crate::type_::tests::infer_module( $src, @@ -62,7 +62,7 @@ macro_rules! assert_infer_with_module { assert_eq!(($src, constructors), ($src, expected)); }; - (($name:expr, $module_src:literal), $src:expr, $module:expr $(,)?) => { + (($name:expr_2021, $module_src:literal), $src:expr_2021, $module:expr_2021 $(,)?) => { let constructors = $crate::type_::tests::infer_module($src, vec![("thepackage", $name, $module_src)]); let expected = $crate::type_::tests::stringify_tuple_strs($module); @@ -73,7 +73,7 @@ macro_rules! assert_infer_with_module { #[macro_export] macro_rules! assert_module_infer { - ($src:expr, $module:expr $(,)?) => {{ + ($src:expr_2021, $module:expr_2021 $(,)?) => {{ let constructors = $crate::type_::tests::infer_module($src, vec![]); let expected = $crate::type_::tests::stringify_tuple_strs($module); assert_eq!(($src, constructors), ($src, expected)); @@ -82,7 +82,7 @@ macro_rules! assert_module_infer { #[macro_export] macro_rules! assert_js_module_infer { - ($src:expr, $module:expr $(,)?) => {{ + ($src:expr_2021, $module:expr_2021 $(,)?) => {{ let constructors = $crate::type_::tests::infer_module_with_target( "test_module", $src, @@ -96,7 +96,7 @@ macro_rules! assert_js_module_infer { #[macro_export] macro_rules! assert_module_error { - ($src:expr) => { + ($src:expr_2021) => { let error = $crate::type_::tests::module_error($src, vec![]); let output = format!("----- SOURCE CODE\n{}\n\n----- ERROR\n{}", $src, error); insta::assert_snapshot!(insta::internals::AutoName, output, $src); @@ -105,7 +105,7 @@ macro_rules! assert_module_error { #[macro_export] macro_rules! assert_internal_module_error { - ($src:expr) => { + ($src:expr_2021) => { let error = $crate::type_::tests::internal_module_error($src, vec![]); let output = format!("----- SOURCE CODE\n{}\n\n----- ERROR\n{}", $src, error); insta::assert_snapshot!(insta::internals::AutoName, output, $src); @@ -114,7 +114,7 @@ macro_rules! assert_internal_module_error { #[macro_export] macro_rules! assert_js_module_error { - ($src:expr) => { + ($src:expr_2021) => { let error = $crate::type_::tests::module_error_with_target( $src, vec![], @@ -127,7 +127,7 @@ macro_rules! assert_js_module_error { #[macro_export] macro_rules! assert_module_syntax_error { - ($src:expr) => { + ($src:expr_2021) => { let error = $crate::type_::tests::syntax_error($src); let output = format!("----- SOURCE CODE\n{}\n\n----- ERROR\n{}", $src, error); insta::assert_snapshot!(insta::internals::AutoName, output, $src); @@ -136,13 +136,13 @@ macro_rules! assert_module_syntax_error { #[macro_export] macro_rules! assert_error { - ($src:expr, $error:expr $(,)?) => { + ($src:expr_2021, $error:expr_2021 $(,)?) => { let result = $crate::type_::tests::compile_statement_sequence($src) .expect_err("should infer an error"); assert_eq!(($src, sort_options($error)), ($src, sort_options(result)),); }; - ($src:expr) => { + ($src:expr_2021) => { let (error, names) = $crate::type_::tests::compile_statement_sequence($src) .expect_err("should infer an error"); let error = $crate::error::Error::Type { @@ -162,7 +162,7 @@ macro_rules! assert_error { #[macro_export] macro_rules! assert_with_module_error { - (($name:expr, $module_src:literal), $src:expr $(,)?) => { + (($name:expr_2021, $module_src:literal), $src:expr_2021 $(,)?) => { let error = $crate::type_::tests::module_error($src, vec![("thepackage", $name, $module_src)]); let output = format!( @@ -181,9 +181,9 @@ macro_rules! assert_with_module_error { }; ( - ($name:expr, $module_src:literal), - ($name2:expr, $module_src2:literal), - $src:expr $(,)? + ($name:expr_2021, $module_src:literal), + ($name2:expr_2021, $module_src2:literal), + $src:expr_2021 $(,)? ) => { let error = $crate::type_::tests::module_error( $src, @@ -271,14 +271,14 @@ macro_rules! assert_warnings_with_imports { #[macro_export] macro_rules! assert_warning { - ($src:expr) => { + ($src:expr_2021) => { let warning = $crate::type_::tests::get_printed_warnings($src, vec![], crate::build::Target::Erlang, None); assert!(!warning.is_empty()); let output = format!("----- SOURCE CODE\n{}\n\n----- WARNING\n{}", $src, warning); insta::assert_snapshot!(insta::internals::AutoName, output, $src); }; - ($(($name:expr, $module_src:literal)),+, $src:expr) => { + ($(($name:expr_2021, $module_src:literal)),+, $src:expr_2021) => { let warning = $crate::type_::tests::get_printed_warnings( $src, vec![$(("thepackage", $name, $module_src)),*], @@ -290,7 +290,7 @@ macro_rules! assert_warning { insta::assert_snapshot!(insta::internals::AutoName, output, $src); }; - ($(($package:expr, $name:expr, $module_src:literal)),+, $src:expr) => { + ($(($package:expr_2021, $name:expr_2021, $module_src:literal)),+, $src:expr_2021) => { let warning = $crate::type_::tests::get_printed_warnings( $src, vec![$(($package, $name, $module_src)),*], @@ -305,7 +305,7 @@ macro_rules! assert_warning { #[macro_export] macro_rules! assert_js_warning { - ($src:expr) => { + ($src:expr_2021) => { let warning = $crate::type_::tests::get_printed_warnings( $src, vec![], @@ -320,7 +320,7 @@ macro_rules! assert_js_warning { #[macro_export] macro_rules! assert_js_no_warnings { - ($src:expr) => { + ($src:expr_2021) => { let warning = $crate::type_::tests::get_printed_warnings( $src, vec![], @@ -333,7 +333,7 @@ macro_rules! assert_js_no_warnings { #[macro_export] macro_rules! assert_warnings_with_gleam_version { - ($gleam_version:expr, $src:expr$(,)?) => { + ($gleam_version:expr_2021, $src:expr_2021$(,)?) => { let warning = $crate::type_::tests::get_printed_warnings( $src, vec![], @@ -348,7 +348,7 @@ macro_rules! assert_warnings_with_gleam_version { #[macro_export] macro_rules! assert_js_warnings_with_gleam_version { - ($gleam_version:expr, $src:expr$(,)?) => { + ($gleam_version:expr_2021, $src:expr_2021$(,)?) => { let warning = $crate::type_::tests::get_printed_warnings( $src, vec![], @@ -363,7 +363,7 @@ macro_rules! assert_js_warnings_with_gleam_version { #[macro_export] macro_rules! assert_js_no_warnings_with_gleam_version { - ($gleam_version:expr, $src:expr$(,)?) => { + ($gleam_version:expr_2021, $src:expr_2021$(,)?) => { let warning = $crate::type_::tests::get_printed_warnings( $src, vec![], @@ -376,11 +376,11 @@ macro_rules! assert_js_no_warnings_with_gleam_version { #[macro_export] macro_rules! assert_no_warnings { - ($src:expr $(,)?) => { + ($src:expr_2021 $(,)?) => { let warnings = $crate::type_::tests::get_warnings($src, vec![], crate::build::Target::Erlang, None); assert_eq!(warnings, vec![]); }; - ($(($package:expr, $name:expr, $module_src:literal)),+, $src:expr $(,)?) => { + ($(($package:expr_2021, $name:expr_2021, $module_src:literal)),+, $src:expr_2021 $(,)?) => { let warnings = $crate::type_::tests::get_warnings( $src, vec![$(($package, $name, $module_src)),*], diff --git a/compiler-core/src/type_/tests/pretty.rs b/compiler-core/src/type_/tests/pretty.rs index ffb79cf0cf1..0c21775e0e7 100644 --- a/compiler-core/src/type_/tests/pretty.rs +++ b/compiler-core/src/type_/tests/pretty.rs @@ -1,9 +1,9 @@ use std::sync::Arc; use crate::type_::{ + Type, prelude::{bool, int, tuple}, pretty::Printer, - Type, }; use super::Publicity; diff --git a/compiler-core/src/type_/tests/target_implementations.rs b/compiler-core/src/type_/tests/target_implementations.rs index beca2a51263..a5605010979 100644 --- a/compiler-core/src/type_/tests/target_implementations.rs +++ b/compiler-core/src/type_/tests/target_implementations.rs @@ -8,7 +8,7 @@ use crate::{ use super::compile_module_with_opts; macro_rules! assert_targets { - ($src:expr, $implementations:expr $(,)?) => { + ($src:expr_2021, $implementations:expr_2021 $(,)?) => { let result = $crate::type_::tests::target_implementations::implementations($src); let expected = $implementations .iter() diff --git a/compiler-core/src/uid.rs b/compiler-core/src/uid.rs index d8c2421694d..6bc33362d04 100644 --- a/compiler-core/src/uid.rs +++ b/compiler-core/src/uid.rs @@ -1,6 +1,6 @@ use std::sync::{ - atomic::{AtomicU64, Ordering}, Arc, + atomic::{AtomicU64, Ordering}, }; /// A generator of unique ids. Only one should be used per compilation run to diff --git a/compiler-core/src/warning.rs b/compiler-core/src/warning.rs index a0a64e7602b..46e55e7abf1 100644 --- a/compiler-core/src/warning.rs +++ b/compiler-core/src/warning.rs @@ -17,7 +17,7 @@ use debug_ignore::DebugIgnore; use ecow::EcoString; use std::{ io::Write, - sync::{atomic::Ordering, Arc}, + sync::{Arc, atomic::Ordering}, }; use std::{rc::Rc, sync::atomic::AtomicUsize}; use termcolor::Buffer; @@ -1002,14 +1002,17 @@ See: https://tour.gleam.run/advanced-features/{name}/" panic_position: unreachable_code_kind, } => { let text = match unreachable_code_kind { - PanicPosition::PreviousExpression => - "This code is unreachable because it comes after a `panic`.", - PanicPosition::PreviousFunctionArgument => + PanicPosition::PreviousExpression => { + "This code is unreachable because it comes after a `panic`." + } + PanicPosition::PreviousFunctionArgument => { "This argument is unreachable because the previous one always panics. \ -Your code will crash before reaching this point.", - PanicPosition::LastFunctionArgument => +Your code will crash before reaching this point." + } + PanicPosition::LastFunctionArgument => { "This function call is unreachable because its last argument always panics. \ -Your code will crash before reaching this point.", +Your code will crash before reaching this point." + } }; Diagnostic { diff --git a/compiler-wasm/Cargo.toml b/compiler-wasm/Cargo.toml index 2886a30cfa5..6682a959f45 100644 --- a/compiler-wasm/Cargo.toml +++ b/compiler-wasm/Cargo.toml @@ -2,7 +2,7 @@ name = "gleam-wasm" version = "1.8.1" authors = ["Louis Pilfold "] -edition = "2021" +edition = "2024" license-file = "LICENCE" [lib] diff --git a/compiler-wasm/src/lib.rs b/compiler-wasm/src/lib.rs index 102cddd138a..87abe7ee8fb 100644 --- a/compiler-wasm/src/lib.rs +++ b/compiler-wasm/src/lib.rs @@ -5,6 +5,7 @@ mod wasm_filesystem; use camino::Utf8PathBuf; use gleam_core::{ + Error, analyse::TargetSupport, build::{ Mode, NullTelemetry, PackageCompiler, StaleTracker, Target, TargetCodegenConfiguration, @@ -13,7 +14,6 @@ use gleam_core::{ io::{FileSystemReader, FileSystemWriter}, uid::UniqueIdGenerator, warning::{VectorWarningEmitterIO, WarningEmitter}, - Error, }; use hexpm::version::Version; use im::HashMap; diff --git a/compiler-wasm/src/tests.rs b/compiler-wasm/src/tests.rs index 0cbf336f7e0..3e0015ae236 100644 --- a/compiler-wasm/src/tests.rs +++ b/compiler-wasm/src/tests.rs @@ -87,9 +87,11 @@ pub fn main() { wibble() } "#, ); - assert!(compile_package(0, "javascript") - .unwrap_err() - .contains("Unsupported feature for compilation target")); + assert!( + compile_package(0, "javascript") + .unwrap_err() + .contains("Unsupported feature for compilation target") + ); } #[wasm_bindgen_test] diff --git a/compiler-wasm/src/wasm_filesystem.rs b/compiler-wasm/src/wasm_filesystem.rs index 50152d3297c..f8afda14244 100644 --- a/compiler-wasm/src/wasm_filesystem.rs +++ b/compiler-wasm/src/wasm_filesystem.rs @@ -1,10 +1,10 @@ use camino::{Utf8Path, Utf8PathBuf}; use gleam_core::{ + Error, Result, io::{ - memory::InMemoryFileSystem, BeamCompiler, Command, CommandExecutor, FileSystemReader, - FileSystemWriter, ReadDir, Stdio, WrappedReader, + BeamCompiler, Command, CommandExecutor, FileSystemReader, FileSystemWriter, ReadDir, Stdio, + WrappedReader, memory::InMemoryFileSystem, }, - Error, Result, }; use std::collections::HashSet; diff --git a/test-helpers-rs/Cargo.toml b/test-helpers-rs/Cargo.toml index 037411ec3df..0136adb845c 100644 --- a/test-helpers-rs/Cargo.toml +++ b/test-helpers-rs/Cargo.toml @@ -1,7 +1,7 @@ [package] name = "test-helpers-rs" version = "0.1.0" -edition = "2021" +edition = "2024" license = "Apache-2.0" [dependencies] diff --git a/test-helpers-rs/src/lib.rs b/test-helpers-rs/src/lib.rs index 5ced9714812..3296c6b6436 100644 --- a/test-helpers-rs/src/lib.rs +++ b/test-helpers-rs/src/lib.rs @@ -1,6 +1,6 @@ use camino::{Utf8Path, Utf8PathBuf}; use gleam_core::{ - io::{memory::InMemoryFileSystem, Content, FileSystemWriter}, + io::{Content, FileSystemWriter, memory::InMemoryFileSystem}, version::COMPILER_VERSION, }; use itertools::Itertools; diff --git a/test-package-compiler/Cargo.toml b/test-package-compiler/Cargo.toml index df1539ec103..a4f140465c4 100644 --- a/test-package-compiler/Cargo.toml +++ b/test-package-compiler/Cargo.toml @@ -2,7 +2,7 @@ name = "test-package-compiler" version = "1.8.1" authors = ["Louis Pilfold "] -edition = "2021" +edition = "2024" license = "Apache-2.0" [dependencies] diff --git a/test-project-compiler/Cargo.toml b/test-project-compiler/Cargo.toml index 9f93900f91d..eff7cd3a2de 100644 --- a/test-project-compiler/Cargo.toml +++ b/test-project-compiler/Cargo.toml @@ -2,7 +2,7 @@ name = "test-project-compiler" version = "1.8.1" authors = ["Louis Pilfold "] -edition = "2021" +edition = "2024" license = "Apache-2.0" [dependencies]