diff --git a/substrate/frame/support/procedural/src/runtime/parse/mod.rs b/substrate/frame/support/procedural/src/runtime/parse/mod.rs
index 893cb4726e2b6016fa2e728add86990e24087c42..dd83cd0da90a2185ebc5015daadba0a9d00ac438 100644
--- a/substrate/frame/support/procedural/src/runtime/parse/mod.rs
+++ b/substrate/frame/support/procedural/src/runtime/parse/mod.rs
@@ -152,8 +152,7 @@ impl Def {
 		let mut pallets = vec![];
 
 		for item in items.iter_mut() {
-			let mut pallet_item = None;
-			let mut pallet_index = 0;
+			let mut pallet_index_and_item = None;
 
 			let mut disable_call = false;
 			let mut disable_unsigned = false;
@@ -170,9 +169,8 @@ impl Def {
 						runtime_types = Some(types);
 					},
 					RuntimeAttr::PalletIndex(span, index) => {
-						pallet_index = index;
-						pallet_item = if let syn::Item::Type(item) = item {
-							Some(item.clone())
+						pallet_index_and_item = if let syn::Item::Type(item) = item {
+							Some((index, item.clone()))
 						} else {
 							let msg = "Invalid runtime::pallet_index, expected type definition";
 							return Err(syn::Error::new(span, msg))
@@ -187,7 +185,7 @@ impl Def {
 				}
 			}
 
-			if let Some(pallet_item) = pallet_item {
+			if let Some((pallet_index, pallet_item)) = pallet_index_and_item {
 				match *pallet_item.ty.clone() {
 					syn::Type::Path(ref path) => {
 						let pallet_decl =
@@ -230,6 +228,11 @@ impl Def {
 					},
 					_ => continue,
 				}
+			} else {
+				if let syn::Item::Type(item) = item {
+					let msg = "Missing pallet index for pallet declaration. Please add `#[runtime::pallet_index(...)]`";
+					return Err(syn::Error::new(item.span(), &msg))
+				}
 			}
 		}
 
diff --git a/substrate/frame/support/test/tests/runtime_ui/missing_pallet_index.rs b/substrate/frame/support/test/tests/runtime_ui/missing_pallet_index.rs
new file mode 100644
index 0000000000000000000000000000000000000000..469a7833e5afce4c3e8b2afda124ce92a05df43e
--- /dev/null
+++ b/substrate/frame/support/test/tests/runtime_ui/missing_pallet_index.rs
@@ -0,0 +1,27 @@
+// This file is part of Substrate.
+
+// Copyright (C) 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.
+
+#[frame_support::runtime]
+mod runtime {
+    #[runtime::runtime]
+    #[runtime::derive(RuntimeCall)]
+    pub struct Runtime;
+
+    pub type System = frame_system;
+}
+
+fn main() {}
diff --git a/substrate/frame/support/test/tests/runtime_ui/missing_pallet_index.stderr b/substrate/frame/support/test/tests/runtime_ui/missing_pallet_index.stderr
new file mode 100644
index 0000000000000000000000000000000000000000..a2cbaa48199d915cef506af495751986e0509874
--- /dev/null
+++ b/substrate/frame/support/test/tests/runtime_ui/missing_pallet_index.stderr
@@ -0,0 +1,5 @@
+error: Missing pallet index for pallet declaration. Please add `#[runtime::pallet_index(...)]`
+  --> tests/runtime_ui/missing_pallet_index.rs:24:5
+   |
+24 |     pub type System = frame_system;
+   |     ^^^