Skip to content

Commit

Permalink
[*.rs] rustfmt
Browse files Browse the repository at this point in the history
  • Loading branch information
SamuelMarks committed Jun 29, 2020
1 parent 81cb8cf commit 620be63
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 16 deletions.
5 changes: 3 additions & 2 deletions src/core_lazy.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@ impl<T: Sync> Lazy<T> {

#[inline(always)]
pub fn get<F>(&'static self, builder: F) -> &T
where F: FnOnce() -> T
where
F: FnOnce() -> T,
{
self.0.call_once(builder)
}
Expand All @@ -27,5 +28,5 @@ impl<T: Sync> Lazy<T> {
macro_rules! __lazy_static_create {
($NAME:ident, $T:ty) => {
static $NAME: $crate::lazy::Lazy<$T> = $crate::lazy::Lazy::INIT;
}
};
}
9 changes: 6 additions & 3 deletions src/inline_lazy.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@
extern crate core;
extern crate std;

use self::std::prelude::v1::*;
use self::std::cell::Cell;
use self::std::hint::unreachable_unchecked;
use self::std::prelude::v1::*;
use self::std::sync::Once;
#[allow(deprecated)]
pub use self::std::sync::ONCE_INIT;
Expand All @@ -37,10 +37,13 @@ impl<T: Sync> Lazy<T> {
match *self.0.as_ptr() {
Some(ref x) => x,
None => {
debug_assert!(false, "attempted to derefence an uninitialized lazy static. This is a bug");
debug_assert!(
false,
"attempted to derefence an uninitialized lazy static. This is a bug"
);

unreachable_unchecked()
},
}
}
}
}
Expand Down
4 changes: 2 additions & 2 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ This crate provides one cargo feature:
#![no_std]

#[cfg(not(feature = "spin_no_std"))]
#[path="inline_lazy.rs"]
#[path = "inline_lazy.rs"]
#[doc(hidden)]
pub mod lazy;

Expand All @@ -110,7 +110,7 @@ extern crate doc_comment;
doctest!("../README.md");

#[cfg(feature = "spin_no_std")]
#[path="core_lazy.rs"]
#[path = "core_lazy.rs"]
#[doc(hidden)]
pub mod lazy;

Expand Down
3 changes: 1 addition & 2 deletions tests/no_std.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
#![cfg(feature="spin_no_std")]

#![cfg(feature = "spin_no_std")]
#![no_std]

#[macro_use]
Expand Down
28 changes: 21 additions & 7 deletions tests/test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,10 @@ fn test_meta() {
assert!(&STRING as *const _ != &copy_of_string as *const _);

// this would not compile if STRING were not marked #[derive(Debug)]
assert_eq!(format!("{:?}", STRING), "STRING { __private_field: () }".to_string());
assert_eq!(
format!("{:?}", STRING),
"STRING { __private_field: () }".to_string()
);
}

mod visibility {
Expand Down Expand Up @@ -111,10 +114,18 @@ struct Once(X);
const ONCE_INIT: Once = Once(X);
static DATA: X = X;
static ONCE: X = X;
fn require_sync() -> X { X }
fn transmute() -> X { X }
fn __static_ref_initialize() -> X { X }
fn test(_: Vec<X>) -> X { X }
fn require_sync() -> X {
X
}
fn transmute() -> X {
X
}
fn __static_ref_initialize() -> X {
X
}
fn test(_: Vec<X>) -> X {
X
}

// All these names should not be shadowed
lazy_static! {
Expand All @@ -133,9 +144,9 @@ fn item_name_shadowing() {
}

use std::sync::atomic::AtomicBool;
use std::sync::atomic::Ordering::SeqCst;
#[allow(deprecated)]
use std::sync::atomic::ATOMIC_BOOL_INIT;
use std::sync::atomic::Ordering::SeqCst;

#[allow(deprecated)]
static PRE_INIT_FLAG: AtomicBool = ATOMIC_BOOL_INIT;
Expand All @@ -155,7 +166,10 @@ fn pre_init() {
}

lazy_static! {
static ref LIFETIME_NAME: for<'a> fn(&'a u8) = { fn f(_: &u8) {} f };
static ref LIFETIME_NAME: for<'a> fn(&'a u8) = {
fn f(_: &u8) {}
f
};
}

#[test]
Expand Down

0 comments on commit 620be63

Please sign in to comment.