Skip to content

Commit 27e2c10

Browse files
author
bors-servo
authored
Auto merge of rust-lang#763 - rigelk:757-unstable-defaults, r=emilio,fitzgen
switch defaults from generating unstable Rust to generating stable Rust As said in the issue: - changing the Builder::no_unstable_rust method to the Builder::unstable_rust method - changing the --no-unstable-rust flag to a --unstable-rust flag in src/options.rs - changing bindgen-flags header in the test headers to remove the --no-unstable-rust flag - removing --no-unstable-rust flag in ./test/test-one.sh Fixes rust-lang#757 r? @fitzgen
2 parents 77d6962 + 41db162 commit 27e2c10

File tree

12 files changed

+18
-26
lines changed

12 files changed

+18
-26
lines changed

bindgen-integration/build.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@ fn main() {
2828
let macros = Arc::new(RwLock::new(HashSet::new()));
2929

3030
let bindings = Builder::default()
31-
.no_unstable_rust()
3231
.enable_cxx_namespaces()
3332
.raw_line("pub use self::root::*;")
3433
.header("cpp/Test.h")

book/src/tutorial-3.md

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,6 @@ fn main() {
2222
// to bindgen, and lets you build up options for
2323
// the resulting bindings.
2424
let bindings = bindgen::Builder::default()
25-
// Do not generate unstable Rust code that
26-
// requires a nightly rustc and enabling
27-
// unstable features.
28-
.no_unstable_rust()
2925
// The input header we would like to generate
3026
// bindings for.
3127
.header("wrapper.h")

book/src/using-unions.md

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
# Using the Union Types Generated by Bindgen
22

3-
**NOTE:** As of Rust version 1.17, Rust does not have a stable `union` type. Issue [#32836](https://github.com/rust-lang/rust/issues/32836) tracks the stabilization of a `union` type in Rust. By default, bindgen will generate the preliminary unstable `union` type, unless the flag `--no-unstable-rust` flag is used.
3+
**NOTE:** As of Rust version 1.17, Rust does not have a stable `union` type. Issue [#32836](https://github.com/rust-lang/rust/issues/32836) tracks the stabilization of a `union` type in Rust.
4+
5+
By using the flag `--unstable-rust`, bindgen will generate the preliminary unstable `union` type.
46

57
In general, most interactions with unions (either reading or writing) are unsafe.
68

@@ -29,12 +31,12 @@ typedef union {
2931

3032
### Library
3133

32-
* [`bindgen::Builder::no_unstable_rust()`](https://docs.rs/bindgen/0.25.3/bindgen/struct.Builder.html#method.no_unstable_rust)
34+
* [`bindgen::Builder::unstable_rust()`](https://docs.rs/bindgen/0.25.3/bindgen/struct.Builder.html#method.unstable_rust)
3335
* [`bindgen::Builder::derive_default()`](https://docs.rs/bindgen/0.25.3/bindgen/struct.Builder.html#method.derive_default)
3436

3537
### Command Line
3638

37-
* `--no-unstable-rust`
39+
* `--unstable-rust`
3840
* `--with-derive-default`
3941

4042
## Using the unstable `union` version
@@ -129,4 +131,4 @@ error[E0308]: mismatched types
129131
|
130132
= note: expected type `bindings::__BindgenUnionField<bindings::alpha_t>`
131133
found type `bindings::alpha_t`
132-
```
134+
```

src/lib.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -333,7 +333,7 @@ impl Builder {
333333
}
334334

335335
if !self.options.unstable_rust {
336-
output_vector.push("--no-unstable-rust".into());
336+
output_vector.push("--unstable-rust".into());
337337
}
338338

339339
self.options
@@ -736,8 +736,8 @@ impl Builder {
736736
}
737737

738738
/// Avoid generating any unstable Rust, such as Rust unions, in the generated bindings.
739-
pub fn no_unstable_rust(mut self) -> Builder {
740-
self.options.unstable_rust = false;
739+
pub fn unstable_rust(mut self, doit: bool) -> Self {
740+
self.options.unstable_rust = doit;
741741
self
742742
}
743743

@@ -959,7 +959,7 @@ impl Default for BindgenOptions {
959959
derive_default: false,
960960
enable_cxx_namespaces: false,
961961
disable_name_namespacing: false,
962-
unstable_rust: true,
962+
unstable_rust: false,
963963
use_core: false,
964964
ctypes_prefix: None,
965965
namespaced_constants: true,

src/options.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -135,9 +135,9 @@ pub fn builder_from_flags<I>
135135
Arg::with_name("no-prepend-enum-name")
136136
.long("no-prepend-enum-name")
137137
.help("Do not prepend the enum name to bitfield or constant variants."),
138-
Arg::with_name("no-unstable-rust")
139-
.long("no-unstable-rust")
140-
.help("Do not generate unstable Rust code.")
138+
Arg::with_name("unstable-rust")
139+
.long("unstable-rust")
140+
.help("Generate unstable Rust code.")
141141
.multiple(true), // FIXME: Pass legacy test suite
142142
Arg::with_name("opaque-type")
143143
.long("opaque-type")
@@ -325,8 +325,8 @@ pub fn builder_from_flags<I>
325325
builder = builder.ignore_methods();
326326
}
327327

328-
if matches.is_present("no-unstable-rust") {
329-
builder = builder.no_unstable_rust();
328+
if matches.is_present("unstable-rust") {
329+
builder = builder.unstable_rust(true);
330330
}
331331

332332
if matches.is_present("no-convert-floats") {

tests/headers/jsval_layout_opaque.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// bindgen-flags: --no-unstable-rust -- -std=c++11
1+
// bindgen-flags: -- -std=c++11
22

33
/**
44
* These typedefs are hacky, but keep our tests consistent across 64-bit

tests/headers/only_bitfields.hpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
// bindgen-flags: --no-unstable-rust
21
class C {
32
bool a: 1;
43
bool b: 7;

tests/headers/struct_with_bitfields.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
// bindgen-flags: --no-unstable-rust
21
struct bitfield {
32
unsigned short
43
a :1,

tests/headers/union_with_anon_struct_bitfield.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
// bindgen-flags: --no-unstable-rust
21
union foo {
32
int a;
43
struct {

tests/headers/weird_bitfields.hpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
// bindgen-flags: --no-unstable-rust
21
// You can guess where this is taken from...
32
enum nsStyleSVGOpacitySource {
43
eStyleSVGOpacitySource_Normal,

tests/test-one.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ TEST_BINDINGS_BINARY=$(mktemp -t bindings.XXXXXX)
4545
FLAGS="$(grep "// bindgen-flags: " "$TEST" || echo)"
4646
FLAGS="${FLAGS/\/\/ bindgen\-flags:/}"
4747
# Prepend the default flags added in test.rs's `create_bindgen_builder`.
48-
FLAGS="--no-unstable-rust --with-derive-default --raw-line '' --raw-line '#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)]' --raw-line '' $FLAGS"
48+
FLAGS="--with-derive-default --raw-line '' --raw-line '#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)]' --raw-line '' $FLAGS"
4949

5050

5151
eval ./target/debug/bindgen \

tests/tests.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,7 @@ fn create_bindgen_builder(header: &PathBuf) -> Result<Option<Builder>, Error> {
146146
.chain(flags.into_iter());
147147

148148
builder_from_flags(args)
149-
.map(|(builder, _, _)| Some(builder.no_unstable_rust()))
149+
.map(|(builder, _, _)| Some(builder))
150150
}
151151

152152
macro_rules! test_header {
@@ -177,7 +177,6 @@ include!(concat!(env!("OUT_DIR"), "/tests.rs"));
177177
fn test_header_contents() {
178178
let bindings = builder()
179179
.header_contents("test.h", "int foo(const char* a);")
180-
.no_unstable_rust()
181180
.generate()
182181
.unwrap()
183182
.to_string();

0 commit comments

Comments
 (0)