Skip to content

Commit cdb7bd0

Browse files
committed
transpile: add comments clarifying the different but duplicative nature of the conservative and experimental const expr checks
1 parent 46a9b91 commit cdb7bd0

File tree

2 files changed

+9
-0
lines changed

2 files changed

+9
-0
lines changed

c2rust-transpile/src/c_ast/mod.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -626,6 +626,8 @@ impl TypedAstContext {
626626

627627
/// Pessimistically try to check if an expression is `const`.
628628
/// If it's not, or we can't tell if it is, return `false`.
629+
///
630+
/// This should be a top-down, complete, pessimistic analysis.
629631
pub fn is_const_expr(&self, expr: CExprId) -> bool {
630632
let is_const = |expr| self.is_const_expr(expr);
631633

c2rust-transpile/src/translator/mod.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2128,6 +2128,13 @@ impl<'c> Translation<'c> {
21282128
TranslateMacros::Conservative => {
21292129
// TODO We still allow `CExprKind::ExplicitCast`s
21302130
// even though they're broken (see #853).
2131+
2132+
// This is a top-down, complete, pessimistic/conservative analysis.
2133+
// This is somewhat duplicative of `fn convert_expr` simply checking
2134+
// `ExprContext::is_const` and returning errors where the expr is not `const`,
2135+
// which is an incomplete analysis scattered across all of the `fn expr_*`s.
2136+
// That's what's done for `TranslateMacros::Experimental`,
2137+
// as opposed to the conservative analysis done here for `TranslateMacros::Conservative`.
21312138
if !self.ast_context.is_const_expr(expr_id) {
21322139
Err(format_err!("non-const expr {expr_id:?}"))?;
21332140
}

0 commit comments

Comments
 (0)