@@ -81,6 +81,9 @@ enum Mode {
81
81
Const ,
82
82
Static ,
83
83
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."
84
87
Var ,
85
88
}
86
89
@@ -131,6 +134,7 @@ impl<'a, 'tcx> CheckCrateVisitor<'a, 'tcx> {
131
134
} )
132
135
}
133
136
137
+ // NDM Nit: can we rename this to "add_qualif" or something?
134
138
fn qualif ( & mut self , qualif : ConstQualif ) {
135
139
self . qualif = self . qualif | qualif;
136
140
}
@@ -407,6 +411,7 @@ fn check_expr<'a, 'tcx>(v: &mut CheckCrateVisitor<'a, 'tcx>,
407
411
ty:: ty_ptr( _) => {
408
412
// This shouldn't be allowed in constants at all.
409
413
v. qualif ( NOT_CONST ) ;
414
+ // NDM how come we don't check and report an error here?
410
415
}
411
416
_ => { }
412
417
}
@@ -453,8 +458,14 @@ fn check_expr<'a, 'tcx>(v: &mut CheckCrateVisitor<'a, 'tcx>,
453
458
v. qualif ( NON_ZERO_SIZED ) ;
454
459
}
455
460
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
+
456
466
Some ( def:: DefStatic ( ..) ) if v. mode == Mode :: Static ||
457
467
v. mode == Mode :: StaticMut => { }
468
+ // NDM do we ... not want NOT_CONST here? Not matter?
458
469
459
470
Some ( def:: DefStatic ( ..) ) if v. mode == Mode :: Const => {
460
471
span_err ! ( v. tcx. sess, e. span, E0013 ,
@@ -467,6 +478,7 @@ fn check_expr<'a, 'tcx>(v: &mut CheckCrateVisitor<'a, 'tcx>,
467
478
if let ast:: ItemConst ( _, ref expr) = const_item. node {
468
479
Some ( & * * expr)
469
480
} else {
481
+ // NDM when would this ever be None here? isn't this a case for "bug()"?
470
482
None
471
483
}
472
484
} else {
@@ -565,6 +577,7 @@ fn check_expr<'a, 'tcx>(v: &mut CheckCrateVisitor<'a, 'tcx>,
565
577
566
578
ast:: ExprClosure ( ..) => {
567
579
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?
568
581
assert ! ( v. mode == Mode :: Var ,
569
582
"global closures can't capture anything" ) ;
570
583
v. qualif ( NOT_CONST ) ;
@@ -725,4 +738,4 @@ impl<'a, 'tcx> euv::Delegate<'tcx> for CheckCrateVisitor<'a, 'tcx> {
725
738
_consume_pat : & ast:: Pat ,
726
739
_cmt : mc:: cmt ,
727
740
_mode : euv:: ConsumeMode ) { }
728
- }
741
+ }
0 commit comments