File tree Expand file tree Collapse file tree 2 files changed +14
-0
lines changed Expand file tree Collapse file tree 2 files changed +14
-0
lines changed Original file line number Diff line number Diff 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, pessimistic/conservative analysis.
629631 pub fn is_const_expr ( & self , expr : CExprId ) -> bool {
630632 let is_const = |expr| self . is_const_expr ( expr) ;
631633
Original file line number Diff line number Diff line change @@ -2128,6 +2128,18 @@ 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, 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 non-conservative analysis scattered across all of the `fn convert_*`s.
2136+ // That's what's done for `TranslateMacros::Experimental`,
2137+ // as opposed to the conservative analysis done here for `TranslateMacros::Conservative`.
2138+ // When the conservative analysis is incomplete,
2139+ // it won't translate the macro, but the result will compile.
2140+ // But when the non-conservative analysis is incomplete,
2141+ // the resulting code may not transpile,
2142+ // which is why the conservative analysis is used for `TranslateMacros::Conservative`.
21312143 if !self . ast_context . is_const_expr ( expr_id) {
21322144 Err ( format_err ! ( "non-const expr {expr_id:?}" ) ) ?;
21332145 }
You can’t perform that action at this time.
0 commit comments