Emit error when Config part is imported but without the std feature (#9225)

* Emit error when Config part is imported but without the std feature

* Add UI test for missing std feature on GenesisConfig

* Update frame/support/test/Cargo.toml

Co-authored-by: Guillaume Thiolliere <gui.thiolliere@gmail.com>

* Remove unused imports

* Unify all dummy party checker macros

* Fix

* Dispaly pallet_path::GenesisConfig instead of PalletConfig in error message

* Revert changes to construct_runtime_ui.rs

* Add additional parameter for dummy part checker macro

* Apply suggestions from code review

* fix master merge: update version

* update Cargo.lock

Co-authored-by: Guillaume Thiolliere <gui.thiolliere@gmail.com>
This commit is contained in:
Keith Yeung
2021-07-16 07:07:19 -07:00
committed by GitHub
parent 1e8035a273
commit 3ce2bd3eec
9 changed files with 268 additions and 89 deletions
+2
View File
@@ -25,6 +25,8 @@ pretty_assertions = "0.6.1"
rustversion = "1.0.0"
frame-metadata = { version = "14.0.0-dev", default-features = false, path = "../../metadata" }
frame-system = { version = "4.0.0-dev", default-features = false, path = "../../system" }
# The "std" feature for this pallet is never activated on purpose, in order to test construct_runtime error message
test-pallet = { package = "frame-support-test-pallet", default-features = false, path = "pallet" }
[features]
default = ["std"]
@@ -0,0 +1,25 @@
[package]
name = "frame-support-test-pallet"
version = "4.0.0-dev"
authors = ["Parity Technologies <admin@parity.io>"]
edition = "2018"
license = "Apache-2.0"
publish = false
homepage = "https://substrate.dev"
repository = "https://github.com/paritytech/substrate/"
[package.metadata.docs.rs]
targets = ["x86_64-unknown-linux-gnu"]
[dependencies]
codec = { package = "parity-scale-codec", version = "2.0.0", default-features = false, features = ["derive"] }
frame-support = { version = "4.0.0-dev", default-features = false, path = "../../" }
frame-system = { version = "4.0.0-dev", default-features = false, path = "../../../system" }
[features]
default = ["std"]
std = [
"codec/std",
"frame-support/std",
"frame-system/std",
]
@@ -0,0 +1,46 @@
// This file is part of Substrate.
// Copyright (C) 2021 Parity Technologies (UK) Ltd.
// SPDX-License-Identifier: Apache-2.0
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
pub use pallet::*;
#[frame_support::pallet]
pub mod pallet {
#[allow(unused_imports)]
use frame_support::pallet_prelude::*;
#[allow(unused_imports)]
use frame_system::pallet_prelude::*;
#[pallet::pallet]
pub struct Pallet<T>(_);
#[pallet::config]
pub trait Config: frame_system::Config {}
#[pallet::genesis_config]
pub struct GenesisConfig {}
#[cfg(feature = "std")]
impl Default for GenesisConfig {
fn default() -> Self {
Self {}
}
}
#[pallet::genesis_build]
impl<T: Config> GenesisBuild<T> for GenesisConfig {
fn build(&self) {}
}
}
@@ -0,0 +1,24 @@
use frame_support::construct_runtime;
use sp_runtime::{generic, traits::BlakeTwo256};
use sp_core::sr25519;
pub type Signature = sr25519::Signature;
pub type BlockNumber = u64;
pub type Header = generic::Header<BlockNumber, BlakeTwo256>;
pub type Block = generic::Block<Header, UncheckedExtrinsic>;
pub type UncheckedExtrinsic = generic::UncheckedExtrinsic<u32, Call, Signature, ()>;
impl test_pallet::Config for Runtime {}
construct_runtime! {
pub enum Runtime where
Block = Block,
NodeBlock = Block,
UncheckedExtrinsic = UncheckedExtrinsic
{
System: system::{Pallet, Call, Storage, Config, Event<T>},
Pallet: test_pallet::{Pallet, Config},
}
}
fn main() {}
@@ -0,0 +1,66 @@
error: `Pallet` does not have the std feature enabled, this will cause the `test_pallet::GenesisConfig` type to be undefined.
--> $DIR/no_std_genesis_config.rs:13:1
|
13 | / construct_runtime! {
14 | | pub enum Runtime where
15 | | Block = Block,
16 | | NodeBlock = Block,
... |
21 | | }
22 | | }
| |_^
|
= note: this error originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info)
error[E0433]: failed to resolve: use of undeclared crate or module `system`
--> $DIR/no_std_genesis_config.rs:19:11
|
19 | System: system::{Pallet, Call, Storage, Config, Event<T>},
| ^^^^^^ use of undeclared crate or module `system`
error[E0433]: failed to resolve: use of undeclared crate or module `system`
--> $DIR/no_std_genesis_config.rs:13:1
|
13 | / construct_runtime! {
14 | | pub enum Runtime where
15 | | Block = Block,
16 | | NodeBlock = Block,
... |
21 | | }
22 | | }
| |_^ not found in `system`
|
= note: this error originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info)
help: consider importing this enum
|
1 | use frame_system::RawOrigin;
|
error[E0412]: cannot find type `GenesisConfig` in crate `test_pallet`
--> $DIR/no_std_genesis_config.rs:13:1
|
13 | / construct_runtime! {
14 | | pub enum Runtime where
15 | | Block = Block,
16 | | NodeBlock = Block,
... |
21 | | }
22 | | }
| |_^ not found in `test_pallet`
|
= note: this error originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info)
help: consider importing this struct
|
1 | use frame_system::GenesisConfig;
|
error[E0277]: the trait bound `Runtime: frame_system::pallet::Config` is not satisfied
--> $DIR/no_std_genesis_config.rs:11:6
|
11 | impl test_pallet::Config for Runtime {}
| ^^^^^^^^^^^^^^^^^^^ the trait `frame_system::pallet::Config` is not implemented for `Runtime`
|
::: $WORKSPACE/frame/support/test/pallet/src/lib.rs
|
| pub trait Config: frame_system::Config {}
| -------------------- required by this bound in `Config`