Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 4955503

Browse files
authoredMar 17, 2017
Rollup merge of rust-lang#40583 - jseyfried:fix_include_macro_regression, r=nrc
macros: fix regression with `include!()` Fixes rust-lang#40469, a regression when `include!()`ing a `macro_rules!` containing `$crate`. r? @nrc
2 parents c4c51ca + 284ece3 commit 4955503

File tree

3 files changed

+31
-1
lines changed

3 files changed

+31
-1
lines changed
 

‎src/librustc_resolve/build_reduced_graph.rs

+4-1
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ use {resolve_error, resolve_struct_error, ResolutionError};
2323

2424
use rustc::middle::cstore::LoadedMacro;
2525
use rustc::hir::def::*;
26-
use rustc::hir::def_id::{CrateNum, CRATE_DEF_INDEX, DefId};
26+
use rustc::hir::def_id::{CrateNum, BUILTIN_MACROS_CRATE, CRATE_DEF_INDEX, DefId};
2727
use rustc::ty;
2828

2929
use std::cell::Cell;
@@ -496,6 +496,9 @@ impl<'a> Resolver<'a> {
496496
let def_id = self.macro_defs[&expansion];
497497
if let Some(id) = self.definitions.as_local_node_id(def_id) {
498498
self.local_macro_def_scopes[&id]
499+
} else if def_id.krate == BUILTIN_MACROS_CRATE {
500+
// FIXME(jseyfried): This happens when `include!()`ing a `$crate::` path, c.f, #40469.
501+
self.graph_root
499502
} else {
500503
let module_def_id = ty::DefIdTree::parent(&*self, def_id).unwrap();
501504
self.get_extern_crate_root(module_def_id.krate)
+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
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+
macro_rules! m { () => { $crate::main(); } }

‎src/test/run-pass/issue-40469.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+
#![allow(dead_code)]
12+
13+
include!("auxiliary/issue_40469.rs");
14+
fn f() { m!(); }
15+
16+
fn main() {}

0 commit comments

Comments
 (0)
Please sign in to comment.