@@ -66,6 +66,7 @@ use ast_util::{as_prec, ident_to_path, operator_prec};
6666use ast_util;
6767use codemap:: { Span , BytePos , Spanned , spanned, mk_sp} ;
6868use codemap;
69+ use diagnostic;
6970use ext:: tt:: macro_parser;
7071use parse;
7172use parse:: attr:: ParserAttr ;
@@ -941,6 +942,11 @@ impl<'a> Parser<'a> {
941942 pub fn span_fatal ( & mut self , sp : Span , m : & str ) -> ! {
942943 self . sess . span_diagnostic . span_fatal ( sp, m)
943944 }
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+ }
944950 pub fn span_note ( & mut self , sp : Span , m : & str ) {
945951 self . sess . span_diagnostic . span_note ( sp, m)
946952 }
@@ -1641,7 +1647,8 @@ impl<'a> Parser<'a> {
16411647 token:: LitByte ( i) => LitByte ( parse:: byte_lit ( i. as_str ( ) ) . val0 ( ) ) ,
16421648 token:: LitChar ( i) => LitChar ( parse:: char_lit ( i. as_str ( ) ) . val0 ( ) ) ,
16431649 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 ) ,
16451652 token:: LitFloat ( s) => parse:: float_lit ( s. as_str ( ) ) ,
16461653 token:: LitStr ( s) => {
16471654 LitStr ( token:: intern_and_get_ident ( parse:: str_lit ( s. as_str ( ) ) . as_slice ( ) ) ,
@@ -3710,7 +3717,14 @@ impl<'a> Parser<'a> {
37103717 maybe_whole ! ( no_clone self , NtBlock ) ;
37113718
37123719 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+ }
37143728
37153729 return self . parse_block_tail_ ( lo, DefaultBlock , Vec :: new ( ) ) ;
37163730 }
@@ -4701,9 +4715,10 @@ impl<'a> Parser<'a> {
47014715 _ => {
47024716 let span = self . span ;
47034717 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" )
47074722 }
47084723 }
47094724 a_var
@@ -4905,19 +4920,24 @@ impl<'a> Parser<'a> {
49054920 ( true , false ) => ( default_path, false ) ,
49064921 ( false , true ) => ( secondary_path, true ) ,
49074922 ( 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 ( ) ) ;
49124931 }
49134932 ( true , true ) => {
4914- self . span_fatal (
4933+ self . span_fatal_help (
49154934 id_sp,
49164935 format ! ( "file for module `{}` found at both {} \
49174936 and {}",
49184937 mod_name,
49194938 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" ) ;
49214941 }
49224942 }
49234943 }
@@ -5070,9 +5090,10 @@ impl<'a> Parser<'a> {
50705090 // skip the ident if there is one
50715091 if self . token . is_ident ( ) { self . bump ( ) ; }
50725092
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?",
50765097 the_ident. as_str( ) ) . as_slice ( ) ) ;
50775098 None
50785099 } else {
@@ -5582,16 +5603,12 @@ impl<'a> Parser<'a> {
55825603 }
55835604
55845605 // 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`" ) ;
55915611 }
5592- s. push ( '`' ) ;
5593- let last_span = self . last_span ;
5594- self . span_fatal ( last_span, s. as_slice ( ) ) ;
55955612 }
55965613 return IoviNone ( attrs) ;
55975614 }
@@ -5913,4 +5930,3 @@ impl<'a> Parser<'a> {
59135930 }
59145931 }
59155932}
5916-
0 commit comments