Skip to content

Commit f17a8b3

Browse files
petreeftimedianpopa
authored andcommitted
Fix trait objects without specific dyn warning
Signed-off-by: Petre Eftime <[email protected]>
1 parent 72c077d commit f17a8b3

File tree

10 files changed

+52
-33
lines changed

10 files changed

+52
-33
lines changed

api_server/src/http_service.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -476,7 +476,7 @@ impl hyper::server::Service for ApiServerHttpService {
476476
type Request = hyper::Request;
477477
type Response = hyper::Response;
478478
type Error = hyper::error::Error;
479-
type Future = Box<Future<Item = Self::Response, Error = Self::Error>>;
479+
type Future = Box<dyn Future<Item = Self::Response, Error = Self::Error>>;
480480

481481
// This function returns a future that will resolve at some point to the response for
482482
// the HTTP request contained in req.

devices/src/bus.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ impl PartialOrd for BusRange {
8989
/// only restriction is that no two devices can overlap in this address space.
9090
#[derive(Clone, Default)]
9191
pub struct Bus {
92-
devices: BTreeMap<BusRange, Arc<Mutex<BusDevice>>>,
92+
devices: BTreeMap<BusRange, Arc<Mutex<dyn BusDevice>>>,
9393
}
9494

9595
impl Bus {
@@ -100,7 +100,7 @@ impl Bus {
100100
}
101101
}
102102

103-
fn first_before(&self, addr: u64) -> Option<(BusRange, &Mutex<BusDevice>)> {
103+
fn first_before(&self, addr: u64) -> Option<(BusRange, &Mutex<dyn BusDevice>)> {
104104
// for when we switch to rustc 1.17: self.devices.range(..addr).iter().rev().next()
105105
for (range, dev) in self.devices.iter().rev() {
106106
if range.0 <= addr {
@@ -110,7 +110,7 @@ impl Bus {
110110
None
111111
}
112112

113-
pub fn get_device(&self, addr: u64) -> Option<(u64, &Mutex<BusDevice>)> {
113+
pub fn get_device(&self, addr: u64) -> Option<(u64, &Mutex<dyn BusDevice>)> {
114114
if let Some((BusRange(start, len), dev)) = self.first_before(addr) {
115115
let offset = addr - start;
116116
if offset < len {
@@ -121,7 +121,7 @@ impl Bus {
121121
}
122122

123123
/// Puts the given device at the given address space.
124-
pub fn insert(&mut self, device: Arc<Mutex<BusDevice>>, base: u64, len: u64) -> Result<()> {
124+
pub fn insert(&mut self, device: Arc<Mutex<dyn BusDevice>>, base: u64, len: u64) -> Result<()> {
125125
if len == 0 {
126126
return Err(Error::Overlap);
127127
}

devices/src/legacy/serial.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -66,11 +66,11 @@ pub struct Serial {
6666
scratch: u8,
6767
baud_divisor: u16,
6868
in_buffer: VecDeque<u8>,
69-
out: Option<Box<io::Write + Send>>,
69+
out: Option<Box<dyn io::Write + Send>>,
7070
}
7171

7272
impl Serial {
73-
fn new(interrupt_evt: EventFd, out: Option<Box<io::Write + Send>>) -> Serial {
73+
fn new(interrupt_evt: EventFd, out: Option<Box<dyn io::Write + Send>>) -> Serial {
7474
Serial {
7575
interrupt_enable: 0,
7676
interrupt_identification: DEFAULT_INTERRUPT_IDENTIFICATION,
@@ -87,7 +87,7 @@ impl Serial {
8787
}
8888

8989
/// Constructs a Serial port ready for output.
90-
pub fn new_out(interrupt_evt: EventFd, out: Box<io::Write + Send>) -> Serial {
90+
pub fn new_out(interrupt_evt: EventFd, out: Box<dyn io::Write + Send>) -> Serial {
9191
Self::new(interrupt_evt, Some(out))
9292
}
9393

devices/src/virtio/block.rs

+6-2
Original file line numberDiff line numberDiff line change
@@ -428,11 +428,15 @@ pub struct EpollConfig {
428428
q_avail_token: u64,
429429
rate_limiter_token: u64,
430430
epoll_raw_fd: RawFd,
431-
sender: mpsc::Sender<Box<EpollHandler>>,
431+
sender: mpsc::Sender<Box<dyn EpollHandler>>,
432432
}
433433

434434
impl EpollConfigConstructor for EpollConfig {
435-
fn new(first_token: u64, epoll_raw_fd: RawFd, sender: mpsc::Sender<Box<EpollHandler>>) -> Self {
435+
fn new(
436+
first_token: u64,
437+
epoll_raw_fd: RawFd,
438+
sender: mpsc::Sender<Box<dyn EpollHandler>>,
439+
) -> Self {
436440
EpollConfig {
437441
q_avail_token: first_token + u64::from(QUEUE_AVAIL_EVENT),
438442
rate_limiter_token: first_token + u64::from(RATE_LIMITER_EVENT),

devices/src/virtio/mmio.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ pub trait VirtioDevice: Send {
8686
/// Typically one page (4096 bytes) of MMIO address space is sufficient to handle this transport
8787
/// and inner virtio device.
8888
pub struct MmioDevice {
89-
device: Box<VirtioDevice>,
89+
device: Box<dyn VirtioDevice>,
9090
device_activated: bool,
9191

9292
features_select: u32,
@@ -103,7 +103,7 @@ pub struct MmioDevice {
103103

104104
impl MmioDevice {
105105
/// Constructs a new MMIO transport for the given virtio device.
106-
pub fn new(mem: GuestMemory, device: Box<VirtioDevice>) -> std::io::Result<MmioDevice> {
106+
pub fn new(mem: GuestMemory, device: Box<dyn VirtioDevice>) -> std::io::Result<MmioDevice> {
107107
let mut queue_evts = Vec::new();
108108
for _ in device.queue_max_sizes().iter() {
109109
queue_evts.push(EventFd::new()?)

devices/src/virtio/mod.rs

+9-5
Original file line numberDiff line numberDiff line change
@@ -56,21 +56,25 @@ pub enum ActivateError {
5656
pub type ActivateResult = std::result::Result<(), ActivateError>;
5757

5858
pub trait EpollConfigConstructor {
59-
fn new(first_token: u64, epoll_raw_fd: RawFd, sender: mpsc::Sender<Box<EpollHandler>>) -> Self;
59+
fn new(
60+
first_token: u64,
61+
epoll_raw_fd: RawFd,
62+
sender: mpsc::Sender<Box<dyn EpollHandler>>,
63+
) -> Self;
6064
}
6165

6266
/// Trait that helps in upcasting an object to Any
6367
pub trait AsAny {
64-
fn as_any(&self) -> &Any;
68+
fn as_any(&self) -> &dyn Any;
6569

66-
fn as_mut_any(&mut self) -> &mut Any;
70+
fn as_mut_any(&mut self) -> &mut dyn Any;
6771
}
6872
impl<T: Any> AsAny for T {
69-
fn as_any(&self) -> &Any {
73+
fn as_any(&self) -> &dyn Any {
7074
self
7175
}
7276

73-
fn as_mut_any(&mut self) -> &mut Any {
77+
fn as_mut_any(&mut self) -> &mut dyn Any {
7478
self
7579
}
7680
}

devices/src/virtio/net.rs

+6-2
Original file line numberDiff line numberDiff line change
@@ -652,11 +652,15 @@ pub struct EpollConfig {
652652
rx_rate_limiter_token: u64,
653653
tx_rate_limiter_token: u64,
654654
epoll_raw_fd: RawFd,
655-
sender: mpsc::Sender<Box<EpollHandler>>,
655+
sender: mpsc::Sender<Box<dyn EpollHandler>>,
656656
}
657657

658658
impl EpollConfigConstructor for EpollConfig {
659-
fn new(first_token: u64, epoll_raw_fd: RawFd, sender: mpsc::Sender<Box<EpollHandler>>) -> Self {
659+
fn new(
660+
first_token: u64,
661+
epoll_raw_fd: RawFd,
662+
sender: mpsc::Sender<Box<dyn EpollHandler>>,
663+
) -> Self {
660664
EpollConfig {
661665
rx_tap_token: first_token + u64::from(RX_TAP_EVENT),
662666
rx_queue_token: first_token + u64::from(RX_QUEUE_EVENT),

devices/src/virtio/vsock/mod.rs

+6-2
Original file line numberDiff line numberDiff line change
@@ -130,11 +130,15 @@ pub struct EpollConfig {
130130
evq_token: u64,
131131
backend_token: u64,
132132
epoll_raw_fd: RawFd,
133-
sender: mpsc::Sender<Box<EpollHandler>>,
133+
sender: mpsc::Sender<Box<dyn EpollHandler>>,
134134
}
135135

136136
impl EpollConfigConstructor for EpollConfig {
137-
fn new(first_token: u64, epoll_raw_fd: RawFd, sender: mpsc::Sender<Box<EpollHandler>>) -> Self {
137+
fn new(
138+
first_token: u64,
139+
epoll_raw_fd: RawFd,
140+
sender: mpsc::Sender<Box<dyn EpollHandler>>,
141+
) -> Self {
138142
EpollConfig {
139143
rxq_token: first_token + u64::from(defs::RXQ_EVENT),
140144
txq_token: first_token + u64::from(defs::TXQ_EVENT),

vmm/src/device_manager/mmio.rs

+7-4
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ pub struct MMIODeviceManager {
8181
irq: u32,
8282
last_irq: u32,
8383
id_to_dev_info: HashMap<(DeviceType, String), MMIODeviceInfo>,
84-
raw_io_handlers: HashMap<(DeviceType, String), Arc<Mutex<RawIOHandler>>>,
84+
raw_io_handlers: HashMap<(DeviceType, String), Arc<Mutex<dyn RawIOHandler>>>,
8585
}
8686

8787
impl MMIODeviceManager {
@@ -109,7 +109,7 @@ impl MMIODeviceManager {
109109
pub fn register_virtio_device(
110110
&mut self,
111111
vm: &VmFd,
112-
device: Box<devices::virtio::VirtioDevice>,
112+
device: Box<dyn devices::virtio::VirtioDevice>,
113113
cmdline: &mut kernel_cmdline::Cmdline,
114114
type_id: u32,
115115
device_id: &str,
@@ -264,7 +264,7 @@ impl MMIODeviceManager {
264264
&self,
265265
device_type: DeviceType,
266266
device_id: &str,
267-
) -> Option<&Mutex<BusDevice>> {
267+
) -> Option<&Mutex<dyn BusDevice>> {
268268
if let Some(dev_info) = self
269269
.id_to_dev_info
270270
.get(&(device_type, device_id.to_string()))
@@ -278,7 +278,10 @@ impl MMIODeviceManager {
278278

279279
// Used only on 'aarch64', but needed by unit tests on all platforms.
280280
#[allow(dead_code)]
281-
pub fn get_raw_io_device(&self, device_type: DeviceType) -> Option<&Arc<Mutex<RawIOHandler>>> {
281+
pub fn get_raw_io_device(
282+
&self,
283+
device_type: DeviceType,
284+
) -> Option<&Arc<Mutex<dyn RawIOHandler>>> {
282285
self.raw_io_handlers
283286
.get(&(device_type, device_type.to_string()))
284287
}

vmm/src/lib.rs

+8-8
Original file line numberDiff line numberDiff line change
@@ -372,7 +372,7 @@ impl Display for VmmActionError {
372372
use self::VmmActionError::*;
373373

374374
let error = match *self {
375-
BootSource(_, ref err) => err as &ToString,
375+
BootSource(_, ref err) => err as &dyn ToString,
376376
DriveConfig(_, ref err) => err,
377377
Logger(_, ref err) => err,
378378
MachineConfig(_, ref err) => err,
@@ -538,12 +538,12 @@ enum EpollDispatch {
538538
}
539539

540540
struct MaybeHandler {
541-
handler: Option<Box<EpollHandler>>,
542-
receiver: Receiver<Box<EpollHandler>>,
541+
handler: Option<Box<dyn EpollHandler>>,
542+
receiver: Receiver<Box<dyn EpollHandler>>,
543543
}
544544

545545
impl MaybeHandler {
546-
fn new(receiver: Receiver<Box<EpollHandler>>) -> Self {
546+
fn new(receiver: Receiver<Box<dyn EpollHandler>>) -> Self {
547547
MaybeHandler {
548548
handler: None,
549549
receiver,
@@ -656,7 +656,7 @@ impl EpollContext {
656656
/// This device's handler will be added to the end of `device_handlers`.
657657
/// This returns the index of the first token, and a channel on which to
658658
/// send an epoll handler for the relevant device.
659-
fn allocate_tokens_for_device(&mut self, count: usize) -> (u64, Sender<Box<EpollHandler>>) {
659+
fn allocate_tokens_for_device(&mut self, count: usize) -> (u64, Sender<Box<dyn EpollHandler>>) {
660660
let dispatch_base = self.dispatch_table.len() as u64;
661661
let device_idx = self.device_handlers.len();
662662
let (sender, receiver) = channel();
@@ -692,7 +692,7 @@ impl EpollContext {
692692
T::new(dispatch_base, self.epoll_raw_fd, sender)
693693
}
694694

695-
fn get_device_handler_by_handler_id(&mut self, id: usize) -> Result<&mut EpollHandler> {
695+
fn get_device_handler_by_handler_id(&mut self, id: usize) -> Result<&mut dyn EpollHandler> {
696696
let maybe = &mut self.device_handlers[id];
697697
match maybe.handler {
698698
Some(ref mut v) => Ok(v.as_mut()),
@@ -818,7 +818,7 @@ impl Vmm {
818818
/// Creates a new VMM object.
819819
pub fn new(
820820
api_shared_info: Arc<RwLock<InstanceInfo>>,
821-
control_fd: &AsRawFd,
821+
control_fd: &dyn AsRawFd,
822822
from_api: Receiver<Box<VmmAction>>,
823823
seccomp_level: u32,
824824
kvm: Kvm,
@@ -1167,7 +1167,7 @@ impl Vmm {
11671167
}
11681168

11691169
#[cfg(target_arch = "x86_64")]
1170-
fn get_serial_device(&self) -> Option<Arc<Mutex<RawIOHandler>>> {
1170+
fn get_serial_device(&self) -> Option<Arc<Mutex<dyn RawIOHandler>>> {
11711171
Some(self.pio_device_manager.stdio_serial.clone())
11721172
}
11731173

0 commit comments

Comments
 (0)