Skip to content

Commit cb96ade

Browse files
committed
Fix regression when include!()ing a macro_rules! containing a $crate:: path.
1 parent d9cf601 commit cb96ade

File tree

3 files changed

+33
-1
lines changed

3 files changed

+33
-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

+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+
// ignore-pretty issue #37195
12+
13+
#![allow(dead_code)]
14+
15+
include!("auxiliary/issue_40469.rs");
16+
fn f() { m!(); }
17+
18+
fn main() {}

0 commit comments

Comments
 (0)