Skip to content

Rust core additions

[email protected] linux-patches lkml rust-for-linux 2 versions – In review

Get series with b4
b4 am [email protected]

Versions newest first · linked by author and title

  1. v2 Latest28 patches 17 repliesIn review
  2. v128 patches 39 repliesSuperseded

Patches in v2 No applies recorded yet

#Subject and filesSizeRepliesApplied
1/28rust: prelude: split re-exports into groupsrust/kernel/prelude.rs+9 -50 replies
2/28rust: print: add more `pr_*!` levelsrust/kernel/prelude.rs rust/kernel/print.rs+155 -10 replies
3/28rust: print: add `pr_cont!` macrorust/kernel/print.rs+63 -90 replies
4/28rust: samples: add `rust_print` examplesamples/rust/Kconfig samples/rust/Makefile samples/rust/rust_print.rs+65 -00 replies
5/28rust: macros: add `concat_idents!` proc macrorust/macros/concat_idents.rs rust/macros/lib.rs+67 -01 reply
6/28rust: macros: add `#[vtable]` proc macrorust/kernel/prelude.rs rust/macros/lib.rs rust/macros/vtable.rs+148 -12 replies
7/28rust: macros: take string literals in `module!`rust/macros/helpers.rs rust/macros/lib.rs rust/macros/module.rs +2 more+37 -250 replies
8/28rust: error: declare errors using macrorust/kernel/error.rs+10 -20 replies
9/28rust: error: add codes from `errno-base.h`rust/kernel/error.rs+33 -01 reply
10/28rust: error: add `From` implementations for `Error`rust/kernel/error.rs rust/kernel/lib.rs+45 -10 replies
11/28rust: prelude: add `error::code::*` constant itemsrust/kernel/prelude.rs+1 -10 replies
12/28rust: alloc: add `RawVec::try_with_capacity_in()` constructorrust/alloc/raw_vec.rs+33 -10 replies
13/28rust: alloc: add `Vec::try_with_capacity{,_in}()` constructorsrust/alloc/raw_vec.rs rust/alloc/vec/mod.rs+89 -11 reply
14/28rust: str: add `BStr` typerust/kernel/str.rs+5 -00 replies
15/28rust: str: add `b_str!` macrorust/kernel/str.rs+21 -00 replies
16/28rust: str: add `CStr` typerust/kernel/prelude.rs rust/kernel/str.rs+170 -10 replies
17/28rust: str: implement several traits for `CStr`rust/kernel/str.rs+123 -10 replies
18/28rust: str: add `CStr` unit testsrust/kernel/str.rs+29 -00 replies
19/28rust: str: add `c_str!` macrorust/kernel/str.rs+23 -00 replies
20/28rust: str: add `Formatter` typerust/kernel/str.rs+57 -03 replies
21/28rust: str: add `CString` typerust/kernel/str.rs+89 -20 replies
22/28rust: str: add `fmt!` macrorust/kernel/str.rs+6 -00 replies
23/28rust: std_vendor: add `dbg!` macro based on `std`'s onerust/kernel/lib.rs rust/kernel/prelude.rs rust/kernel/std_vendor.rs+166 -10 replies
24/28rust: static_assert: add `static_assert!` macrorust/kernel/lib.rs rust/kernel/prelude.rs rust/kernel/static_assert.rs+37 -00 replies
25/28rust: add `build_error` cratelib/Kconfig.debug rust/Makefile rust/build_error.rs +2 more+76 -61 reply
26/28rust: build_assert: add `build_{error,assert}!` macrosrust/kernel/build_assert.rs rust/kernel/lib.rs rust/kernel/prelude.rs+88 -01 reply
27/28rust: types: add `Either` typerust/kernel/lib.rs rust/kernel/types.rs+13 -06 replies
28/28rust: types: add `Opaque` typerust/kernel/types.rs+25 -00 replies

Reviews trailers per patch

17 of 28 patches have a Reviewed-by or Acked-by.

PatchBoqun FengWei LiuSergio Gonzalez ColladoFinn BehrensGary Guo
1/28R-b R-b
2/28R-b R-b R-b
3/28R-b R-b
4/28R-b T-b R-b
5/28R-b R-b
6/28R-b R-b
7/28
8/28R-b
9/28R-b R-b
10/28R-b
11/28R-b
12/28R-b
13/28R-b R-b
14/28
15/28
16/28
17/28
18/28
19/28
20/28R-b
21/28
22/28R-b
23/28
24/28
25/28R-b
26/28R-b
27/28R-b
28/28

