Skip to content
This repository has been archived by the owner on Nov 15, 2023. It is now read-only.

Have the decl_storage! macro import rstd::prelude::* #1334

Closed
shawntabrizi opened this issue Dec 27, 2018 · 0 comments · Fixed by #1317 or libp2p/rust-libp2p#2289
Closed

Have the decl_storage! macro import rstd::prelude::* #1334

shawntabrizi opened this issue Dec 27, 2018 · 0 comments · Fixed by #1317 or libp2p/rust-libp2p#2289
Assignees

Comments

@shawntabrizi
Copy link
Member

When trying to use the decl_storage macro and build to wasm, the compiler complains that the Vec type has not been declared.

For example, this minimum runtime:

use srml_support::{StorageValue, dispatch::Result};
pub trait Trait: system::Trait {}

decl_module! {
  pub struct Module<T: Trait> for enum Call where origin: T::Origin {
    fn set_value(_origin, value: u32) -> Result {
      <Value<T>>::put(value);
      Ok(())
    }
  }
}

decl_storage! {
  trait Store for Module<T: Trait> as RuntimeExampleStorage {
    Value: u32;
  }
}

will give the following error:

error[E0412]: cannot find type `Vec` in this scope
  --> src/runtime_example.rs:13:1
   |
13 | / decl_storage! {
14 | |   trait Store for Module<T: Trait> as RuntimeExampleStorage {
15 | |     Value: u32;
16 | |   }
17 | | }
   | |_^ not found in this scope
help: possible candidates are found in other modules, you can import them into scope
   |
1  | use rstd::alloc::prelude::Vec;
   |
1  | use rstd::prelude::Vec;
   |
1  | use rstd::vec::Vec;
   |
1  | use srml_support::dispatch::Vec;
   |
and 1 other candidates

error: aborting due to previous error

For more information about this error, try `rustc --explain E0412`.
error: Could not compile `runtime-example-runtime`.

To solve this issue, you simply need to add: use rstd::prelude::*;

We should have the decl_storage macro automatically do this if it requires this import.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
2 participants