Skip to content

Commit e295a90

Browse files
committed
Treat "proc-macro" crate type the same as proc-macro = true
1 parent 0eee76e commit e295a90

File tree

2 files changed

+74
-1
lines changed

2 files changed

+74
-1
lines changed

src/cargo/util/toml/mod.rs

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1474,7 +1474,14 @@ impl TomlTarget {
14741474
}
14751475

14761476
fn proc_macro(&self) -> Option<bool> {
1477-
self.proc_macro.or(self.proc_macro2)
1477+
self.proc_macro.or(self.proc_macro2).or_else(|| {
1478+
if let Some(types) = self.crate_types() {
1479+
if types.contains(&"proc-macro".to_string()) {
1480+
return Some(true);
1481+
}
1482+
}
1483+
None
1484+
})
14781485
}
14791486

14801487
fn crate_types(&self) -> Option<&Vec<String>> {

tests/testsuite/proc_macro.rs

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -279,3 +279,69 @@ fn a() {
279279
.with_stdout_contains_n("test [..] ... ok", 2)
280280
.run();
281281
}
282+
283+
#[test]
284+
fn proc_macro_crate_type() {
285+
// Verify that `crate-type = ["proc-macro"]` is the same as `proc-macro = true`
286+
// and that everything, including rustdoc, works correctly.
287+
let foo = project()
288+
.file(
289+
"Cargo.toml",
290+
r#"
291+
[package]
292+
name = "foo"
293+
version = "0.1.0"
294+
[dependencies]
295+
pm = { path = "pm" }
296+
"#,
297+
)
298+
.file(
299+
"src/lib.rs",
300+
r#"
301+
//! ```
302+
//! use foo::THING;
303+
//! assert_eq!(THING, 123);
304+
//! ```
305+
#[macro_use]
306+
extern crate pm;
307+
#[derive(MkItem)]
308+
pub struct S;
309+
#[cfg(test)]
310+
mod tests {
311+
use super::THING;
312+
#[test]
313+
fn it_works() {
314+
assert_eq!(THING, 123);
315+
}
316+
}
317+
"#,
318+
)
319+
.file(
320+
"pm/Cargo.toml",
321+
r#"
322+
[package]
323+
name = "pm"
324+
version = "0.1.0"
325+
[lib]
326+
crate-type = ["proc-macro"]
327+
"#,
328+
)
329+
.file(
330+
"pm/src/lib.rs",
331+
r#"
332+
extern crate proc_macro;
333+
use proc_macro::TokenStream;
334+
335+
#[proc_macro_derive(MkItem)]
336+
pub fn mk_item(_input: TokenStream) -> TokenStream {
337+
"pub const THING: i32 = 123;".parse().unwrap()
338+
}
339+
"#,
340+
)
341+
.build();
342+
343+
foo.cargo("test")
344+
.with_stdout_contains("test tests::it_works ... ok")
345+
.with_stdout_contains_n("test [..] ... ok", 2)
346+
.run();
347+
}

0 commit comments

Comments
 (0)