Repository: paritytech/substrate
File: frame/support/procedural/src/pallet/expand/hooks.rs (Rust)

Code before:
			target: #frame_support::LOG_TARGET,
			"🩺 try-state pallet {:?}",
			pallet_name,
		);
	};

	let hooks_impl = if def.hooks.is_none() {
		let frame_system = &def.frame_system;
		quote::quote! {
			impl<#type_impl_gen>
				#frame_support::traits::Hooks<<T as #frame_system::Config>::BlockNumber>
				for #pallet_ident<#type_use_gen> #where_clause {}
		}
	} else {
		proc_macro2::TokenStream::new()
	};

	// If a storage version is set, we should ensure that the storage version on chain matches the
	// current storage version. This assumes that `Executive` is running custom migrations before
	// the pallets are called.
	let post_storage_version_check = if def.pallet_struct.storage_version.is_some() {
		quote::quote! {
			let on_chain_version = <Self as #frame_support::traits::GetStorageVersion>::on_chain_storage_version();
			let current_version = <Self as #frame_support::traits::GetStorageVersion>::current_storage_version();

			if on_chain_version != current_version {
				let pallet_name = <
					<T as #frame_system::Config>::PalletInfo
					as
					#frame_support::traits::PalletInfo
				>::name::<Self>().unwrap_or("<unknown pallet name>");

				#frame_support::log::error!(
					target: #frame_support::LOG_TARGET,
					"{}: On chain storage version {:?} doesn't match current storage version {:?}.",
					pallet_name,
					on_chain_version,
					current_version,
				);

				return Err("On chain and current storage version do not match. Missing runtime upgrade?");
			}
		}
	} else {
		quote::quote! {}
	};

	quote::quote_spanned!(span =>
		#hooks_impl

		impl<#type_impl_gen>

Review comment (suggestion):
I see this does works for pallets without storage versions. But why?  
I thought it would try to compare `NoStorageVersionSet` which should error.

Code after:
			target: #frame_support::LOG_TARGET,
			"🩺 try-state pallet {:?}",
			pallet_name,
		);
	};

	let hooks_impl = if def.hooks.is_none() {
		let frame_system = &def.frame_system;
		quote::quote! {
			impl<#type_impl_gen>
				#frame_support::traits::Hooks<<T as #frame_system::Config>::BlockNumber>
				for #pallet_ident<#type_use_gen> #where_clause {}
		}
	} else {
		proc_macro2::TokenStream::new()
	};

	// If a storage version is set, we should ensure that the storage version on chain matches the
	// current storage version. This assumes that `Executive` is running custom migrations before
	// the pallets are called.
	let post_storage_version_check = if def.pallet_struct.storage_version.is_some() {
		quote::quote! {
			let on_chain_version = <Self as #frame_support::traits::GetStorageVersion>::on_chain_storage_version();
			let current_version = <Self as #frame_support::traits::GetStorageVersion>::current_storage_version();

			if on_chain_version != current_version {
				let pallet_name = <
					<T as #frame_system::Config>::PalletInfo
					as
					#frame_support::traits::PalletInfo
				>::name::<Self>().unwrap_or("<unknown pallet name>");

				#frame_support::log::error!(
					target: #frame_support::LOG_TARGET,
					"{}: On chain storage version {:?} doesn't match current storage version {:?}.",
					pallet_name,
					on_chain_version,
					current_version,
				);

				return Err("On chain and current storage version do not match. Missing runtime upgrade?");
			}
		}
	} else {
		quote::quote! {
			let on_chain_version = <Self as #frame_support::traits::GetStorageVersion>::on_chain_storage_version();

			if on_chain_version != #frame_support::traits::StorageVersion::new(0) {
				let pallet_name = <
					<T as #frame_system::Config>::PalletInfo
					as