File tree 3 files changed +28
-10
lines changed
3 files changed +28
-10
lines changed Original file line number Diff line number Diff line change @@ -653,11 +653,22 @@ pub fn pretty_print_input(sess: Session,
653
653
PpmFlowGraph ( nodeid) => {
654
654
let ast_map = ast_map. expect ( "--pretty flowgraph missing ast_map" ) ;
655
655
let node = ast_map. find ( nodeid) . unwrap_or_else ( || {
656
- fail ! ( "--pretty flowgraph=id couldn't find id: {}" , id)
656
+ sess. fatal ( format_strbuf ! ( "--pretty flowgraph couldn't find id: {}" ,
657
+ nodeid) . as_slice ( ) )
657
658
} ) ;
658
659
let block = match node {
659
660
syntax:: ast_map:: NodeBlock ( block) => block,
660
- _ => fail ! ( "--pretty=flowgraph needs block, got {:?}" , node)
661
+ _ => {
662
+ let message = format_strbuf ! ( "--pretty=flowgraph needs block, got {:?}" ,
663
+ node) ;
664
+
665
+ // point to what was found, if there's an
666
+ // accessible span.
667
+ match ast_map. opt_span ( nodeid) {
668
+ Some ( sp) => sess. span_fatal ( sp, message. as_slice ( ) ) ,
669
+ None => sess. fatal ( message. as_slice ( ) )
670
+ }
671
+ }
661
672
} ;
662
673
let analysis = phase_3_run_analysis_passes ( sess, & krate, ast_map) ;
663
674
print_flowgraph ( analysis, block, out)
Original file line number Diff line number Diff line change @@ -302,11 +302,12 @@ pub fn parse_pretty(sess: &Session, name: &str) -> PpMode {
302
302
( None , "typed" ) => PpmTyped ,
303
303
( None , "expanded,identified" ) => PpmExpandedIdentified ,
304
304
( None , "identified" ) => PpmIdentified ,
305
- ( Some ( s ) , "flowgraph" ) => {
306
- match from_str ( s ) {
305
+ ( arg , "flowgraph" ) => {
306
+ match arg . and_then ( from_str ) {
307
307
Some ( id) => PpmFlowGraph ( id) ,
308
- None => sess. fatal ( format ! ( "`pretty flowgraph=<nodeid>` needs \
309
- an integer <nodeid>; got {}", s) )
308
+ None => sess. fatal ( format_strbuf ! ( "`pretty flowgraph=<nodeid>` needs \
309
+ an integer <nodeid>; got {}",
310
+ arg. unwrap_or( "nothing" ) ) . as_slice ( ) )
310
311
}
311
312
}
312
313
_ => {
Original file line number Diff line number Diff line change @@ -388,8 +388,8 @@ impl Map {
388
388
f ( attrs)
389
389
}
390
390
391
- pub fn span ( & self , id : NodeId ) -> Span {
392
- match self . find ( id) {
391
+ pub fn opt_span ( & self , id : NodeId ) -> Option < Span > {
392
+ let sp = match self . find ( id) {
393
393
Some ( NodeItem ( item) ) => item. span ,
394
394
Some ( NodeForeignItem ( foreign_item) ) => foreign_item. span ,
395
395
Some ( NodeTraitMethod ( trait_method) ) => {
@@ -406,8 +406,14 @@ impl Map {
406
406
Some ( NodePat ( pat) ) => pat. span ,
407
407
Some ( NodeBlock ( block) ) => block. span ,
408
408
Some ( NodeStructCtor ( _) ) => self . expect_item ( self . get_parent ( id) ) . span ,
409
- _ => fail ! ( "node_span: could not find span for id {}" , id) ,
410
- }
409
+ _ => return None ,
410
+ } ;
411
+ Some ( sp)
412
+ }
413
+
414
+ pub fn span ( & self , id : NodeId ) -> Span {
415
+ self . opt_span ( id)
416
+ . unwrap_or_else ( || fail ! ( "AstMap.span: could not find span for id {}" , id) )
411
417
}
412
418
413
419
pub fn node_to_str ( & self , id : NodeId ) -> StrBuf {
You can’t perform that action at this time.
0 commit comments