File tree Expand file tree Collapse file tree 2 files changed +74
-1
lines changed Expand file tree Collapse file tree 2 files changed +74
-1
lines changed Original file line number Diff line number Diff line change @@ -1474,7 +1474,14 @@ impl TomlTarget {
1474
1474
}
1475
1475
1476
1476
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
+ } )
1478
1485
}
1479
1486
1480
1487
fn crate_types ( & self ) -> Option < & Vec < String > > {
Original file line number Diff line number Diff line change @@ -279,3 +279,69 @@ fn a() {
279
279
. with_stdout_contains_n ( "test [..] ... ok" , 2 )
280
280
. run ( ) ;
281
281
}
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
+ }
You can’t perform that action at this time.
0 commit comments