mirror of
				https://github.com/torvalds/linux.git
				synced 2025-10-31 08:38:45 +02:00 
			
		
		
		
	 de7cd3e4d6
			
		
	
	
		de7cd3e4d6
		
	
	
	
	
		
			
			Macros and auto-generated code should use absolute paths, `::core::...` and `::kernel::...`, for core and kernel references. This prevents issues where user-defined modules named `core` or `kernel` could be picked up instead of the `core` or `kernel` crates. Thus clean some references up. Suggested-by: Benno Lossin <benno.lossin@proton.me> Closes: https://github.com/Rust-for-Linux/linux/issues/1150 Signed-off-by: Igor Korotin <igor.korotin.linux@gmail.com> Reviewed-by: Benno Lossin <lossin@kernel.org> Acked-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org> Link: https://lore.kernel.org/r/20250519164615.3310844-1-igor.korotin.linux@gmail.com [ Applied `rustfmt`. Reworded slightly. - Miguel ] Signed-off-by: Miguel Ojeda <ojeda@kernel.org>
		
			
				
	
	
		
			39 lines
		
	
	
	
		
			1.2 KiB
		
	
	
	
		
			Rust
		
	
	
	
	
	
			
		
		
	
	
			39 lines
		
	
	
	
		
			1.2 KiB
		
	
	
	
		
			Rust
		
	
	
	
	
	
| // SPDX-License-Identifier: GPL-2.0
 | |
| 
 | |
| //! Static assert.
 | |
| 
 | |
| /// Static assert (i.e. compile-time assert).
 | |
| ///
 | |
| /// Similar to C11 [`_Static_assert`] and C++11 [`static_assert`].
 | |
| ///
 | |
| /// An optional panic message can be supplied after the expression.
 | |
| /// Currently only a string literal without formatting is supported
 | |
| /// due to constness limitations of the [`assert!`] macro.
 | |
| ///
 | |
| /// The feature may be added to Rust in the future: see [RFC 2790].
 | |
| ///
 | |
| /// [`_Static_assert`]: https://en.cppreference.com/w/c/language/_Static_assert
 | |
| /// [`static_assert`]: https://en.cppreference.com/w/cpp/language/static_assert
 | |
| /// [RFC 2790]: https://github.com/rust-lang/rfcs/issues/2790
 | |
| ///
 | |
| /// # Examples
 | |
| ///
 | |
| /// ```
 | |
| /// static_assert!(42 > 24);
 | |
| /// static_assert!(core::mem::size_of::<u8>() == 1);
 | |
| ///
 | |
| /// const X: &[u8] = b"bar";
 | |
| /// static_assert!(X[1] == b'a');
 | |
| ///
 | |
| /// const fn f(x: i32) -> i32 {
 | |
| ///     x + 2
 | |
| /// }
 | |
| /// static_assert!(f(40) == 42);
 | |
| /// static_assert!(f(40) == 42, "f(x) must add 2 to the given input.");
 | |
| /// ```
 | |
| #[macro_export]
 | |
| macro_rules! static_assert {
 | |
|     ($condition:expr $(,$arg:literal)?) => {
 | |
|         const _: () = ::core::assert!($condition $(,$arg)?);
 | |
|     };
 | |
| }
 |