Skip to content

Commit

Permalink
rust: automatically provide use kernel::prelude::* for doctests
Browse files Browse the repository at this point in the history
Many tests use bits from the prelude one way or another
(e.g. `Result`), thus it seems simpler to provide it by default.

Signed-off-by: Miguel Ojeda <ojeda@kernel.org>
  • Loading branch information
ojeda committed May 5, 2022
1 parent 58aca84 commit d5e044e
Show file tree
Hide file tree
Showing 21 changed files with 3 additions and 56 deletions.
2 changes: 0 additions & 2 deletions rust/kernel/amba.rs
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,6 @@ unsafe impl device::RawDevice for Device {
/// # Examples
///
/// ```ignore
/// # use kernel::prelude::*;
/// # use kernel::{amba, define_amba_id_table, module_amba_driver};
/// #
/// struct MyDriver;
Expand Down Expand Up @@ -237,7 +236,6 @@ macro_rules! module_amba_driver {
/// # Examples
///
/// ```
/// # use kernel::prelude::*;
/// # use kernel::{amba, define_amba_id_table};
/// #
/// # struct Sample;
Expand Down
2 changes: 0 additions & 2 deletions rust/kernel/build_assert.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,6 @@ macro_rules! build_error {
/// possible, so [`static_assert!`] should be used whenever possible.
// TODO: Could be `compile_fail` when supported.
/// ```ignore
/// # use kernel::prelude::*;
/// fn foo() {
/// static_assert!(1 > 1); // Compile-time error
/// build_assert!(1 > 1); // Build-time error
Expand All @@ -55,7 +54,6 @@ macro_rules! build_error {
/// When the condition refers to generic parameters or parameters of an inline function,
/// [`static_assert!`] cannot be used. Use `build_assert!` in this scenario.
/// ```
/// # use kernel::prelude::*;
/// fn foo<const N: usize>() {
/// // `static_assert!(N > 1);` is not allowed
/// build_assert!(N > 1); // Build-time check
Expand Down
8 changes: 0 additions & 8 deletions rust/kernel/device.rs
Original file line number Diff line number Diff line change
Expand Up @@ -359,7 +359,6 @@ macro_rules! dev_printk {
/// # Examples
///
/// ```
/// # use kernel::prelude::*;
/// # use kernel::device::Device;
///
/// fn example(dev: &Device) {
Expand All @@ -385,7 +384,6 @@ macro_rules! dev_emerg {
/// # Examples
///
/// ```
/// # use kernel::prelude::*;
/// # use kernel::device::Device;
///
/// fn example(dev: &Device) {
Expand All @@ -411,7 +409,6 @@ macro_rules! dev_alert {
/// # Examples
///
/// ```
/// # use kernel::prelude::*;
/// # use kernel::device::Device;
///
/// fn example(dev: &Device) {
Expand All @@ -437,7 +434,6 @@ macro_rules! dev_crit {
/// # Examples
///
/// ```
/// # use kernel::prelude::*;
/// # use kernel::device::Device;
///
/// fn example(dev: &Device) {
Expand All @@ -463,7 +459,6 @@ macro_rules! dev_err {
/// # Examples
///
/// ```
/// # use kernel::prelude::*;
/// # use kernel::device::Device;
///
/// fn example(dev: &Device) {
Expand All @@ -489,7 +484,6 @@ macro_rules! dev_warn {
/// # Examples
///
/// ```
/// # use kernel::prelude::*;
/// # use kernel::device::Device;
///
/// fn example(dev: &Device) {
Expand All @@ -515,7 +509,6 @@ macro_rules! dev_notice {
/// # Examples
///
/// ```
/// # use kernel::prelude::*;
/// # use kernel::device::Device;
///
/// fn example(dev: &Device) {
Expand All @@ -541,7 +534,6 @@ macro_rules! dev_info {
/// # Examples
///
/// ```
/// # use kernel::prelude::*;
/// # use kernel::device::Device;
///
/// fn example(dev: &Device) {
Expand Down
1 change: 0 additions & 1 deletion rust/kernel/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -514,7 +514,6 @@ pub(crate) use from_kernel_result;
/// # Examples
///
/// ```ignore
/// # use kernel::prelude::*;
/// # use kernel::from_kernel_err_ptr;
/// # use kernel::c_types;
/// # use kernel::bindings;
Expand Down
1 change: 0 additions & 1 deletion rust/kernel/io_mem.rs
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,6 @@ impl<const SIZE: usize> IoMem<SIZE> {
///
/// # Examples
/// ```
/// # use kernel::prelude::*;
/// use kernel::io_mem::{self, IoMem, Resource};
///
/// fn test(res: Resource) -> Result {
Expand Down
1 change: 0 additions & 1 deletion rust/kernel/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -227,7 +227,6 @@ macro_rules! offset_of {
/// # Example
///
/// ```
/// # use kernel::prelude::*;
/// # use kernel::container_of;
/// struct Test {
/// a: u64,
Expand Down
1 change: 0 additions & 1 deletion rust/kernel/net/filter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,6 @@ pub enum Family {
/// all packets after printing their lengths) on the specified device (in the `init` ns).
///
/// ```
/// # use kernel::prelude::*;
/// use kernel::net::{self, filter as netfilter};
///
/// struct MyFilter;
Expand Down
1 change: 0 additions & 1 deletion rust/kernel/platform.rs
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,6 @@ unsafe impl device::RawDevice for Device {
/// # Examples
///
/// ```ignore
/// # use kernel::prelude::*;
/// # use kernel::{platform, define_of_id_table, module_platform_driver};
/// #
/// struct MyDriver;
Expand Down
9 changes: 0 additions & 9 deletions rust/kernel/print.rs
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,6 @@ macro_rules! print_macro (
/// # Examples
///
/// ```
/// # use kernel::prelude::*;
/// pr_emerg!("hello {}\n", "there");
/// ```
#[macro_export]
Expand All @@ -221,7 +220,6 @@ macro_rules! pr_emerg (
/// # Examples
///
/// ```
/// # use kernel::prelude::*;
/// pr_alert!("hello {}\n", "there");
/// ```
#[macro_export]
Expand All @@ -246,7 +244,6 @@ macro_rules! pr_alert (
/// # Examples
///
/// ```
/// # use kernel::prelude::*;
/// pr_crit!("hello {}\n", "there");
/// ```
#[macro_export]
Expand All @@ -271,7 +268,6 @@ macro_rules! pr_crit (
/// # Examples
///
/// ```
/// # use kernel::prelude::*;
/// pr_err!("hello {}\n", "there");
/// ```
#[macro_export]
Expand All @@ -296,7 +292,6 @@ macro_rules! pr_err (
/// # Examples
///
/// ```
/// # use kernel::prelude::*;
/// pr_warn!("hello {}\n", "there");
/// ```
#[macro_export]
Expand All @@ -321,7 +316,6 @@ macro_rules! pr_warn (
/// # Examples
///
/// ```
/// # use kernel::prelude::*;
/// pr_notice!("hello {}\n", "there");
/// ```
#[macro_export]
Expand All @@ -346,7 +340,6 @@ macro_rules! pr_notice (
/// # Examples
///
/// ```
/// # use kernel::prelude::*;
/// pr_info!("hello {}\n", "there");
/// ```
#[macro_export]
Expand All @@ -373,7 +366,6 @@ macro_rules! pr_info (
/// # Examples
///
/// ```
/// # use kernel::prelude::*;
/// pr_debug!("hello {}\n", "there");
/// ```
#[macro_export]
Expand Down Expand Up @@ -401,7 +393,6 @@ macro_rules! pr_debug (
/// # Examples
///
/// ```
/// # use kernel::prelude::*;
/// # use kernel::pr_cont;
/// pr_info!("hello");
/// pr_cont!(" {}\n", "there");
Expand Down
3 changes: 0 additions & 3 deletions rust/kernel/rbtree.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@ struct Node<K, V> {
/// the system is out of memory.
///
/// ```
/// # use kernel::prelude::*;
/// use kernel::rbtree::RBTree;
///
/// # fn test() -> Result {
Expand Down Expand Up @@ -122,7 +121,6 @@ struct Node<K, V> {
/// holding a spinlock.
///
/// ```
/// # use kernel::prelude::*;
/// use kernel::{rbtree::RBTree, sync::SpinLock};
///
/// fn insert_test(tree: &SpinLock<RBTree<u32, u32>>) -> Result {
Expand All @@ -140,7 +138,6 @@ struct Node<K, V> {
/// In the example below, we reuse an existing node allocation from an element we removed.
///
/// ```
/// # use kernel::prelude::*;
/// use kernel::rbtree::RBTree;
///
/// # fn test() -> Result {
Expand Down
1 change: 0 additions & 1 deletion rust/kernel/static_assert.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
/// # Examples
///
/// ```
/// # use kernel::prelude::*;
/// static_assert!(42 > 24);
/// static_assert!(core::mem::size_of::<u8>() == 1);
///
Expand Down
6 changes: 0 additions & 6 deletions rust/kernel/std_vendor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
/// An example:
///
/// ```rust
/// # use kernel::prelude::*;
/// let a = 2;
/// # #[allow(clippy::dbg_macro)]
/// let b = dbg!(a * 2) + 1;
Expand Down Expand Up @@ -49,7 +48,6 @@
/// With a method call:
///
/// ```rust
/// # use kernel::prelude::*;
/// # #[allow(clippy::dbg_macro)]
/// fn foo(n: usize) {
/// if dbg!(n.checked_sub(4)).is_some() {
Expand All @@ -69,7 +67,6 @@
/// Naive factorial implementation:
///
/// ```rust
/// # use kernel::prelude::*;
/// # #[allow(clippy::dbg_macro)]
/// # {
/// fn factorial(n: u32) -> u32 {
Expand Down Expand Up @@ -102,7 +99,6 @@
///
// TODO: Could be `compile_fail` when supported.
/// ```ignore
/// # use kernel::prelude::*;
/// /// A wrapper around `usize` which importantly is not Copyable.
/// #[derive(Debug)]
/// struct NoCopy(usize);
Expand All @@ -119,7 +115,6 @@
/// a tuple (and return it, too):
///
/// ```
/// # use kernel::prelude::*;
/// # #[allow(clippy::dbg_macro)]
/// assert_eq!(dbg!(1usize, 2u32), (1, 2));
/// ```
Expand All @@ -129,7 +124,6 @@
/// invocations. You can use a 1-tuple directly if you need one:
///
/// ```
/// # use kernel::prelude::*;
/// # #[allow(clippy::dbg_macro)]
/// # {
/// assert_eq!(1, dbg!(1u32,)); // trailing comma ignored
Expand Down
3 changes: 0 additions & 3 deletions rust/kernel/str.rs
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,6 @@ impl fmt::Display for CStr {
/// Formats printable ASCII characters, escaping the rest.
///
/// ```
/// # use kernel::prelude::*;
/// # use kernel::c_str;
/// # use kernel::str::CStr;
/// # use kernel::str::CString;
Expand Down Expand Up @@ -243,7 +242,6 @@ impl fmt::Debug for CStr {
/// Formats printable ASCII characters with a double quote on either end, escaping the rest.
///
/// ```
/// # use kernel::prelude::*;
/// # use kernel::c_str;
/// # use kernel::str::CStr;
/// # use kernel::str::CString;
Expand Down Expand Up @@ -530,7 +528,6 @@ impl fmt::Write for Formatter {
/// # Examples
///
/// ```
/// # use kernel::prelude::*;
/// use kernel::str::CString;
///
/// let s = CString::try_from_fmt(fmt!("{}{}{}", "abc", 10, 20)).unwrap();
Expand Down
1 change: 0 additions & 1 deletion rust/kernel/sync.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
//! # Example
//!
//! ```
//! # use kernel::prelude::*;
//! # use kernel::mutex_init;
//! # use kernel::sync::Mutex;
//! # use alloc::boxed::Box;
Expand Down
3 changes: 0 additions & 3 deletions rust/kernel/sync/arc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -391,7 +391,6 @@ impl<T: ?Sized> Deref for RefBorrow<'_, T> {
/// cannot fail.
///
/// ```
/// # use kernel::prelude::*;
/// use kernel::sync::{Ref, UniqueRef};
///
/// struct Example {
Expand All @@ -415,7 +414,6 @@ impl<T: ?Sized> Deref for RefBorrow<'_, T> {
/// in one context (e.g., sleepable) and initialisation in another (e.g., atomic):
///
/// ```
/// # use kernel::prelude::*;
/// use kernel::sync::{Ref, UniqueRef};
///
/// struct Example {
Expand All @@ -436,7 +434,6 @@ impl<T: ?Sized> Deref for RefBorrow<'_, T> {
/// initialisation, for example, when initialising fields that are wrapped in locks.
///
/// ```
/// # use kernel::prelude::*;
/// use kernel::sync::{Ref, UniqueRef};
///
/// struct Example {
Expand Down
1 change: 0 additions & 1 deletion rust/kernel/sync/locked_by.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ use core::{cell::UnsafeCell, ops::Deref, ptr};
/// locked; we enforce at run time that the right `InnerDirectory` is locked.
///
/// ```
/// # use kernel::prelude::*;
/// use kernel::sync::{LockedBy, Mutex};
///
/// struct InnerFile {
Expand Down
1 change: 0 additions & 1 deletion rust/kernel/sync/seqlock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ use core::{cell::UnsafeCell, marker::PhantomPinned, ops::Deref, pin::Pin};
/// # Examples
///
///```
/// # use kernel::prelude::*;
/// use kernel::sync::{SeqLock, SpinLock};
/// use core::sync::atomic::{AtomicU32, Ordering};
///
Expand Down
2 changes: 0 additions & 2 deletions rust/kernel/sync/spinlock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@ macro_rules! spinlock_init {
/// # Examples
///
/// ```
/// # use kernel::prelude::*;
/// # use kernel::sync::SpinLock;
/// # use core::pin::Pin;
///
Expand Down Expand Up @@ -212,7 +211,6 @@ macro_rules! rawspinlock_init {
/// # Examples
///
/// ```
/// # use kernel::prelude::*;
/// # use kernel::sync::RawSpinLock;
/// # use core::pin::Pin;
///
Expand Down
3 changes: 0 additions & 3 deletions rust/kernel/task.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ use core::{marker::PhantomData, mem::ManuallyDrop, ops::Deref};
/// when compared to the C version:
///
/// ```
/// # use kernel::prelude::*;
/// use kernel::task::Task;
///
/// let pid = Task::current().pid();
Expand All @@ -28,7 +27,6 @@ use core::{marker::PhantomData, mem::ManuallyDrop, ops::Deref};
/// Getting the PID of the current process, also zero additional cost:
///
/// ```
/// # use kernel::prelude::*;
/// use kernel::task::Task;
///
/// let pid = Task::current().group_leader().pid();
Expand All @@ -38,7 +36,6 @@ use core::{marker::PhantomData, mem::ManuallyDrop, ops::Deref};
/// incremented when creating `State` and decremented when it is dropped:
///
/// ```
/// # use kernel::prelude::*;
/// use kernel::task::Task;
///
/// struct State {
Expand Down

0 comments on commit d5e044e

Please sign in to comment.