Skip to content

Commit 4401565

Browse files
committed
rust: add build_error! to the prelude
The sibling `build_assert!` is already in the prelude, it makes sense that a "core"/"language" facility like this is part of the prelude and users should not be defining their own one (thus there should be no risk of future name collisions and we would want to be aware of them anyway). Thus add `build_error!` into the prelude. Reviewed-by: Alice Ryhl <[email protected]> Link: https://lore.kernel.org/r/[email protected] [ Applied the change to the new miscdevice cases. - Miguel ] Signed-off-by: Miguel Ojeda <[email protected]>
1 parent 614724e commit 4401565

File tree

6 files changed

+18
-18
lines changed

6 files changed

+18
-18
lines changed

rust/kernel/block/mq/operations.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ use crate::{
99
block::mq::request::RequestDataWrapper,
1010
block::mq::Request,
1111
error::{from_result, Result},
12+
prelude::*,
1213
types::ARef,
1314
};
1415
use core::{marker::PhantomData, sync::atomic::AtomicU64, sync::atomic::Ordering};
@@ -35,7 +36,7 @@ pub trait Operations: Sized {
3536
/// Called by the kernel to poll the device for completed requests. Only
3637
/// used for poll queues.
3738
fn poll() -> bool {
38-
crate::build_error!(crate::error::VTABLE_DEFAULT_ERROR)
39+
build_error!(crate::error::VTABLE_DEFAULT_ERROR)
3940
}
4041
}
4142

rust/kernel/build_assert.rs

-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@ pub use build_error::build_error;
1414
/// # Examples
1515
///
1616
/// ```
17-
/// # use kernel::build_error;
1817
/// #[inline]
1918
/// fn foo(a: usize) -> usize {
2019
/// a.checked_add(1).unwrap_or_else(|| build_error!("overflow"))

rust/kernel/miscdevice.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ pub trait MiscDevice {
116116
_cmd: u32,
117117
_arg: usize,
118118
) -> Result<isize> {
119-
kernel::build_error!(VTABLE_DEFAULT_ERROR)
119+
build_error!(VTABLE_DEFAULT_ERROR)
120120
}
121121

122122
/// Handler for ioctls.
@@ -132,7 +132,7 @@ pub trait MiscDevice {
132132
_cmd: u32,
133133
_arg: usize,
134134
) -> Result<isize> {
135-
kernel::build_error!(VTABLE_DEFAULT_ERROR)
135+
build_error!(VTABLE_DEFAULT_ERROR)
136136
}
137137
}
138138

rust/kernel/net/phy.rs

