Simplify error output

This commit is contained in:
Esteban Küber
2017-03-27 17:15:16 -07:00
parent 57009caabd
commit c963d613a2
2 changed files with 9 additions and 18 deletions

View File

@@ -4708,26 +4708,21 @@ impl<'a> Parser<'a> {
if let Err(mut bang_err) = bang_err { if let Err(mut bang_err) = bang_err {
// Given this code `pub path(`, it seems like this is not setting the // Given this code `pub path(`, it seems like this is not setting the
// visibility of a macro invocation, but rather a mistyped method declaration. // visibility of a macro invocation, but rather a mistyped method declaration.
// Keep the macro diagnostic, but also provide a hint that `fn` might be // Create a diagnostic pointing out that `fn` is missing.
// missing. Don't complain about the missing `!` as a separate diagnostic, add
// label in the appropriate place as part of one unified diagnostic.
// //
// x | pub path(&self) { // x | pub path(&self) {
// | ^^^- - expected `!` here for a macro invocation // | ^ missing `fn` for method declaration
// | |
// | did you mean to write `fn` here for a method declaration?
err.cancel();
bang_err.cancel(); bang_err.cancel();
err.span_label(self.span, &"expected `!` here for a macro invocation");
// pub path( // pub path(
// ^^ `sp` below will point to this // ^^ `sp` below will point to this
let sp = mk_sp(prev_span.hi, self.prev_span.lo); let sp = mk_sp(prev_span.hi, self.prev_span.lo);
err.span_label(sp, err = self.diagnostic()
&"did you mean to write `fn` here for a method declaration?"); .struct_span_err(sp, "missing `fn` for method declaration");
err.span_label(sp, &"missing `fn`");
} }
return Err(err); return Err(err);
} else if let Err(bang_err) = bang_err {
return Err(bang_err);
} }
// eat a matched-delimiter token tree: // eat a matched-delimiter token tree:

View File

@@ -1,12 +1,8 @@
error: can't qualify macro invocation with `pub` error: missing `fn` for method declaration
--> $DIR/issue-40006.rs:14:5 --> $DIR/issue-40006.rs:14:8
| |
14 | pub hello_method(&self) { 14 | pub hello_method(&self) {
| ^^^- - expected `!` here for a macro invocation | ^ missing `fn`
| |
| did you mean to write `fn` here for a method declaration?
|
= help: try adjusting the macro to put `pub` inside the invocation
error: aborting due to previous error error: aborting due to previous error