Skip to content

Commit c963d61

Browse files
committed
Simplify error output
1 parent 57009ca commit c963d61

File tree

2 files changed

+9
-18
lines changed

2 files changed

+9
-18
lines changed

src/libsyntax/parse/parser.rs

+6-11
Original file line numberDiff line numberDiff line change
@@ -4708,26 +4708,21 @@ impl<'a> Parser<'a> {
47084708
if let Err(mut bang_err) = bang_err {
47094709
// Given this code `pub path(`, it seems like this is not setting the
47104710
// visibility of a macro invocation, but rather a mistyped method declaration.
4711-
// Keep the macro diagnostic, but also provide a hint that `fn` might be
4712-
// missing. Don't complain about the missing `!` as a separate diagnostic, add
4713-
// label in the appropriate place as part of one unified diagnostic.
4711+
// Create a diagnostic pointing out that `fn` is missing.
47144712
//
47154713
// x | pub path(&self) {
4716-
// | ^^^- - expected `!` here for a macro invocation
4717-
// | |
4718-
// | did you mean to write `fn` here for a method declaration?
4714+
// | ^ missing `fn` for method declaration
47194715

4716+
err.cancel();
47204717
bang_err.cancel();
4721-
err.span_label(self.span, &"expected `!` here for a macro invocation");
47224718
// pub path(
47234719
// ^^ `sp` below will point to this
47244720
let sp = mk_sp(prev_span.hi, self.prev_span.lo);
4725-
err.span_label(sp,
4726-
&"did you mean to write `fn` here for a method declaration?");
4721+
err = self.diagnostic()
4722+
.struct_span_err(sp, "missing `fn` for method declaration");
4723+
err.span_label(sp, &"missing `fn`");
47274724
}
47284725
return Err(err);
4729-
} else if let Err(bang_err) = bang_err {
4730-
return Err(bang_err);
47314726
}
47324727

47334728
// eat a matched-delimiter token tree:
+3-7
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,8 @@
1-
error: can't qualify macro invocation with `pub`
2-
--> $DIR/issue-40006.rs:14:5
1+
error: missing `fn` for method declaration
2+
--> $DIR/issue-40006.rs:14:8
33
|
44
14 | pub hello_method(&self) {
5-
| ^^^- - expected `!` here for a macro invocation
6-
| |
7-
| did you mean to write `fn` here for a method declaration?
8-
|
9-
= help: try adjusting the macro to put `pub` inside the invocation
5+
| ^ missing `fn`
106

117
error: aborting due to previous error
128

0 commit comments

Comments
 (0)