Skip to content

Commit be2f59c

Browse files
authored
Fix unused_code warnings without experimental (#2482)
This fixes the `unused_code` warnings that appear when compiling `bindgen` without the `experimental` and `__cli` features.
1 parent 0f1a404 commit be2f59c

File tree

6 files changed

+26
-24
lines changed

6 files changed

+26
-24
lines changed

bindgen/codegen/mod.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4338,9 +4338,9 @@ impl CodeGenerator for Function {
43384338

43394339
fn unsupported_abi_diagnostic<const VARIADIC: bool>(
43404340
fn_name: &str,
4341-
location: Option<&crate::clang::SourceLocation>,
4341+
_location: Option<&crate::clang::SourceLocation>,
43424342
abi: &str,
4343-
ctx: &BindgenContext,
4343+
_ctx: &BindgenContext,
43444344
) {
43454345
warn!(
43464346
"Skipping {}function `{}` with the {} ABI that isn't supported by the configured Rust target",
@@ -4350,7 +4350,7 @@ fn unsupported_abi_diagnostic<const VARIADIC: bool>(
43504350
);
43514351

43524352
#[cfg(feature = "experimental")]
4353-
if ctx.options().emit_diagnostics {
4353+
if _ctx.options().emit_diagnostics {
43544354
use crate::diagnostics::{get_line, Diagnostic, Level, Slice};
43554355

43564356
let mut diag = Diagnostic::default();
@@ -4361,9 +4361,9 @@ fn unsupported_abi_diagnostic<const VARIADIC: bool>(
43614361
if VARIADIC { "variadic " } else { "" },
43624362
abi), Level::Warn)
43634363
.add_annotation("No code will be generated for this function.", Level::Warn)
4364-
.add_annotation(format!("The configured Rust version is {}.", String::from(ctx.options().rust_target)), Level::Note);
4364+
.add_annotation(format!("The configured Rust version is {}.", String::from(_ctx.options().rust_target)), Level::Note);
43654365

4366-
if let Some(loc) = location {
4366+
if let Some(loc) = _location {
43674367
let (file, line, col, _) = loc.location();
43684368

43694369
if let Some(filename) = file.name() {

bindgen/ir/context.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2960,11 +2960,11 @@ impl TemplateParameters for PartialType {
29602960
}
29612961
}
29622962

2963-
fn unused_regex_diagnostic(item: &str, name: &str, ctx: &BindgenContext) {
2963+
fn unused_regex_diagnostic(item: &str, name: &str, _ctx: &BindgenContext) {
29642964
warn!("unused option: {} {}", name, item);
29652965

29662966
#[cfg(feature = "experimental")]
2967-
if ctx.options().emit_diagnostics {
2967+
if _ctx.options().emit_diagnostics {
29682968
use crate::diagnostics::{Diagnostic, Level};
29692969

29702970
Diagnostic::default()

bindgen/ir/var.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -443,8 +443,8 @@ fn get_integer_literal_from_cursor(cursor: &clang::Cursor) -> Option<i64> {
443443

444444
fn duplicated_macro_diagnostic(
445445
macro_name: &str,
446-
location: crate::clang::SourceLocation,
447-
ctx: &BindgenContext,
446+
_location: crate::clang::SourceLocation,
447+
_ctx: &BindgenContext,
448448
) {
449449
warn!("Duplicated macro definition: {}", macro_name);
450450

@@ -462,14 +462,14 @@ fn duplicated_macro_diagnostic(
462462
//
463463
// Will trigger this message even though there's nothing wrong with it.
464464
#[allow(clippy::overly_complex_bool_expr)]
465-
if false && ctx.options().emit_diagnostics {
465+
if false && _ctx.options().emit_diagnostics {
466466
use crate::diagnostics::{get_line, Diagnostic, Level, Slice};
467467
use std::borrow::Cow;
468468

469469
let mut slice = Slice::default();
470470
let mut source = Cow::from(macro_name);
471471

472-
let (file, line, col, _) = location.location();
472+
let (file, line, col, _) = _location.location();
473473
if let Some(filename) = file.name() {
474474
if let Ok(Some(code)) = get_line(&filename, line) {
475475
source = code.into();

bindgen/lib.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -407,7 +407,6 @@ impl Builder {
407407
impl BindgenOptions {
408408
fn build(&mut self) {
409409
const REGEX_SETS_LEN: usize = 27;
410-
let sets_len = REGEX_SETS_LEN + self.abi_overrides.len();
411410

412411
let regex_sets: [_; REGEX_SETS_LEN] = [
413412
&mut self.allowlisted_vars,
@@ -442,8 +441,9 @@ impl BindgenOptions {
442441
let record_matches = self.record_matches;
443442
#[cfg(feature = "experimental")]
444443
{
444+
let sets_len = REGEX_SETS_LEN + self.abi_overrides.len();
445445
let names = if self.emit_diagnostics {
446-
<[&str; 27]>::into_iter([
446+
<[&str; REGEX_SETS_LEN]>::into_iter([
447447
"--blocklist-type",
448448
"--blocklist-function",
449449
"--blocklist-item",
@@ -544,12 +544,12 @@ impl BindgenOptions {
544544
}
545545
}
546546

547-
fn deprecated_target_diagnostic(target: RustTarget, options: &BindgenOptions) {
547+
fn deprecated_target_diagnostic(target: RustTarget, _options: &BindgenOptions) {
548548
let target = String::from(target);
549549
warn!("The {} Rust target is deprecated. If you have a good reason to use this target please report it at https://github.com/rust-lang/rust-bindgen/issues", target,);
550550

551551
#[cfg(feature = "experimental")]
552-
if options.emit_diagnostics {
552+
if _options.emit_diagnostics {
553553
use crate::diagnostics::{Diagnostic, Level};
554554

555555
let mut diagnostic = Diagnostic::default();
@@ -1013,11 +1013,11 @@ impl Bindings {
10131013
}
10141014
}
10151015

1016-
fn rustfmt_non_fatal_error_diagnostic(msg: &str, options: &BindgenOptions) {
1016+
fn rustfmt_non_fatal_error_diagnostic(msg: &str, _options: &BindgenOptions) {
10171017
warn!("{}", msg);
10181018

10191019
#[cfg(feature = "experimental")]
1020-
if options.emit_diagnostics {
1020+
if _options.emit_diagnostics {
10211021
use crate::diagnostics::{Diagnostic, Level};
10221022

10231023
Diagnostic::default()

bindgen/options/mod.rs

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,9 @@ use crate::HashMap;
2121
use crate::DEFAULT_ANON_FIELDS_PREFIX;
2222

2323
use std::env;
24-
use std::path::{Path, PathBuf};
24+
#[cfg(feature = "experimental")]
25+
use std::path::Path;
26+
use std::path::PathBuf;
2527
use std::rc::Rc;
2628

2729
use as_args::AsArgs;
@@ -1195,10 +1197,10 @@ options! {
11951197
self
11961198
}
11971199
},
1198-
as_args: |parse_callbacks, args| {
1200+
as_args: |_callbacks, _args| {
11991201
#[cfg(feature = "__cli")]
1200-
for callbacks in parse_callbacks {
1201-
args.extend(callbacks.cli_args());
1202+
for cb in _callbacks {
1203+
_args.extend(cb.cli_args());
12021204
}
12031205
},
12041206
},

bindgen/regex_set.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -96,16 +96,16 @@ impl RegexSet {
9696
fn build_inner(
9797
&mut self,
9898
record_matches: bool,
99-
name: Option<&'static str>,
99+
_name: Option<&'static str>,
100100
) {
101101
let items = self.items.iter().map(|item| format!("^({})$", item));
102102
self.record_matches = record_matches;
103103
self.set = match RxSet::new(items) {
104104
Ok(x) => Some(x),
105105
Err(e) => {
106106
warn!("Invalid regex in {:?}: {:?}", self.items, e);
107-
if let Some(name) = name {
108-
#[cfg(feature = "experimental")]
107+
#[cfg(feature = "experimental")]
108+
if let Some(name) = _name {
109109
invalid_regex_warning(self, e, name);
110110
}
111111
None

0 commit comments

Comments
 (0)