Skip to content

Commit 34fa70f

Browse files
alexcrichtonsteveklabnik
authored andcommitted
std: Move the bitflags! macro to a gated crate
In accordance with [collections reform part 2][rfc] this macro has been moved to an external [bitflags crate][crate] which is [available though crates.io][cratesio]. Inside the standard distribution the macro has been moved to a crate called `rustc_bitflags` for current users to continue using. [rfc]: https://github.com/rust-lang/rfcs/blob/master/text/0509-collections-reform-part-2.md [crate]: https://github.com/rust-lang/bitflags [cratesio]: http://crates.io/crates/bitflags The major user of `bitflags!` in terms of a public-facing possibly-stable API today is the `FilePermissions` structure inside of `std::io`. This user, however, will likely no longer use `bitflags!` after I/O reform has landed. To prevent breaking APIs today, this structure remains as-is. Current users of the `bitflags!` macro should add this to their `Cargo.toml`: bitflags = "0.1" and this to their crate root: #[macro_use] extern crate bitflags; Due to the removal of a public macro, this is a: [breaking-change]
1 parent 0296838 commit 34fa70f

File tree

7 files changed

+24
-8
lines changed

7 files changed

+24
-8
lines changed

mk/crates.mk

+5-2
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@
5252
TARGET_CRATES := libc std flate arena term \
5353
serialize getopts collections test rand \
5454
log regex graphviz core rbml alloc \
55-
unicode
55+
unicode rustc_bitflags
5656
RUSTC_CRATES := rustc rustc_typeck rustc_borrowck rustc_resolve rustc_driver \
5757
rustc_trans rustc_back rustc_llvm rustc_privacy
5858
HOST_CRATES := syntax $(RUSTC_CRATES) rustdoc fmt_macros
@@ -64,7 +64,8 @@ DEPS_libc := core
6464
DEPS_unicode := core
6565
DEPS_alloc := core libc native:jemalloc
6666
DEPS_std := core libc rand alloc collections unicode \
67-
native:rust_builtin native:backtrace native:rustrt_native
67+
native:rust_builtin native:backtrace native:rustrt_native \
68+
rustc_bitflags
6869
DEPS_graphviz := std
6970
DEPS_syntax := std term serialize log fmt_macros arena libc
7071
DEPS_rustc_driver := arena flate getopts graphviz libc rustc rustc_back rustc_borrowck \
@@ -83,6 +84,7 @@ DEPS_rustc_llvm := native:rustllvm libc std
8384
DEPS_rustc_back := std syntax rustc_llvm flate log libc
8485
DEPS_rustdoc := rustc rustc_driver native:hoedown serialize getopts \
8586
test
87+
DEPS_rustc_bitflags := core
8688
DEPS_flate := std native:miniz
8789
DEPS_arena := std
8890
DEPS_graphviz := std
@@ -114,6 +116,7 @@ ONLY_RLIB_alloc := 1
114116
ONLY_RLIB_rand := 1
115117
ONLY_RLIB_collections := 1
116118
ONLY_RLIB_unicode := 1
119+
ONLY_RLIB_rustc_bitflags := 1
117120

118121
################################################################################
119122
# You should not need to edit below this line

src/librustc/lib.rs

+1
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ extern crate rbml;
4444
extern crate collections;
4545
#[macro_use] extern crate log;
4646
#[macro_use] extern crate syntax;
47+
#[macro_use] #[no_link] extern crate rustc_bitflags;
4748

4849
extern crate "serialize" as rustc_serialize; // used by deriving
4950

src/libstd/bitflags.rs renamed to src/librustc_bitflags/lib.rs

+12-2
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,16 @@
88
// option. This file may not be copied, modified, or distributed
99
// except according to those terms.
1010

11+
#![crate_name = "rustc_bitflags"]
1112
#![unstable]
13+
#![staged_api]
14+
#![crate_type = "rlib"]
15+
#![no_std]
1216

1317
//! A typesafe bitmask flag generator.
1418
19+
#[cfg(test)] #[macro_use] extern crate std;
20+
1521
/// The `bitflags!` macro generates a `struct` that holds a set of C-style
1622
/// bitmask flags. It is useful for creating typesafe wrappers for C APIs.
1723
///
@@ -21,6 +27,8 @@
2127
/// # Example
2228
///
2329
/// ```{.rust}
30+
/// #[macro_use] extern crate rustc_bitflags;
31+
///
2432
/// bitflags! {
2533
/// flags Flags: u32 {
2634
/// const FLAG_A = 0b00000001,
@@ -45,6 +53,8 @@
4553
/// The generated `struct`s can also be extended with type and trait implementations:
4654
///
4755
/// ```{.rust}
56+
/// #[macro_use] extern crate rustc_bitflags;
57+
///
4858
/// use std::fmt;
4959
///
5060
/// bitflags! {
@@ -273,8 +283,8 @@ macro_rules! bitflags {
273283
#[cfg(test)]
274284
#[allow(non_upper_case_globals)]
275285
mod tests {
276-
use hash::{self, SipHasher};
277-
use option::Option::{Some, None};
286+
use std::hash::{self, SipHasher};
287+
use std::option::Option::{Some, None};
278288

279289
bitflags! {
280290
#[doc = "> The first principle is that you must not fool yourself — and"]

src/librustc_llvm/lib.rs

+1
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
#![allow(unknown_features)] #![feature(int_uint)]
2929

3030
extern crate libc;
31+
#[macro_use] #[no_link] extern crate rustc_bitflags;
3132

3233
pub use self::OtherAttribute::*;
3334
pub use self::SpecialAttribute::*;

src/librustc_resolve/lib.rs

+1
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323

2424
#[macro_use] extern crate log;
2525
#[macro_use] extern crate syntax;
26+
#[macro_use] #[no_link] extern crate rustc_bitflags;
2627

2728
extern crate rustc;
2829

src/libstd/lib.rs

+3-4
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@
111111
#![feature(box_syntax)]
112112
#![feature(old_impl_check)]
113113
#![feature(optin_builtin_traits)]
114-
#![allow(unknown_features)] #![feature(int_uint)]
114+
#![feature(int_uint)]
115115

116116
// Don't link to std. We are std.
117117
#![no_std]
@@ -136,6 +136,8 @@ extern crate alloc;
136136
extern crate unicode;
137137
extern crate libc;
138138

139+
#[macro_use] #[no_link] extern crate rustc_bitflags;
140+
139141
// Make std testable by not duplicating lang items. See #2912
140142
#[cfg(test)] extern crate "std" as realstd;
141143
#[cfg(test)] pub use realstd::marker;
@@ -181,9 +183,6 @@ pub use unicode::char;
181183
#[macro_use]
182184
mod macros;
183185

184-
#[macro_use]
185-
pub mod bitflags;
186-
187186
mod rtdeps;
188187

189188
/* The Prelude. */

src/libsyntax/lib.rs

+1
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ extern crate serialize;
3535
extern crate term;
3636
extern crate libc;
3737
#[macro_use] extern crate log;
38+
#[macro_use] #[no_link] extern crate rustc_bitflags;
3839

3940
extern crate "serialize" as rustc_serialize; // used by deriving
4041

0 commit comments

Comments
 (0)