Skip to content

Commit b952c0e

Browse files
committed
Add comments about the checks for recursive variant definition, as requested by @nrc.
1 parent faf7302 commit b952c0e

File tree

2 files changed

+8
-0
lines changed

2 files changed

+8
-0
lines changed

src/librustc/middle/check_static_recursion.rs

+4
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,10 @@ struct CheckCrateVisitor<'a, 'ast: 'a> {
2727
sess: &'a Session,
2828
def_map: &'a DefMap,
2929
ast_map: &'a ast_map::Map<'ast>,
30+
// `discriminant_map` is a cache that associates the `NodeId`s of local
31+
// variant definitions with the discriminant expression that applies to
32+
// each one. If the variant uses the default values (starting from `0`),
33+
// then `None` is stored.
3034
discriminant_map: RefCell<NodeMap<Option<&'ast ast::Expr>>>,
3135
}
3236

src/test/compile-fail/issue-23302.rs

+4
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,14 @@
88
// option. This file may not be copied, modified, or distributed
99
// except according to those terms.
1010

11+
// Check that an enum with recursion in the discriminant throws
12+
// the appropriate error (rather than, say, blowing the stack).
1113
enum X {
1214
A = X::A as isize, //~ ERROR E0265
1315
}
1416

17+
// Since `Y::B` here defaults to `Y::A+1`, this is also a
18+
// recursive definition.
1519
enum Y {
1620
A = Y::B as isize, //~ ERROR E0265
1721
B,

0 commit comments

Comments
 (0)