1// This file is part of Substrate.
23// Copyright (C) Parity Technologies (UK) Ltd.
4// SPDX-License-Identifier: Apache-2.0
56// Licensed under the Apache License, Version 2.0 (the "License");
7// you may not use this file except in compliance with the License.
8// You may obtain a copy of the License at
9//
10// http://www.apache.org/licenses/LICENSE-2.0
11//
12// Unless required by applicable law or agreed to in writing, software
13// distributed under the License is distributed on an "AS IS" BASIS,
14// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15// See the License for the specific language governing permissions and
16// limitations under the License.
1718use crate::{pallet::Def, COUNTER};
19use proc_macro2::TokenStream;
20use quote::quote;
21use syn::{spanned::Spanned, Ident};
2223pub fn expand_validate_unsigned(def: &mut Def) -> TokenStream {
24let count = COUNTER.with(|counter| counter.borrow_mut().inc());
25let macro_ident =
26 Ident::new(&format!("__is_validate_unsigned_part_defined_{}", count), def.item.span());
2728let maybe_compile_error = if def.validate_unsigned.is_none() {
29quote! {
30compile_error!(concat!(
31"`",
32stringify!($pallet_name),
33"` does not have #[pallet::validate_unsigned] defined, perhaps you should \
34 remove `ValidateUnsigned` from construct_runtime?",
35 ));
36 }
37 } else {
38 TokenStream::new()
39 };
4041quote! {
42#[doc(hidden)]
43pub mod __substrate_validate_unsigned_check {
44#[macro_export]
45 #[doc(hidden)]
46macro_rules! #macro_ident {
47 ($pallet_name:ident) => {
48 #maybe_compile_error
49 }
50 }
5152#[doc(hidden)]
53pub use #macro_ident as is_validate_unsigned_part_defined;
54 }
55 }
56}