Skip to content

Commit d2977e8

Browse files
committed
feat: Raise error on Cython on panic with if cfg!()
1 parent f34453d commit d2977e8

File tree

1 file changed

+12
-3
lines changed

1 file changed

+12
-3
lines changed

src/bindgen/language_backend/cython.rs

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
use crate::bindgen::ir::{
22
to_known_assoc_constant, ConditionWrite, DeprecatedNoteKind, Documentation, Enum, EnumVariant,
3-
Field, Item, Literal, OpaqueItem, ReprAlign, Static, Struct, ToCondition, Type, Typedef, Union,
3+
Field, Item, Literal, OpaqueItem, PanicMacroKind, ReprAlign, Static, Struct, ToCondition, Type,
4+
Typedef, Union,
45
};
56
use crate::bindgen::language_backend::LanguageBackend;
67
use crate::bindgen::writer::{ListType, SourceWriter};
@@ -404,8 +405,16 @@ impl LanguageBackend for CythonLanguageBackend<'_> {
404405
}
405406
write!(out, " }}");
406407
}
407-
Literal::PanicMacro(_) => {
408-
warn!("SKIP: Not implemented")
408+
Literal::PanicMacro(kind) => {
409+
out.write("raise TypeError(");
410+
match kind {
411+
PanicMacroKind::Todo => write!(out, r#""not yet implemented""#),
412+
PanicMacroKind::Unreachable => write!(out, r#""reached unreachable code""#),
413+
PanicMacroKind::Unimplemented => write!(out, r#""not implemented""#),
414+
// Debug print of &str and String already add the `"`
415+
PanicMacroKind::Panic(msg) => write!(out, "{:?}", msg),
416+
}
417+
out.write(")");
409418
}
410419
}
411420
}

0 commit comments

Comments
 (0)