Skip to content

Commit 737511e

Browse files
committed
Ensure that macro resolutions in trait positions get finalized.
1 parent 7846dbe commit 737511e

File tree

3 files changed

+22
-3
lines changed

3 files changed

+22
-3
lines changed

src/librustc_resolve/lib.rs

+4
Original file line numberDiff line numberDiff line change
@@ -922,6 +922,10 @@ impl<'a> ModuleData<'a> {
922922
fn is_local(&self) -> bool {
923923
self.normal_ancestor_id.is_local()
924924
}
925+
926+
fn nearest_item_scope(&'a self) -> Module<'a> {
927+
if self.is_trait() { self.parent.unwrap() } else { self }
928+
}
925929
}
926930

927931
impl<'a> fmt::Debug for ModuleData<'a> {

src/librustc_resolve/macros.rs

+2-3
Original file line numberDiff line numberDiff line change
@@ -172,7 +172,6 @@ impl<'a> base::Resolver for Resolver<'a> {
172172
expansion: mark,
173173
};
174174
expansion.visit_with(&mut visitor);
175-
self.current_module.unresolved_invocations.borrow_mut().remove(&mark);
176175
invocation.expansion.set(visitor.legacy_scope);
177176
}
178177

@@ -390,7 +389,7 @@ impl<'a> Resolver<'a> {
390389
Err(Determinacy::Determined)
391390
},
392391
};
393-
self.current_module.macro_resolutions.borrow_mut()
392+
self.current_module.nearest_item_scope().macro_resolutions.borrow_mut()
394393
.push((path.into_boxed_slice(), span));
395394
return def;
396395
}
@@ -410,7 +409,7 @@ impl<'a> Resolver<'a> {
410409
}
411410
};
412411

413-
self.current_module.legacy_macro_resolutions.borrow_mut()
412+
self.current_module.nearest_item_scope().legacy_macro_resolutions.borrow_mut()
414413
.push((scope, path[0], span, kind));
415414

416415
result

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

+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
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+
trait T { m!(); } //~ ERROR cannot find macro `m!` in this scope
12+
13+
struct S;
14+
impl S { m!(); } //~ ERROR cannot find macro `m!` in this scope
15+
16+
fn main() {}

0 commit comments

Comments
 (0)