Rust 'rustfmt' cleanup
'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. Document in our guidelines that we will handle this for the moment with the trailing empty comment workaround and make the tree 'rustfmt'-clean again. -----BEGIN PGP SIGNATURE----- iQIzBAABCgAdFiEEPjU5OPd5QIZ9jqqOGXyLc2htIW0FAmjzy+0ACgkQGXyLc2ht IW2K9BAAmdHFQlI5kE2qFBVrk5JeTBmr/3GJ7wzPXKgQ/XdKgYILK5qx8SaqXo95 RXnGSFzPXmVx1xds5NojVqJ65gnoyL9KK4qsxFOUVVoH2vjSWXL5DFrRDcVKFlGY IRlsdRBGdX8/M6gPgLAy2m2eEeNgrwEA/xcWgfvZhI7CILSfvXDNKfGvnzg0mRHp cssYtKTACwzE3/uJUA8lX+HAWNrb1aijEUlvfK5K9CMYwP9wFXzXy1eI2kJ4Yzvx aqiK1vvieAl4gbLAoCD513nSxCQaUzpuHJvELA6bVa8uJ5GtWcuCA9U8qn8zcaaG tOmC/kF/+5jNwc4/4wCSHhcQD+1qaXZVQjeMBYsObqFv7ixabOlxVfGk/oDbAHEI BAtWsqHFMhQlo/E/YdH0palVhvslecnoAhTzURwL9231Sqp6ZeQl5ESya8ArmMFB SFeYMHtDhA557pA4G3R88IIVS+xWklNOVtcW1+c+YnW4d+Sb77aU9E78VKYmH0mt 5rYB0ni09rcDBNRGUSy7fscfUV5ItJd/lccwjRGasM0LzZ6KoMWE2B0Cww5vG27W FXQ9hTsn1q92XY3AFiqR5IBiztNLZfjFEq6HAVSQrmXgHJ53ZT/0oFRcObYAsr49 AjoLzkHcevdj7EUdm9q1o/KVk+t+bkDYjmb3kRgHVOwdekK/Jk8= =44ap -----END PGP SIGNATURE----- Merge tag 'rust-rustfmt' of git://git.kernel.org/pub/scm/linux/kernel/git/ojeda/linux Pull rustfmt fixes from Miguel Ojeda: "Rust 'rustfmt' cleanup '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. Document in our guidelines that we will handle this for the moment with the trailing empty comment workaround and make the tree 'rustfmt'-clean again" * tag 'rust-rustfmt' of git://git.kernel.org/pub/scm/linux/kernel/git/ojeda/linux: rust: bitmap: fix formatting rust: cpufreq: fix formatting rust: alloc: employ a trailing comment to keep vertical layout docs: rust: add section on imports formatting
This commit is contained in:
commit
1c64efcb08
|
@ -38,6 +38,81 @@ Like ``clang-format`` for the rest of the kernel, ``rustfmt`` works on
|
|||
individual files, and does not require a kernel configuration. Sometimes it may
|
||||
even work with broken code.
|
||||
|
||||
Imports
|
||||
~~~~~~~
|
||||
|
||||
``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:
|
||||
|
||||
.. 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 that,
|
||||
``rustfmt`` will actually reformat imports vertically when the empty comment is
|
||||
added. That is, it is possible to easily reformat the original example into 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 well as
|
||||
for single item imports -- this can be useful to minimize diffs within patch
|
||||
series:
|
||||
|
||||
.. code-block:: rust
|
||||
|
||||
use crate::{
|
||||
example1, //
|
||||
};
|
||||
|
||||
The trailing empty comment works in any of the lines within the braces, but 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 moving
|
||||
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 style (or
|
||||
a similar one) automatically in a stable release without requiring the trailing
|
||||
empty comment. Thus, at some point, the goal is to remove those comments.
|
||||
|
||||
|
||||
Comments
|
||||
--------
|
||||
|
|
|
@ -9,7 +9,7 @@ use super::{
|
|||
};
|
||||
use crate::{
|
||||
fmt,
|
||||
page::AsPageIter,
|
||||
page::AsPageIter, //
|
||||
};
|
||||
use core::{
|
||||
borrow::{Borrow, BorrowMut},
|
||||
|
|
|
@ -167,7 +167,9 @@ impl core::ops::Deref for BitmapVec {
|
|||
let ptr = if self.nbits <= BITS_PER_LONG {
|
||||
// SAFETY: Bitmap is represented inline.
|
||||
#[allow(unused_unsafe, reason = "Safe since Rust 1.92.0")]
|
||||
unsafe { core::ptr::addr_of!(self.repr.bitmap) }
|
||||
unsafe {
|
||||
core::ptr::addr_of!(self.repr.bitmap)
|
||||
}
|
||||
} else {
|
||||
// SAFETY: Bitmap is represented as array of `unsigned long`.
|
||||
unsafe { self.repr.ptr.as_ptr() }
|
||||
|
@ -184,7 +186,9 @@ impl core::ops::DerefMut for BitmapVec {
|
|||
let ptr = if self.nbits <= BITS_PER_LONG {
|
||||
// SAFETY: Bitmap is represented inline.
|
||||
#[allow(unused_unsafe, reason = "Safe since Rust 1.92.0")]
|
||||
unsafe { core::ptr::addr_of_mut!(self.repr.bitmap) }
|
||||
unsafe {
|
||||
core::ptr::addr_of_mut!(self.repr.bitmap)
|
||||
}
|
||||
} else {
|
||||
// SAFETY: Bitmap is represented as array of `unsigned long`.
|
||||
unsafe { self.repr.ptr.as_ptr() }
|
||||
|
|
|
@ -38,8 +38,7 @@ use macros::vtable;
|
|||
const CPUFREQ_NAME_LEN: usize = bindings::CPUFREQ_NAME_LEN as usize;
|
||||
|
||||
/// Default transition latency value in nanoseconds.
|
||||
pub const DEFAULT_TRANSITION_LATENCY_NS: u32 =
|
||||
bindings::CPUFREQ_DEFAULT_TRANSITION_LATENCY_NS;
|
||||
pub const DEFAULT_TRANSITION_LATENCY_NS: u32 = bindings::CPUFREQ_DEFAULT_TRANSITION_LATENCY_NS;
|
||||
|
||||
/// CPU frequency driver flags.
|
||||
pub mod flags {
|
||||
|
|
Loading…
Reference in New Issue