Skip to content

Commit 4d21d69

Browse files
author
Gabi Ganam
committed
Fix generated constants: f64::INFINITY, f64::NEG_ INFINITY, f64::NAN
rust-lang#2853
1 parent 38c9f24 commit 4d21d69

File tree

2 files changed

+25
-14
lines changed

2 files changed

+25
-14
lines changed

bindgen/codegen/helpers.rs

+23-13
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,7 @@ pub(crate) mod ast_ty {
131131
use crate::ir::function::FunctionSig;
132132
use crate::ir::layout::Layout;
133133
use crate::ir::ty::{FloatKind, IntKind};
134+
use crate::RustTarget;
134135
use proc_macro2::TokenStream;
135136
use std::str::FromStr;
136137

@@ -312,35 +313,44 @@ pub(crate) mod ast_ty {
312313
}
313314

314315
let prefix = ctx.trait_prefix();
316+
let rust_target = ctx.options().rust_target;
315317

316318
if f.is_nan() {
317-
return Ok(quote! {
318-
if rust_target >= RustTarget::Stable_1_43 {
319+
let tokens = if rust_target >= RustTarget::Stable_1_43 {
320+
quote! {
319321
f64::NAN
320-
} else {
322+
}
323+
} else {
324+
quote! {
321325
::#prefix::f64::NAN
322326
}
323-
});
327+
};
328+
return Ok(tokens);
324329
}
325330

326331
if f.is_infinite() {
327-
return Ok(if f.is_sign_positive() {
328-
quote! {
329-
if rust_target >= RustTarget::Stable_1_43 {
332+
let tokens = if f.is_sign_positive() {
333+
if rust_target >= RustTarget::Stable_1_43 {
334+
quote! {
330335
f64::INFINITY
331-
} else {
336+
}
337+
} else {
338+
quote! {
332339
::#prefix::f64::INFINITY
333340
}
334341
}
335-
} else {
336-
quote! {
337-
if rust_target >= RustTarget::Stable_1_43 {
342+
} else { // sign_negative
343+
if rust_target >= RustTarget::Stable_1_43 {
344+
quote! {
338345
f64::NEG_INFINITY
339-
} else {
346+
}
347+
} else {
348+
quote! {
340349
::#prefix::f64::NEG_INFINITY
341350
}
342351
}
343-
});
352+
};
353+
return Ok(tokens);
344354
}
345355

346356
warn!("Unknown non-finite float number: {:?}", f);

bindgen/features.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,8 @@ define_rust_targets! {
106106
Stable_1_64(64) => { core_ffi_c: #94503 },
107107
Stable_1_59(59) => { const_cstr: #54745 },
108108
Stable_1_47(47) => { larger_arrays: #74060 },
109-
Stable_1_40(40) => { non_exhaustive: #44109 },
109+
Stable_1_43(43) => { non_exhaustive: #44109 },
110+
Stable_1_40(40) => {},
110111
Stable_1_36(36) => { maybe_uninit: #60445 },
111112
Stable_1_33(33) => { repr_packed_n: #57049 },
112113
#[deprecated]

0 commit comments

Comments
 (0)