diff options
| author | bors <bors@rust-lang.org> | 2016-09-27 20:21:12 -0700 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2016-09-27 20:21:12 -0700 |
| commit | 755516bb96cc0f74c3098d2a64917f4e0a6f3f03 (patch) | |
| tree | 8068f125b99e456b83d593b753b16c9d91d23bcc /src | |
| parent | a059cb2f3344c0a9efae17dde3d0e16a55ce93db (diff) | |
| parent | 20a71b25c0af2b27e9152911479d45f941b2a97e (diff) | |
| download | rust-755516bb96cc0f74c3098d2a64917f4e0a6f3f03.tar.gz rust-755516bb96cc0f74c3098d2a64917f4e0a6f3f03.zip | |
Auto merge of #36776 - alexcrichton:rustc-macro-dep-files, r=nrc
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 #36625
Diffstat (limited to 'src')
| -rw-r--r-- | src/librustc_macro/lib.rs | 2 | ||||
| -rw-r--r-- | src/test/run-make/rustc-macro-dep-files/Makefile | 6 | ||||
| -rw-r--r-- | src/test/run-make/rustc-macro-dep-files/bar.rs | 21 | ||||
| -rw-r--r-- | src/test/run-make/rustc-macro-dep-files/foo.rs | 24 |
4 files changed, 52 insertions, 1 deletions
diff --git a/src/librustc_macro/lib.rs b/src/librustc_macro/lib.rs index c2a2cc2ecd6..1f3b705671d 100644 --- a/src/librustc_macro/lib.rs +++ b/src/librustc_macro/lib.rs @@ -139,7 +139,7 @@ impl FromStr for TokenStream { __internal::with_parse_sess(|sess| { let src = src.to_string(); let cfg = Vec::new(); - let name = "rustc-macro source code".to_string(); + let name = "<rustc-macro source code>".to_string(); let mut parser = parse::new_parser_from_source_str(sess, cfg, name, src); let mut ret = TokenStream { inner: Vec::new() }; diff --git a/src/test/run-make/rustc-macro-dep-files/Makefile b/src/test/run-make/rustc-macro-dep-files/Makefile new file mode 100644 index 00000000000..d27b5d0f3c4 --- /dev/null +++ b/src/test/run-make/rustc-macro-dep-files/Makefile @@ -0,0 +1,6 @@ +-include ../tools.mk + +all: + $(RUSTC) foo.rs + $(RUSTC) bar.rs --emit dep-info + grep "rustc-macro source" $(TMPDIR)/bar.d && exit 1 || exit 0 diff --git a/src/test/run-make/rustc-macro-dep-files/bar.rs b/src/test/run-make/rustc-macro-dep-files/bar.rs new file mode 100644 index 00000000000..dac652797e6 --- /dev/null +++ b/src/test/run-make/rustc-macro-dep-files/bar.rs @@ -0,0 +1,21 @@ +// Copyright 2016 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. + +#![feature(rustc_macro)] + +#[macro_use] +extern crate foo; + +#[derive(A)] +struct A; + +fn main() { + let _b = B; +} diff --git a/src/test/run-make/rustc-macro-dep-files/foo.rs b/src/test/run-make/rustc-macro-dep-files/foo.rs new file mode 100644 index 00000000000..c302ca824d0 --- /dev/null +++ b/src/test/run-make/rustc-macro-dep-files/foo.rs @@ -0,0 +1,24 @@ +// Copyright 2016 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. + +#![crate_type = "rustc-macro"] +#![feature(rustc_macro)] +#![feature(rustc_macro_lib)] + +extern crate rustc_macro; + +use rustc_macro::TokenStream; + +#[rustc_macro_derive(A)] +pub fn derive(input: TokenStream) -> TokenStream { + let input = input.to_string(); + assert!(input.contains("struct A;")); + "struct B;".parse().unwrap() +} |
