Skip to content

Commit be57cc2

Browse files
authored
Improve error message on where clause on pallet error (#7821)
* improve error message on where clause on pallet error * Revert "improve error message on where clause on pallet error" This reverts commit 5a3cc38976813fccef3357833553ce30f5b988ea. * Revert "Revert "improve error message on where clause on pallet error"" This reverts commit e3b3fca6bc4fa89816f80dbcb82dc4536a9b2549.
1 parent e733231 commit be57cc2

File tree

4 files changed

+31
-1
lines changed

4 files changed

+31
-1
lines changed

procedural/src/pallet/parse/error.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ impl ErrorDef {
5353
instances.push(helper::check_type_def_gen_no_bounds(&item.generics, item.ident.span())?);
5454

5555
if item.generics.where_clause.is_some() {
56-
let msg = "Invalid pallet::error, unexpected where clause";
56+
let msg = "Invalid pallet::error, where clause is not allowed on pallet error item";
5757
return Err(syn::Error::new(item.generics.where_clause.as_ref().unwrap().span(), msg));
5858
}
5959

src/lib.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1256,6 +1256,8 @@ pub mod pallet_prelude {
12561256
/// }
12571257
/// ```
12581258
/// I.e. a regular rust enum named `Error`, with generic `T` and fieldless variants.
1259+
/// The generic `T` mustn't bound anything and where clause is not allowed. But bounds and where
1260+
/// clause shouldn't be needed for any usecase.
12591261
///
12601262
/// ### Macro expansion
12611263
///
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
#[frame_support::pallet]
2+
mod pallet {
3+
use frame_support::pallet_prelude::Hooks;
4+
use frame_system::pallet_prelude::BlockNumberFor;
5+
6+
#[pallet::config]
7+
pub trait Config: frame_system::Config {}
8+
9+
#[pallet::pallet]
10+
pub struct Pallet<T>(core::marker::PhantomData<T>);
11+
12+
#[pallet::hooks]
13+
impl<T: Config> Hooks<BlockNumberFor<T>> for Pallet<T> {}
14+
15+
#[pallet::call]
16+
impl<T: Config> Pallet<T> {}
17+
18+
#[pallet::error]
19+
pub enum Error<T> where u32: From<u8> {}
20+
}
21+
22+
fn main() {
23+
}
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
error: Invalid pallet::error, where clause is not allowed on pallet error item
2+
--> $DIR/error_where_clause.rs:19:20
3+
|
4+
19 | pub enum Error<T> where u32: From<u8> {}
5+
| ^^^^^

0 commit comments

Comments
 (0)