[RFC 01/26] rust/hpet: Fix the error caused by vm-memory

Zhao Liu posted 26 patches 4 months, 1 week ago
Maintainers: Paolo Bonzini <pbonzini@redhat.com>, Peter Xu <peterx@redhat.com>, David Hildenbrand <david@redhat.com>, "Philippe Mathieu-Daudé" <philmd@linaro.org>, Manos Pitsidianakis <manos.pitsidianakis@linaro.org>, "Alex Bennée" <alex.bennee@linaro.org>, Thomas Huth <thuth@redhat.com>
[RFC 01/26] rust/hpet: Fix the error caused by vm-memory
Posted by Zhao Liu 4 months, 1 week ago
error[E0283]: type annotations needed
   --> hw/timer/hpet/src/device.rs:884:55
    |
884 |         self.num_timers == self.num_timers_save.get().into()
    |                         --                            ^^^^
    |                         |
    |                         type must be known at this point
    |
    = note: multiple `impl`s satisfying `usize: PartialEq<_>` found in the following crates: `core`, `vm_memory`:
            - impl PartialEq<vm_memory::endian::BeSize> for usize;
            - impl PartialEq<vm_memory::endian::LeSize> for usize;
            - impl<host> PartialEq for usize
              where the constant `host` has type `bool`;
help: try using a fully qualified path to specify the expected types
    |
884 |         self.num_timers == <u8 as Into<T>>::into(self.num_timers_save.get())
    |                            ++++++++++++++++++++++                          ~

For more information about this error, try `rustc --explain E0283`.
error: could not compile `hpet` (lib) due to 1 previous error

Signed-off-by: Zhao Liu <zhao1.liu@intel.com>
---
 rust/hw/timer/hpet/src/device.rs | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/rust/hw/timer/hpet/src/device.rs b/rust/hw/timer/hpet/src/device.rs
index acf7251029e9..9fd75bf096e4 100644
--- a/rust/hw/timer/hpet/src/device.rs
+++ b/rust/hw/timer/hpet/src/device.rs
@@ -881,7 +881,7 @@ fn is_offset_needed(&self) -> bool {
     }
 
     fn validate_num_timers(&self, _version_id: u8) -> bool {
-        self.num_timers == self.num_timers_save.get().into()
+        self.num_timers == Into::<usize>::into(self.num_timers_save.get())
     }
 }
 
-- 
2.34.1
Re: [RFC 01/26] rust/hpet: Fix the error caused by vm-memory
Posted by Paolo Bonzini 4 months, 1 week ago
On 8/7/25 14:30, Zhao Liu wrote:
> error[E0283]: type annotations needed
>     --> hw/timer/hpet/src/device.rs:884:55
>      |
> 884 |         self.num_timers == self.num_timers_save.get().into()
>      |                         --                            ^^^^
>      |                         |
>      |                         type must be known at this point
>      |
>      = note: multiple `impl`s satisfying `usize: PartialEq<_>` found in the following crates: `core`, `vm_memory`:
>              - impl PartialEq<vm_memory::endian::BeSize> for usize;
>              - impl PartialEq<vm_memory::endian::LeSize> for usize;
>              - impl<host> PartialEq for usize
>                where the constant `host` has type `bool`;
> help: try using a fully qualified path to specify the expected types
>      |
> 884 |         self.num_timers == <u8 as Into<T>>::into(self.num_timers_save.get())
>      |                            ++++++++++++++++++++++                          ~

Oh, interesting.  In this case, you can write:

     usize::from(self.num_timers_save.get())

Paolo
Re: [RFC 01/26] rust/hpet: Fix the error caused by vm-memory
Posted by Zhao Liu 4 months, 1 week ago
On Thu, Aug 07, 2025 at 03:52:37PM +0200, Paolo Bonzini wrote:
> Date: Thu, 7 Aug 2025 15:52:37 +0200
> From: Paolo Bonzini <pbonzini@redhat.com>
> Subject: Re: [RFC 01/26] rust/hpet: Fix the error caused by vm-memory
> 
> On 8/7/25 14:30, Zhao Liu wrote:
> > error[E0283]: type annotations needed
> >     --> hw/timer/hpet/src/device.rs:884:55
> >      |
> > 884 |         self.num_timers == self.num_timers_save.get().into()
> >      |                         --                            ^^^^
> >      |                         |
> >      |                         type must be known at this point
> >      |
> >      = note: multiple `impl`s satisfying `usize: PartialEq<_>` found in the following crates: `core`, `vm_memory`:
> >              - impl PartialEq<vm_memory::endian::BeSize> for usize;
> >              - impl PartialEq<vm_memory::endian::LeSize> for usize;
> >              - impl<host> PartialEq for usize
> >                where the constant `host` has type `bool`;
> > help: try using a fully qualified path to specify the expected types
> >      |
> > 884 |         self.num_timers == <u8 as Into<T>>::into(self.num_timers_save.get())
> >      |                            ++++++++++++++++++++++                          ~
> 
> Oh, interesting.  In this case, you can write:
> 
>     usize::from(self.num_timers_save.get())

Ah, yes, this way is simpler! Thanks.

-Zhao