@@ -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 ;
@@ -940,6 +941,11 @@ impl<'a> Parser<'a> {
940
941
pub fn span_fatal ( & mut self , sp : Span , m : & str ) -> ! {
941
942
self . sess . span_diagnostic . span_fatal ( sp, m)
942
943
}
944
+ pub fn span_fatal_help ( & mut self , sp : Span , m : & str , help : & str ) -> ! {
945
+ self . span_err ( sp, m) ;
946
+ self . span_help ( sp, help) ;
947
+ panic ! ( diagnostic:: FatalError ) ;
948
+ }
943
949
pub fn span_note ( & mut self , sp : Span , m : & str ) {
944
950
self . sess . span_diagnostic . span_note ( sp, m)
945
951
}
@@ -3702,7 +3708,14 @@ impl<'a> Parser<'a> {
3702
3708
maybe_whole ! ( no_clone self , NtBlock ) ;
3703
3709
3704
3710
let lo = self . span . lo ;
3705
- self . expect ( & token:: OpenDelim ( token:: Brace ) ) ;
3711
+
3712
+ if !self . eat ( & token:: OpenDelim ( token:: Brace ) ) {
3713
+ let sp = self . span ;
3714
+ let tok = self . this_token_to_string ( ) ;
3715
+ self . span_fatal_help ( sp,
3716
+ format ! ( "expected `{{`, found `{}`" , tok) . as_slice ( ) ,
3717
+ "place this code inside a block" ) ;
3718
+ }
3706
3719
3707
3720
return self . parse_block_tail_ ( lo, DefaultBlock , Vec :: new ( ) ) ;
3708
3721
}
@@ -4693,9 +4706,10 @@ impl<'a> Parser<'a> {
4693
4706
_ => {
4694
4707
let span = self . span ;
4695
4708
let token_str = self . this_token_to_string ( ) ;
4696
- self . span_fatal ( span,
4697
- format ! ( "expected `,`, or `}}`, found `{}`" ,
4698
- token_str) . as_slice ( ) )
4709
+ self . span_fatal_help ( span,
4710
+ format ! ( "expected `,`, or `}}`, found `{}`" ,
4711
+ token_str) . as_slice ( ) ,
4712
+ "struct fields should be separated by commas" )
4699
4713
}
4700
4714
}
4701
4715
a_var
@@ -4897,19 +4911,24 @@ impl<'a> Parser<'a> {
4897
4911
( true , false ) => ( default_path, false ) ,
4898
4912
( false , true ) => ( secondary_path, true ) ,
4899
4913
( false , false ) => {
4900
- self . span_fatal ( id_sp,
4901
- format ! ( "file not found for module \
4902
- `{}`",
4903
- mod_name) . as_slice ( ) ) ;
4914
+ self . span_fatal_help ( id_sp,
4915
+ format ! ( "file not found for module `{}`" ,
4916
+ mod_name) . as_slice ( ) ,
4917
+ format ! ( "name the file either {} or {} inside \
4918
+ the directory {}",
4919
+ default_path_str,
4920
+ secondary_path_str,
4921
+ dir_path. display( ) ) . as_slice ( ) ) ;
4904
4922
}
4905
4923
( true , true ) => {
4906
- self . span_fatal (
4924
+ self . span_fatal_help (
4907
4925
id_sp,
4908
4926
format ! ( "file for module `{}` found at both {} \
4909
4927
and {}",
4910
4928
mod_name,
4911
4929
default_path_str,
4912
- secondary_path_str) . as_slice ( ) ) ;
4930
+ secondary_path_str) . as_slice ( ) ,
4931
+ "delete or rename one of them to remove the ambiguity" ) ;
4913
4932
}
4914
4933
}
4915
4934
}
@@ -5062,9 +5081,10 @@ impl<'a> Parser<'a> {
5062
5081
// skip the ident if there is one
5063
5082
if self . token . is_ident ( ) { self . bump ( ) ; }
5064
5083
5065
- self . span_err ( span,
5066
- format ! ( "expected `;`, found `as`; perhaps you meant \
5067
- to enclose the crate name `{}` in a string?",
5084
+ self . span_err ( span, "expected `;`, found `as`" ) ;
5085
+ self . span_help ( span,
5086
+ format ! ( "perhaps you meant to enclose the crate name `{}` in \
5087
+ a string?",
5068
5088
the_ident. as_str( ) ) . as_slice ( ) ) ;
5069
5089
None
5070
5090
} else {
@@ -5574,16 +5594,12 @@ impl<'a> Parser<'a> {
5574
5594
}
5575
5595
5576
5596
// FAILURE TO PARSE ITEM
5577
- if visibility != Inherited {
5578
- let mut s = String :: from_str ( "unmatched visibility `" ) ;
5579
- if visibility == Public {
5580
- s. push_str ( "pub" )
5581
- } else {
5582
- s. push_str ( "priv" )
5597
+ match visibility {
5598
+ Inherited => { }
5599
+ Public => {
5600
+ let last_span = self . last_span ;
5601
+ self . span_fatal ( last_span, "unmatched visibility `pub`" ) ;
5583
5602
}
5584
- s. push ( '`' ) ;
5585
- let last_span = self . last_span ;
5586
- self . span_fatal ( last_span, s. as_slice ( ) ) ;
5587
5603
}
5588
5604
return IoviNone ( attrs) ;
5589
5605
}
@@ -5905,4 +5921,3 @@ impl<'a> Parser<'a> {
5905
5921
}
5906
5922
}
5907
5923
}
5908
-
0 commit comments