mirror of
https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
synced 2025-01-22 07:53:11 -05:00
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 <aliceryhl@google.com> Link: https://lore.kernel.org/r/20241123222849.350287-3-ojeda@kernel.org [ Applied the change to the new miscdevice cases. - Miguel ] Signed-off-by: Miguel Ojeda <ojeda@kernel.org>
This commit is contained in:
parent
614724e780
commit
4401565fe9
6 changed files with 18 additions and 18 deletions
|
@ -9,6 +9,7 @@
|
||||||
block::mq::request::RequestDataWrapper,
|
block::mq::request::RequestDataWrapper,
|
||||||
block::mq::Request,
|
block::mq::Request,
|
||||||
error::{from_result, Result},
|
error::{from_result, Result},
|
||||||
|
prelude::*,
|
||||||
types::ARef,
|
types::ARef,
|
||||||
};
|
};
|
||||||
use core::{marker::PhantomData, sync::atomic::AtomicU64, sync::atomic::Ordering};
|
use core::{marker::PhantomData, sync::atomic::AtomicU64, sync::atomic::Ordering};
|
||||||
|
@ -35,7 +36,7 @@ pub trait Operations: Sized {
|
||||||
/// Called by the kernel to poll the device for completed requests. Only
|
/// Called by the kernel to poll the device for completed requests. Only
|
||||||
/// used for poll queues.
|
/// used for poll queues.
|
||||||
fn poll() -> bool {
|
fn poll() -> bool {
|
||||||
crate::build_error!(crate::error::VTABLE_DEFAULT_ERROR)
|
build_error!(crate::error::VTABLE_DEFAULT_ERROR)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -14,7 +14,6 @@
|
||||||
/// # Examples
|
/// # Examples
|
||||||
///
|
///
|
||||||
/// ```
|
/// ```
|
||||||
/// # use kernel::build_error;
|
|
||||||
/// #[inline]
|
/// #[inline]
|
||||||
/// fn foo(a: usize) -> usize {
|
/// fn foo(a: usize) -> usize {
|
||||||
/// a.checked_add(1).unwrap_or_else(|| build_error!("overflow"))
|
/// a.checked_add(1).unwrap_or_else(|| build_error!("overflow"))
|
||||||
|
|
|
@ -116,7 +116,7 @@ fn ioctl(
|
||||||
_cmd: u32,
|
_cmd: u32,
|
||||||
_arg: usize,
|
_arg: usize,
|
||||||
) -> Result<isize> {
|
) -> Result<isize> {
|
||||||
kernel::build_error!(VTABLE_DEFAULT_ERROR)
|
build_error!(VTABLE_DEFAULT_ERROR)
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Handler for ioctls.
|
/// Handler for ioctls.
|
||||||
|
@ -132,7 +132,7 @@ fn compat_ioctl(
|
||||||
_cmd: u32,
|
_cmd: u32,
|
||||||
_arg: usize,
|
_arg: usize,
|
||||||
) -> Result<isize> {
|
) -> Result<isize> {
|
||||||
kernel::build_error!(VTABLE_DEFAULT_ERROR)
|
build_error!(VTABLE_DEFAULT_ERROR)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -587,17 +587,17 @@ pub trait Driver {
|
||||||
|
|
||||||
/// Issues a PHY software reset.
|
/// Issues a PHY software reset.
|
||||||
fn soft_reset(_dev: &mut Device) -> Result {
|
fn soft_reset(_dev: &mut Device) -> Result {
|
||||||
kernel::build_error!(VTABLE_DEFAULT_ERROR)
|
build_error!(VTABLE_DEFAULT_ERROR)
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Sets up device-specific structures during discovery.
|
/// Sets up device-specific structures during discovery.
|
||||||
fn probe(_dev: &mut Device) -> Result {
|
fn probe(_dev: &mut Device) -> Result {
|
||||||
kernel::build_error!(VTABLE_DEFAULT_ERROR)
|
build_error!(VTABLE_DEFAULT_ERROR)
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Probes the hardware to determine what abilities it has.
|
/// Probes the hardware to determine what abilities it has.
|
||||||
fn get_features(_dev: &mut Device) -> Result {
|
fn get_features(_dev: &mut Device) -> Result {
|
||||||
kernel::build_error!(VTABLE_DEFAULT_ERROR)
|
build_error!(VTABLE_DEFAULT_ERROR)
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Returns true if this is a suitable driver for the given phydev.
|
/// Returns true if this is a suitable driver for the given phydev.
|
||||||
|
@ -609,32 +609,32 @@ fn match_phy_device(_dev: &Device) -> bool {
|
||||||
/// Configures the advertisement and resets auto-negotiation
|
/// Configures the advertisement and resets auto-negotiation
|
||||||
/// if auto-negotiation is enabled.
|
/// if auto-negotiation is enabled.
|
||||||
fn config_aneg(_dev: &mut Device) -> Result {
|
fn config_aneg(_dev: &mut Device) -> Result {
|
||||||
kernel::build_error!(VTABLE_DEFAULT_ERROR)
|
build_error!(VTABLE_DEFAULT_ERROR)
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Determines the negotiated speed and duplex.
|
/// Determines the negotiated speed and duplex.
|
||||||
fn read_status(_dev: &mut Device) -> Result<u16> {
|
fn read_status(_dev: &mut Device) -> Result<u16> {
|
||||||
kernel::build_error!(VTABLE_DEFAULT_ERROR)
|
build_error!(VTABLE_DEFAULT_ERROR)
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Suspends the hardware, saving state if needed.
|
/// Suspends the hardware, saving state if needed.
|
||||||
fn suspend(_dev: &mut Device) -> Result {
|
fn suspend(_dev: &mut Device) -> Result {
|
||||||
kernel::build_error!(VTABLE_DEFAULT_ERROR)
|
build_error!(VTABLE_DEFAULT_ERROR)
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Resumes the hardware, restoring state if needed.
|
/// Resumes the hardware, restoring state if needed.
|
||||||
fn resume(_dev: &mut Device) -> Result {
|
fn resume(_dev: &mut Device) -> Result {
|
||||||
kernel::build_error!(VTABLE_DEFAULT_ERROR)
|
build_error!(VTABLE_DEFAULT_ERROR)
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Overrides the default MMD read function for reading a MMD register.
|
/// Overrides the default MMD read function for reading a MMD register.
|
||||||
fn read_mmd(_dev: &mut Device, _devnum: u8, _regnum: u16) -> Result<u16> {
|
fn read_mmd(_dev: &mut Device, _devnum: u8, _regnum: u16) -> Result<u16> {
|
||||||
kernel::build_error!(VTABLE_DEFAULT_ERROR)
|
build_error!(VTABLE_DEFAULT_ERROR)
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Overrides the default MMD write function for writing a MMD register.
|
/// Overrides the default MMD write function for writing a MMD register.
|
||||||
fn write_mmd(_dev: &mut Device, _devnum: u8, _regnum: u16, _val: u16) -> Result {
|
fn write_mmd(_dev: &mut Device, _devnum: u8, _regnum: u16, _val: u16) -> Result {
|
||||||
kernel::build_error!(VTABLE_DEFAULT_ERROR)
|
build_error!(VTABLE_DEFAULT_ERROR)
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Callback for notification of link change.
|
/// Callback for notification of link change.
|
||||||
|
|
|
@ -19,7 +19,7 @@
|
||||||
#[doc(no_inline)]
|
#[doc(no_inline)]
|
||||||
pub use macros::{module, pin_data, pinned_drop, vtable, Zeroable};
|
pub use macros::{module, pin_data, pinned_drop, vtable, Zeroable};
|
||||||
|
|
||||||
pub use super::build_assert;
|
pub use super::{build_assert, build_error};
|
||||||
|
|
||||||
// `super::std_vendor` is hidden, which makes the macro inline for some reason.
|
// `super::std_vendor` is hidden, which makes the macro inline for some reason.
|
||||||
#[doc(no_inline)]
|
#[doc(no_inline)]
|
||||||
|
|
|
@ -123,12 +123,12 @@ pub fn module(ts: TokenStream) -> TokenStream {
|
||||||
/// used on the Rust side, it should not be possible to call the default
|
/// used on the Rust side, it should not be possible to call the default
|
||||||
/// implementation. This is done to ensure that we call the vtable methods
|
/// implementation. This is done to ensure that we call the vtable methods
|
||||||
/// through the C vtable, and not through the Rust vtable. Therefore, the
|
/// through the C vtable, and not through the Rust vtable. Therefore, the
|
||||||
/// default implementation should call `kernel::build_error!`, which prevents
|
/// default implementation should call `build_error!`, which prevents
|
||||||
/// calls to this function at compile time:
|
/// calls to this function at compile time:
|
||||||
///
|
///
|
||||||
/// ```compile_fail
|
/// ```compile_fail
|
||||||
/// # // Intentionally missing `use`s to simplify `rusttest`.
|
/// # // Intentionally missing `use`s to simplify `rusttest`.
|
||||||
/// kernel::build_error!(VTABLE_DEFAULT_ERROR)
|
/// build_error!(VTABLE_DEFAULT_ERROR)
|
||||||
/// ```
|
/// ```
|
||||||
///
|
///
|
||||||
/// Note that you might need to import [`kernel::error::VTABLE_DEFAULT_ERROR`].
|
/// Note that you might need to import [`kernel::error::VTABLE_DEFAULT_ERROR`].
|
||||||
|
@ -145,11 +145,11 @@ pub fn module(ts: TokenStream) -> TokenStream {
|
||||||
/// #[vtable]
|
/// #[vtable]
|
||||||
/// pub trait Operations: Send + Sync + Sized {
|
/// pub trait Operations: Send + Sync + Sized {
|
||||||
/// fn foo(&self) -> Result<()> {
|
/// fn foo(&self) -> Result<()> {
|
||||||
/// kernel::build_error!(VTABLE_DEFAULT_ERROR)
|
/// build_error!(VTABLE_DEFAULT_ERROR)
|
||||||
/// }
|
/// }
|
||||||
///
|
///
|
||||||
/// fn bar(&self) -> Result<()> {
|
/// fn bar(&self) -> Result<()> {
|
||||||
/// kernel::build_error!(VTABLE_DEFAULT_ERROR)
|
/// build_error!(VTABLE_DEFAULT_ERROR)
|
||||||
/// }
|
/// }
|
||||||
/// }
|
/// }
|
||||||
///
|
///
|
||||||
|
|
Loading…
Reference in a new issue