Skip to content

Commit da942c4

Browse files
author
bors-servo
authored
Auto merge of rust-lang#1000 - pepyakin:hide-bindgen-options, r=fitzgen
Make BindgenOptions private Fixes rust-lang#958 r? @fitzgen
2 parents ab6d51b + e8e6f37 commit da942c4

File tree

3 files changed

+50
-79
lines changed

3 files changed

+50
-79
lines changed

src/ir/context.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -321,7 +321,7 @@ fn find_effective_target(clang_args: &[String]) -> (String, bool) {
321321

322322
impl BindgenContext {
323323
/// Construct the context for the given `options`.
324-
pub fn new(options: BindgenOptions) -> Self {
324+
pub(crate) fn new(options: BindgenOptions) -> Self {
325325
use clang_sys;
326326

327327
// TODO(emilio): Use the CXTargetInfo here when available.
@@ -1795,7 +1795,7 @@ impl BindgenContext {
17951795
}
17961796

17971797
/// Get the options used to configure this bindgen context.
1798-
pub fn options(&self) -> &BindgenOptions {
1798+
pub(crate) fn options(&self) -> &BindgenOptions {
17991799
&self.options
18001800
}
18011801

src/lib.rs

Lines changed: 48 additions & 62 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,6 @@
77
#![deny(missing_docs)]
88
#![deny(warnings)]
99
#![deny(unused_extern_crates)]
10-
// We internally use the deprecated BindgenOptions all over the place. Once we
11-
// remove its `pub` declaration, we can un-deprecate it and remove this pragma.
12-
#![allow(deprecated)]
1310
// To avoid rather annoying warnings when matching with CXCursor_xxx as a
1411
// constant.
1512
#![allow(non_upper_case_globals)]
@@ -1101,152 +1098,149 @@ impl Builder {
11011098
}
11021099

11031100
/// Configuration options for generated bindings.
1104-
///
1105-
/// Deprecated: use a `Builder` instead.
11061101
#[derive(Debug)]
1107-
#[deprecated]
1108-
pub struct BindgenOptions {
1102+
struct BindgenOptions {
11091103
/// The set of types that have been blacklisted and should not appear
11101104
/// anywhere in the generated code.
1111-
pub blacklisted_types: RegexSet,
1105+
blacklisted_types: RegexSet,
11121106

11131107
/// The set of types that should be treated as opaque structures in the
11141108
/// generated code.
1115-
pub opaque_types: RegexSet,
1109+
opaque_types: RegexSet,
11161110

11171111
/// The set of types that we should have bindings for in the generated
11181112
/// code.
11191113
///
11201114
/// This includes all types transitively reachable from any type in this
11211115
/// set. One might think of whitelisted types/vars/functions as GC roots,
11221116
/// and the generated Rust code as including everything that gets marked.
1123-
pub whitelisted_types: RegexSet,
1117+
whitelisted_types: RegexSet,
11241118

11251119
/// Whitelisted functions. See docs for `whitelisted_types` for more.
1126-
pub whitelisted_functions: RegexSet,
1120+
whitelisted_functions: RegexSet,
11271121

11281122
/// Whitelisted variables. See docs for `whitelisted_types` for more.
1129-
pub whitelisted_vars: RegexSet,
1123+
whitelisted_vars: RegexSet,
11301124

11311125
/// The enum patterns to mark an enum as bitfield.
1132-
pub bitfield_enums: RegexSet,
1126+
bitfield_enums: RegexSet,
11331127

11341128
/// The enum patterns to mark an enum as a Rust enum.
1135-
pub rustified_enums: RegexSet,
1129+
rustified_enums: RegexSet,
11361130

11371131
/// The enum patterns to mark an enum as a module of constants.
1138-
pub constified_enum_modules: RegexSet,
1132+
constified_enum_modules: RegexSet,
11391133

11401134
/// Whether we should generate builtins or not.
1141-
pub builtins: bool,
1135+
builtins: bool,
11421136

11431137
/// The set of libraries we should link in the generated Rust code.
1144-
pub links: Vec<(String, LinkType)>,
1138+
links: Vec<(String, LinkType)>,
11451139

11461140
/// True if we should dump the Clang AST for debugging purposes.
1147-
pub emit_ast: bool,
1141+
emit_ast: bool,
11481142

11491143
/// True if we should dump our internal IR for debugging purposes.
1150-
pub emit_ir: bool,
1144+
emit_ir: bool,
11511145

11521146
/// Output graphviz dot file.
1153-
pub emit_ir_graphviz: Option<String>,
1147+
emit_ir_graphviz: Option<String>,
11541148

11551149
/// True if we should emulate C++ namespaces with Rust modules in the
11561150
/// generated bindings.
1157-
pub enable_cxx_namespaces: bool,
1151+
enable_cxx_namespaces: bool,
11581152

11591153
/// True if we should avoid mangling names with namespaces.
1160-
pub disable_name_namespacing: bool,
1154+
disable_name_namespacing: bool,
11611155

11621156
/// True if we should generate layout tests for generated structures.
1163-
pub layout_tests: bool,
1157+
layout_tests: bool,
11641158

11651159
/// True if we should derive Copy trait implementations for C/C++ structures
11661160
/// and types.
1167-
pub derive_copy: bool,
1161+
derive_copy: bool,
11681162

11691163
/// True if we should derive Debug trait implementations for C/C++ structures
11701164
/// and types.
1171-
pub derive_debug: bool,
1165+
derive_debug: bool,
11721166

11731167
/// True if we should implement the Debug trait for C/C++ structures and types
11741168
/// that do not support automatically deriving Debug.
1175-
pub impl_debug: bool,
1169+
impl_debug: bool,
11761170

11771171
/// True if we should derive Default trait implementations for C/C++ structures
11781172
/// and types.
1179-
pub derive_default: bool,
1173+
derive_default: bool,
11801174

11811175
/// True if we should derive Hash trait implementations for C/C++ structures
11821176
/// and types.
1183-
pub derive_hash: bool,
1177+
derive_hash: bool,
11841178

11851179
/// True if we should derive PartialEq trait implementations for C/C++ structures
11861180
/// and types.
1187-
pub derive_partialeq: bool,
1181+
derive_partialeq: bool,
11881182

11891183
/// True if we should derive Eq trait implementations for C/C++ structures
11901184
/// and types.
1191-
pub derive_eq: bool,
1185+
derive_eq: bool,
11921186

11931187
/// True if we should avoid using libstd to use libcore instead.
1194-
pub use_core: bool,
1188+
use_core: bool,
11951189

11961190
/// An optional prefix for the "raw" types, like `c_int`, `c_void`...
1197-
pub ctypes_prefix: Option<String>,
1191+
ctypes_prefix: Option<String>,
11981192

11991193
/// Whether to time the bindgen phases.
1200-
pub time_phases: bool,
1194+
time_phases: bool,
12011195

12021196
/// True if we should generate constant names that are **directly** under
12031197
/// namespaces.
1204-
pub namespaced_constants: bool,
1198+
namespaced_constants: bool,
12051199

12061200
/// True if we should use MSVC name mangling rules.
1207-
pub msvc_mangling: bool,
1201+
msvc_mangling: bool,
12081202

12091203
/// Whether we should convert float types to f32/f64 types.
1210-
pub convert_floats: bool,
1204+
convert_floats: bool,
12111205

12121206
/// The set of raw lines to prepend to the generated Rust code.
1213-
pub raw_lines: Vec<String>,
1207+
raw_lines: Vec<String>,
12141208

12151209
/// The set of arguments to pass straight through to Clang.
1216-
pub clang_args: Vec<String>,
1210+
clang_args: Vec<String>,
12171211

12181212
/// The input header file.
1219-
pub input_header: Option<String>,
1213+
input_header: Option<String>,
12201214

12211215
/// Unsaved files for input.
1222-
pub input_unsaved_files: Vec<clang::UnsavedFile>,
1216+
input_unsaved_files: Vec<clang::UnsavedFile>,
12231217

12241218
/// A user-provided visitor to allow customizing different kinds of
12251219
/// situations.
1226-
pub parse_callbacks: Option<Box<callbacks::ParseCallbacks>>,
1220+
parse_callbacks: Option<Box<callbacks::ParseCallbacks>>,
12271221

12281222
/// Which kind of items should we generate? By default, we'll generate all
12291223
/// of them.
1230-
pub codegen_config: CodegenConfig,
1224+
codegen_config: CodegenConfig,
12311225

12321226
/// Whether to treat inline namespaces conservatively.
12331227
///
12341228
/// See the builder method description for more details.
1235-
pub conservative_inline_namespaces: bool,
1229+
conservative_inline_namespaces: bool,
12361230

12371231
/// Wether to keep documentation comments in the generated output. See the
12381232
/// documentation for more details.
1239-
pub generate_comments: bool,
1233+
generate_comments: bool,
12401234

12411235
/// Whether to generate inline functions. Defaults to false.
1242-
pub generate_inline_functions: bool,
1236+
generate_inline_functions: bool,
12431237

12441238
/// Wether to whitelist types recursively. Defaults to true.
1245-
pub whitelist_recursively: bool,
1239+
whitelist_recursively: bool,
12461240

12471241
/// Intead of emitting 'use objc;' to files generated from objective c files,
12481242
/// generate '#[macro_use] extern crate objc;'
1249-
pub objc_extern_crate: bool,
1243+
objc_extern_crate: bool,
12501244

12511245
/// Whether to use the clang-provided name mangling. This is true and
12521246
/// probably needed for C++ features.
@@ -1255,10 +1249,10 @@ pub struct BindgenOptions {
12551249
/// some cases for non-mangled functions, see [1], so we allow disabling it.
12561250
///
12571251
/// [1]: https://github.com/rust-lang-nursery/rust-bindgen/issues/528
1258-
pub enable_mangling: bool,
1252+
enable_mangling: bool,
12591253

12601254
/// Whether to prepend the enum name to bitfield or constant variants.
1261-
pub prepend_enum_name: bool,
1255+
prepend_enum_name: bool,
12621256

12631257
/// Version of the Rust compiler to target
12641258
rust_target: RustTarget,
@@ -1267,11 +1261,11 @@ pub struct BindgenOptions {
12671261
rust_features: RustFeatures,
12681262

12691263
/// Whether rustfmt should format the generated bindings.
1270-
pub rustfmt_bindings: bool,
1264+
rustfmt_bindings: bool,
12711265

12721266
/// The absolute path to the rustfmt configuration file, if None, the standard rustfmt
12731267
/// options are used.
1274-
pub rustfmt_configuration_file: Option<PathBuf>,
1268+
rustfmt_configuration_file: Option<PathBuf>,
12751269
}
12761270

12771271
/// TODO(emilio): This is sort of a lie (see the error message that results from
@@ -1299,11 +1293,6 @@ impl BindgenOptions {
12991293
self.rust_features = rust_target.into();
13001294
}
13011295

1302-
/// Get target Rust version
1303-
pub fn rust_target(&self) -> RustTarget {
1304-
self.rust_target
1305-
}
1306-
13071296
/// Get features supported by target Rust version
13081297
pub fn rust_features(&self) -> RustFeatures {
13091298
self.rust_features
@@ -1408,10 +1397,7 @@ pub struct Bindings {
14081397

14091398
impl Bindings {
14101399
/// Generate bindings for the given options.
1411-
///
1412-
/// Deprecated - use a `Builder` instead
1413-
#[deprecated]
1414-
pub fn generate(
1400+
pub(crate) fn generate(
14151401
mut options: BindgenOptions,
14161402
) -> Result<Bindings, ()> {
14171403
ensure_libclang_is_loaded();
@@ -1737,8 +1723,8 @@ fn commandline_flag_unit_test_function() {
17371723
//Test 2
17381724
let bindings = ::builder()
17391725
.header("input_header")
1740-
.whitelisted_type("Distinct_Type")
1741-
.whitelisted_function("safe_function");
1726+
.whitelist_type("Distinct_Type")
1727+
.whitelist_function("safe_function");
17421728

17431729
let command_line_flags = bindings.command_line_flags();
17441730
let test_cases = vec![

src/regex_set.rs

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -18,17 +18,6 @@ impl RegexSet {
1818
self.items.is_empty()
1919
}
2020

21-
/// Extend this set with every regex in the iterator.
22-
pub fn extend<I, S>(&mut self, iter: I)
23-
where
24-
I: IntoIterator<Item = S>,
25-
S: AsRef<str>,
26-
{
27-
for s in iter.into_iter() {
28-
self.insert(s)
29-
}
30-
}
31-
3221
/// Insert a new regex into this set.
3322
pub fn insert<S>(&mut self, string: S)
3423
where
@@ -42,10 +31,6 @@ impl RegexSet {
4231
pub fn get_items(&self) -> &[String] {
4332
&self.items[..]
4433
}
45-
/// Returns reference of its field 'set'
46-
pub fn get_set(&self) -> Option<&RxSet> {
47-
self.set.as_ref()
48-
}
4934

5035
/// Construct a RegexSet from the set of entries we've accumulated.
5136
///

0 commit comments

Comments
 (0)