Skip to content

Migrate subcrates to Rust Edition 2024 #11208

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

Merged
merged 6 commits into from
May 20, 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 crates/crates_io_cdn_logs/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
name = "crates_io_cdn_logs"
version = "0.0.0"
license = "MIT OR Apache-2.0"
edition = "2021"
edition = "2024"

[lints]
workspace = true
Expand Down
2 changes: 1 addition & 1 deletion crates/crates_io_cdn_logs/benches/count_downloads.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use crates_io_cdn_logs::{cloudfront, fastly};
use criterion::{criterion_group, criterion_main, Criterion};
use criterion::{Criterion, criterion_group, criterion_main};
use std::hint::black_box;
use std::io::Cursor;

Expand Down
4 changes: 2 additions & 2 deletions crates/crates_io_cdn_logs/examples/count_downloads.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
use anyhow::Context;
use clap::Parser;
use crates_io_cdn_logs::{count_downloads, Decompressor};
use crates_io_cdn_logs::{Decompressor, count_downloads};
use std::path::PathBuf;
use tokio::fs::File;
use tokio::io::BufReader;
use tracing::level_filters::LevelFilter;
use tracing_subscriber::{fmt, EnvFilter};
use tracing_subscriber::{EnvFilter, fmt};

#[derive(Debug, clap::Parser)]
struct Options {
Expand Down
2 changes: 1 addition & 1 deletion crates/crates_io_cdn_logs/src/cloudfront.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
//! see <https://docs.aws.amazon.com/AmazonCloudFront/latest/DeveloperGuide/AccessLogs.html#LogFileFormat>
//! and <https://www.w3.org/TR/WD-logfile.html>.

use crate::paths::parse_path;
use crate::DownloadsMap;
use crate::paths::parse_path;
use chrono::NaiveDate;
use std::borrow::Cow;
use tokio::io::{AsyncBufRead, AsyncBufReadExt};
Expand Down
2 changes: 1 addition & 1 deletion crates/crates_io_cdn_logs/src/fastly/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@

mod json;

use crate::paths::parse_path;
use crate::DownloadsMap;
use crate::paths::parse_path;
use std::borrow::Cow;
use tokio::io::{AsyncBufRead, AsyncBufReadExt};
use tracing::{debug_span, instrument, warn};
Expand Down
2 changes: 1 addition & 1 deletion crates/crates_io_database/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
name = "crates_io_database"
version = "0.0.0"
license = "MIT OR Apache-2.0"
edition = "2021"
edition = "2024"

[lints]
workspace = true
Expand Down
10 changes: 5 additions & 5 deletions crates/crates_io_database/src/models/category.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,8 @@ use diesel::dsl;
use diesel::prelude::*;
use diesel_async::scoped_futures::ScopedFutureExt;
use diesel_async::{AsyncConnection, AsyncPgConnection, RunQueryDsl};
use futures_util::future::BoxFuture;
use futures_util::FutureExt;
use std::future::Future;
use futures_util::future::BoxFuture;

#[derive(Clone, Identifiable, Queryable, QueryableByName, Debug, Selectable)]
#[diesel(table_name = categories, check_for_backend(diesel::pg::Pg))]
Expand Down Expand Up @@ -97,12 +96,12 @@ impl Category {
.await
}

pub fn toplevel(
pub fn toplevel<'a>(
conn: &mut AsyncPgConnection,
sort: &str,
sort: &'a str,
limit: i64,
offset: i64,
) -> impl Future<Output = QueryResult<Vec<Category>>> {
) -> BoxFuture<'a, QueryResult<Vec<Category>>> {
use diesel::sql_types::Int8;

let sort_sql = match sort {
Expand All @@ -116,6 +115,7 @@ impl Category {
.bind::<Int8, _>(limit)
.bind::<Int8, _>(offset)
.load(conn)
.boxed()
}

pub fn subcategories(
Expand Down
7 changes: 4 additions & 3 deletions crates/crates_io_database/src/models/token.rs
Original file line number Diff line number Diff line change
Expand Up @@ -145,8 +145,9 @@ mod tests {
};
let json = serde_json::to_string(&tok).unwrap();
assert_some!(json.as_str().find(r#""created_at":"2017-01-06T14:23:11Z""#));
assert_some!(json
.as_str()
.find(r#""last_used_at":"2017-01-06T14:23:12Z""#));
assert_some!(
json.as_str()
.find(r#""last_used_at":"2017-01-06T14:23:12Z""#)
);
}
}
2 changes: 1 addition & 1 deletion crates/crates_io_database_dump/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
name = "crates_io_database_dump"
version = "0.0.0"
license = "MIT OR Apache-2.0"
edition = "2021"
edition = "2024"

[lints]
workspace = true
Expand Down
2 changes: 1 addition & 1 deletion crates/crates_io_database_dump/src/configuration.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ impl VisibilityConfig {
}
let mut ready: VecDeque<&str> = num_deps
.iter()
.filter(|(_, &count)| count == 0)
.filter(|&(_, &count)| count == 0)
.map(|(&table, _)| table)
.collect();
let mut result = Vec::with_capacity(ready.len());
Expand Down
2 changes: 1 addition & 1 deletion crates/crates_io_database_dump/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#![doc = include_str!("../README.md")]

use anyhow::{anyhow, Context};
use anyhow::{Context, anyhow};
use serde::Serialize;
use std::fs;
use std::fs::File;
Expand Down
2 changes: 1 addition & 1 deletion crates/crates_io_diesel_helpers/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
name = "crates_io_diesel_helpers"
version = "0.0.0"
license = "MIT OR Apache-2.0"
edition = "2021"
edition = "2024"

[lints]
workspace = true
Expand Down
2 changes: 1 addition & 1 deletion crates/crates_io_diesel_helpers/src/semver.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use diesel::Queryable;
use diesel::pg::Pg;
use diesel::sql_types::Text;
use diesel::Queryable;

/// A wrapper around `semver::Version` that implements `diesel::Queryable`.
///
Expand Down
2 changes: 1 addition & 1 deletion crates/crates_io_env_vars/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
name = "crates_io_env_vars"
version = "0.0.0"
license = "MIT OR Apache-2.0"
edition = "2021"
edition = "2024"

[lints]
workspace = true
Expand Down
40 changes: 20 additions & 20 deletions crates/crates_io_env_vars/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#![doc = include_str!("../README.md")]

use anyhow::{anyhow, Context};
use anyhow::{Context, anyhow};
use std::error::Error;
use std::str::FromStr;

Expand Down Expand Up @@ -139,21 +139,21 @@ mod tests {
fn test_var() {
let _guard = MUTEX.lock().unwrap();

std::env::set_var(TEST_VAR, "test");
unsafe { std::env::set_var(TEST_VAR, "test") };
assert_some_eq!(assert_ok!(var(TEST_VAR)), "test");

std::env::remove_var(TEST_VAR);
unsafe { std::env::remove_var(TEST_VAR) };
assert_none!(assert_ok!(var(TEST_VAR)));
}

#[test]
fn test_required_var() {
let _guard = MUTEX.lock().unwrap();

std::env::set_var(TEST_VAR, "test");
unsafe { std::env::set_var(TEST_VAR, "test") };
assert_ok_eq!(required_var(TEST_VAR), "test");

std::env::remove_var(TEST_VAR);
unsafe { std::env::remove_var(TEST_VAR) };
let error = assert_err!(required_var(TEST_VAR));
assert_eq!(
error.to_string(),
Expand All @@ -165,35 +165,35 @@ mod tests {
fn test_var_parsed() {
let _guard = MUTEX.lock().unwrap();

std::env::set_var(TEST_VAR, "42");
unsafe { std::env::set_var(TEST_VAR, "42") };
assert_some_eq!(assert_ok!(var_parsed::<i32>(TEST_VAR)), 42);

std::env::set_var(TEST_VAR, "test");
unsafe { std::env::set_var(TEST_VAR, "test") };
let error = assert_err!(var_parsed::<i32>(TEST_VAR));
assert_eq!(
error.to_string(),
"Failed to parse CRATES_IO_ENV_VARS_TEST_VAR environment variable"
);

std::env::remove_var(TEST_VAR);
unsafe { std::env::remove_var(TEST_VAR) };
assert_none!(assert_ok!(var_parsed::<i32>(TEST_VAR)));
}

#[test]
fn test_required_var_parsed() {
let _guard = MUTEX.lock().unwrap();

std::env::set_var(TEST_VAR, "42");
unsafe { std::env::set_var(TEST_VAR, "42") };
assert_ok_eq!(required_var_parsed::<i32>(TEST_VAR), 42);

std::env::set_var(TEST_VAR, "test");
unsafe { std::env::set_var(TEST_VAR, "test") };
let error = assert_err!(required_var_parsed::<i32>(TEST_VAR));
assert_eq!(
error.to_string(),
"Failed to parse CRATES_IO_ENV_VARS_TEST_VAR environment variable"
);

std::env::remove_var(TEST_VAR);
unsafe { std::env::remove_var(TEST_VAR) };
let error = assert_err!(required_var_parsed::<i32>(TEST_VAR));
assert_eq!(
error.to_string(),
Expand All @@ -205,40 +205,40 @@ mod tests {
fn test_list() {
let _guard = MUTEX.lock().unwrap();

std::env::set_var(TEST_VAR, "test");
unsafe { std::env::set_var(TEST_VAR, "test") };
assert_ok_eq!(list(TEST_VAR), vec!["test"]);

std::env::set_var(TEST_VAR, "test, foo, bar ");
unsafe { std::env::set_var(TEST_VAR, "test, foo, bar ") };
assert_ok_eq!(list(TEST_VAR), vec!["test", "foo", "bar"]);

std::env::set_var(TEST_VAR, "");
unsafe { std::env::set_var(TEST_VAR, "") };
assert_ok_eq!(list(TEST_VAR), Vec::<String>::new());

std::env::remove_var(TEST_VAR);
unsafe { std::env::remove_var(TEST_VAR) };
assert_ok_eq!(list(TEST_VAR), Vec::<String>::new());
}

#[test]
fn test_list_parsed() {
let _guard = MUTEX.lock().unwrap();

std::env::set_var(TEST_VAR, "42");
unsafe { std::env::set_var(TEST_VAR, "42") };
assert_ok_eq!(list_parsed(TEST_VAR, i32::from_str), vec![42]);

std::env::set_var(TEST_VAR, "42, 1, -53 ");
unsafe { std::env::set_var(TEST_VAR, "42, 1, -53 ") };
assert_ok_eq!(list_parsed(TEST_VAR, i32::from_str), vec![42, 1, -53]);

std::env::set_var(TEST_VAR, "42, what");
unsafe { std::env::set_var(TEST_VAR, "42, what") };
let error = assert_err!(list_parsed(TEST_VAR, i32::from_str));
assert_eq!(
error.to_string(),
"Failed to parse value \"what\" of CRATES_IO_ENV_VARS_TEST_VAR environment variable"
);

std::env::set_var(TEST_VAR, "");
unsafe { std::env::set_var(TEST_VAR, "") };
assert_ok_eq!(list_parsed(TEST_VAR, i32::from_str), Vec::<i32>::new());

std::env::remove_var(TEST_VAR);
unsafe { std::env::remove_var(TEST_VAR) };
assert_ok_eq!(list_parsed(TEST_VAR, i32::from_str), Vec::<i32>::new());
}
}
2 changes: 1 addition & 1 deletion crates/crates_io_github/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
name = "crates_io_github"
version = "0.0.0"
license = "MIT OR Apache-2.0"
edition = "2021"
edition = "2024"

[lints]
workspace = true
Expand Down
2 changes: 1 addition & 1 deletion crates/crates_io_github/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
extern crate tracing;

use oauth2::AccessToken;
use reqwest::{self, header, RequestBuilder};
use reqwest::{self, RequestBuilder, header};

use serde::de::DeserializeOwned;

Expand Down
2 changes: 1 addition & 1 deletion crates/crates_io_index/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ version = "0.0.0"
license = "MIT OR Apache-2.0"
repository = "https://github.com/rust-lang/crates.io"
description = "crates.io package index utilities"
edition = "2021"
edition = "2024"

[lints]
workspace = true
Expand Down
2 changes: 1 addition & 1 deletion crates/crates_io_index/credentials.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use anyhow::{anyhow, Context};
use anyhow::{Context, anyhow};
use secrecy::{ExposeSecret, SecretString};
use std::io::Write;

Expand Down
4 changes: 2 additions & 2 deletions crates/crates_io_index/repo.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use crate::credentials::Credentials;
use anyhow::{anyhow, Context};
use base64::{engine::general_purpose, Engine};
use anyhow::{Context, anyhow};
use base64::{Engine, engine::general_purpose};
use crates_io_env_vars::{required_var, required_var_parsed, var};
use secrecy::{ExposeSecret, SecretString};
use std::path::{Path, PathBuf};
Expand Down
14 changes: 10 additions & 4 deletions crates/crates_io_index/ser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,12 @@ mod tests {
};
let mut buffer = Vec::new();
assert_ok!(write_crate(&krate, &mut buffer));
assert_ok_eq!(String::from_utf8(buffer), "\
assert_ok_eq!(
String::from_utf8(buffer),
"\
{\"name\":\"foo\",\"vers\":\"1.2.3\",\"deps\":[],\"cksum\":\"0123456789asbcdef\",\"features\":{},\"yanked\":null}\n\
");
"
);
}

#[test]
Expand All @@ -61,11 +64,14 @@ mod tests {

let mut buffer = Vec::new();
assert_ok!(write_crates(&crates, &mut buffer));
assert_ok_eq!(String::from_utf8(buffer), "\
assert_ok_eq!(
String::from_utf8(buffer),
"\
{\"name\":\"foo\",\"vers\":\"0.1.0\",\"deps\":[],\"cksum\":\"0123456789asbcdef\",\"features\":{},\"yanked\":null}\n\
{\"name\":\"foo\",\"vers\":\"1.0.0-beta.1\",\"deps\":[],\"cksum\":\"0123456789asbcdef\",\"features\":{},\"yanked\":null}\n\
{\"name\":\"foo\",\"vers\":\"1.0.0\",\"deps\":[],\"cksum\":\"0123456789asbcdef\",\"features\":{},\"yanked\":null}\n\
{\"name\":\"foo\",\"vers\":\"1.2.3\",\"deps\":[],\"cksum\":\"0123456789asbcdef\",\"features\":{},\"yanked\":null}\n\
");
"
);
}
}
2 changes: 1 addition & 1 deletion crates/crates_io_markdown/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ version = "0.0.0"
license = "MIT OR Apache-2.0"
repository = "https://github.com/rust-lang/crates.io"
description = "crates.io markdown renderer"
edition = "2021"
edition = "2024"

[lints]
workspace = true
Expand Down
10 changes: 4 additions & 6 deletions crates/crates_io_markdown/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -67,8 +67,8 @@ impl<'a> MarkdownRenderer<'a> {
/// Renders the given markdown to HTML using the current settings.
fn to_html(&self, text: &str) -> String {
use comrak::{
format_html, parse_document, Arena, ComrakExtensionOptions, ComrakOptions,
ComrakRenderOptions,
Arena, ComrakExtensionOptions, ComrakOptions, ComrakRenderOptions, format_html,
parse_document,
};

let render_options = ComrakRenderOptions::builder()
Expand Down Expand Up @@ -566,8 +566,7 @@ There can also be some text in between!

#[test]
fn absolute_links_dont_get_resolved() {
let text =
"[![crates.io](https://img.shields.io/crates/v/clap.svg)](https://crates.io/crates/clap)";
let text = "[![crates.io](https://img.shields.io/crates/v/clap.svg)](https://crates.io/crates/clap)";
let repository = "https://github.com/kbknapp/clap-rs/";
assert_snapshot!(markdown_to_html(text, Some(repository), ""), @r#"<p><a href="https://crates.io/crates/clap" rel="nofollow noopener noreferrer"><img src="https://img.shields.io/crates/v/clap.svg" alt="crates.io"></a></p>"#);
}
Expand Down Expand Up @@ -650,8 +649,7 @@ There can also be some text in between!

#[test]
fn image_alignment() {
let text =
"<p align=\"center\"><img src=\"https://img.shields.io/crates/v/clap.svg\" alt=\"\"></p>\n";
let text = "<p align=\"center\"><img src=\"https://img.shields.io/crates/v/clap.svg\" alt=\"\"></p>\n";
assert_snapshot!(markdown_to_html(text, None, ""), @r#"<p align="center"><img src="https://img.shields.io/crates/v/clap.svg" alt=""></p>"#);
}

Expand Down
Loading