Skip to content

Commit 8a88602

Browse files
committed
Make TargetInfo::new infallible
It is not clear why this interface was fallible previously anyway.
1 parent aa06b0e commit 8a88602

File tree

2 files changed

+6
-12
lines changed

2 files changed

+6
-12
lines changed

src/clang.rs

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

20662066
impl TargetInfo {
20672067
/// Tries to obtain target information from libclang.
2068-
pub fn new(tu: &TranslationUnit) -> Option<Self> {
2068+
pub fn new(tu: &TranslationUnit) -> Self {
20692069
let triple;
20702070
let pointer_width;
20712071
unsafe {
@@ -2076,9 +2076,9 @@ impl TargetInfo {
20762076
}
20772077
assert!(pointer_width > 0);
20782078
assert_eq!(pointer_width % 8, 0);
2079-
Some(TargetInfo {
2079+
TargetInfo {
20802080
triple,
20812081
pointer_width: pointer_width as usize,
2082-
})
2082+
}
20832083
}
20842084
}

src/ir/context.rs

Lines changed: 3 additions & 9 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,
@@ -584,10 +584,7 @@ If you encounter an error missing from this list, please file an issue or a PR!"
584584

585585
/// Returns `true` if the target architecture is wasm32
586586
pub fn is_target_wasm32(&self) -> bool {
587-
match self.target_info {
588-
Some(ref ti) => ti.triple.starts_with("wasm32-"),
589-
None => false,
590-
}
587+
self.target_info.triple.starts_with("wasm32-")
591588
}
592589

593590
/// Creates a timer for the current bindgen phase. If time_phases is `true`,
@@ -600,10 +597,7 @@ If you encounter an error missing from this list, please file an issue or a PR!"
600597
/// Returns the pointer width to use for the target for the current
601598
/// translation.
602599
pub fn target_pointer_size(&self) -> usize {
603-
if let Some(ref ti) = self.target_info {
604-
return ti.pointer_width / 8;
605-
}
606-
mem::size_of::<*mut ()>()
600+
return self.target_info.pointer_width / 8;
607601
}
608602

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

0 commit comments

Comments
 (0)