Skip to content

Commit 604c58a

Browse files
committed
transpile: add comments clarifying the different but duplicative nature of the conservative and experimental const expr checks
1 parent 8b6aad4 commit 604c58a

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
@@ -2140,6 +2140,13 @@ impl<'c> Translation<'c> {
21402140
TranslateMacros::Conservative => {
21412141
// TODO We still allow `CExprKind::ExplicitCast`s
21422142
// even though they're broken (see #853).
2143+
2144+
// This is a top-down, complete, pessimistic/conservative analysis.
2145+
// This is somewhat duplicative of `fn convert_expr` simply checking
2146+
// `ExprContext::is_const` and returning errors where the expr is not `const`,
2147+
// which is an incomplete analysis scattered across all of the `fn expr_*`s.
2148+
// That's what's done for `TranslateMacros::Experimental`,
2149+
// as opposed to the conservative analysis done here for `TranslateMacros::Conservative`.
21432150
if !self.ast_context.is_const_expr(expr_id) {
21442151
Err(format_err!("non-const expr {expr_id:?}"))?;
21452152
}

0 commit comments

Comments
 (0)