Skip to content

Commit b24d12e

Browse files
committed
Auto merge of #47031 - topecongiro:issue-41719, r=jseyfried
Report an error when resolving non-ident macro path failed Closes #41719. Please feel free to bikeshed on the error message.
2 parents 5f7aeaf + d1b287c commit b24d12e

File tree

2 files changed

+27
-1
lines changed

2 files changed

+27
-1
lines changed

src/librustc_resolve/macros.rs

+9-1
Original file line numberDiff line numberDiff line change
@@ -429,7 +429,15 @@ impl<'a> Resolver<'a> {
429429
let def = match self.resolve_path(&path, Some(MacroNS), false, span) {
430430
PathResult::NonModule(path_res) => match path_res.base_def() {
431431
Def::Err => Err(Determinacy::Determined),
432-
def @ _ => Ok(def),
432+
def @ _ => {
433+
if path_res.unresolved_segments() > 0 {
434+
self.found_unresolved_macro = true;
435+
self.session.span_err(span, "fail to resolve non-ident macro path");
436+
Err(Determinacy::Determined)
437+
} else {
438+
Ok(def)
439+
}
440+
}
433441
},
434442
PathResult::Module(..) => unreachable!(),
435443
PathResult::Indeterminate if !force => return Err(Determinacy::Undetermined),

src/test/compile-fail/extern-macro.rs

+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
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+
// #41719
12+
13+
#![feature(use_extern_macros)]
14+
15+
fn main() {
16+
enum Foo {}
17+
let _ = Foo::bar!(); //~ ERROR fail to resolve non-ident macro path
18+
}

0 commit comments

Comments
 (0)