Rust 1.75 (#736)

The `async fn` and return-position `impl Trait` in traits improve
`BuildContext` ergonomics. The traits use `impl Future` over `async fn`
to make the send bound explicit
(https://blog.rust-lang.org/2023/12/21/async-fn-rpit-in-traits.html).

The remaining changes are due to clippy.
This commit is contained in:
konsti 2023-12-28 21:08:35 +01:00 committed by GitHub
parent 7bf2790a25
commit 2d4cb1ebf2
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
8 changed files with 34 additions and 46 deletions

View file

@ -105,3 +105,11 @@ impl<'a> IntoIterator for &'a IndexUrls {
self.index.iter().chain(self.extra_index.iter()) self.index.iter().chain(self.extra_index.iter())
} }
} }
impl<'a> IndexUrls {
pub fn iter(
&'a self,
) -> Chain<std::option::Iter<'a, IndexUrl>, std::slice::Iter<'a, IndexUrl>> {
self.into_iter()
}
}

View file

@ -8,7 +8,6 @@ use std::future::Future;
use std::io; use std::io;
use std::io::BufRead; use std::io::BufRead;
use std::path::{Path, PathBuf}; use std::path::{Path, PathBuf};
use std::pin::Pin;
use std::process::Output; use std::process::Output;
use std::str::FromStr; use std::str::FromStr;
use std::sync::Arc; use std::sync::Arc;
@ -544,16 +543,14 @@ impl SourceBuild {
} }
impl SourceBuildTrait for SourceBuild { impl SourceBuildTrait for SourceBuild {
fn metadata<'a>( fn metadata(&mut self) -> impl Future<Output = anyhow::Result<Option<PathBuf>>> + Send {
&'a mut self,
) -> Pin<Box<dyn Future<Output = anyhow::Result<Option<PathBuf>>> + Send + 'a>> {
Box::pin(async { Ok(self.get_metadata_without_build().await?) }) Box::pin(async { Ok(self.get_metadata_without_build().await?) })
} }
fn wheel<'a>( fn wheel<'a>(
&'a self, &'a self,
wheel_dir: &'a Path, wheel_dir: &'a Path,
) -> Pin<Box<dyn Future<Output = anyhow::Result<String>> + Send + 'a>> { ) -> impl Future<Output = anyhow::Result<String>> + Send + 'a {
Box::pin(async { Ok(self.build(wheel_dir).await?) }) Box::pin(async { Ok(self.build(wheel_dir).await?) })
} }
} }

View file

