mirror of
https://github.com/openharmony/third_party_rust_memoffset.git
synced 2026-07-18 20:34:36 -04:00
Added travis configuration
This commit is contained in:
+5
-4
@@ -22,7 +22,7 @@
|
||||
//!
|
||||
//! Some of the funcationality of the crate makes no sense when used along with structs that
|
||||
//! are not `#[repr(C, packed)]`, but it is up to the user to make sure that they are.
|
||||
//!
|
||||
//!
|
||||
//! This functionality should work for `const`s but presently doesn't work on `const fn`. Storing a
|
||||
//! value in a const and then returning it from a `const fn` should workaround most cases.
|
||||
//!
|
||||
@@ -67,9 +67,11 @@
|
||||
#[doc(hidden)]
|
||||
pub use core::mem;
|
||||
|
||||
// A helper to get a const fn version of size_of_val
|
||||
// A helper to get a const fn version of size_of_val
|
||||
#[doc(hidden)]
|
||||
pub const fn size_of<T>(_: &T) -> usize { mem::size_of::<T>() }
|
||||
pub const fn size_of<T>(_: &T) -> usize {
|
||||
mem::size_of::<T>()
|
||||
}
|
||||
|
||||
// While constant pointer transmutation isn't stable, union transmutation is
|
||||
// This hack should go away after rust-lang/rust#51910
|
||||
@@ -79,7 +81,6 @@ pub union Transmuter<T: 'static> {
|
||||
pub int: usize,
|
||||
}
|
||||
|
||||
|
||||
#[macro_use]
|
||||
mod offset_of;
|
||||
#[macro_use]
|
||||
|
||||
+8
-8
@@ -43,11 +43,11 @@
|
||||
/// span_of!(Struct, start ..)
|
||||
/// ```
|
||||
///
|
||||
/// *Note*:
|
||||
/// *Note*:
|
||||
/// This macro uses recursion in order to resolve the range expressions, so there is a limit to the complexity of the expression.
|
||||
/// In order to raise the limit, the compiler's recursion limit should be lifted.
|
||||
///
|
||||
/// *Note*:
|
||||
/// *Note*:
|
||||
/// This macro may not make much sense when used on structs that are not `#[repr(C, packed)]`
|
||||
///
|
||||
/// ## Examples
|
||||
@@ -77,7 +77,7 @@
|
||||
/// assert_eq!(0..42, span_of!(Blarg, x .. y[34]));
|
||||
/// assert_eq!(0..64, span_of!(Blarg, x ..= y));
|
||||
/// assert_eq!(58..68, span_of!(Blarg, y[50] ..= z));
|
||||
///
|
||||
///
|
||||
/// const SPAN: std::ops::Range<usize> = span_of!(Blarg, y[50] ..= z);
|
||||
/// assert_eq!(58..68, SPAN);
|
||||
/// }
|
||||
@@ -90,7 +90,7 @@ macro_rules! span_of {
|
||||
(@helper $root:ident, [] ..) => (
|
||||
compile_error!("Expected a range, found '..'")
|
||||
);
|
||||
(@helper $root:ident, [] ..= $($field:tt)+) => (
|
||||
(@helper $root:ident, [] ..= $($field:tt)+) => (
|
||||
0..($crate::Transmuter { ptr: &$root.$($field)+ }.int + $crate::size_of(&$root.$($field)+))
|
||||
);
|
||||
(@helper $root:ident, [] .. $($field:tt)+) => (
|
||||
@@ -120,7 +120,7 @@ macro_rules! span_of {
|
||||
span_of!(@helper $root, #$tt [] $($rest)*)
|
||||
};
|
||||
|
||||
($parent:ty, $($exp:tt)+) => (unsafe {
|
||||
($parent:ty, $($exp:tt)+) => (unsafe {
|
||||
let root: &'static $parent = $crate::Transmuter::<$parent> { int: 0 }.ptr;
|
||||
span_of!(@helper root, [] $($exp)*)
|
||||
});
|
||||
@@ -128,7 +128,7 @@ macro_rules! span_of {
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use ::core::mem;
|
||||
use core::mem;
|
||||
|
||||
#[repr(C, packed)]
|
||||
struct Foo {
|
||||
@@ -171,8 +171,8 @@ mod tests {
|
||||
|
||||
assert_eq!(8..64, span_of!(Blarg, y[0]..z));
|
||||
assert_eq!(0..42, span_of!(Blarg, x..y[34]));
|
||||
assert_eq!(0..64, span_of!(Blarg, x ..= y));
|
||||
assert_eq!(58..68, span_of!(Blarg, y[50] ..= z));
|
||||
assert_eq!(0..64, span_of!(Blarg, x..=y));
|
||||
assert_eq!(58..68, span_of!(Blarg, y[50]..=z));
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
||||
Reference in New Issue
Block a user