From nobody Fri Dec 19 12:12:25 2025 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id CC714231A30; Fri, 10 Oct 2025 17:44:28 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1760118268; cv=none; b=ETwHP8TcTUaUrxSRzVzJhQn3qgLzmmEUqjsKjwMgVeU4aVbByx5KMJLhWvEBnJFyiQTFhhvYrk5naHt1srgr+6fvKYPgYVRfZRMWfBmlh8wUWriicCLn0CzHr7vb6evnxJpFfXAisPSrW8ulqHJi9WeQ4yAt5CgxHQ5v+Atk9go= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1760118268; c=relaxed/simple; bh=wZIygxQdT5DiLOau68Xpa/62K8oxbMttfztozN2k3NE=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=LXicn1OdPo3dmWEjGJHqvXiQ0vL3H5XxvKHBaUF0NSU4VYWfYgNzClVaFLK0wqokpftupx5TxntamXr7hvcjstwgkooDcooTuReLSQC5XenJYCm6GUcTK2P42LBWdDHH5OPvL/nmeirGldxGIJ6VD2g8ge8Rradtyv8jyn4Uig0= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=asRYPEXR; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="asRYPEXR" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 0E481C4CEF1; Fri, 10 Oct 2025 17:44:22 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1760118268; bh=wZIygxQdT5DiLOau68Xpa/62K8oxbMttfztozN2k3NE=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=asRYPEXRzT1luNvkcZaBy21Pq50KVSDex9TSms/6xJ3w2+VFaZPMEZYh6RphuGtUA N69H4XKEaLiYKcolZwEYq2UzpBzH10DNcICViMhopZOLWU0sujq2xjOXzIsnjHe06C xlwzwOo0h8Bus+C5Q49FBi9jU/rXs2LAucGpSUMFJyQQnqU/RUy8HviGWOChntZDno YMwBXKPQ8f2FK/CFf1pgQnIfyYKp3SOlVlyJevdvRETG4SomNVG+B+v7Uxkn7Im8df 0DrXsN5qiJfwxP6IKnL5BtdPPIs5VFiw+jJkZ01tJ4xGvHR2vn9/Al1JiZnan9dprw 3DWQkrGKbyQpw== From: Miguel Ojeda To: Linus Torvalds Cc: Miguel Ojeda , Alex Gaynor , Boqun Feng , Gary Guo , =?UTF-8?q?Bj=C3=B6rn=20Roy=20Baron?= , Benno Lossin , Andreas Hindborg , Alice Ryhl , Trevor Gross , Danilo Krummrich , "Rafael J. Wysocki" , Viresh Kumar , rust-for-linux@vger.kernel.org, linux-kernel@vger.kernel.org, patches@lists.linux.dev, Caleb Cartwright , Yacin Tmimi , Manish Goregaokar , Deadbeef , Cameron Steffen , Jieyou Xu Subject: [PATCH 1/3] docs: rust: add section on imports formatting Date: Fri, 10 Oct 2025 19:43:49 +0200 Message-ID: <20251010174351.948650-2-ojeda@kernel.org> In-Reply-To: <20251010174351.948650-1-ojeda@kernel.org> References: <20251010174351.948650-1-ojeda@kernel.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" `rustfmt`, by default, formats imports in a way that is prone to conflicts while merging and rebasing, since in some cases it condenses several items into the same line. For instance, Linus mentioned [1] that the following case: use crate::{ fmt, page::AsPageIter, }; is compressed by `rustfmt` into: use crate::{fmt, page::AsPageIter}; which is undesirable. Similarly, `rustfmt` may put several items in the same line even if the braces span already multiple lines, e.g.: use kernel::{ acpi, c_str, device::{property, Core}, of, platform, }; The options that control the formatting behavior around imports are generally unstable, and `rustfmt` releases do not allow to use nightly features, unlike the compiler and other Rust tooling [2]. For the moment, we can introduce a workaround to prevent `rustfmt` from compressing the example above -- the "trailing empty comment": use crate::{ fmt, page::AsPageIter, // }; which is reminiscent of the trailing comma behavior in other formatters. We already used empty comments for formatting purposes in the past, e.g. in commit b9b701fce49a ("rust: clarify the language unstable features in use"). In addition, `rustfmt` actually reformats with a vertical layout (i.e. it does not put two items in the same line) when seeing such a comment, i.e. it doesn't just preserve the formatting, which is good in the sense that we can use it to easily reformat some imports, since it matches the style we generally want to have. A Git merge driver would help (suggested by Gary and Wedson), though maintainers would need to set it up, the diffs would still be larger and the formatting rules for imports would remain hard to predict. Thus document the style that we will follow in the coding guidelines by introducing a new section and explain how the trailing empty comment works there too. We discussed the issue with upstream Rust in our usual Rust <-> Rust for Linux meeting [3], and there have also been a few other discussions in parallel in issues [4][5] and Zulip [6]. We will see what happens, but upstream Rust has already created a subteam of `rustfmt` to try to overcome the bandwidth issue [7], which is a good signal, and some organization work has already started (e.g. tracking issues). We will continue our discussions with them about it. Cc: Caleb Cartwright Cc: Yacin Tmimi Cc: Manish Goregaokar Cc: Deadbeef Cc: Cameron Steffen Cc: Jieyou Xu Link: https://lore.kernel.org/all/CAHk-=3DwgO7S_FZUSBbngG5vtejWOpzDfTTBkVvP= 3_yjJmFddbzA@mail.gmail.com/ [1] Link: https://github.com/rust-lang/rustfmt/issues/4884 [2] Link: https://hackmd.io/iSCyY3JTTz-g8YM-nnzTTA [3] Link: https://github.com/rust-lang/rustfmt/issues/4991 [4] Link: https://github.com/rust-lang/rustfmt/issues/3361 [5] Link: https://rust-lang.zulipchat.com/#narrow/channel/392734-council/topic/= rustfmt.20maintenance/near/543815381 [6] Link: https://github.com/rust-lang/team/pull/2017 [7] Signed-off-by: Miguel Ojeda Reviewed-by: Benno Lossin --- Documentation/rust/coding-guidelines.rst | 75 ++++++++++++++++++++++++ 1 file changed, 75 insertions(+) diff --git a/Documentation/rust/coding-guidelines.rst b/Documentation/rust/= coding-guidelines.rst index 6ff9e754755d..3198be3a6d63 100644 --- a/Documentation/rust/coding-guidelines.rst +++ b/Documentation/rust/coding-guidelines.rst @@ -38,6 +38,81 @@ Like ``clang-format`` for the rest of the kernel, ``rust= fmt`` works on individual files, and does not require a kernel configuration. Sometimes i= t may even work with broken code. =20 +Imports +~~~~~~~ + +``rustfmt``, by default, formats imports in a way that is prone to conflic= ts +while merging and rebasing, since in some cases it condenses several items= into +the same line. For instance: + +.. code-block:: rust + + // Do not use this style. + use crate::{ + example1, + example2::{example3, example4, example5}, + example6, example7, + example8::example9, + }; + +Instead, the kernel uses a vertical layout that looks like this: + +.. code-block:: rust + + use crate::{ + example1, + example2::{ + example3, + example4, + example5, // + }, + example6, + example7, + example8::example9, // + }; + +That is, each item goes into its own line, and braces are used as soon as = there +is more than one item in a list. + +The trailing empty comment allows to preserve this formatting. Not only th= at, +``rustfmt`` will actually reformat imports vertically when the empty comme= nt is +added. That is, it is possible to easily reformat the original example int= o the +expected style by running ``rustfmt`` on an input like: + +.. code-block:: rust + + // Do not use this style. + use crate::{ + example1, + example2::{example3, example4, example5, // + }, + example6, example7, + example8::example9, // + }; + +The trailing empty comment works for nested imports, as shown above, as we= ll as +for single item imports -- this can be useful to minimize diffs within pat= ch +series: + +.. code-block:: rust + + use crate::{ + example1, // + }; + +The trailing empty comment works in any of the lines within the braces, bu= t it +is preferred to keep it in the last item, since it is reminiscent of the +trailing comma in other formatters. Sometimes it may be simpler to avoid m= oving +the comment several times within a patch series due to changes in the list. + +There may be cases where exceptions may need to be made, i.e. none of this= is +a hard rule. There is also code that is not migrated to this style yet, but +please do not introduce code in other styles. + +Eventually, the goal is to get ``rustfmt`` to support this formatting styl= e (or +a similar one) automatically in a stable release without requiring the tra= iling +empty comment. Thus, at some point, the goal is to remove those comments. + =20 Comments -------- --=20 2.51.0 From nobody Fri Dec 19 12:12:25 2025 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id ADE5A231A30; Fri, 10 Oct 2025 17:44:32 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1760118272; cv=none; b=iSaRi6uWhn34vFVJnLoQsvP1uFtkqi2osG4DeKW3pSqA3rcyyhEmDZJpzFSifaMGgtSDbfK5o+IYeTd7dk6mKnms0ln8cH+Dr1jjHb8XVeINigM4aHO1FyoZ6CtncpNb79tFSyffgr5LLcsk/E+NPvXACn1rELsnbWQrzdcc/rg= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1760118272; c=relaxed/simple; bh=O7/bjHM+l6J8JLrW0eLWostgUJ5Nl0LYFfN4tBaYkIY=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=hFxLkU2lka1NCvB8gIp/x3v/9nefPaGo6poYTcndGRq4bWe0zY5bF9QwptXg5QkucuNsGcDpcN2FkCf/5Fni9NezrSh65s+Fz1FCrAgg9gnpMe/oSYfQY4bWo7ReuMQZl8r16Ev97RXGrgTLBn+Ik8cajG/wyOwy4DGCVyUv6to= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=qVlww11Z; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="qVlww11Z" Received: by smtp.kernel.org (Postfix) with ESMTPSA id CB85BC4CEFE; Fri, 10 Oct 2025 17:44:28 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1760118272; bh=O7/bjHM+l6J8JLrW0eLWostgUJ5Nl0LYFfN4tBaYkIY=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=qVlww11ZjxiAHIDJr58Zrsbblim2/3VpjuicUsy1UX1n/tH9vs1qqv9P0jMQ51Nv0 Q+y/nLiJ/bui4/fiQKHth4BoIDvjQwANa808B4DiLrO0PV899/PIkcZWG17dLLnEu6 NqgISiJARP+dJK3alYYC8Qs40ErXB8rz0j29GiUhalngipcwnYWfFddnW1mlYA0eSs gfcuUAnz8A5JoY8fp8hxlCwkPn4RY3wYFzV5g+06X1oUeccCcM0tWWnPJb3wAxewF/ eKpliZf0+C8hCN/kO7pjD+ULJLcH5aPSxHXOs0OvVpxZ0dsYM4WfI7NexORMaE6N/6 tayciRwW01T0g== From: Miguel Ojeda To: Linus Torvalds Cc: Miguel Ojeda , Alex Gaynor , Boqun Feng , Gary Guo , =?UTF-8?q?Bj=C3=B6rn=20Roy=20Baron?= , Benno Lossin , Andreas Hindborg , Alice Ryhl , Trevor Gross , Danilo Krummrich , "Rafael J. Wysocki" , Viresh Kumar , rust-for-linux@vger.kernel.org, linux-kernel@vger.kernel.org, patches@lists.linux.dev Subject: [PATCH 2/3] rust: alloc: employ a trailing comment to keep vertical layout Date: Fri, 10 Oct 2025 19:43:50 +0200 Message-ID: <20251010174351.948650-3-ojeda@kernel.org> In-Reply-To: <20251010174351.948650-1-ojeda@kernel.org> References: <20251010174351.948650-1-ojeda@kernel.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Apply the formatting guidelines introduced in the previous commit to make the file `rustfmt`-clean again. Signed-off-by: Miguel Ojeda Reviewed-by: Benno Lossin --- rust/kernel/alloc/kvec.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/rust/kernel/alloc/kvec.rs b/rust/kernel/alloc/kvec.rs index e94aebd084c8..ac8d6f763ae8 100644 --- a/rust/kernel/alloc/kvec.rs +++ b/rust/kernel/alloc/kvec.rs @@ -9,7 +9,7 @@ }; use crate::{ fmt, - page::AsPageIter, + page::AsPageIter, // }; use core::{ borrow::{Borrow, BorrowMut}, --=20 2.51.0 From nobody Fri Dec 19 12:12:25 2025 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 09F8822157F; Fri, 10 Oct 2025 17:44:37 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1760118277; cv=none; b=SXkqphSwSO6GDd8OgabFHfF8c0Z1QlCuzJYSHtVsxUBA2QwMXxyDxsJLeIvFGsDNH5nBZe7ZoZZsMtqf40MMLHmnKvuUCCMZ7B2oyrsa5yM9rEuuV9nv/r5TCt4/MD2PJTJUkMmX5heaeIM8+ZuxKS2pVOxBLm6SvtpJyvsKqqw= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1760118277; c=relaxed/simple; bh=EOO32wpZESIcy0ZfUtjAk8LVrqNlpQog8AW67jHQPQU=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=h2Ig4D71T/F9HcUb2gnAZGCXxI1kIoZOJzmD03/sdsbT6cAsCK4KHiBt88LleDrLGIQY/1B/pBjkr/d4C9MSjllualcVFngj9EZLNovaIImVK8LcESHhBh8SbXOIPFwi5Pnz0p6ca6K4y4qa9LuC/89n/HYXkZfsq0We1AP/q1Q= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=QfVYyn5d; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="QfVYyn5d" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 1C08AC4CEF5; Fri, 10 Oct 2025 17:44:32 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1760118276; bh=EOO32wpZESIcy0ZfUtjAk8LVrqNlpQog8AW67jHQPQU=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=QfVYyn5dpB1xT+oJKw25VvakfVVGQslIqweOhC98t/ZvQ4OZKEz0DdDk8xUyDw2JC NApXVTDtx5tqVQ3mpw+X40kaBt1a2EnrJsfvA37ZObo8ldhlOl6SrdPzr6cHf+Kz9L Z4Qemq1/vru0W1mpb2jblPhm4kO6lez+5MQWT0KzRMFGUi0rlDC56dC2JsrsG4mYvq +I07qBdtLO1SxsIqZCz41RNxKRYxCe/GnBUxzKlW6BogPYM+Fwn3Fces1CtBb0AT1F NGcF6hpUoSdbITdnzoPGRyMl8My620hEp4jF+fJRLAbL1FTRDD8u2f0Dc7aDIQBPu4 aiQ2xzQpM+uJQ== From: Miguel Ojeda To: Linus Torvalds Cc: Miguel Ojeda , Alex Gaynor , Boqun Feng , Gary Guo , =?UTF-8?q?Bj=C3=B6rn=20Roy=20Baron?= , Benno Lossin , Andreas Hindborg , Alice Ryhl , Trevor Gross , Danilo Krummrich , "Rafael J. Wysocki" , Viresh Kumar , rust-for-linux@vger.kernel.org, linux-kernel@vger.kernel.org, patches@lists.linux.dev Subject: [PATCH 3/3] rust: cpufreq: fix formatting Date: Fri, 10 Oct 2025 19:43:51 +0200 Message-ID: <20251010174351.948650-4-ojeda@kernel.org> In-Reply-To: <20251010174351.948650-1-ojeda@kernel.org> References: <20251010174351.948650-1-ojeda@kernel.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" We do our best to keep the repository `rustfmt`-clean, thus run the tool to fix the formatting issue. Link: https://docs.kernel.org/rust/coding-guidelines.html#style-formatting Link: https://rust-for-linux.com/contributing#submit-checklist-addendum Fixes: f97aef092e19 ("cpufreq: Make drivers using CPUFREQ_ETERNAL specify t= ransition latency") Signed-off-by: Miguel Ojeda Acked-by: Viresh Kumar Reviewed-by: Benno Lossin --- rust/kernel/cpufreq.rs | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/rust/kernel/cpufreq.rs b/rust/kernel/cpufreq.rs index 21b5b9b8acc1..1a555fcb120a 100644 --- a/rust/kernel/cpufreq.rs +++ b/rust/kernel/cpufreq.rs @@ -38,8 +38,7 @@ const CPUFREQ_NAME_LEN: usize =3D bindings::CPUFREQ_NAME_LEN as usize; =20 /// Default transition latency value in nanoseconds. -pub const DEFAULT_TRANSITION_LATENCY_NS: u32 =3D - bindings::CPUFREQ_DEFAULT_TRANSITION_LATENCY_NS; +pub const DEFAULT_TRANSITION_LATENCY_NS: u32 =3D bindings::CPUFREQ_DEFAULT= _TRANSITION_LATENCY_NS; =20 /// CPU frequency driver flags. pub mod flags { --=20 2.51.0