@ -58,7 +58,7 @@ enum Cli {
ResolveMany(ResolveManyArgs), ResolveMany(ResolveManyArgs),
InstallMany(InstallManyArgs), InstallMany(InstallManyArgs),
/// Resolve requirements passed on the CLI /// Resolve requirements passed on the CLI
ResolveCli(ResolveCliArgs), Resolve(ResolveCliArgs),
WheelMetadata(WheelMetadataArgs), WheelMetadata(WheelMetadataArgs),
} }
@ -75,7 +75,7 @@ async fn run() -> Result<()> {
Cli::InstallMany(args) => { Cli::InstallMany(args) => {
install_many::install_many(args).await?; install_many::install_many(args).await?;
} }
Cli::ResolveCli(args) => { Cli::Resolve(args) => {
resolve_cli::resolve_cli(args).await?; resolve_cli::resolve_cli(args).await?;
} }
Cli::WheelMetadata(args) => wheel_metadata::wheel_metadata(args).await?, Cli::WheelMetadata(args) => wheel_metadata::wheel_metadata(args).await?,

View file

@ -4,7 +4,6 @@
use std::future::Future; use std::future::Future;
use std::path::{Path, PathBuf}; use std::path::{Path, PathBuf};
use std::pin::Pin;
use anyhow::{bail, Context, Result}; use anyhow::{bail, Context, Result};
use itertools::Itertools; use itertools::Itertools;
@ -86,7 +85,7 @@ impl<'a> BuildContext for BuildDispatch<'a> {
fn resolve<'data>( fn resolve<'data>(
&'data self, &'data self,
requirements: &'data [Requirement], requirements: &'data [Requirement],
) -> Pin<Box<dyn Future<Output = Result<Resolution>> + Send + 'data>> { ) -> impl Future<Output = Result<Resolution>> + Send + 'data {
Box::pin(async { Box::pin(async {
let markers = self.interpreter.markers(); let markers = self.interpreter.markers();
let tags = self.interpreter.tags()?; let tags = self.interpreter.tags()?;
@ -119,7 +118,7 @@ impl<'a> BuildContext for BuildDispatch<'a> {
&'data self, &'data self,
resolution: &'data Resolution, resolution: &'data Resolution,
venv: &'data Virtualenv, venv: &'data Virtualenv,
) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'data>> { ) -> impl Future<Output = Result<()>> + Send + 'data {
Box::pin(async move { Box::pin(async move {
debug!( debug!(
"Installing in {} in {}", "Installing in {} in {}",
@ -223,7 +222,7 @@ impl<'a> BuildContext for BuildDispatch<'a> {
subdirectory: Option<&'data Path>, subdirectory: Option<&'data Path>,
package_id: &'data str, package_id: &'data str,
build_kind: BuildKind, build_kind: BuildKind,
) -> Pin<Box<dyn Future<Output = Result<SourceBuild>> + Send + 'data>> { ) -> impl Future<Output = Result<SourceBuild>> + Send + 'data {
Box::pin(async move { Box::pin(async move {
if self.no_build { if self.no_build {
bail!("Building source distributions is disabled"); bail!("Building source distributions is disabled");

View file

@ -1,7 +1,6 @@
//! Given a set of requirements, find a set of compatible packages. //! Given a set of requirements, find a set of compatible packages.
use std::future::Future; use std::future::Future;
use std::pin::Pin;
use std::sync::Arc; use std::sync::Arc;
use anyhow::Result; use anyhow::Result;
@ -52,7 +51,7 @@ pub trait ResolverProvider: Send + Sync {
fn get_version_map<'io>( fn get_version_map<'io>(
&'io self, &'io self,
package_name: &'io PackageName, package_name: &'io PackageName,
) -> Pin<Box<dyn Future<Output = VersionMapResponse> + Send + 'io>>; ) -> impl Future<Output = VersionMapResponse> + Send + 'io;
/// Get the metadata for a distribution. /// Get the metadata for a distribution.
/// ///
@ -62,7 +61,7 @@ pub trait ResolverProvider: Send + Sync {
fn get_or_build_wheel_metadata<'io>( fn get_or_build_wheel_metadata<'io>(
&'io self, &'io self,
dist: &'io Dist, dist: &'io Dist,
) -> Pin<Box<dyn Future<Output = WheelMetadataResponse> + Send + 'io>>; ) -> impl Future<Output = WheelMetadataResponse> + Send + 'io;
/// Set the [`Reporter`] to use for this installer. /// Set the [`Reporter`] to use for this installer.
#[must_use] #[must_use]
@ -109,7 +108,7 @@ impl<'a, Context: BuildContext + Send + Sync> ResolverProvider
fn get_version_map<'io>( fn get_version_map<'io>(
&'io self, &'io self,
package_name: &'io PackageName, package_name: &'io PackageName,
) -> Pin<Box<dyn Future<Output = VersionMapResponse> + Send + 'io>> { ) -> impl Future<Output = VersionMapResponse> + Send + 'io {
Box::pin( Box::pin(
self.client self.client
.simple(package_name) .simple(package_name)
@ -134,7 +133,7 @@ impl<'a, Context: BuildContext + Send + Sync> ResolverProvider
fn get_or_build_wheel_metadata<'io>( fn get_or_build_wheel_metadata<'io>(
&'io self, &'io self,
dist: &'io Dist, dist: &'io Dist,
) -> Pin<Box<dyn Future<Output = WheelMetadataResponse> + Send + 'io>> { ) -> impl Future<Output = WheelMetadataResponse> + Send + 'io {
Box::pin(self.fetcher.get_or_build_wheel_metadata(dist)) Box::pin(self.fetcher.get_or_build_wheel_metadata(dist))
} }

View file

@ -3,9 +3,7 @@
//! Integration tests for the resolver. These tests rely on a live network connection, and hit //! Integration tests for the resolver. These tests rely on a live network connection, and hit
//! `PyPI` directly. //! `PyPI` directly.
use std::future::Future;
use std::path::{Path, PathBuf}; use std::path::{Path, PathBuf};
use std::pin::Pin;
use std::str::FromStr; use std::str::FromStr;
use anyhow::Result; use anyhow::Result;
@ -51,45 +49,37 @@ impl BuildContext for DummyContext {
panic!("The test should not need to build source distributions") panic!("The test should not need to build source distributions")
} }
fn resolve<'a>( async fn resolve<'a>(&'a self, _requirements: &'a [Requirement]) -> Result<Resolution> {
&'a self,
_requirements: &'a [Requirement],
) -> Pin<Box<dyn Future<Output = Result<Resolution>> + Send + 'a>> {
panic!("The test should not need to build source distributions") panic!("The test should not need to build source distributions")
} }
fn install<'a>( async fn install<'a>(
&'a self, &'a self,
_resolution: &'a Resolution, _resolution: &'a Resolution,
_venv: &'a Virtualenv, _venv: &'a Virtualenv,
) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'a>> { ) -> Result<()> {
panic!("The test should not need to build source distributions") panic!("The test should not need to build source distributions")
} }
fn setup_build<'a>( async fn setup_build<'a>(
&'a self, &'a self,
_source: &'a Path, _source: &'a Path,
_subdirectory: Option<&'a Path>, _subdirectory: Option<&'a Path>,
_package_id: &'a str, _package_id: &'a str,
_build_kind: BuildKind, _build_kind: BuildKind,
) -> Pin<Box<dyn Future<Output = Result<Self::SourceDistBuilder>> + Send + 'a>> { ) -> Result<Self::SourceDistBuilder> {
Box::pin(async { Ok(DummyBuilder) }) Ok(DummyBuilder)
} }
} }
struct DummyBuilder; struct DummyBuilder;
impl SourceBuildTrait for DummyBuilder { impl SourceBuildTrait for DummyBuilder {
fn metadata<'a>( async fn metadata(&mut self) -> Result<Option<PathBuf>> {
&'a mut self,
) -> Pin<Box<dyn Future<Output = Result<Option<PathBuf>>> + Send + 'a>> {
panic!("The test should not need to build source distributions") panic!("The test should not need to build source distributions")
} }
fn wheel<'a>( async fn wheel<'a>(&'a self, _wheel_dir: &'a Path) -> Result<String> {
&'a self,
_wheel_dir: &'a Path,
) -> Pin<Box<dyn Future<Output = Result<String>> + Send + 'a>> {
panic!("The test should not need to build source distributions") panic!("The test should not need to build source distributions")
} }
} }

View file

@ -3,7 +3,6 @@
use std::fmt::{Display, Formatter}; use std::fmt::{Display, Formatter};
use std::future::Future; use std::future::Future;
use std::path::{Path, PathBuf}; use std::path::{Path, PathBuf};
use std::pin::Pin;
use anyhow::Result; use anyhow::Result;
@ -77,7 +76,7 @@ pub trait BuildContext {
fn resolve<'a>( fn resolve<'a>(
&'a self, &'a self,
requirements: &'a [Requirement], requirements: &'a [Requirement],
) -> Pin<Box<dyn Future<Output = Result<Resolution>> + Send + 'a>>; ) -> impl Future<Output = Result<Resolution>> + Send + 'a;
/// Install the given set of package versions into the virtual environment. The environment must /// Install the given set of package versions into the virtual environment. The environment must
/// use the same base python as [`BuildContext::base_python`] /// use the same base python as [`BuildContext::base_python`]
@ -85,7 +84,7 @@ pub trait BuildContext {
&'a self, &'a self,
resolution: &'a Resolution, resolution: &'a Resolution,
venv: &'a Virtualenv, venv: &'a Virtualenv,
) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'a>>; ) -> impl Future<Output = Result<()>> + Send + 'a;
/// Setup a source distribution build by installing the required dependencies. A wrapper for /// Setup a source distribution build by installing the required dependencies. A wrapper for
/// `puffin_build::SourceBuild::setup`. /// `puffin_build::SourceBuild::setup`.
@ -99,7 +98,7 @@ pub trait BuildContext {
subdirectory: Option<&'a Path>, subdirectory: Option<&'a Path>,
package_id: &'a str, package_id: &'a str,
build_kind: BuildKind, build_kind: BuildKind,
) -> Pin<Box<dyn Future<Output = Result<Self::SourceDistBuilder>> + Send + 'a>>; ) -> impl Future<Output = Result<Self::SourceDistBuilder>> + Send + 'a;
} }
/// A wrapper for `puffin_build::SourceBuild` to avoid cyclical crate dependencies. /// A wrapper for `puffin_build::SourceBuild` to avoid cyclical crate dependencies.
@ -113,19 +112,15 @@ pub trait SourceBuildTrait {
/// ///
/// Returns the metadata directory if we're having a PEP 517 build and the /// Returns the metadata directory if we're having a PEP 517 build and the
/// `prepare_metadata_for_build_wheel` hook exists /// `prepare_metadata_for_build_wheel` hook exists
fn metadata<'a>( fn metadata(&mut self) -> impl Future<Output = Result<Option<PathBuf>>> + Send;
&'a mut self,
) -> Pin<Box<dyn Future<Output = Result<Option<PathBuf>>> + Send + 'a>>;
/// A wrapper for `puffin_build::SourceBuild::build`. /// A wrapper for `puffin_build::SourceBuild::build`.
/// ///
/// For PEP 517 builds, this calls `build_wheel`. /// For PEP 517 builds, this calls `build_wheel`.
/// ///
/// Returns the filename of the built wheel inside the given `wheel_dir`. /// Returns the filename of the built wheel inside the given `wheel_dir`.
fn wheel<'a>( fn wheel<'a>(&'a self, wheel_dir: &'a Path)
&'a self, -> impl Future<Output = Result<String>> + Send + 'a;
wheel_dir: &'a Path,
) -> Pin<Box<dyn Future<Output = Result<String>> + Send + 'a>>;
} }
#[derive(Copy, Clone, Debug, Default, PartialEq, Eq)] #[derive(Copy, Clone, Debug, Default, PartialEq, Eq)]

View file

@ -1,2 +1,2 @@
[toolchain] [toolchain]
channel = "1.74" channel = "1.75"