diff options
| author | Huon Wilson <dbau.pp+github@gmail.com> | 2014-05-21 22:21:11 +1000 |
|---|---|---|
| committer | Huon Wilson <dbau.pp+github@gmail.com> | 2014-05-21 22:41:23 +1000 |
| commit | feb91f3216c7a60c9f7da582b3a02551fe73bb40 (patch) | |
| tree | ba8bcfb15e80b453337127a5373a875cba90a2a2 /src/libsyntax | |
| parent | dd5365af2c4281f2808ffa35faf6f53411814267 (diff) | |
| download | rust-feb91f3216c7a60c9f7da582b3a02551fe73bb40.tar.gz rust-feb91f3216c7a60c9f7da582b3a02551fe73bb40.zip | |
rustc: improve error messages from wrong --pretty flowgraph use.
This defers to .fatal and .span_fatal for errors (rather than `fail!` which prints the ICE message). It also adds the span lookup when an id doesn't correspond to a block, to show what it is pointing at. It also makes the argument parser slightly looser, so that passing `--pretty flowgraph` recognises the `flowgraph` part and suggests to use an integer.
Diffstat (limited to 'src/libsyntax')
| -rw-r--r-- | src/libsyntax/ast_map.rs | 14 |
1 files changed, 10 insertions, 4 deletions
diff --git a/src/libsyntax/ast_map.rs b/src/libsyntax/ast_map.rs index f1561ea31f9..d0b820044da 100644 --- a/src/libsyntax/ast_map.rs +++ b/src/libsyntax/ast_map.rs @@ -388,8 +388,8 @@ impl Map { f(attrs) } - pub fn span(&self, id: NodeId) -> Span { - match self.find(id) { + pub fn opt_span(&self, id: NodeId) -> Option<Span> { + let sp = match self.find(id) { Some(NodeItem(item)) => item.span, Some(NodeForeignItem(foreign_item)) => foreign_item.span, Some(NodeTraitMethod(trait_method)) => { @@ -406,8 +406,14 @@ impl Map { Some(NodePat(pat)) => pat.span, Some(NodeBlock(block)) => block.span, Some(NodeStructCtor(_)) => self.expect_item(self.get_parent(id)).span, - _ => fail!("node_span: could not find span for id {}", id), - } + _ => return None, + }; + Some(sp) + } + + pub fn span(&self, id: NodeId) -> Span { + self.opt_span(id) + .unwrap_or_else(|| fail!("AstMap.span: could not find span for id {}", id)) } pub fn node_to_str(&self, id: NodeId) -> StrBuf { |
