Skip to content

Commit 083f4f0

Browse files
committed
Add missing error-return case
1 parent fa332c9 commit 083f4f0

File tree

2 files changed

+18
-4
lines changed

2 files changed

+18
-4
lines changed

src/libsyntax/parse/parser.rs

+6-4
Original file line numberDiff line numberDiff line change
@@ -4744,8 +4744,8 @@ impl<'a> Parser<'a> {
47444744
let lo = self.span;
47454745
let pth = self.parse_path(PathStyle::Mod)?;
47464746
let bang_err = self.expect(&token::Not);
4747-
if let Err(mut err) = err {
4748-
if let Err(mut bang_err) = bang_err {
4747+
match (err, bang_err) {
4748+
(Err(mut err), Err(mut bang_err)) => {
47494749
// Given this code `pub path(`, it seems like this is not setting the
47504750
// visibility of a macro invocation, but rather a mistyped method declaration.
47514751
// Create a diagnostic pointing out that `fn` is missing.
@@ -4758,11 +4758,13 @@ impl<'a> Parser<'a> {
47584758
// pub path(
47594759
// ^^ `sp` below will point to this
47604760
let sp = prev_span.between(self.prev_span);
4761-
err = self.diagnostic()
4761+
let mut err = self.diagnostic()
47624762
.struct_span_err(sp, "missing `fn` for method declaration");
47634763
err.span_label(sp, &"missing `fn`");
4764+
return Err(err);
47644765
}
4765-
return Err(err);
4766+
(Err(err), _) | (_, Err(err)) => return Err(err),
4767+
(_, _) => ()
47664768
}
47674769

47684770
// eat a matched-delimiter token tree:

src/test/compile-fail/issue-41161.rs

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
// Copyright 2017 The Rust Project Developers. See the COPYRIGHT
2+
// file at the top-level directory of this distribution and at
3+
// http://rust-lang.org/COPYRIGHT.
4+
//
5+
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6+
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7+
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8+
// option. This file may not be copied, modified, or distributed
9+
// except according to those terms.
10+
11+
impl X { not_a_macro_invocation }
12+
//~^ ERROR expected one of `!` or `::`, found `}`

0 commit comments

Comments
 (0)