@@ -66,6 +66,7 @@ use ast_util::{as_prec, ident_to_path, operator_prec};
66
66
use ast_util;
67
67
use codemap:: { Span , BytePos , Spanned , spanned, mk_sp} ;
68
68
use codemap;
69
+ use diagnostic;
69
70
use ext:: tt:: macro_parser;
70
71
use parse;
71
72
use parse:: attr:: ParserAttr ;
@@ -941,6 +942,11 @@ impl<'a> Parser<'a> {
941
942
pub fn span_fatal ( & mut self , sp : Span , m : & str ) -> ! {
942
943
self . sess . span_diagnostic . span_fatal ( sp, m)
943
944
}
945
+ pub fn span_fatal_help ( & mut self , sp : Span , m : & str , help : & str ) -> ! {
946
+ self . span_err ( sp, m) ;
947
+ self . span_help ( sp, help) ;
948
+ panic ! ( diagnostic:: FatalError ) ;
949
+ }
944
950
pub fn span_note ( & mut self , sp : Span , m : & str ) {
945
951
self . sess . span_diagnostic . span_note ( sp, m)
946
952
}
@@ -1641,7 +1647,8 @@ impl<'a> Parser<'a> {
1641
1647
token:: LitByte ( i) => LitByte ( parse:: byte_lit ( i. as_str ( ) ) . val0 ( ) ) ,
1642
1648
token:: LitChar ( i) => LitChar ( parse:: char_lit ( i. as_str ( ) ) . val0 ( ) ) ,
1643
1649
token:: LitInteger ( s) => parse:: integer_lit ( s. as_str ( ) ,
1644
- & self . sess . span_diagnostic , self . span ) ,
1650
+ & self . sess . span_diagnostic ,
1651
+ self . last_span ) ,
1645
1652
token:: LitFloat ( s) => parse:: float_lit ( s. as_str ( ) ) ,
1646
1653
token:: LitStr ( s) => {
1647
1654
LitStr ( token:: intern_and_get_ident ( parse:: str_lit ( s. as_str ( ) ) . as_slice ( ) ) ,
@@ -3710,7 +3717,14 @@ impl<'a> Parser<'a> {
3710
3717
maybe_whole ! ( no_clone self , NtBlock ) ;
3711
3718
3712
3719
let lo = self . span . lo ;
3713
- self . expect ( & token:: OpenDelim ( token:: Brace ) ) ;
3720
+
3721
+ if !self . eat ( & token:: OpenDelim ( token:: Brace ) ) {
3722
+ let sp = self . span ;
3723
+ let tok = self . this_token_to_string ( ) ;
3724
+ self . span_fatal_help ( sp,
3725
+ format ! ( "expected `{{`, found `{}`" , tok) . as_slice ( ) ,
3726
+ "place this code inside a block" ) ;
3727
+ }
3714
3728
3715
3729
return self . parse_block_tail_ ( lo, DefaultBlock , Vec :: new ( ) ) ;
3716
3730
}
@@ -4701,9 +4715,10 @@ impl<'a> Parser<'a> {
4701
4715
_ => {
4702
4716
let span = self . span ;
4703
4717
let token_str = self . this_token_to_string ( ) ;
4704
- self . span_fatal ( span,
4705
- format ! ( "expected `,`, or `}}`, found `{}`" ,
4706
- token_str) . as_slice ( ) )
4718
+ self . span_fatal_help ( span,
4719
+ format ! ( "expected `,`, or `}}`, found `{}`" ,
4720
+ token_str) . as_slice ( ) ,
4721
+ "struct fields should be separated by commas" )
4707
4722
}
4708
4723
}
4709
4724
a_var
@@ -4905,19 +4920,24 @@ impl<'a> Parser<'a> {
4905
4920
( true , false ) => ( default_path, false ) ,
4906
4921
( false , true ) => ( secondary_path, true ) ,
4907
4922
( false , false ) => {
4908
- self . span_fatal ( id_sp,
4909
- format ! ( "file not found for module \
4910
- `{}`",
4911
- mod_name) . as_slice ( ) ) ;
4923
+ self . span_fatal_help ( id_sp,
4924
+ format ! ( "file not found for module `{}`" ,
4925
+ mod_name) . as_slice ( ) ,
4926
+ format ! ( "name the file either {} or {} inside \
4927
+ the directory {}",
4928
+ default_path_str,
4929
+ secondary_path_str,
4930
+ dir_path. display( ) ) . as_slice ( ) ) ;
4912
4931
}
4913
4932
( true , true ) => {
4914
- self . span_fatal (
4933
+ self . span_fatal_help (
4915
4934
id_sp,
4916
4935
format ! ( "file for module `{}` found at both {} \
4917
4936
and {}",
4918
4937
mod_name,
4919
4938
default_path_str,
4920
- secondary_path_str) . as_slice ( ) ) ;
4939
+ secondary_path_str) . as_slice ( ) ,
4940
+ "delete or rename one of them to remove the ambiguity" ) ;
4921
4941
}
4922
4942
}
4923
4943
}
@@ -5070,9 +5090,10 @@ impl<'a> Parser<'a> {
5070
5090
// skip the ident if there is one
5071
5091
if self . token . is_ident ( ) { self . bump ( ) ; }
5072
5092
5073
- self . span_err ( span,
5074
- format ! ( "expected `;`, found `as`; perhaps you meant \
5075
- to enclose the crate name `{}` in a string?",
5093
+ self . span_err ( span, "expected `;`, found `as`" ) ;
5094
+ self . span_help ( span,
5095
+ format ! ( "perhaps you meant to enclose the crate name `{}` in \
5096
+ a string?",
5076
5097
the_ident. as_str( ) ) . as_slice ( ) ) ;
5077
5098
None
5078
5099
} else {
@@ -5582,16 +5603,12 @@ impl<'a> Parser<'a> {
5582
5603
}
5583
5604
5584
5605
// FAILURE TO PARSE ITEM
5585
- if visibility != Inherited {
5586
- let mut s = String :: from_str ( "unmatched visibility `" ) ;
5587
- if visibility == Public {
5588
- s. push_str ( "pub" )
5589
- } else {
5590
- s. push_str ( "priv" )
5606
+ match visibility {
5607
+ Inherited => { }
5608
+ Public => {
5609
+ let last_span = self . last_span ;
5610
+ self . span_fatal ( last_span, "unmatched visibility `pub`" ) ;
5591
5611
}
5592
- s. push ( '`' ) ;
5593
- let last_span = self . last_span ;
5594
- self . span_fatal ( last_span, s. as_slice ( ) ) ;
5595
5612
}
5596
5613
return IoviNone ( attrs) ;
5597
5614
}
@@ -5913,4 +5930,3 @@ impl<'a> Parser<'a> {
5913
5930
}
5914
5931
}
5915
5932
}
5916
-
0 commit comments