Skip to content

Commit 0b41c3f

Browse files
committed
Make header parsing slightly more robust
1 parent d856c6a commit 0b41c3f

File tree

3 files changed

+7
-6
lines changed

3 files changed

+7
-6
lines changed

crates/header-translator/src/id.rs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -291,9 +291,7 @@ impl<N: ToOptionString> ItemIdentifier<N> {
291291
pub fn with_name(name: N, entity: &Entity<'_>, _context: &Context<'_>) -> Self {
292292
let file = entity
293293
.get_location()
294-
.unwrap_or_else(|| panic!("no entity location: {entity:?}"))
295-
.get_expansion_location()
296-
.file;
294+
.and_then(|loc| loc.get_expansion_location().file);
297295

298296
let mut location = if let Some(file) = file {
299297
Location::from_file(file)

crates/header-translator/src/rust_type.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2342,7 +2342,10 @@ impl Ty {
23422342
} if pointee.is_object_like() => {
23432343
write!(f, "{}", pointee.behind_pointer())
23442344
}
2345-
Self::IncompleteArray { .. } => unimplemented!("incomplete array in typedef"),
2345+
Self::IncompleteArray { .. } => {
2346+
error!("incomplete array in typedef");
2347+
write!(f, "{}", self.behind_pointer())
2348+
}
23462349
// We mark `typedefs` as-if behind a pointer, as even though
23472350
// typedefs are _usually_ to a pointer of the type (handled
23482351
// above), we sometimes have typedefs to the inner type as well.

crates/header-translator/src/stmt.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1285,7 +1285,7 @@ impl Stmt {
12851285
}
12861286
EntityKind::FieldDecl => {
12871287
drop(span);
1288-
let name = entity.get_name().expect("struct/union field name");
1288+
let name = entity.get_name().unwrap_or_else(|| "__unknown__".into());
12891289
let _span = debug_span!("field", name).entered();
12901290

12911291
let ty = entity.get_type().expect("struct/union field type");
@@ -1553,7 +1553,7 @@ impl Stmt {
15531553
error!(?value, ?entity, "got variable value twice");
15541554
}
15551555
}
1556-
_ => panic!("unknown vardecl child in {id:?}: {entity:?}"),
1556+
_ => error!(?id, ?entity, "unknown vardecl child"),
15571557
});
15581558

15591559
vec![Self::VarDecl {

0 commit comments

Comments
 (0)