Skip to content

Commit 35f7de2

Browse files
committed
---
yaml --- r: 160033 b: refs/heads/try c: 26282ac h: refs/heads/master i: 160031: 2382216 v: v3
1 parent 05ca1b6 commit 35f7de2

File tree

4 files changed

+42
-25
lines changed

4 files changed

+42
-25
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
refs/heads/master: e09d98603e608c9e47d4c89f7b4dca87a4b56da3
33
refs/heads/snap-stage1: e33de59e47c5076a89eadeb38f4934f58a3618a6
44
refs/heads/snap-stage3: 9c96a79a74f10bed18b031ce0ac4126c56d6cfb3
5-
refs/heads/try: e621e3216bfb074b03ddeb045dc467d9ec4641f8
5+
refs/heads/try: 26282ac33777e3e7b3b483cdd2546a76807215d7
66
refs/tags/release-0.1: 1f5c5126e96c79d22cb7862f75304136e204f105
77
refs/heads/dist-snap: ba4081a5a8573875fed17545846f6f6902c8ba8d
88
refs/tags/release-0.2: c870d2dffb391e14efb05aa27898f1f6333a9596

branches/try/src/libsyntax/parse/parser.rs

Lines changed: 38 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@ use ast_util::{as_prec, ident_to_path, operator_prec};
6666
use ast_util;
6767
use codemap::{Span, BytePos, Spanned, spanned, mk_sp};
6868
use codemap;
69+
use diagnostic;
6970
use ext::tt::macro_parser;
7071
use parse;
7172
use parse::attr::ParserAttr;
@@ -940,6 +941,11 @@ impl<'a> Parser<'a> {
940941
pub fn span_fatal(&mut self, sp: Span, m: &str) -> ! {
941942
self.sess.span_diagnostic.span_fatal(sp, m)
942943
}
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+
}
943949
pub fn span_note(&mut self, sp: Span, m: &str) {
944950
self.sess.span_diagnostic.span_note(sp, m)
945951
}
@@ -3702,7 +3708,14 @@ impl<'a> Parser<'a> {
37023708
maybe_whole!(no_clone self, NtBlock);
37033709

37043710
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+
}
37063719

37073720
return self.parse_block_tail_(lo, DefaultBlock, Vec::new());
37083721
}
@@ -4693,9 +4706,10 @@ impl<'a> Parser<'a> {
46934706
_ => {
46944707
let span = self.span;
46954708
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")
46994713
}
47004714
}
47014715
a_var
@@ -4897,19 +4911,24 @@ impl<'a> Parser<'a> {
48974911
(true, false) => (default_path, false),
48984912
(false, true) => (secondary_path, true),
48994913
(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());
49044922
}
49054923
(true, true) => {
4906-
self.span_fatal(
4924+
self.span_fatal_help(
49074925
id_sp,
49084926
format!("file for module `{}` found at both {} \
49094927
and {}",
49104928
mod_name,
49114929
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");
49134932
}
49144933
}
49154934
}
@@ -5062,9 +5081,10 @@ impl<'a> Parser<'a> {
50625081
// skip the ident if there is one
50635082
if self.token.is_ident() { self.bump(); }
50645083

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?",
50685088
the_ident.as_str()).as_slice());
50695089
None
50705090
} else {
@@ -5574,16 +5594,12 @@ impl<'a> Parser<'a> {
55745594
}
55755595

55765596
// 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`");
55835602
}
5584-
s.push('`');
5585-
let last_span = self.last_span;
5586-
self.span_fatal(last_span, s.as_slice());
55875603
}
55885604
return IoviNone(attrs);
55895605
}
@@ -5905,4 +5921,3 @@ impl<'a> Parser<'a> {
59055921
}
59065922
}
59075923
}
5908-

branches/try/src/test/compile-fail/extern-crate-as-no-string-help.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,4 +11,5 @@
1111
// Tests that the proper help is displayed in the error message
1212

1313
extern crate foo as bar;
14-
//~^ ERROR expected `;`, found `as`; perhaps you meant to enclose the crate name `foo` in a string?
14+
//~^ ERROR expected `;`, found `as`
15+
//~^^ HELP perhaps you meant to enclose the crate name `foo` in a string?

branches/try/src/test/compile-fail/mod_file_not_exist.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
// except according to those terms.
1010

1111
mod not_a_real_file; //~ ERROR file not found for module `not_a_real_file`
12+
//~^ HELP name the file either not_a_real_file.rs or not_a_real_file/mod.rs inside the directory
1213

1314
fn main() {
1415
assert_eq!(mod_file_aux::bar(), 10);

0 commit comments

Comments
 (0)