Skip to content

Commit 861cced

Browse files
committed
auto merge of #10600 : ktt3ja/rust/add-doc, r=huonw
I received a lot of helpful explanations when I was going through rustc's middle-end code. I document some of them here.
2 parents b3ff24a + 9a4c8da commit 861cced

File tree

4 files changed

+24
-0
lines changed

4 files changed

+24
-0
lines changed

src/librustc/middle/pat_util.rs

+2
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,8 @@ pub fn pat_is_binding_or_wild(dm: resolve::DefMap, pat: @Pat) -> bool {
7070
}
7171
}
7272

73+
/// Call `it` on every "binding" in a pattern, e.g., on `a` in
74+
/// `match foo() { Some(a) => (), None => () }`
7375
pub fn pat_bindings(dm: resolve::DefMap,
7476
pat: @Pat,
7577
it: |BindingMode, NodeId, Span, &Path|) {

src/librustc/middle/ty.rs

+5
Original file line numberDiff line numberDiff line change
@@ -259,6 +259,9 @@ pub enum AutoRef {
259259

260260
pub type ctxt = @ctxt_;
261261

262+
/// The data structure to keep track of all the information that typechecker
263+
/// generates so that so that it can be reused and doesn't have to be redone
264+
/// later on.
262265
struct ctxt_ {
263266
diag: @mut syntax::diagnostic::span_handler,
264267
interner: @mut HashMap<intern_key, ~t_box_>,
@@ -296,6 +299,8 @@ struct ctxt_ {
296299
trait_refs: @mut HashMap<NodeId, @TraitRef>,
297300
trait_defs: @mut HashMap<DefId, @TraitDef>,
298301

302+
/// Despite its name, `items` does not only map NodeId to an item but
303+
/// also to expr/stmt/local/arg/etc
299304
items: ast_map::map,
300305
intrinsic_defs: @mut HashMap<ast::DefId, t>,
301306
freevars: freevars::freevar_map,

src/libsyntax/ast.rs

+11
Original file line numberDiff line numberDiff line change
@@ -173,6 +173,8 @@ pub struct DefId {
173173
node: NodeId,
174174
}
175175

176+
/// Item definitions in the currently-compiled crate would have the CrateNum
177+
/// LOCAL_CRATE in their DefId.
176178
pub static LOCAL_CRATE: CrateNum = 0;
177179
pub static CRATE_NODE_ID: NodeId = 0;
178180

@@ -244,6 +246,10 @@ pub enum Def {
244246
@Def, // closed over def
245247
NodeId, // expr node that creates the closure
246248
NodeId), // id for the block/body of the closure expr
249+
250+
/// Note that if it's a tuple struct's definition, the node id
251+
/// of the DefId refers to the struct_def.ctor_id (whereas normally it
252+
/// refers to the item definition's id).
247253
DefStruct(DefId),
248254
DefTyParamBinder(NodeId), /* struct, impl or trait with ty params */
249255
DefRegion(NodeId),
@@ -451,6 +457,7 @@ pub enum Stmt_ {
451457

452458
// FIXME (pending discussion of #1697, #2178...): local should really be
453459
// a refinement on pat.
460+
/// Local represents a `let` statement, e.g., `let <pat>:<ty> = <expr>;`
454461
#[deriving(Eq, Encodable, Decodable,IterBytes)]
455462
pub struct Local {
456463
ty: Ty,
@@ -553,6 +560,10 @@ pub enum Expr_ {
553560
ExprAssignOp(NodeId, BinOp, @Expr, @Expr),
554561
ExprField(@Expr, Ident, ~[Ty]),
555562
ExprIndex(NodeId, @Expr, @Expr),
563+
564+
/// Expression that looks like a "name". For example,
565+
/// `std::vec::from_elem::<uint>` is an ExprPath that's the "name" part
566+
/// of a function call.
556567
ExprPath(Path),
557568

558569
/// The special identifier `self`.

src/libsyntax/ast_map.rs

+6
Original file line numberDiff line numberDiff line change
@@ -111,12 +111,18 @@ pub enum ast_node {
111111
node_trait_method(@trait_method, DefId /* trait did */,
112112
@path /* path to the trait */),
113113
node_method(@method, DefId /* impl did */, @path /* path to the impl */),
114+
115+
/// node_variant represents a variant of an enum, e.g., for
116+
/// `enum A { B, C, D }`, there would be a node_item for `A`, and a
117+
/// node_variant item for each of `B`, `C`, and `D`.
114118
node_variant(variant, @item, @path),
115119
node_expr(@Expr),
116120
node_stmt(@Stmt),
117121
node_arg(@Pat),
118122
node_local(Ident),
119123
node_block(Block),
124+
125+
/// node_struct_ctor represents a tuple struct.
120126
node_struct_ctor(@struct_def, @item, @path),
121127
node_callee_scope(@Expr)
122128
}

0 commit comments

Comments
 (0)