Skip to content

Commit 5ec0ea3

Browse files
committed
Make TargetInfo::new infallible
It is not clear why this interface was fallible previously anyway.
1 parent 38280ca commit 5ec0ea3

File tree

2 files changed

+13
-18
lines changed

2 files changed

+13
-18
lines changed

src/clang.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2026,7 +2026,7 @@ pub struct TargetInfo {
20262026

20272027
impl TargetInfo {
20282028
/// Tries to obtain target information from libclang.
2029-
pub fn new(tu: &TranslationUnit) -> Option<Self> {
2029+
pub fn new(tu: &TranslationUnit) -> Self {
20302030
let triple;
20312031
let pointer_width;
20322032
unsafe {
@@ -2037,9 +2037,9 @@ impl TargetInfo {
20372037
}
20382038
assert!(pointer_width > 0);
20392039
assert_eq!(pointer_width % 8, 0);
2040-
Some(TargetInfo {
2040+
TargetInfo {
20412041
triple,
20422042
pointer_width: pointer_width as usize,
2043-
})
2043+
}
20442044
}
20452045
}

src/ir/context.rs

Lines changed: 10 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -368,7 +368,7 @@ pub struct BindgenContext {
368368
translation_unit: clang::TranslationUnit,
369369

370370
/// Target information that can be useful for some stuff.
371-
target_info: Option<clang::TargetInfo>,
371+
target_info: clang::TargetInfo,
372372

373373
/// The options given by the user via cli or other medium.
374374
options: BindgenOptions,
@@ -583,16 +583,14 @@ If you encounter an error missing from this list, please file an issue or a PR!"
583583

584584
#[cfg(debug_assertions)]
585585
{
586-
if let Some(ref ti) = target_info {
587-
if effective_target == HOST_TARGET {
588-
assert_eq!(
589-
ti.pointer_width / 8,
590-
mem::size_of::<*mut ()>(),
591-
"{:?} {:?}",
592-
effective_target,
593-
HOST_TARGET
594-
);
595-
}
586+
if effective_target == HOST_TARGET {
587+
assert_eq!(
588+
target_info.pointer_width / 8,
589+
mem::size_of::<*mut ()>(),
590+
"{:?} {:?}",
591+
effective_target,
592+
HOST_TARGET
593+
);
596594
}
597595
}
598596

@@ -645,10 +643,7 @@ If you encounter an error missing from this list, please file an issue or a PR!"
645643
/// Returns the pointer width to use for the target for the current
646644
/// translation.
647645
pub fn target_pointer_size(&self) -> usize {
648-
if let Some(ref ti) = self.target_info {
649-
return ti.pointer_width / 8;
650-
}
651-
mem::size_of::<*mut ()>()
646+
return self.target_info.pointer_width / 8;
652647
}
653648

654649
/// Get the stack of partially parsed types that we are in the middle of

0 commit comments

Comments
 (0)