Skip to content

Commit 39b271f

Browse files
pnkfelixalexcrichton
authored andcommitted
Add EntryPat and NodePat variants to ast_map.
Add `EntryPat` and `NodePat` variants to ast_map, so that lookups for id 1 in `let S{val: _x /* pat 2 */} /* pat 1 */ = ...` will actually resolve to the pattern `S{ ... }`, rather than "unknown node", in a function like `node_id_to_str`.
1 parent b9e4fcb commit 39b271f

File tree

2 files changed

+12
-1
lines changed

2 files changed

+12
-1
lines changed

src/librustc/middle/trans/monomorphize.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -309,6 +309,7 @@ pub fn monomorphic_fn(ccx: &CrateContext,
309309
ast_map::NodeStmt(..) |
310310
ast_map::NodeArg(..) |
311311
ast_map::NodeBlock(..) |
312+
ast_map::NodePat(..) |
312313
ast_map::NodeLocal(..) => {
313314
ccx.sess().bug(format!("can't monomorphize a {:?}", map_node))
314315
}

src/libsyntax/ast_map.rs

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,7 @@ pub enum Node {
103103
NodeStmt(@Stmt),
104104
NodeArg(@Pat),
105105
NodeLocal(@Pat),
106+
NodePat(@Pat),
106107
NodeBlock(P<Block>),
107108

108109
/// NodeStructCtor represents a tuple struct.
@@ -127,6 +128,7 @@ enum MapEntry {
127128
EntryStmt(NodeId, @Stmt),
128129
EntryArg(NodeId, @Pat),
129130
EntryLocal(NodeId, @Pat),
131+
EntryPat(NodeId, @Pat),
130132
EntryBlock(NodeId, P<Block>),
131133
EntryStructCtor(NodeId, @StructDef),
132134
EntryLifetime(NodeId, @Lifetime),
@@ -154,6 +156,7 @@ impl MapEntry {
154156
EntryStmt(id, _) => id,
155157
EntryArg(id, _) => id,
156158
EntryLocal(id, _) => id,
159+
EntryPat(id, _) => id,
157160
EntryBlock(id, _) => id,
158161
EntryStructCtor(id, _) => id,
159162
EntryLifetime(id, _) => id,
@@ -172,6 +175,7 @@ impl MapEntry {
172175
EntryStmt(_, p) => NodeStmt(p),
173176
EntryArg(_, p) => NodeArg(p),
174177
EntryLocal(_, p) => NodeLocal(p),
178+
EntryPat(_, p) => NodePat(p),
175179
EntryBlock(_, p) => NodeBlock(p),
176180
EntryStructCtor(_, p) => NodeStructCtor(p),
177181
EntryLifetime(_, p) => NodeLifetime(p),
@@ -399,6 +403,7 @@ impl Map {
399403
Some(NodeExpr(expr)) => expr.span,
400404
Some(NodeStmt(stmt)) => stmt.span,
401405
Some(NodeArg(pat)) | Some(NodeLocal(pat)) => pat.span,
406+
Some(NodePat(pat)) => pat.span,
402407
Some(NodeBlock(block)) => block.span,
403408
Some(NodeStructCtor(_)) => self.expect_item(self.get_parent(id)).span,
404409
_ => fail!("node_span: could not find span for id {}", id),
@@ -513,7 +518,9 @@ impl<'a, F: FoldOps> Folder for Ctx<'a, F> {
513518
// Note: this is at least *potentially* a pattern...
514519
self.insert(pat.id, EntryLocal(self.parent, pat));
515520
}
516-
_ => {}
521+
_ => {
522+
self.insert(pat.id, EntryPat(self.parent, pat));
523+
}
517524
}
518525

519526
pat
@@ -704,6 +711,9 @@ fn node_id_to_str(map: &Map, id: NodeId) -> StrBuf {
704711
(format!("local {} (id={})",
705712
pprust::pat_to_str(pat), id)).to_strbuf()
706713
}
714+
Some(NodePat(pat)) => {
715+
(format!("pat {} (id={})", pprust::pat_to_str(pat), id)).to_strbuf()
716+
}
707717
Some(NodeBlock(block)) => {
708718
(format!("block {} (id={})",
709719
pprust::block_to_str(block), id)).to_strbuf()

0 commit comments

Comments
 (0)