+9-9
Original file line numberDiff line numberDiff line change
@@ -587,17 +587,17 @@ pub trait Driver {
587587

588588
/// Issues a PHY software reset.
589589
fn soft_reset(_dev: &mut Device) -> Result {
590-
kernel::build_error!(VTABLE_DEFAULT_ERROR)
590+
build_error!(VTABLE_DEFAULT_ERROR)
591591
}
592592

593593
/// Sets up device-specific structures during discovery.
594594
fn probe(_dev: &mut Device) -> Result {
595-
kernel::build_error!(VTABLE_DEFAULT_ERROR)
595+
build_error!(VTABLE_DEFAULT_ERROR)
596596
}
597597

598598
/// Probes the hardware to determine what abilities it has.
599599
fn get_features(_dev: &mut Device) -> Result {
600-
kernel::build_error!(VTABLE_DEFAULT_ERROR)
600+
build_error!(VTABLE_DEFAULT_ERROR)
601601
}
602602

603603
/// Returns true if this is a suitable driver for the given phydev.
@@ -609,32 +609,32 @@ pub trait Driver {
609609
/// Configures the advertisement and resets auto-negotiation
610610
/// if auto-negotiation is enabled.
611611
fn config_aneg(_dev: &mut Device) -> Result {
612-
kernel::build_error!(VTABLE_DEFAULT_ERROR)
612+
build_error!(VTABLE_DEFAULT_ERROR)
613613
}
614614

615615
/// Determines the negotiated speed and duplex.
616616
fn read_status(_dev: &mut Device) -> Result<u16> {
617-
kernel::build_error!(VTABLE_DEFAULT_ERROR)
617+
build_error!(VTABLE_DEFAULT_ERROR)
618618
}
619619

620620
/// Suspends the hardware, saving state if needed.
621621
fn suspend(_dev: &mut Device) -> Result {
622-
kernel::build_error!(VTABLE_DEFAULT_ERROR)
622+
build_error!(VTABLE_DEFAULT_ERROR)
623623
}
624624

625625
/// Resumes the hardware, restoring state if needed.
626626
fn resume(_dev: &mut Device) -> Result {
627-
kernel::build_error!(VTABLE_DEFAULT_ERROR)
627+
build_error!(VTABLE_DEFAULT_ERROR)
628628
}
629629

630630
/// Overrides the default MMD read function for reading a MMD register.
631631
fn read_mmd(_dev: &mut Device, _devnum: u8, _regnum: u16) -> Result<u16> {
632-
kernel::build_error!(VTABLE_DEFAULT_ERROR)
632+
build_error!(VTABLE_DEFAULT_ERROR)
633633
}
634634

635635
/// Overrides the default MMD write function for writing a MMD register.
636636
fn write_mmd(_dev: &mut Device, _devnum: u8, _regnum: u16, _val: u16) -> Result {
637-
kernel::build_error!(VTABLE_DEFAULT_ERROR)
637+
build_error!(VTABLE_DEFAULT_ERROR)
638638
}
639639

640640
/// Callback for notification of link change.

rust/kernel/prelude.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ pub use crate::alloc::{flags::*, Box, KBox, KVBox, KVVec, KVec, VBox, VVec, Vec}
1919
#[doc(no_inline)]
2020
pub use macros::{module, pin_data, pinned_drop, vtable, Zeroable};
2121

22-
pub use super::build_assert;
22+
pub use super::{build_assert, build_error};
2323

2424
// `super::std_vendor` is hidden, which makes the macro inline for some reason.
2525
#[doc(no_inline)]

rust/macros/lib.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -123,12 +123,12 @@ pub fn module(ts: TokenStream) -> TokenStream {
123123
/// used on the Rust side, it should not be possible to call the default
124124
/// implementation. This is done to ensure that we call the vtable methods
125125
/// through the C vtable, and not through the Rust vtable. Therefore, the
126-
/// default implementation should call `kernel::build_error!`, which prevents
126+
/// default implementation should call `build_error!`, which prevents
127127
/// calls to this function at compile time:
128128
///
129129
/// ```compile_fail
130130
/// # // Intentionally missing `use`s to simplify `rusttest`.
131-
/// kernel::build_error!(VTABLE_DEFAULT_ERROR)
131+
/// build_error!(VTABLE_DEFAULT_ERROR)
132132
/// ```
133133
///
134134
/// Note that you might need to import [`kernel::error::VTABLE_DEFAULT_ERROR`].
@@ -145,11 +145,11 @@ pub fn module(ts: TokenStream) -> TokenStream {
145145
/// #[vtable]
146146
/// pub trait Operations: Send + Sync + Sized {
147147
/// fn foo(&self) -> Result<()> {
148-
/// kernel::build_error!(VTABLE_DEFAULT_ERROR)
148+
/// build_error!(VTABLE_DEFAULT_ERROR)
149149
/// }
150150
///
151151
/// fn bar(&self) -> Result<()> {
152-
/// kernel::build_error!(VTABLE_DEFAULT_ERROR)
152+
/// build_error!(VTABLE_DEFAULT_ERROR)
153153
/// }
154154
/// }
155155
///

0 commit comments

Comments
 (0)