1
- //! This pass checks the HIR bodies in a const context (e.g., `const`, `static`, `const fn`) for
2
- //! structured control flow (e.g. `if`, `while`), which is forbidden in a const context.
1
+ //! This pass checks HIR bodies that may be evaluated at compile-time (e.g., `const`, `static`,
2
+ //! `const fn`) for structured control flow (e.g. `if`, `while`), which is forbidden in a const
3
+ //! context.
3
4
//!
4
5
//! By the time the MIR const-checker runs, these high-level constructs have been lowered to
5
6
//! control-flow primitives (e.g., `Goto`, `SwitchInt`), making it tough to properly attribute
@@ -98,7 +99,7 @@ impl<'tcx> CheckConstVisitor<'tcx> {
98
99
span_err ! ( self . sess, span, E0744 , "`{}` is not allowed in a `{}`" , bad_op, const_kind) ;
99
100
}
100
101
101
- /// Saves the parent `const_kind` before visiting a nested `Body ` and restores it afterwards.
102
+ /// Saves the parent `const_kind` before calling `f ` and restores it afterwards.
102
103
fn recurse_into ( & mut self , kind : Option < ConstKind > , f : impl FnOnce ( & mut Self ) ) {
103
104
let parent_kind = self . const_kind ;
104
105
self . const_kind = kind;
@@ -124,7 +125,7 @@ impl<'tcx> Visitor<'tcx> for CheckConstVisitor<'tcx> {
124
125
125
126
fn visit_expr ( & mut self , e : & ' tcx hir:: Expr ) {
126
127
match & e. kind {
127
- // Skip these checks if the current item is not const.
128
+ // Skip the following checks if we are not currently in a const context .
128
129
_ if self . const_kind . is_none ( ) => { }
129
130
130
131
hir:: ExprKind :: Loop ( _, _, source) => {
0 commit comments