Trailers given in replies are filled; those carried in the patches from earlier versions are outlined with dashes. Scroll the table sideways for all 5 reviewers.

Read the v2 thread

Cover letter [PATCH v2 00/28] Rust core additions

From: Miguel Ojeda <[email protected]>

This is v2 of the first batch of changes to upstream the rest of the Rust support. v1 is at:

    https://lore.kernel.org/rust-for-linux/[email protected]/

I collected the tags and applied the agreed changes. The full diff follows (with respect to v1), since they are minor enough.

I will be applying the patches tomorrow, since v1 has had more than three weeks of review time.

rust/build_error.rs +13 -6
index 0ff6b33059aa..fa24eeef9929 100644
@@ -2,19 +2,26 @@
 
 //! Build-time error.
 //!
-//! This crate provides a function `build_error`, which will panic in
-//! compile-time if executed in const context, and will cause a build error
-//! if not executed at compile time and the optimizer does not optimise away the
-//! call.
+//! This crate provides a [const function][const-functions] `build_error`, which will panic in
+//! compile-time if executed in [const context][const-context], and will cause a build error
+//! if not executed at compile time and the optimizer does not optimise away the call.
 //!
 //! It is used by `build_assert!` in the kernel crate, allowing checking of
 //! conditions that could be checked statically, but could not be enforced in
-//! Rust yet (e.g. perform some checks in const functions, but those
+//! Rust yet (e.g. perform some checks in [const functions][const-functions], but those
 //! functions could still be called in the runtime).
+//!
+//! For details on constant evaluation in Rust, please see the [Reference][const-eval].
+//!
+//! [const-eval]: https://doc.rust-lang.org/reference/const_eval.html
+//! [const-functions]: https://doc.rust-lang.org/reference/const_eval.html#const-functions
+//! [const-context]: https://doc.rust-lang.org/reference/const_eval.html#const-context
 
 #![no_std]
 
-/// Panics if executed in const context, or triggers a build error if not.
+/// Panics if executed in [const context][const-context], or triggers a build error if not.
+///
+/// [const-context]: https://doc.rust-lang.org/reference/const_eval.html#const-context
 #[inline(never)]
 #[cold]
 #[export_name = "rust_build_error"]
rust/kernel/std_vendor.rs +6 -3
index da57b4e521f4..b3e68b24a8c6 100644
@@ -35,9 +35,12 @@
 /// This is useful when debugging issues that only occur in release
 /// builds or when debugging in release mode is significantly faster.
 ///
-/// Note that the macro is intended as a debugging tool and therefore you
-/// should avoid having uses of it in version control for long periods
-/// (other than in tests and similar).
+/// Note that the macro is intended as a temporary debugging tool to be
+/// used during development. Therefore, avoid committing `dbg!` macro
+/// invocations into the kernel tree.
+///
+/// For debug output that is intended to be kept in the kernel tree,
+/// use [`pr_debug`] and similar facilities instead.
 ///
 /// # Stability
 ///
rust/kernel/str.rs +4 -13
index ffac633423db..b771310fa4a4 100644
@@ -129,18 +129,6 @@ impl CStr {
         Ok(unsafe { Self::from_bytes_with_nul_unchecked(bytes) })
     }
 
-    /// Creates a [`CStr`] from a `[u8]`, panic if input is not valid.
-    ///
-    /// This function is only meant to be used by `c_str!` macro, so
-    /// crates using `c_str!` macro don't have to enable `const_panic` feature.
-    #[doc(hidden)]
-    pub const fn from_bytes_with_nul_unwrap(bytes: &[u8]) -> &Self {
-        match Self::from_bytes_with_nul(bytes) {
-            Ok(v) => v,
-            Err(_) => panic!("string contains interior NUL"),
-        }
-    }
-
     /// Creates a [`CStr`] from a `[u8]` without performing any additional
     /// checks.
     ///
