Skip to content

Commit 6375461

Browse files
authored
Fixup return position impl trait overcapturing for the 2024 edition (#528)
The Rust 2024 edition will be changing how `impl Trait` in return position functions. Namely it will be changing the rules from capturing no lifetimes, to capturing all lifetimes. The reasons for this are documented in [RFC 3498](https://github.com/rust-lang/rfcs/blob/master/text/3498-lifetime-capture-rules-2024.md) and [the migration guide](https://doc.rust-lang.org/nightly/edition-guide/rust-2024/rpit-lifetime-capture.html). A new 'precise capturing' syntax has been added to allow cases that don't need everything captured to scope down what they take. This PR updates all such cases to use the new syntax. Note that currently this new syntax requires all type parameters in scope to be listed. This currently results in overcapturing of type parameters. This will be relaxed in the future, and is tracked by [RFC 3617](rust-lang/rust#130043). This PR also marks the edition_2024_expr_fragment_specifier lint as no longer needing fixing, as I have completed an audit of all our macros that it flagged and none of them need changing. Part of #288
1 parent 1cde7ab commit 6375461

File tree

15 files changed

+25
-26
lines changed

15 files changed

+25
-26
lines changed

Cargo.toml

+1-2
Original file line numberDiff line numberDiff line change
@@ -588,9 +588,8 @@ nonstandard_style = { level = "deny", priority = -2 }
588588
rust_2018_idioms = { level = "deny", priority = -2 }
589589

590590
rust-2024-compatibility = { level = "warn", priority = -1 }
591-
# TODO: Fix all of the below, https://github.com/microsoft/openvmm/issues/288
592591
edition_2024_expr_fragment_specifier = "allow"
593-
impl_trait_overcaptures = "allow"
592+
# TODO: Fix all of the below, https://github.com/microsoft/openvmm/issues/288
594593
deprecated-safe-2024 = "allow"
595594
tail-expr-drop-order = "allow"
596595
if-let-rescope = "allow"

openhcl/openhcl_boot/src/host_params/dt.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ fn allocate_vtl2_ram(
6969
params: &ShimParams,
7070
partition_memory_map: &[MemoryEntry],
7171
ram_size: Option<u64>,
72-
) -> OffStackRef<'static, impl AsRef<[MemoryEntry]>> {
72+
) -> OffStackRef<'static, impl AsRef<[MemoryEntry]> + use<>> {
7373
// First, calculate how many numa nodes there are by looking at unique numa
7474
// nodes in the memory map.
7575
let mut numa_nodes = off_stack!(ArrayVec<u32, MAX_NUMA_NODES>, ArrayVec::new_const());
@@ -262,7 +262,7 @@ fn allocate_vtl2_ram(
262262
fn parse_host_vtl2_ram(
263263
params: &ShimParams,
264264
memory: &[MemoryEntry],
265-
) -> OffStackRef<'static, impl AsRef<[MemoryEntry]>> {
265+
) -> OffStackRef<'static, impl AsRef<[MemoryEntry]> + use<>> {
266266
// If no VTL2 protectable ram was provided by the host, use the build time
267267
// value encoded in ShimParams.
268268
let mut vtl2_ram = off_stack!(ArrayVec<MemoryEntry, MAX_NUMA_NODES>, ArrayVec::new_const());

openhcl/openhcl_boot/src/host_params/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@ impl PartitionInfo {
126126
}
127127

128128
/// Returns the parameter regions that are not being reclaimed.
129-
pub fn vtl2_config_regions(&self) -> impl Iterator<Item = MemoryRange> {
129+
pub fn vtl2_config_regions(&self) -> impl Iterator<Item = MemoryRange> + use<> {
130130
subtract_ranges(
131131
[self.vtl2_full_config_region],
132132
[self.vtl2_config_region_reclaim],

openhcl/openhcl_boot/src/main.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -314,7 +314,7 @@ enum ReservedMemoryType {
314314
fn reserved_memory_regions(
315315
partition_info: &PartitionInfo,
316316
sidecar: Option<&SidecarConfig<'_>>,
317-
) -> OffStackRef<'static, impl AsRef<[(MemoryRange, ReservedMemoryType)]>> {
317+
) -> OffStackRef<'static, impl AsRef<[(MemoryRange, ReservedMemoryType)]> + use<>> {
318318
let mut reserved = off_stack!(ArrayVec<(MemoryRange, ReservedMemoryType), MAX_RESERVED_MEM_RANGES>, ArrayVec::new_const());
319319
reserved.clear();
320320
reserved.extend(

openvmm/openvmm_entry/src/ttrpc/mod.rs

+6-6
Original file line numberDiff line numberDiff line change
@@ -364,7 +364,7 @@ impl VmService {
364364
&self,
365365
ctx: mesh::CancelContext,
366366
request: inspect_proto::InspectRequest,
367-
) -> impl Future<Output = anyhow::Result<InspectResponse2>> {
367+
) -> impl Future<Output = anyhow::Result<InspectResponse2>> + use<> {
368368
let mut inspection = InspectionBuilder::new(&request.path)
369369
.depth(Some(request.depth as usize))
370370
.inspect(inspect::adhoc(|req| {
@@ -387,7 +387,7 @@ impl VmService {
387387
&self,
388388
ctx: mesh::CancelContext,
389389
request: inspect_proto::UpdateRequest,
390-
) -> impl Future<Output = anyhow::Result<UpdateResponse2>> {
390+
) -> impl Future<Output = anyhow::Result<UpdateResponse2>> + use<> {
391391
let update = inspect::update(
392392
&request.path,
393393
&request.value,
@@ -603,12 +603,12 @@ impl VmService {
603603
Ok(())
604604
}
605605

606-
fn pause_vm(&mut self, vm: &Vm) -> impl Future<Output = anyhow::Result<()>> {
606+
fn pause_vm(&mut self, vm: &Vm) -> impl Future<Output = anyhow::Result<()>> + use<> {
607607
let recv = vm.worker_rpc.call(VmRpc::Pause, ());
608608
async move { recv.await.map(drop).context("pause failed") }
609609
}
610610

611-
fn resume_vm(&mut self, vm: &Vm) -> impl Future<Output = anyhow::Result<()>> {
611+
fn resume_vm(&mut self, vm: &Vm) -> impl Future<Output = anyhow::Result<()>> + use<> {
612612
let recv = vm.worker_rpc.call(VmRpc::Resume, ());
613613
async move { recv.await.map(drop).context("resume failed") }
614614
}
@@ -617,7 +617,7 @@ impl VmService {
617617
&mut self,
618618
mut ctx: mesh::CancelContext,
619619
vm: Arc<Vm>,
620-
) -> anyhow::Result<impl Future<Output = anyhow::Result<()>>> {
620+
) -> anyhow::Result<impl Future<Output = anyhow::Result<()>> + use<>> {
621621
let mut notify_recv = vm
622622
.notify_recv
623623
.lock()
@@ -642,7 +642,7 @@ impl VmService {
642642
&mut self,
643643
vm: &Vm,
644644
request: vmservice::ModifyResourceRequest,
645-
) -> anyhow::Result<impl Future<Output = anyhow::Result<()>>> {
645+
) -> anyhow::Result<impl Future<Output = anyhow::Result<()>> + use<>> {
646646
use vmservice::modify_resource_request::Resource;
647647
match request.resource.context("missing resource")? {
648648
Resource::ScsiDisk(disk) => {

support/fdt/src/parser.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -671,7 +671,7 @@ impl<'a> Property<'a> {
671671
}
672672

673673
/// Read data as an iterator of u64 values.
674-
pub fn as_64_list(&self) -> Result<impl Iterator<Item = u64> + 'a, Error<'a>> {
674+
pub fn as_64_list(&self) -> Result<impl Iterator<Item = u64> + use<'a>, Error<'a>> {
675675
Ok(U64b::slice_from(self.data)
676676
.ok_or(Error(ErrorKind::PropertyDataTypeBuffer {
677677
node_name: self.node_name,

support/mesh/mesh_protobuf/src/protobuf.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -666,7 +666,7 @@ impl<'a, 'b, R> MessageReader<'a, 'b, R> {
666666
}
667667

668668
/// Returns an iterator to consume the resources for this message.
669-
pub fn take_resources(&mut self) -> impl 'b + ExactSizeIterator<Item = Result<R>> {
669+
pub fn take_resources(&mut self) -> impl ExactSizeIterator<Item = Result<R>> + use<'b, R> {
670670
let state = self.state;
671671
self.resources.clone().map(move |i| {
672672
state

vm/devices/pci/pci_core/src/capabilities/msix.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -233,7 +233,7 @@ impl MsixEmulator {
233233
bar: u8,
234234
count: u16,
235235
register_msi: &mut dyn RegisterMsi,
236-
) -> (Self, impl PciCapability) {
236+
) -> (Self, impl PciCapability + use<>) {
237237
let state = MsixState {
238238
enabled: false,
239239
vectors: (0..count)

vm/devices/storage/disk_nvme/nvme_driver/src/driver.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -452,7 +452,7 @@ impl<T: DeviceBacking> NvmeDriver<T> {
452452
drop(self);
453453
}
454454

455-
fn reset(&mut self) -> impl 'static + Send + std::future::Future<Output = ()> {
455+
fn reset(&mut self) -> impl Send + std::future::Future<Output = ()> + use<T> {
456456
let driver = self.driver.clone();
457457
let mut task = std::mem::take(&mut self.task).unwrap();
458458
async move {

vm/devices/vmbus/vmbus_client/src/lib.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -221,7 +221,7 @@ impl VmbusClientAccess {
221221
pub fn connect_hvsock(
222222
&self,
223223
request: HvsockConnectRequest,
224-
) -> impl Future<Output = Option<OfferInfo>> {
224+
) -> impl Future<Output = Option<OfferInfo>> + use<> {
225225
self.client_request_send
226226
.call(ClientRequest::HvsockConnect, request)
227227
.map(|r| r.ok().flatten())

vm/devices/vmbus/vmbus_client_hcl/src/lib.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -32,9 +32,9 @@ use zerocopy::AsBytes;
3232

3333
/// Returns the synic client and message source for use with
3434
/// [`vmbus_client::VmbusClient`].
35-
pub fn new_synic_client_and_messsage_source(
36-
driver: &(impl Driver + ?Sized),
37-
) -> anyhow::Result<(impl SynicClient, impl VmbusMessageSource)> {
35+
pub fn new_synic_client_and_messsage_source<T: Driver + ?Sized>(
36+
driver: &T,
37+
) -> anyhow::Result<(impl SynicClient + use<T>, impl VmbusMessageSource + use<T>)> {
3838
// Open an HCL vmbus fd for issuing synic requests.
3939
let hcl_vmbus = Arc::new(HclVmbus::new().context("failed to open hcl_vmbus")?);
4040
let synic = HclSynic {

vm/devices/vmbus/vmbus_server/src/hvsock.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ impl HvsockRelay {
114114
&self,
115115
ctx: &mut CancelContext,
116116
service_id: Guid,
117-
) -> impl std::future::Future<Output = anyhow::Result<UnixStream>> + Send {
117+
) -> impl std::future::Future<Output = anyhow::Result<UnixStream>> + Send + use<> {
118118
let inner = self.inner.clone();
119119
let host_send = self.host_send.clone();
120120
let (send, recv) = mesh::oneshot();

vmm_core/state_unit/src/lib.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -888,12 +888,12 @@ impl ReadySet {
888888
/// future with a span, and wrapping its error with something more informative.
889889
///
890890
/// `operation` and `name` are used in tracing and error construction.
891-
fn state_change<I: 'static, R: 'static + Send>(
891+
fn state_change<I: 'static, R: 'static + Send, Req: FnOnce(Rpc<I, R>) -> StateRequest>(
892892
name: Arc<str>,
893893
unit: &Unit,
894-
request: impl FnOnce(Rpc<I, R>) -> StateRequest,
894+
request: Req,
895895
input: Option<I>,
896-
) -> impl Future<Output = Result<Option<R>, UnitRecvError>> {
896+
) -> impl Future<Output = Result<Option<R>, UnitRecvError>> + use<I, R, Req> {
897897
let send = unit.send.clone();
898898

899899
async move {

vmm_core/virt_whp/src/lib.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1642,7 +1642,7 @@ mod aarch64 {
16421642
&self,
16431643
vp: VpIndex,
16441644
vtl: Vtl,
1645-
) -> impl hv1_emulator::RequestInterrupt {
1645+
) -> impl hv1_emulator::RequestInterrupt + use<> {
16461646
let _ = (vp, vtl);
16471647
move |_vec, _auto_eoi| todo!("TODO-aarch64")
16481648
}

vmm_core/virt_whp/src/vtl2.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -190,7 +190,7 @@ pub(crate) struct Vtl2Emulation {
190190
mod inspect_helpers {
191191
use super::*;
192192

193-
pub(super) fn vsm_config_raw(raw: &AtomicU64) -> impl Inspect {
193+
pub(super) fn vsm_config_raw(raw: &AtomicU64) -> impl Inspect + use<> {
194194
let config = HvRegisterVsmPartitionConfig::from(raw.load(Ordering::Relaxed));
195195
inspect::AsDebug(config)
196196
}

0 commit comments

Comments
 (0)