зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1438954 - geckodriver: Upgrade to lazy_static 1.0.0. r=jgraham
MozReview-Commit-ID: 2LelV9rdyB5 --HG-- extra : rebase_source : adb01cb74e6fb9653c881dd03fd3374ceb140aa1
This commit is contained in:
Родитель
511d92a9fe
Коммит
0e0df51227
|
@ -119,7 +119,7 @@ dependencies = [
|
|||
"chrono 0.2.25 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"clap 2.29.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"hyper 0.10.13 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"lazy_static 0.1.16 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"lazy_static 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"log 0.4.1 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"mozprofile 0.3.0",
|
||||
"mozrunner 0.5.0",
|
||||
|
@ -180,12 +180,12 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
|
|||
|
||||
[[package]]
|
||||
name = "lazy_static"
|
||||
version = "0.1.16"
|
||||
version = "0.2.11"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
|
||||
[[package]]
|
||||
name = "lazy_static"
|
||||
version = "0.2.11"
|
||||
version = "1.0.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
|
||||
[[package]]
|
||||
|
@ -596,8 +596,8 @@ dependencies = [
|
|||
"checksum idna 0.1.4 (registry+https://github.com/rust-lang/crates.io-index)" = "014b298351066f1512874135335d62a789ffe78a9974f94b43ed5621951eaf7d"
|
||||
"checksum kernel32-sys 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)" = "7507624b29483431c0ba2d82aece8ca6cdba9382bff4ddd0f7490560c056098d"
|
||||
"checksum language-tags 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)" = "a91d884b6667cd606bb5a69aa0c99ba811a115fc68915e7056ec08a46e93199a"
|
||||
"checksum lazy_static 0.1.16 (registry+https://github.com/rust-lang/crates.io-index)" = "cf186d1a8aa5f5bee5fd662bc9c1b949e0259e1bcc379d1f006847b0080c7417"
|
||||
"checksum lazy_static 0.2.11 (registry+https://github.com/rust-lang/crates.io-index)" = "76f033c7ad61445c5b347c7382dd1237847eb1bce590fe50365dcb33d546be73"
|
||||
"checksum lazy_static 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)" = "c8f31047daa365f19be14b47c29df4f7c3b581832407daabe6ae77397619237d"
|
||||
"checksum libc 0.2.33 (registry+https://github.com/rust-lang/crates.io-index)" = "5ba3df4dcb460b9dfbd070d41c94c19209620c191b0340b929ce748a2bcd42d2"
|
||||
"checksum log 0.3.8 (registry+https://github.com/rust-lang/crates.io-index)" = "880f77541efa6e5cc74e76910c9884d9859683118839d6a1dc3b11e63512565b"
|
||||
"checksum log 0.4.1 (registry+https://github.com/rust-lang/crates.io-index)" = "89f010e843f2b1a31dbd316b3b8d443758bc634bed37aabade59c686d644e0a2"
|
||||
|
|
|
@ -13,7 +13,7 @@ publish = false
|
|||
chrono = "^0.2"
|
||||
clap = { version = "^2.19", default-features = false, features = ["suggestions", "wrap_help"] }
|
||||
hyper = "0.10"
|
||||
lazy_static = "0.1"
|
||||
lazy_static = "1.0"
|
||||
log = { version = "0.4", features = ["std"] }
|
||||
mozprofile = { path = "../mozbase/rust/mozprofile" }
|
||||
mozrunner = { path = "../mozbase/rust/mozrunner" }
|
||||
|
|
|
@ -1 +0,0 @@
|
|||
{"files":{".travis.yml":"eea0007a95867df1d3c5b8701b893bfda2773c95f3cd2e4e44d159c4ef834cdd","Cargo.toml":"e50632bb46a33d96af38ec11201ea2371cab8992cae328fd20e3a6bc1e323f06","LICENSE":"79d26c3d855d83d92837c49a868339ec7c2ef7d2a19d7a779ebb4c30d160d90a","README.md":"932d081be16cf7b787400973604712c80b2bc119764c7b742c53cf093cd056fa","src/lib.rs":"0ee6b5a09c6781a9a420cc9ac66790a47b7303aea74093c26d6758a20c248917","src/liblib.so":"34037b491a9d4c55de6f630d47b43ea9ea384d8b915c5bae58495a0982d9f99f","tests/test.rs":"72d312e97491667dee4082d9880df23496d2cd8aa01ff2f9af22cdc6df2c8216"},"package":"cf186d1a8aa5f5bee5fd662bc9c1b949e0259e1bcc379d1f006847b0080c7417"}
|
|
@ -1,21 +0,0 @@
|
|||
language: rust
|
||||
rust:
|
||||
- nightly
|
||||
- beta
|
||||
- stable
|
||||
before_script:
|
||||
- |
|
||||
pip install 'travis-cargo<0.2' --user &&
|
||||
export PATH=$HOME/.local/bin:$PATH
|
||||
script:
|
||||
- |
|
||||
travis-cargo build &&
|
||||
travis-cargo test &&
|
||||
travis-cargo bench &&
|
||||
travis-cargo --only stable doc
|
||||
after_success:
|
||||
- travis-cargo --only stable doc-upload
|
||||
env:
|
||||
global:
|
||||
- TRAVIS_CARGO_NIGHTLY_FEATURE=nightly
|
||||
- secure: YXu24LptjeYirjWYjWGsMT2m3mB7LvQATE6TVo7VEUXv8GYoy2ORIHD83PeImxC93MmZ01QeUezRzuCW51ZcK92VnNSBttlF60SvIX18VsJrV92tsAhievFstqYQ+fB8DIuQ8noU0jPz7GpI+R9dlTRSImAqWOnVIghA+Wzz7Js=
|
|
@ -1,15 +0,0 @@
|
|||
[package]
|
||||
name = "lazy_static"
|
||||
version = "0.1.16"
|
||||
authors = ["Marvin Löbel <loebel.marvin@gmail.com>"]
|
||||
license = "MIT"
|
||||
|
||||
description = "A macro for declaring lazily evaluated statics in Rust."
|
||||
readme = "README.md"
|
||||
documentation = "http://rust-lang-nursery.github.io/lazy-static.rs/lazy_static/index.html"
|
||||
|
||||
repository = "https://github.com/rust-lang-nursery/lazy-static.rs"
|
||||
keywords = ["macro", "lazy", "static"]
|
||||
|
||||
[features]
|
||||
nightly = []
|
|
@ -1,21 +0,0 @@
|
|||
The MIT License (MIT)
|
||||
|
||||
Copyright (c) 2014 Marvin Löbel
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
|
@ -1,81 +0,0 @@
|
|||
lazy-static.rs
|
||||
==============
|
||||
|
||||
[![Travis-CI Status](https://travis-ci.org/rust-lang-nursery/lazy-static.rs.svg?branch=master)](https://travis-ci.org/rust-lang-nursery/lazy-static.rs)
|
||||
|
||||
A macro for declaring lazily evaluated statics in Rust.
|
||||
|
||||
Using this macro, it is possible to have `static`s that require code to be
|
||||
executed at runtime in order to be initialized.
|
||||
This includes anything requiring heap allocations, like vectors or hash maps,
|
||||
as well as anything that requires function calls to be computed.
|
||||
|
||||
# Syntax
|
||||
|
||||
```rust
|
||||
lazy_static! {
|
||||
[pub] static ref NAME_1: TYPE_1 = EXPR_1;
|
||||
[pub] static ref NAME_2: TYPE_2 = EXPR_2;
|
||||
...
|
||||
[pub] static ref NAME_N: TYPE_N = EXPR_N;
|
||||
}
|
||||
```
|
||||
|
||||
# Semantic
|
||||
|
||||
For a given `static ref NAME: TYPE = EXPR;`, the macro generates a
|
||||
unique type that implements `Deref<TYPE>` and stores it in a static with name `NAME`.
|
||||
|
||||
On first deref, `EXPR` gets evaluated and stored internally, such that all further derefs
|
||||
can return a reference to the same object.
|
||||
|
||||
Like regular `static mut`s, this macro only works for types that fulfill the `Sync`
|
||||
trait.
|
||||
|
||||
# Getting Started
|
||||
|
||||
[lazy-static.rs is available on crates.io](https://crates.io/crates/lazy_static).
|
||||
Add the following dependency to your Cargo manifest to get the latest version of the 0.1 branch:
|
||||
|
||||
```toml
|
||||
[dependencies]
|
||||
lazy_static = "0.1.*"
|
||||
```
|
||||
|
||||
To always get the latest version, add this git repository to your
|
||||
Cargo manifest:
|
||||
|
||||
```toml
|
||||
[dependencies.lazy_static]
|
||||
git = "https://github.com/rust-lang-nursery/lazy-static.rs"
|
||||
```
|
||||
# Example
|
||||
|
||||
Using the macro:
|
||||
|
||||
```rust
|
||||
#[macro_use]
|
||||
extern crate lazy_static;
|
||||
|
||||
use std::collections::HashMap;
|
||||
|
||||
lazy_static! {
|
||||
static ref HASHMAP: HashMap<u32, &'static str> = {
|
||||
let mut m = HashMap::new();
|
||||
m.insert(0, "foo");
|
||||
m.insert(1, "bar");
|
||||
m.insert(2, "baz");
|
||||
m
|
||||
};
|
||||
static ref COUNT: usize = HASHMAP.len();
|
||||
static ref NUMBER: u32 = times_two(21);
|
||||
}
|
||||
|
||||
fn times_two(n: u32) -> u32 { n * 2 }
|
||||
|
||||
fn main() {
|
||||
println!("The map has {} entries.", *COUNT);
|
||||
println!("The entry for `0` is \"{}\".", HASHMAP.get(&0).unwrap());
|
||||
println!("An expensive calculation on a static results in: {}.", *NUMBER);
|
||||
}
|
||||
```
|
|
@ -1,157 +0,0 @@
|
|||
/*!
|
||||
A macro for declaring lazily evaluated statics.
|
||||
|
||||
Using this macro, it is possible to have `static`s that require code to be
|
||||
executed at runtime in order to be initialized.
|
||||
This includes anything requiring heap allocations, like vectors or hash maps,
|
||||
as well as anything that requires function calls to be computed.
|
||||
|
||||
# Syntax
|
||||
|
||||
```ignore
|
||||
lazy_static! {
|
||||
[pub] static ref NAME_1: TYPE_1 = EXPR_1;
|
||||
[pub] static ref NAME_2: TYPE_2 = EXPR_2;
|
||||
...
|
||||
[pub] static ref NAME_N: TYPE_N = EXPR_N;
|
||||
}
|
||||
```
|
||||
|
||||
Metadata (such as doc comments) is allowed on each ref.
|
||||
|
||||
# Semantic
|
||||
|
||||
For a given `static ref NAME: TYPE = EXPR;`, the macro generates a unique type that
|
||||
implements `Deref<TYPE>` and stores it in a static with name `NAME`. (Metadata ends up
|
||||
attaching to this type.)
|
||||
|
||||
On first deref, `EXPR` gets evaluated and stored internally, such that all further derefs
|
||||
can return a reference to the same object.
|
||||
|
||||
Like regular `static mut`s, this macro only works for types that fulfill the `Sync`
|
||||
trait.
|
||||
|
||||
# Example
|
||||
|
||||
Using the macro:
|
||||
|
||||
```rust
|
||||
#[macro_use]
|
||||
extern crate lazy_static;
|
||||
|
||||
use std::collections::HashMap;
|
||||
|
||||
lazy_static! {
|
||||
static ref HASHMAP: HashMap<u32, &'static str> = {
|
||||
let mut m = HashMap::new();
|
||||
m.insert(0, "foo");
|
||||
m.insert(1, "bar");
|
||||
m.insert(2, "baz");
|
||||
m
|
||||
};
|
||||
static ref COUNT: usize = HASHMAP.len();
|
||||
static ref NUMBER: u32 = times_two(21);
|
||||
}
|
||||
|
||||
fn times_two(n: u32) -> u32 { n * 2 }
|
||||
|
||||
fn main() {
|
||||
println!("The map has {} entries.", *COUNT);
|
||||
println!("The entry for `0` is \"{}\".", HASHMAP.get(&0).unwrap());
|
||||
println!("A expensive calculation on a static results in: {}.", *NUMBER);
|
||||
}
|
||||
```
|
||||
|
||||
# Implementation details
|
||||
|
||||
The `Deref` implementation uses a hidden static variable that is guarded by a atomic check on each access. On stable Rust, the macro may need to allocate each static on the heap.
|
||||
|
||||
*/
|
||||
|
||||
#![cfg_attr(feature="nightly", feature(const_fn, core_intrinsics))]
|
||||
#![crate_type = "dylib"]
|
||||
|
||||
#[macro_export]
|
||||
macro_rules! lazy_static {
|
||||
($(#[$attr:meta])* static ref $N:ident : $T:ty = $e:expr; $($t:tt)*) => {
|
||||
lazy_static!(PRIV, $(#[$attr])* static ref $N : $T = $e; $($t)*);
|
||||
};
|
||||
($(#[$attr:meta])* pub static ref $N:ident : $T:ty = $e:expr; $($t:tt)*) => {
|
||||
lazy_static!(PUB, $(#[$attr])* static ref $N : $T = $e; $($t)*);
|
||||
};
|
||||
($VIS:ident, $(#[$attr:meta])* static ref $N:ident : $T:ty = $e:expr; $($t:tt)*) => {
|
||||
lazy_static!(MAKE TY, $VIS, $(#[$attr])*, $N);
|
||||
impl ::std::ops::Deref for $N {
|
||||
type Target = $T;
|
||||
fn deref<'a>(&'a self) -> &'a $T {
|
||||
#[inline(always)]
|
||||
fn __static_ref_initialize() -> $T { $e }
|
||||
|
||||
unsafe {
|
||||
use std::sync::{Once, ONCE_INIT};
|
||||
|
||||
#[inline(always)]
|
||||
fn require_sync<T: Sync>(_: &T) { }
|
||||
|
||||
#[inline(always)]
|
||||
#[cfg(feature="nightly")]
|
||||
unsafe fn __stability() -> &'static $T {
|
||||
use std::cell::UnsafeCell;
|
||||
|
||||
struct SyncCell(UnsafeCell<Option<$T>>);
|
||||
unsafe impl Sync for SyncCell {}
|
||||
|
||||
static DATA: SyncCell = SyncCell(UnsafeCell::new(None));
|
||||
static ONCE: Once = ONCE_INIT;
|
||||
ONCE.call_once(|| {
|
||||
*DATA.0.get() = Some(__static_ref_initialize());
|
||||
});
|
||||
match *DATA.0.get() {
|
||||
Some(ref x) => x,
|
||||
None => ::std::intrinsics::unreachable(),
|
||||
}
|
||||
}
|
||||
|
||||
#[inline(always)]
|
||||
#[cfg(not(feature="nightly"))]
|
||||
unsafe fn __stability() -> &'static $T {
|
||||
use std::mem::transmute;
|
||||
use std::boxed::Box;
|
||||
|
||||
static mut DATA: *const $T = 0 as *const $T;
|
||||
static mut ONCE: Once = ONCE_INIT;
|
||||
ONCE.call_once(|| {
|
||||
DATA = transmute::<Box<$T>, *const $T>(
|
||||
Box::new(__static_ref_initialize()));
|
||||
});
|
||||
&*DATA
|
||||
}
|
||||
|
||||
let static_ref = __stability();
|
||||
require_sync(static_ref);
|
||||
static_ref
|
||||
}
|
||||
}
|
||||
}
|
||||
lazy_static!($($t)*);
|
||||
};
|
||||
(MAKE TY, PUB, $(#[$attr:meta])*, $N:ident) => {
|
||||
#[allow(missing_copy_implementations)]
|
||||
#[allow(non_camel_case_types)]
|
||||
#[allow(dead_code)]
|
||||
$(#[$attr])*
|
||||
pub struct $N {__private_field: ()}
|
||||
#[doc(hidden)]
|
||||
pub static $N: $N = $N {__private_field: ()};
|
||||
};
|
||||
(MAKE TY, PRIV, $(#[$attr:meta])*, $N:ident) => {
|
||||
#[allow(missing_copy_implementations)]
|
||||
#[allow(non_camel_case_types)]
|
||||
#[allow(dead_code)]
|
||||
$(#[$attr])*
|
||||
struct $N {__private_field: ()}
|
||||
#[doc(hidden)]
|
||||
static $N: $N = $N {__private_field: ()};
|
||||
};
|
||||
() => ()
|
||||
}
|
Двоичный файл не отображается.
|
@ -1,116 +0,0 @@
|
|||
#![cfg_attr(feature="nightly", feature(const_fn, core_intrinsics))]
|
||||
|
||||
#[macro_use]
|
||||
extern crate lazy_static;
|
||||
use std::collections::HashMap;
|
||||
|
||||
lazy_static! {
|
||||
/// Documentation!
|
||||
pub static ref NUMBER: u32 = times_two(3);
|
||||
|
||||
static ref ARRAY_BOXES: [Box<u32>; 3] = [Box::new(1), Box::new(2), Box::new(3)];
|
||||
|
||||
/// More documentation!
|
||||
#[allow(unused_variables)]
|
||||
#[derive(Copy, Clone, Debug)]
|
||||
pub static ref STRING: String = "hello".to_string();
|
||||
|
||||
static ref HASHMAP: HashMap<u32, &'static str> = {
|
||||
let mut m = HashMap::new();
|
||||
m.insert(0, "abc");
|
||||
m.insert(1, "def");
|
||||
m.insert(2, "ghi");
|
||||
m
|
||||
};
|
||||
|
||||
// This should not compile if the unsafe is removed.
|
||||
static ref UNSAFE: u32 = unsafe {
|
||||
std::mem::transmute::<i32, u32>(-1)
|
||||
};
|
||||
|
||||
// This *should* triggger warn(dead_code) by design.
|
||||
static ref UNUSED: () = ();
|
||||
|
||||
}
|
||||
|
||||
fn times_two(n: u32) -> u32 {
|
||||
n * 2
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_basic() {
|
||||
assert_eq!(&**STRING, "hello");
|
||||
assert_eq!(*NUMBER, 6);
|
||||
assert!(HASHMAP.get(&1).is_some());
|
||||
assert!(HASHMAP.get(&3).is_none());
|
||||
assert_eq!(&*ARRAY_BOXES, &[Box::new(1), Box::new(2), Box::new(3)]);
|
||||
assert_eq!(*UNSAFE, std::u32::MAX);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_repeat() {
|
||||
assert_eq!(*NUMBER, 6);
|
||||
assert_eq!(*NUMBER, 6);
|
||||
assert_eq!(*NUMBER, 6);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_meta() {
|
||||
// this would not compile if STRING were not marked #[derive(Copy, Clone)]
|
||||
let copy_of_string = STRING;
|
||||
// just to make sure it was copied
|
||||
assert!(&STRING as *const _ != ©_of_string as *const _);
|
||||
|
||||
// this would not compile if STRING were not marked #[derive(Debug)]
|
||||
assert_eq!(format!("{:?}", STRING), "STRING { __private_field: () }".to_string());
|
||||
}
|
||||
|
||||
mod visibility {
|
||||
lazy_static! {
|
||||
pub static ref FOO: Box<u32> = Box::new(0);
|
||||
static ref BAR: Box<u32> = Box::new(98);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn sub_test() {
|
||||
assert_eq!(**FOO, 0);
|
||||
assert_eq!(**BAR, 98);
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_visibility() {
|
||||
assert_eq!(*visibility::FOO, Box::new(0));
|
||||
}
|
||||
|
||||
// This should not cause a warning about a missing Copy implementation
|
||||
lazy_static! {
|
||||
pub static ref VAR: i32 = { 0 };
|
||||
}
|
||||
|
||||
#[derive(Copy, Clone, Debug, PartialEq)]
|
||||
struct X;
|
||||
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 }
|
||||
|
||||
// All these names should not be shadowed
|
||||
lazy_static! {
|
||||
static ref ITEM_NAME_TEST: X = {
|
||||
test(vec![X, Once(X).0, ONCE_INIT.0, DATA, ONCE,
|
||||
require_sync(), transmute(),
|
||||
// Except this, which will sadly be shadowed by internals:
|
||||
// __static_ref_initialize()
|
||||
])
|
||||
};
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn item_name_shadowing() {
|
||||
assert_eq!(*ITEM_NAME_TEST, X);
|
||||
}
|
Загрузка…
Ссылка в новой задаче