Repository: paritytech/substrate
File: frame/support/src/dispatch.rs (Rust)

Code before:
/// implement the [`OnRuntimeUpgrade`](../sp_runtime/traits/trait.OnRuntimeUpgrade.html) trait.
/// Function signature must be `fn on_runtime_upgrade() -> frame_support::weights::Weight`.
///
/// * `on_initialize`: Executes at the beginning of a block. Using this function will
/// implement the [`OnInitialize`](./trait.OnInitialize.html) trait.
/// Function signature can be either:
///   * `fn on_initialize(n: BlockNumber) -> frame_support::weights::Weight` or
///   * `fn on_initialize() -> frame_support::weights::Weight`
///
/// * `on_idle`: Executes at the end of a block. Passes a remaining weight to provide a threshold
/// for when to execute non vital functions. Using this function will implement the
/// [`OnIdle`](./traits/trait.OnIdle.html) trait.
/// Function signature is:
///   * `fn on_idle(n: BlockNumber, remaining_weight: Weight) -> frame_support::weights::Weight`
///
/// * `on_finalize`: Executes at the end of a block. Using this function will
/// implement the [`OnFinalize`](./traits/trait.OnFinalize.html) trait.
/// Function signature can be either:
///   * `fn on_finalize(n: BlockNumber) -> frame_support::weights::Weight` or
///   * `fn on_finalize() -> frame_support::weights::Weight`
///
/// * `offchain_worker`: Executes at the beginning of a block and produces extrinsics for a future
///   block upon completion. Using this function will implement the
///   [`OffchainWorker`](./traits/trait.OffchainWorker.html) trait.
/// * `integrity_test`: Executes in a test generated by `construct_runtime`, note it does execute it
/// * in an externalities-provided environment. Implement
///   [`IntegrityTest`](./trait.IntegrityTest.html) trait.
#[macro_export]
#[deprecated(note = "Will be removed after July 2023; use the attribute `#[pallet]` macro instead.
	For more info, see: <https://github.com/paritytech/substrate/pull/13705>")]
macro_rules! decl_module {
	// Entry point #1.
	(
		$(#[$attr:meta])*
		pub struct $mod_type:ident<
			$trait_instance:ident: $trait_name:ident
			$( <I>, I: $instantiable:path $( = $module_default_instance:path )? )?
		>
		for enum $call_type:ident where origin: $origin_type:ty $(, $where_ty:ty: $where_bound:path )* $(,)? {
			$( $t:tt )*
		}
	) => {
		$crate::decl_module!(@normalize
			$(#[$attr])*
			pub struct $mod_type<
				$trait_instance: $trait_name $(<I>, I: $instantiable $(= $module_default_instance)?)?
			>
			for enum $call_type where origin: $origin_type, system = frame_system
			{ $( $where_ty: $where_bound ),* }
			{}
			{}

Review comment (suggestion):
```suggestion
///   in an externalities-provided environment. Implement
```

Code after:
	) => {
		compile_error!(
			"`on_finalize` can't be given weight attribute anymore, weight must be returned by \
			`on_initialize` or `on_runtime_upgrade` instead"
		);
	};
	// Compile error on `on_finalize` being added a second time.
	(@normalize
		$(#[$attr:meta])*
		pub struct $mod_type:ident<
			$trait_instance:ident: $trait_name:ident$(<I>, I: $instantiable:path $(= $module_default_instance:path)?)?
		>
		for enum $call_type:ident where origin: $origin_type:ty, system = $system:ident
		{ $( $other_where_bounds:tt )* }
		{ $( $deposit_event:tt )* }
		{ $( $on_initialize:tt )* }
		{ $( $on_runtime_upgrade:tt )* }
		{ $( $on_idle:tt )* }
		{ $( $on_finalize:tt )+ }
		{ $( $offchain:tt )* }
		{ $( $constants:tt )* }
		{ $( $error_type:tt )* }
		{ $( $integrity_test:tt )* }
		{ $( $storage_version:tt )* }
		[ $( $dispatchables:tt )* ]
		$(#[doc = $doc_attr:tt])*
		#[weight = $weight:expr]
		fn on_finalize( $( $param_name:ident : $param:ty ),* $(,)? ) { $( $impl:tt )* }
		$($rest:tt)*
	) => {
		compile_error!("`on_finalize` can only be passed once as input.");
	};

	// Add on_idle
	(@normalize
		$(#[$attr:meta])*
		pub struct $mod_type:ident<$trait_instance:ident: $trait_name:ident$(<I>, I: $instantiable:path $(= $module_default_instance:path)?)?>
		for enum $call_type:ident where origin: $origin_type:ty, system = $system:ident
		{ $( $other_where_bounds:tt )* }
		{ $( $deposit_event:tt )* }
		{ $( $on_initialize:tt )* }
		{ $( $on_runtime_upgrade:tt )* }
		{}
		{ $( $on_finalize:tt )* }
		{ $( $offchain:tt )* }
		{ $( $constants:tt )* }
		{ $( $error_type:tt )* }
		{ $( $integrity_test:tt )* }
		{ $( $storage_version:tt )* }
		[ $( $dispatchables:tt )* ]
		$(#[doc = $doc_attr:tt])*