Skip to content

Commit 20a71b2

Browse files
committed
rustc: Use a special filename for macros 1.1
This "special filename" is surrounded by `<>` to ensure that `FileMap::is_real_file` returns `false`. This way the "files" parsed here aren't emitted as dep info `.d` files and don't confuse Cargo about non-existent files. Closes rust-lang#36625
1 parent ea65ab6 commit 20a71b2

File tree

4 files changed

+52
-1
lines changed

4 files changed

+52
-1
lines changed

src/librustc_macro/lib.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,7 @@ impl FromStr for TokenStream {
139139
__internal::with_parse_sess(|sess| {
140140
let src = src.to_string();
141141
let cfg = Vec::new();
142-
let name = "rustc-macro source code".to_string();
142+
let name = "<rustc-macro source code>".to_string();
143143
let mut parser = parse::new_parser_from_source_str(sess, cfg, name,
144144
src);
145145
let mut ret = TokenStream { inner: Vec::new() };
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
-include ../tools.mk
2+
3+
all:
4+
$(RUSTC) foo.rs
5+
$(RUSTC) bar.rs --emit dep-info
6+
grep "rustc-macro source" $(TMPDIR)/bar.d && exit 1 || exit 0
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
// Copyright 2016 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+
#![feature(rustc_macro)]
12+
13+
#[macro_use]
14+
extern crate foo;
15+
16+
#[derive(A)]
17+
struct A;
18+
19+
fn main() {
20+
let _b = B;
21+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
// Copyright 2016 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+
#![crate_type = "rustc-macro"]
12+
#![feature(rustc_macro)]
13+
#![feature(rustc_macro_lib)]
14+
15+
extern crate rustc_macro;
16+
17+
use rustc_macro::TokenStream;
18+
19+
#[rustc_macro_derive(A)]
20+
pub fn derive(input: TokenStream) -> TokenStream {
21+
let input = input.to_string();
22+
assert!(input.contains("struct A;"));
23+
"struct B;".parse().unwrap()
24+
}

0 commit comments

Comments
 (0)