0

I've got the error:

cannot find trait WeightInfo in this scope

I've added this in runtime:

impl my_pallet::Config for Runtime {
    type Event = Event;
    type WeightInfo = my_pallet::weights::SubstrateWeight<Runtime>;
}

And this in my lib.rs pallet:

pub mod weights;
pub use weights::WeightInfo;

with this also in config:

type WeightInfo: WeightInfo;

And of course I've generated a weights.rs file using the benchmark tool which looks correct comparing to the examples and other pallets.

Why can't the compiler find the trait for WeightInfo?

Edit: I forgot to paste the exact output:

error[E0405]: cannot find trait `WeightInfo` in this scope
  --> pallets/my_pallet/src/lib.rs:33:20
   |
33 |         type WeightInfo: WeightInfo;
   |                          ^^^^^^^^^^
   |
help: you might have meant to use the associated type
   |
33 |         type WeightInfo: Self::WeightInfo;
   |                          ~~~~~~~~~~~~~~~~
help: consider importing one of these items
   |
23 |     use crate::WeightInfo;
   |
23 |     use frame_system::WeightInfo;
   |
4

1 Answer 1

1

The problem is that a pallet does not import the surrounding imports.
The fix is to add a use super::*; to your pallet like this:

#[frame_support::pallet]
pub mod pallet {
    use super::*;  // Here
    #[allow(unused_imports)]

Also I don't see the maintain template in your executed command. Therefore the next error is about the () type not implementing your WeightInfo trait. The maintainer template does that here for you.
Or you use pallet_sim_renault::weights::SubstrateWeight<Test> instead of ().

2
  • use super::*; did the trick ! Thanks !
    – lucgerrits
    Jul 25, 2022 at 13:52
  • 1
    Indeed WeightInfo trait was missing, but I did the benchmark again with use super::*;, now its all good :)
    – lucgerrits
    Jul 25, 2022 at 13:54

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.