Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 18 additions & 2 deletions src/tools/compiletest/src/directives/auxiliary.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,12 @@ pub struct AuxCrate {
}

/// The value of a `proc-macro` directive.
#[derive(Clone, Debug, Default)]
#[derive(Clone, Debug, Default, PartialEq, Eq)]
pub(crate) struct ProcMacro {
/// Contains `--extern` modifiers, if any. See the tracking issue for more
/// info: <https://github.com/rust-lang/rust/issues/98405>
/// With `proc-macro: noprelude:bar.rs` this will be `noprelude`.
pub extern_modifiers: Option<String>,
/// With `proc-macro: bar.rs` this will be `bar.rs`.
pub path: String,
}
Expand Down Expand Up @@ -108,5 +112,17 @@ fn parse_aux_crate(r: String) -> AuxCrate {
}

fn parse_proc_macro(r: String) -> ProcMacro {
ProcMacro { path: r.trim().to_string() }
let r = r.trim();

// Matches:
// path
// modifiers:path
let caps = static_regex!(r"^(?:(?<modifiers>[^=]*?):)?(?<path>.*)$")
.captures(r)
.expect("can never fail");

let modifiers = caps.name("modifiers").map(|m| m.as_str().to_string());
let path = caps["path"].to_string();

ProcMacro { extern_modifiers: modifiers, path }
}
16 changes: 16 additions & 0 deletions src/tools/compiletest/src/directives/auxiliary/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,3 +25,19 @@ fn test_aux_crate_value_with_modifiers() {
fn test_aux_crate_value_invalid() {
parse_aux_crate("foo.rs".to_string());
}

#[test]
fn test_proc_macro_value_no_modifiers() {
assert_eq!(
ProcMacro { extern_modifiers: None, path: "foo.rs".to_string() },
parse_proc_macro("foo.rs".to_string())
);
}

#[test]
fn test_proc_macro_value_with_modifiers() {
assert_eq!(
ProcMacro { extern_modifiers: Some("noprelude".to_string()), path: "foo.rs".to_string() },
parse_proc_macro("noprelude:foo.rs".to_string())
);
}
2 changes: 1 addition & 1 deletion src/tools/compiletest/src/runtest.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1302,7 +1302,7 @@ impl<'test> TestCx<'test> {
let crate_name = path_to_crate_name(&proc_macro.path);
add_extern(
rustc,
None, // `extern_modifiers`
proc_macro.extern_modifiers.as_deref(),
&crate_name,
&proc_macro.path,
AuxType::ProcMacro,
Expand Down
5 changes: 0 additions & 5 deletions tests/ui/privacy/pub-priv-dep/auxiliary/pm.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,3 @@
//@ force-host
//@ no-prefer-dynamic

#![crate_type = "proc-macro"]

extern crate proc_macro;
use proc_macro::TokenStream;

Expand Down
2 changes: 1 addition & 1 deletion tests/ui/privacy/pub-priv-dep/pub-priv1.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
//@ aux-crate:priv:priv_dep=priv_dep.rs
//@ aux-build:pub_dep.rs
//@ aux-crate:priv:pm=pm.rs
//@ proc-macro:priv:pm.rs
//@ compile-flags: -Zunstable-options

// Basic behavior check of exported_private_dependencies from either a public
Expand Down
Loading