Skip to content

Commit

Permalink
Rollup merge of rust-lang#40849 - jseyfried:finalize_trait_macro_reso…
Browse files Browse the repository at this point in the history
…lutions, r=nrc

bugfix: finalize resolutions of macros in trait positions

Fixes rust-lang#40845.
r? @nrc
  • Loading branch information
alexcrichton committed Mar 27, 2017
2 parents 498da9f + 737511e commit 68c7385
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 3 deletions.
4 changes: 4 additions & 0 deletions src/librustc_resolve/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -922,6 +922,10 @@ impl<'a> ModuleData<'a> {
fn is_local(&self) -> bool {
self.normal_ancestor_id.is_local()
}

fn nearest_item_scope(&'a self) -> Module<'a> {
if self.is_trait() { self.parent.unwrap() } else { self }
}
}

impl<'a> fmt::Debug for ModuleData<'a> {
Expand Down
5 changes: 2 additions & 3 deletions src/librustc_resolve/macros.rs
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,6 @@ impl<'a> base::Resolver for Resolver<'a> {
expansion: mark,
};
expansion.visit_with(&mut visitor);
self.current_module.unresolved_invocations.borrow_mut().remove(&mark);
invocation.expansion.set(visitor.legacy_scope);
}

Expand Down Expand Up @@ -390,7 +389,7 @@ impl<'a> Resolver<'a> {
Err(Determinacy::Determined)
},
};
self.current_module.macro_resolutions.borrow_mut()
self.current_module.nearest_item_scope().macro_resolutions.borrow_mut()
.push((path.into_boxed_slice(), span));
return def;
}
Expand All @@ -410,7 +409,7 @@ impl<'a> Resolver<'a> {
}
};

self.current_module.legacy_macro_resolutions.borrow_mut()
self.current_module.nearest_item_scope().legacy_macro_resolutions.borrow_mut()
.push((scope, path[0], span, kind));

result
Expand Down
16 changes: 16 additions & 0 deletions src/test/compile-fail/issue-40845.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
// Copyright 2017 The Rust Project Developers. See the COPYRIGHT
// file at the top-level directory of this distribution and at
// http://rust-lang.org/COPYRIGHT.
//
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
// option. This file may not be copied, modified, or distributed
// except according to those terms.

trait T { m!(); } //~ ERROR cannot find macro `m!` in this scope

struct S;
impl S { m!(); } //~ ERROR cannot find macro `m!` in this scope

fn main() {}

0 comments on commit 68c7385

Please sign in to comment.