Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update to Rust 1.85 and Rust Edition 2024 #4270

Merged
merged 2 commits into from
Feb 27, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion compiler-cli/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
name = "gleam"
version = "1.8.1"
authors = ["Louis Pilfold <[email protected]>"]
edition = "2021"
edition = "2024"
license-file = "LICENCE"

[dependencies]
Expand Down
4 changes: 2 additions & 2 deletions compiler-cli/src/add.rs
Original file line number Diff line number Diff line change
@@ -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,
};

Expand Down
16 changes: 7 additions & 9 deletions compiler-cli/src/beam_compiler.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
use gleam_core::{
Result,
error::{Error, ShellCommandFailureReason},
io::{FileSystemWriter, Stdio},
paths, Result,
paths,
};

use crate::fs::get_os;
Expand Down Expand Up @@ -37,13 +38,10 @@ impl BeamCompiler {
stdio: Stdio,
) -> Result<Vec<String>, 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)?),
};
Expand Down Expand Up @@ -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:") {
Expand Down
2 changes: 1 addition & 1 deletion compiler-cli/src/build.rs
Original file line number Diff line number Diff line change
@@ -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::{
Expand Down
2 changes: 1 addition & 1 deletion compiler-cli/src/build_lock.rs
Original file line number Diff line number Diff line change
@@ -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;

Expand Down
5 changes: 2 additions & 3 deletions compiler-cli/src/compile_package.rs
Original file line number Diff line number Diff line change
@@ -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,
},
Expand All @@ -14,7 +14,6 @@ use gleam_core::{
type_::ModuleInterface,
uid::UniqueIdGenerator,
warning::WarningEmitter,
Error, Result,
};
use std::{collections::HashSet, rc::Rc};

Expand Down
8 changes: 4 additions & 4 deletions compiler-cli/src/dependencies.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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;
Expand All @@ -29,11 +29,11 @@ use strum::IntoEnumIterator;
mod tests;

use crate::{
TreeOptions,
build_lock::BuildLock,
cli,
fs::{self, ProjectIO},
http::HttpClient,
TreeOptions,
};

struct Symbols {
Expand Down Expand Up @@ -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}"
),
})
});
}
};

Expand Down
42 changes: 25 additions & 17 deletions compiler-cli/src/dependencies/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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::*;
Expand Down Expand Up @@ -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")
}
}
}

Expand Down Expand Up @@ -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")
}
}
}

Expand All @@ -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!")
}
}
}

Expand Down
2 changes: 1 addition & 1 deletion compiler-cli/src/docs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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},
Expand All @@ -12,7 +13,6 @@ use gleam_core::{
hex,
io::HttpClient as _,
paths::ProjectPaths,
Result,
};

pub fn remove(package: String, version: String) -> Result<()> {
Expand Down
2 changes: 1 addition & 1 deletion compiler-cli/src/export.rs
Original file line number Diff line number Diff line change
@@ -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")]
Expand Down
2 changes: 1 addition & 1 deletion compiler-cli/src/fix.rs
Original file line number Diff line number Diff line change
@@ -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;

Expand Down
4 changes: 2 additions & 2 deletions compiler-cli/src/fs.rs
Original file line number Diff line number Diff line change
@@ -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,
Expand All @@ -9,7 +10,6 @@ use gleam_core::{
manifest::Manifest,
paths::ProjectPaths,
warning::WarningEmitterIO,
Result, Warning,
};
use std::{
collections::HashSet,
Expand Down
2 changes: 1 addition & 1 deletion compiler-cli/src/hex.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion compiler-cli/src/hex/auth.rs
Original file line number Diff line number Diff line change
@@ -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";
Expand Down
2 changes: 1 addition & 1 deletion compiler-cli/src/http.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};
Expand Down
2 changes: 1 addition & 1 deletion compiler-cli/src/lsp.rs
Original file line number Diff line number Diff line change
@@ -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<()> {
Expand Down
2 changes: 1 addition & 1 deletion compiler-cli/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
8 changes: 4 additions & 4 deletions compiler-cli/src/new.rs
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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";
Expand Down Expand Up @@ -419,7 +419,7 @@ fn get_valid_project_name(name: Option<String>, project_root: &str) -> Result<St
return Err(Error::InvalidProjectName {
name: initial_name,
reason: invalid_reason,
})
});
}
};
let prompt_for_suggested_name = error::format_invalid_project_name_error(
Expand Down
Loading
Loading