Skip to content

Commit feb8ca7

Browse files
committed
Minor nits
1 parent acb37ce commit feb8ca7

File tree

1 file changed

+14
-1
lines changed

1 file changed

+14
-1
lines changed

src/librustc/middle/check_const.rs

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,9 @@ enum Mode {
8181
Const,
8282
Static,
8383
StaticMut,
84+
85+
// NDM a better name or at least a comment. I kind of like something like "Code", but mainly I think
86+
// we need a comment saying: "An expression that occurs outside of any const or static declaration."
8487
Var,
8588
}
8689

@@ -131,6 +134,7 @@ impl<'a, 'tcx> CheckCrateVisitor<'a, 'tcx> {
131134
})
132135
}
133136

137+
// NDM Nit: can we rename this to "add_qualif" or something?
134138
fn qualif(&mut self, qualif: ConstQualif) {
135139
self.qualif = self.qualif | qualif;
136140
}
@@ -407,6 +411,7 @@ fn check_expr<'a, 'tcx>(v: &mut CheckCrateVisitor<'a, 'tcx>,
407411
ty::ty_ptr(_) => {
408412
// This shouldn't be allowed in constants at all.
409413
v.qualif(NOT_CONST);
414+
// NDM how come we don't check and report an error here?
410415
}
411416
_ => {}
412417
}
@@ -453,8 +458,14 @@ fn check_expr<'a, 'tcx>(v: &mut CheckCrateVisitor<'a, 'tcx>,
453458
v.qualif(NON_ZERO_SIZED);
454459
}
455460

461+
// NDM can we rewrite this to match on v.mode? It's
462+
// not clear to me e.g. what should happen if v.mode
463+
// == Mode::Var, and if new modes are added, these
464+
// `if` checks will hide cases.
465+
456466
Some(def::DefStatic(..)) if v.mode == Mode::Static ||
457467
v.mode == Mode::StaticMut => {}
468+
// NDM do we ... not want NOT_CONST here? Not matter?
458469

459470
Some(def::DefStatic(..)) if v.mode == Mode::Const => {
460471
span_err!(v.tcx.sess, e.span, E0013,
@@ -467,6 +478,7 @@ fn check_expr<'a, 'tcx>(v: &mut CheckCrateVisitor<'a, 'tcx>,
467478
if let ast::ItemConst(_, ref expr) = const_item.node {
468479
Some(&**expr)
469480
} else {
481+
// NDM when would this ever be None here? isn't this a case for "bug()"?
470482
None
471483
}
472484
} else {
@@ -565,6 +577,7 @@ fn check_expr<'a, 'tcx>(v: &mut CheckCrateVisitor<'a, 'tcx>,
565577

566578
ast::ExprClosure(..) => {
567579
if ty::with_freevars(v.tcx, e.id, |fv| !fv.is_empty()) {
580+
// NDM where is this enforced? can we add a comment specifying that?
568581
assert!(v.mode == Mode::Var,
569582
"global closures can't capture anything");
570583
v.qualif(NOT_CONST);
@@ -725,4 +738,4 @@ impl<'a, 'tcx> euv::Delegate<'tcx> for CheckCrateVisitor<'a, 'tcx> {
725738
_consume_pat: &ast::Pat,
726739
_cmt: mc::cmt,
727740
_mode: euv::ConsumeMode) {}
728-
}
741+
}

0 commit comments

Comments
 (0)