@@ -349,7 +337,10 @@ where
 macro_rules! c_str {
     ($str:expr) => {{
         const S: &str = concat!($str, "\0");
-        const C: &$crate::str::CStr = $crate::str::CStr::from_bytes_with_nul_unwrap(S.as_bytes());
+        const C: &$crate::str::CStr = match $crate::str::CStr::from_bytes_with_nul(S.as_bytes()) {
+            Ok(v) => v,
+            Err(_) => panic!("string contains interior NUL"),
+        };
         C
     }};
 }
rust/macros/concat_idents.rs +1 -1
index 3b5a9dd70e8a..7e4b450f3a50 100644
@@ -18,6 +18,6 @@ pub(crate) fn concat_idents(ts: TokenStream) -> TokenStream {
     assert_eq!(expect_punct(&mut it), ',');
     let b = expect_ident(&mut it);
     assert!(it.next().is_none(), "only two idents can be concatenated");
-    let res = Ident::new(&(a.to_string() + &b.to_string()), b.span());
+    let res = Ident::new(&format!("{a}{b}"), b.span());
     TokenStream::from_iter([TokenTree::Ident(res)])
 }

Björn Roy Baron (1):
rust: macros: add concat_idents! proc macro

Finn Behrens (1):
rust: error: declare errors using macro

Gary Guo (9):
rust: macros: add #[vtable] proc macro
rust: macros: take string literals in module!
rust: str: add BStr type
rust: str: add b_str! macro
rust: str: add CStr type
rust: str: implement several traits for CStr
rust: str: add c_str! macro
rust: add build_error crate
rust: build_assert: add build_{error,assert}! macros

Miguel Ojeda (7):
rust: prelude: split re-exports into groups
rust: print: add more pr_*! levels
rust: print: add pr_cont! macro
rust: samples: add rust_print example
rust: alloc: add RawVec::try_with_capacity_in() constructor
rust: alloc: add Vec::try_with_capacity{,_in}() constructors
rust: static_assert: add static_assert! macro

Milan Landaverde (1):
rust: str: add CStr unit tests

Niklas Mohrin (1):
rust: std_vendor: add dbg! macro based on std's one

Viktor Garske (1):
rust: error: add codes from errno-base.h

Wedson Almeida Filho (7):
rust: error: add From implementations for Error
rust: prelude: add error::code::* constant items
rust: str: add Formatter type
rust: str: add CString type
rust: str: add fmt! macro
rust: types: add Either type
rust: types: add Opaque type

 lib/Kconfig.debug                 |  16 +
 rust/Makefile                     |  22 +-
 rust/alloc/raw_vec.rs             |  33 +-
 rust/alloc/vec/mod.rs             |  89 +++++
 rust/build_error.rs               |  31 ++
 rust/exports.c                    |   5 +
 rust/kernel/build_assert.rs       |  82 +++++
 rust/kernel/error.rs              |  90 ++++-
 rust/kernel/lib.rs                |   9 +
 rust/kernel/prelude.rs            |  20 +-
 rust/kernel/print.rs              | 214 +++++++++++-
 rust/kernel/static_assert.rs      |  34 ++
 rust/kernel/std_vendor.rs         | 163 ++++++++++
 rust/kernel/str.rs                | 523 +++++++++++++++++++++++++++++-
 rust/kernel/types.rs              |  37 +++
 rust/macros/concat_idents.rs      |  23 ++
 rust/macros/helpers.rs            |  24 +-
 rust/macros/lib.rs                | 108 +++++-
 rust/macros/module.rs             |  10 +-
 rust/macros/vtable.rs             |  95 ++++++
 samples/rust/Kconfig              |  10 +
 samples/rust/Makefile             |   1 +
 samples/rust/rust_minimal.rs      |   8 +-
 samples/rust/rust_print.rs        |  54 +++
 scripts/generate_rust_analyzer.py |   8 +-
 25 files changed, 1667 insertions(+), 42 deletions(-)
 create mode 100644 rust/build_error.rs
 create mode 100644 rust/kernel/build_assert.rs
 create mode 100644 rust/kernel/static_assert.rs
 create mode 100644 rust/kernel/std_vendor.rs
 create mode 100644 rust/kernel/types.rs
 create mode 100644 rust/macros/concat_idents.rs
 create mode 100644 rust/macros/vtable.rs
 create mode 100644 samples/rust/rust_print.rs

base-commit: f0c4d9fc9cc9462659728d168387191387e903cc

Signature · 1 line
2.38.1