Remove Box::pin usages (#738)

Rust 1.75 update follow-up, simplifies the code.
This commit is contained in:
konsti 2023-12-29 16:49:12 +01:00 committed by GitHub
parent 2cfa4a3574
commit 35f6ea204b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 47 additions and 56 deletions

View File

@ -4,7 +4,6 @@
use std::env;
use std::fmt::{Display, Formatter};
use std::future::Future;
use std::io;
use std::io::BufRead;
use std::path::{Path, PathBuf};
@ -543,15 +542,12 @@ impl SourceBuild {
}
impl SourceBuildTrait for SourceBuild {
fn metadata(&mut self) -> impl Future<Output = anyhow::Result<Option<PathBuf>>> + Send {
Box::pin(async { Ok(self.get_metadata_without_build().await?) })
async fn metadata(&mut self) -> anyhow::Result<Option<PathBuf>> {
Ok(self.get_metadata_without_build().await?)
}
fn wheel<'a>(
&'a self,
wheel_dir: &'a Path,
) -> impl Future<Output = anyhow::Result<String>> + Send + 'a {
Box::pin(async { Ok(self.build(wheel_dir).await?) })
async fn wheel<'a>(&'a self, wheel_dir: &'a Path) -> anyhow::Result<String> {
Ok(self.build(wheel_dir).await?)
}
}

View File

@ -81,32 +81,28 @@ impl<'a> BuildContext for BuildDispatch<'a> {
self.no_build
}
#[instrument(skip(self, requirements), fields(requirements = requirements.iter().map(ToString::to_string).join(", ")))]
fn resolve<'data>(
&'data self,
requirements: &'data [Requirement],
) -> impl Future<Output = Result<Resolution>> + Send + 'data {
Box::pin(async {
let markers = self.interpreter.markers();
let tags = self.interpreter.tags()?;
let resolver = Resolver::new(
Manifest::simple(requirements.to_vec()),
self.options,
markers,
tags,
self.client,
self,
);
let graph = resolver.resolve().await.with_context(|| {
format!(
"No solution found when resolving: {}",
requirements.iter().map(ToString::to_string).join(", "),
)
})?;
Ok(Resolution::from(graph))
})
//#[instrument(skip(self, requirements), fields(requirements = requirements.iter().map(ToString::to_string).join(", ")))]
async fn resolve<'data>(&'data self, requirements: &'data [Requirement]) -> Result<Resolution> {
let markers = self.interpreter.markers();
let tags = self.interpreter.tags()?;
let resolver = Resolver::new(
Manifest::simple(requirements.to_vec()),
self.options,
markers,
tags,
self.client,
self,
);
let graph = resolver.resolve().await.with_context(|| {
format!(
"No solution found when resolving: {}",
requirements.iter().map(ToString::to_string).join(", "),
)
})?;
Ok(Resolution::from(graph))
}
#[allow(clippy::manual_async_fn)] // TODO(konstin): rustc 1.75 gets into a type inference cycle with async fn
#[instrument(
skip(self, resolution, venv),
fields(
@ -119,7 +115,7 @@ impl<'a> BuildContext for BuildDispatch<'a> {
resolution: &'data Resolution,
venv: &'data Virtualenv,
) -> impl Future<Output = Result<()>> + Send + 'data {
Box::pin(async move {
async move {
debug!(
"Installing in {} in {}",
resolution
@ -212,9 +208,10 @@ impl<'a> BuildContext for BuildDispatch<'a> {
}
Ok(())
})
}
}
#[allow(clippy::manual_async_fn)] // TODO(konstin): rustc 1.75 gets into a type inference cycle with async fn
#[instrument(skip_all, fields(package_id = package_id, subdirectory = ?subdirectory))]
fn setup_build<'data>(
&'data self,
@ -223,7 +220,7 @@ impl<'a> BuildContext for BuildDispatch<'a> {
package_id: &'data str,
build_kind: BuildKind,
) -> impl Future<Output = Result<SourceBuild>> + Send + 'data {
Box::pin(async move {
async move {
if self.no_build {
bail!("Building source distributions is disabled");
}
@ -238,6 +235,6 @@ impl<'a> BuildContext for BuildDispatch<'a> {
)
.await?;
Ok(builder)
})
}
}
}

View File

@ -109,32 +109,30 @@ impl<'a, Context: BuildContext + Send + Sync> ResolverProvider
&'io self,
package_name: &'io PackageName,
) -> impl Future<Output = VersionMapResponse> + Send + 'io {
Box::pin(
self.client
.simple(package_name)
.map_ok(move |(index, base, metadata)| {
(
index,
base,
VersionMap::from_metadata(
metadata,
package_name,
self.tags,
self.markers,
self.build_context.interpreter(),
&self.allowed_yanks,
self.exclude_newer.as_ref(),
),
)
}),
)
self.client
.simple(package_name)
.map_ok(move |(index, base, metadata)| {
(
index,
base,
VersionMap::from_metadata(
metadata,
package_name,
self.tags,
self.markers,
self.build_context.interpreter(),
&self.allowed_yanks,
self.exclude_newer.as_ref(),
),
)
})
}
fn get_or_build_wheel_metadata<'io>(
&'io self,
dist: &'io Dist,
) -> impl Future<Output = WheelMetadataResponse> + Send + 'io {
Box::pin(self.fetcher.get_or_build_wheel_metadata(dist))
self.fetcher.get_or_build_wheel_metadata(dist)
}
/// Set the [`puffin_distribution::Reporter`] to use for this installer.