Skip to content

Commit 0d05ea2

Browse files
committed
add rustfmt.toml
Signed-off-by: Finn Behrens <[email protected]>
1 parent c17d290 commit 0d05ea2

File tree

6 files changed

+63
-29
lines changed

6 files changed

+63
-29
lines changed

drivers/char/rust_example/src/lib.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
use kernel::prelude::*;
77

8-
module!{
8+
module! {
99
type: RustExample,
1010
name: b"rust_example",
1111
author: b"Rust for Linux Contributors",
@@ -48,4 +48,3 @@ impl Drop for RustExample {
4848
println!("Rust Example (exit)");
4949
}
5050
}
51-

rust/kernel/build.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
// SPDX-License-Identifier: GPL-2.0
22

3-
use std::path::PathBuf;
43
use std::env;
4+
use std::path::PathBuf;
55

66
const INCLUDED_TYPES: &[&str] = &["file_system_type", "mode_t", "umode_t", "ctl_table"];
77
const INCLUDED_FUNCTIONS: &[&str] = &[
@@ -92,8 +92,7 @@ fn main() {
9292
println!("cargo:rerun-if-env-changed=RUST_BINDGEN_CFLAGS");
9393

9494
let kernel_dir = "../../";
95-
let cflags = env::var("RUST_BINDGEN_CFLAGS")
96-
.expect("Must be invoked from kernel makefile");
95+
let cflags = env::var("RUST_BINDGEN_CFLAGS").expect("Must be invoked from kernel makefile");
9796

9897
let kernel_args = prepare_cflags(&cflags, &kernel_dir);
9998

rust/kernel/src/prelude.rs

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,8 @@
22

33
//! The `kernel` prelude
44
5-
pub use alloc::{
6-
string::String,
7-
borrow::ToOwned,
8-
};
5+
pub use alloc::{borrow::ToOwned, string::String};
96

107
pub use module::module;
118

12-
pub use super::{
13-
println,
14-
KernelResult,
15-
KernelModule,
16-
};
17-
9+
pub use super::{println, KernelModule, KernelResult};

rust/kernel/src/user_ptr.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,8 @@ use crate::c_types;
99
use crate::error;
1010

1111
extern "C" {
12-
fn rust_helper_access_ok(addr: *const c_types::c_void, len: c_types::c_ulong) -> c_types::c_int;
12+
fn rust_helper_access_ok(addr: *const c_types::c_void, len: c_types::c_ulong)
13+
-> c_types::c_int;
1314
}
1415

1516
/// A reference to an area in userspace memory, which can be either

rust/module/src/lib.rs

Lines changed: 54 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
55
extern crate proc_macro;
66

7-
use proc_macro::{TokenStream, TokenTree, Group, Delimiter, token_stream};
7+
use proc_macro::{token_stream, Delimiter, Group, TokenStream, TokenTree};
88

99
fn expect_ident(it: &mut token_stream::IntoIter) -> String {
1010
if let TokenTree::Ident(ident) = it.next().unwrap() {
@@ -78,13 +78,24 @@ fn get_byte_string(it: &mut token_stream::IntoIter, expected_name: &str) -> Stri
7878
byte_string[2..byte_string.len() - 1].to_string()
7979
}
8080

81-
fn __build_modinfo_string_base(module: &str, field: &str, content: &str, variable: &str, builtin: bool) -> String {
81+
fn __build_modinfo_string_base(
82+
module: &str,
83+
field: &str,
84+
content: &str,
85+
variable: &str,
86+
builtin: bool,
87+
) -> String {
8288
let string = if builtin {
8389
// Built-in modules prefix their modinfo strings by `module.`
84-
format!("{module}.{field}={content}", module=module, field=field, content=content)
90+
format!(
91+
"{module}.{field}={content}",
92+
module = module,
93+
field = field,
94+
content = content
95+
)
8596
} else {
8697
// Loadable modules' modinfo strings go as-is
87-
format!("{field}={content}", field=field, content=content)
98+
format!("{field}={content}", field = field, content = content)
8899
};
89100

90101
format!(
@@ -94,23 +105,39 @@ fn __build_modinfo_string_base(module: &str, field: &str, content: &str, variabl
94105
#[used]
95106
pub static {variable}: [u8; {length}] = *b\"{string}\\0\";
96107
",
97-
cfg = if builtin { "#[cfg(not(MODULE))]" } else { "#[cfg(MODULE)]" },
108+
cfg = if builtin {
109+
"#[cfg(not(MODULE))]"
110+
} else {
111+
"#[cfg(MODULE)]"
112+
},
98113
variable = variable,
99114
length = string.len() + 1,
100115
string = string,
101116
)
102117
}
103118

104119
fn __build_modinfo_string_variable(module: &str, field: &str) -> String {
105-
format!("__{module}_{field}", module=module, field=field)
120+
format!("__{module}_{field}", module = module, field = field)
106121
}
107122

108123
fn build_modinfo_string_only_builtin(module: &str, field: &str, content: &str) -> String {
109-
__build_modinfo_string_base(module, field, content, &__build_modinfo_string_variable(module, field), true)
124+
__build_modinfo_string_base(
125+
module,
126+
field,
127+
content,
128+
&__build_modinfo_string_variable(module, field),
129+
true,
130+
)
110131
}
111132

112133
fn build_modinfo_string_only_loadable(module: &str, field: &str, content: &str) -> String {
113-
__build_modinfo_string_base(module, field, content, &__build_modinfo_string_variable(module, field), false)
134+
__build_modinfo_string_base(
135+
module,
136+
field,
137+
content,
138+
&__build_modinfo_string_variable(module, field),
139+
false,
140+
)
114141
}
115142

116143
fn build_modinfo_string(module: &str, field: &str, content: &str) -> String {
@@ -119,8 +146,13 @@ fn build_modinfo_string(module: &str, field: &str, content: &str) -> String {
119146
}
120147

121148
fn build_modinfo_string_param(module: &str, field: &str, param: &str, content: &str) -> String {
122-
let variable = format!("__{module}_{field}_{param}", module=module, field=field, param=param);
123-
let content = format!("{param}:{content}", param=param, content=content);
149+
let variable = format!(
150+
"__{module}_{field}_{param}",
151+
module = module,
152+
field = field,
153+
param = param
154+
);
155+
let content = format!("{param}:{content}", param = param, content = content);
124156
__build_modinfo_string_base(module, field, &content, &variable, true)
125157
+ &__build_modinfo_string_base(module, field, &content, &variable, false)
126158
}
@@ -202,8 +234,18 @@ pub fn module(ts: TokenStream) -> TokenStream {
202234
t => panic!("Unrecognized type {}", t),
203235
};
204236

205-
params_modinfo.push_str(&build_modinfo_string_param(&name, "parmtype", &param_name, &param_kernel_type));
206-
params_modinfo.push_str(&build_modinfo_string_param(&name, "parm", &param_name, &param_description));
237+
params_modinfo.push_str(&build_modinfo_string_param(
238+
&name,
239+
"parmtype",
240+
&param_name,
241+
&param_kernel_type,
242+
));
243+
params_modinfo.push_str(&build_modinfo_string_param(
244+
&name,
245+
"parm",
246+
&param_name,
247+
&param_description,
248+
));
207249
params_modinfo.push_str(
208250
&format!(
209251
"
@@ -352,4 +394,3 @@ pub fn module(ts: TokenStream) -> TokenStream {
352394
initcall_section = ".initcall6.init"
353395
).parse().unwrap()
354396
}
355-

rustfmt.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
ignore = [ "rust/shlex" ]
2+

0 commit comments

Comments
 (0)