From df1ac7aa63ea89a067c57663eab035f7b83f6933 Mon Sep 17 00:00:00 2001 From: Huon Wilson Date: Tue, 3 Feb 2015 20:11:38 +1100 Subject: [PATCH] Deprecate in-tree `rand`, `std::rand` and `#[derive(Rand)]`. Use the crates.io crate `rand` (version 0.1 should be a drop in replacement for `std::rand`) and `rand_macros` (`#[derive_Rand]` should be a drop-in replacement). [breaking-change] --- src/etc/generate-deriving-span-tests.py | 3 +-- src/libcollections/lib.rs | 1 + src/libcoretest/lib.rs | 1 + src/libflate/lib.rs | 1 + src/librand/lib.rs | 4 +++ src/librustc_back/sha2.rs | 1 + src/libstd/collections/hash/map.rs | 1 + src/libstd/lib.rs | 2 +- src/libstd/num/strconv.rs | 1 + src/libstd/old_io/fs.rs | 1 + src/libstd/old_io/tempfile.rs | 1 + src/libstd/os.rs | 2 ++ src/libstd/rand/mod.rs | 3 +++ src/libstd/sync/rwlock.rs | 2 ++ src/libsyntax/ext/deriving/rand.rs | 4 +++ .../deriving-span-Rand-enum-struct-variant.rs | 25 ------------------- .../compile-fail/deriving-span-Rand-enum.rs | 25 ------------------- .../compile-fail/deriving-span-Rand-struct.rs | 23 ----------------- .../deriving-span-Rand-tuple-struct.rs | 23 ----------------- .../compile-fail/lint-unused-extern-crate.rs | 1 + .../compile-fail/macros-nonfatal-errors.rs | 1 - 21 files changed, 26 insertions(+), 100 deletions(-) delete mode 100644 src/test/compile-fail/deriving-span-Rand-enum-struct-variant.rs delete mode 100644 src/test/compile-fail/deriving-span-Rand-enum.rs delete mode 100644 src/test/compile-fail/deriving-span-Rand-struct.rs delete mode 100644 src/test/compile-fail/deriving-span-Rand-tuple-struct.rs diff --git a/src/etc/generate-deriving-span-tests.py b/src/etc/generate-deriving-span-tests.py index eeb1b89472b3d..a8a62358d3afe 100755 --- a/src/etc/generate-deriving-span-tests.py +++ b/src/etc/generate-deriving-span-tests.py @@ -114,8 +114,7 @@ def write_file(name, string): 'Encodable': (0, [], 0), # FIXME: quoting gives horrible spans } -for (trait, supers, errs) in [('Rand', [], 1), - ('Clone', [], 1), +for (trait, supers, errs) in [('Clone', [], 1), ('PartialEq', [], 2), ('PartialOrd', ['PartialEq'], 8), ('Eq', ['PartialEq'], 1), diff --git a/src/libcollections/lib.rs b/src/libcollections/lib.rs index ce00bd48bb8ba..dea2d509676bf 100644 --- a/src/libcollections/lib.rs +++ b/src/libcollections/lib.rs @@ -34,6 +34,7 @@ #![feature(unicode)] #![feature(unsafe_destructor, slicing_syntax)] #![cfg_attr(test, feature(test))] +#![cfg_attr(test, allow(deprecated))] // rand #![no_std] diff --git a/src/libcoretest/lib.rs b/src/libcoretest/lib.rs index c26d3e7bb8a7d..50066ab07f555 100644 --- a/src/libcoretest/lib.rs +++ b/src/libcoretest/lib.rs @@ -12,6 +12,7 @@ #![feature(int_uint)] #![feature(unboxed_closures)] #![feature(unsafe_destructor, slicing_syntax)] +#![allow(deprecated)] // rand extern crate core; extern crate test; diff --git a/src/libflate/lib.rs b/src/libflate/lib.rs index e7fb2ba56ab35..d42849ed758fc 100644 --- a/src/libflate/lib.rs +++ b/src/libflate/lib.rs @@ -130,6 +130,7 @@ pub fn inflate_bytes_zlib(bytes: &[u8]) -> Option { #[cfg(test)] mod tests { + #![allow(deprecated)] use super::{inflate_bytes, deflate_bytes}; use std::rand; use std::rand::Rng; diff --git a/src/librand/lib.rs b/src/librand/lib.rs index 3ff400388721a..3b78e5f88ee98 100644 --- a/src/librand/lib.rs +++ b/src/librand/lib.rs @@ -28,6 +28,10 @@ #![feature(staged_api)] #![staged_api] #![feature(core)] +#![deprecated(reason = "use the crates.io `rand` library instead", + since = "1.0.0-alpha")] + +#![allow(deprecated)] #[macro_use] extern crate core; diff --git a/src/librustc_back/sha2.rs b/src/librustc_back/sha2.rs index d99ce8b64b0fb..4dc95088e983a 100644 --- a/src/librustc_back/sha2.rs +++ b/src/librustc_back/sha2.rs @@ -528,6 +528,7 @@ static H256: [u32; 8] = [ #[cfg(test)] mod tests { + #![allow(deprecated)] extern crate rand; use self::rand::Rng; diff --git a/src/libstd/collections/hash/map.rs b/src/libstd/collections/hash/map.rs index 3e2c7627dbe55..449c8a9e5dc3a 100644 --- a/src/libstd/collections/hash/map.rs +++ b/src/libstd/collections/hash/map.rs @@ -1566,6 +1566,7 @@ pub struct RandomState { impl RandomState { /// Construct a new `RandomState` that is initialized with random keys. #[inline] + #[allow(deprecated)] pub fn new() -> RandomState { let mut r = rand::thread_rng(); RandomState { k0: r.gen(), k1: r.gen() } diff --git a/src/libstd/lib.rs b/src/libstd/lib.rs index 96aebb735ef12..21197f639ad72 100644 --- a/src/libstd/lib.rs +++ b/src/libstd/lib.rs @@ -142,7 +142,7 @@ extern crate core; #[macro_reexport(vec)] extern crate "collections" as core_collections; -extern crate "rand" as core_rand; +#[allow(deprecated)] extern crate "rand" as core_rand; extern crate alloc; extern crate unicode; extern crate libc; diff --git a/src/libstd/num/strconv.rs b/src/libstd/num/strconv.rs index 1d3bf484edb9a..9c4741b3ce316 100644 --- a/src/libstd/num/strconv.rs +++ b/src/libstd/num/strconv.rs @@ -459,6 +459,7 @@ mod tests { #[cfg(test)] mod bench { + #![allow(deprecated)] // rand extern crate test; mod uint { diff --git a/src/libstd/old_io/fs.rs b/src/libstd/old_io/fs.rs index 0a9aeb849be4b..82ede30cb91f1 100644 --- a/src/libstd/old_io/fs.rs +++ b/src/libstd/old_io/fs.rs @@ -822,6 +822,7 @@ fn access_string(access: FileAccess) -> &'static str { #[allow(unused_imports)] #[allow(unused_variables)] #[allow(unused_mut)] +#[allow(deprecated)] // rand mod test { use prelude::v1::*; use old_io::{SeekSet, SeekCur, SeekEnd, Read, Open, ReadWrite, FileType}; diff --git a/src/libstd/old_io/tempfile.rs b/src/libstd/old_io/tempfile.rs index 20cbde5db715a..d2c3a8e60ad0b 100644 --- a/src/libstd/old_io/tempfile.rs +++ b/src/libstd/old_io/tempfile.rs @@ -9,6 +9,7 @@ // except according to those terms. //! Temporary files and directories +#![allow(deprecated)] // rand use old_io::{fs, IoError, IoErrorKind, IoResult}; use old_io; diff --git a/src/libstd/os.rs b/src/libstd/os.rs index 600ca60349ae2..7a9f61f1d64c1 100644 --- a/src/libstd/os.rs +++ b/src/libstd/os.rs @@ -1425,6 +1425,8 @@ mod arch_consts { #[cfg(test)] mod tests { + #![allow(deprecated)] // rand + use prelude::v1::*; use iter::repeat; diff --git a/src/libstd/rand/mod.rs b/src/libstd/rand/mod.rs index 211abc2fc83e7..48ff6db43920d 100644 --- a/src/libstd/rand/mod.rs +++ b/src/libstd/rand/mod.rs @@ -220,6 +220,9 @@ //! ``` #![unstable(feature = "rand")] +#![deprecated(reason = "use the crates.io `rand` library instead", + since = "1.0.0-alpha")] +#![allow(deprecated)] use cell::RefCell; use clone::Clone; diff --git a/src/libstd/sync/rwlock.rs b/src/libstd/sync/rwlock.rs index 95b570dd9c82a..63ca5b5669ac5 100644 --- a/src/libstd/sync/rwlock.rs +++ b/src/libstd/sync/rwlock.rs @@ -383,6 +383,8 @@ impl<'a, T> Drop for RwLockWriteGuard<'a, T> { #[cfg(test)] mod tests { + #![allow(deprecated)] // rand + use prelude::v1::*; use rand::{self, Rng}; diff --git a/src/libsyntax/ext/deriving/rand.rs b/src/libsyntax/ext/deriving/rand.rs index 9fd5091e194dc..ec6eb9bee610f 100644 --- a/src/libsyntax/ext/deriving/rand.rs +++ b/src/libsyntax/ext/deriving/rand.rs @@ -24,6 +24,10 @@ pub fn expand_deriving_rand(cx: &mut ExtCtxt, push: F) where F: FnOnce(P), { + cx.span_warn(span, + "`#[derive(Rand)]` is deprecated in favour of `#[derive_Rand]` from \ + `rand_macros` on crates.io"); + let trait_def = TraitDef { span: span, attributes: Vec::new(), diff --git a/src/test/compile-fail/deriving-span-Rand-enum-struct-variant.rs b/src/test/compile-fail/deriving-span-Rand-enum-struct-variant.rs deleted file mode 100644 index 4d3542c586b0a..0000000000000 --- a/src/test/compile-fail/deriving-span-Rand-enum-struct-variant.rs +++ /dev/null @@ -1,25 +0,0 @@ -// Copyright 2014 The Rust Project Developers. See the COPYRIGHT -// file at the top-level directory of this distribution and at -// http://rust-lang.org/COPYRIGHT. -// -// Licensed under the Apache License, Version 2.0 or the MIT license -// , at your -// option. This file may not be copied, modified, or distributed -// except according to those terms. - -// This file was auto-generated using 'src/etc/generate-deriving-span-tests.py' - -extern crate rand; - - -struct Error; - -#[derive(Rand)] -enum Enum { - A { - x: Error //~ ERROR - } -} - -fn main() {} diff --git a/src/test/compile-fail/deriving-span-Rand-enum.rs b/src/test/compile-fail/deriving-span-Rand-enum.rs deleted file mode 100644 index dcfdbdc8062ce..0000000000000 --- a/src/test/compile-fail/deriving-span-Rand-enum.rs +++ /dev/null @@ -1,25 +0,0 @@ -// Copyright 2014 The Rust Project Developers. See the COPYRIGHT -// file at the top-level directory of this distribution and at -// http://rust-lang.org/COPYRIGHT. -// -// Licensed under the Apache License, Version 2.0 or the MIT license -// , at your -// option. This file may not be copied, modified, or distributed -// except according to those terms. - -// This file was auto-generated using 'src/etc/generate-deriving-span-tests.py' - -extern crate rand; - - -struct Error; - -#[derive(Rand)] -enum Enum { - A( - Error //~ ERROR - ) -} - -fn main() {} diff --git a/src/test/compile-fail/deriving-span-Rand-struct.rs b/src/test/compile-fail/deriving-span-Rand-struct.rs deleted file mode 100644 index 73d89693b2bc4..0000000000000 --- a/src/test/compile-fail/deriving-span-Rand-struct.rs +++ /dev/null @@ -1,23 +0,0 @@ -// Copyright 2014 The Rust Project Developers. See the COPYRIGHT -// file at the top-level directory of this distribution and at -// http://rust-lang.org/COPYRIGHT. -// -// Licensed under the Apache License, Version 2.0 or the MIT license -// , at your -// option. This file may not be copied, modified, or distributed -// except according to those terms. - -// This file was auto-generated using 'src/etc/generate-deriving-span-tests.py' - -extern crate rand; - - -struct Error; - -#[derive(Rand)] -struct Struct { - x: Error //~ ERROR -} - -fn main() {} diff --git a/src/test/compile-fail/deriving-span-Rand-tuple-struct.rs b/src/test/compile-fail/deriving-span-Rand-tuple-struct.rs deleted file mode 100644 index 8038bf3ff0925..0000000000000 --- a/src/test/compile-fail/deriving-span-Rand-tuple-struct.rs +++ /dev/null @@ -1,23 +0,0 @@ -// Copyright 2014 The Rust Project Developers. See the COPYRIGHT -// file at the top-level directory of this distribution and at -// http://rust-lang.org/COPYRIGHT. -// -// Licensed under the Apache License, Version 2.0 or the MIT license -// , at your -// option. This file may not be copied, modified, or distributed -// except according to those terms. - -// This file was auto-generated using 'src/etc/generate-deriving-span-tests.py' - -extern crate rand; - - -struct Error; - -#[derive(Rand)] -struct Struct( - Error //~ ERROR -); - -fn main() {} diff --git a/src/test/compile-fail/lint-unused-extern-crate.rs b/src/test/compile-fail/lint-unused-extern-crate.rs index 03bb7cc1f15e0..ada0cd2bc98f8 100644 --- a/src/test/compile-fail/lint-unused-extern-crate.rs +++ b/src/test/compile-fail/lint-unused-extern-crate.rs @@ -12,6 +12,7 @@ #![deny(unused_extern_crates)] #![allow(unused_variables)] +#![allow(deprecated)] #![feature(libc)] #![feature(collections)] #![feature(rand)] diff --git a/src/test/compile-fail/macros-nonfatal-errors.rs b/src/test/compile-fail/macros-nonfatal-errors.rs index ce1b372a4c11e..42a0f41dd97c3 100644 --- a/src/test/compile-fail/macros-nonfatal-errors.rs +++ b/src/test/compile-fail/macros-nonfatal-errors.rs @@ -15,7 +15,6 @@ #![feature(trace_macros, concat_idents)] #[derive(Default, //~ ERROR - Rand, //~ ERROR Zero)] //~ ERROR enum CantDeriveThose {}