@@ -473,22 +473,38 @@ fn configure_and_expand_inner<'a>(
473
473
ast_validation:: check_crate ( sess, & krate)
474
474
} ) ;
475
475
476
- krate = time ( sess, "maybe creating a macro crate" , || {
477
- let crate_types = sess. crate_types . borrow ( ) ;
478
- let num_crate_types = crate_types. len ( ) ;
479
- let is_proc_macro_crate = crate_types. contains ( & config:: CrateType :: ProcMacro ) ;
480
- let is_test_crate = sess. opts . test ;
481
- syntax_ext:: proc_macro_harness:: inject (
482
- & sess. parse_sess ,
483
- & mut resolver,
484
- krate,
485
- is_proc_macro_crate,
486
- has_proc_macro_decls,
487
- is_test_crate,
488
- num_crate_types,
489
- sess. diagnostic ( ) ,
490
- )
491
- } ) ;
476
+
477
+ let crate_types = sess. crate_types . borrow ( ) ;
478
+ let is_proc_macro_crate = crate_types. contains ( & config:: CrateType :: ProcMacro ) ;
479
+
480
+ // For backwards compatibility, we don't try to run proc macro injection
481
+ // if rustdoc is run on a proc macro crate without '--crate-type proc-macro' being
482
+ // specified. This should only affect users who manually invoke 'rustdoc', as
483
+ // 'cargo doc' will automatically pass the proper '--crate-type' flags.
484
+ // However, we do emit a warning, to let such users know that they should
485
+ // start passing '--crate-type proc-macro'
486
+ if has_proc_macro_decls && sess. opts . actually_rustdoc && !is_proc_macro_crate {
487
+ let mut msg = sess. diagnostic ( ) . struct_warn ( & "Trying to document proc macro crate \
488
+ without passing '--crate-type proc-macro to rustdoc") ;
489
+
490
+ msg. warn ( "The generated documentation may be incorrect" ) ;
491
+ msg. emit ( )
492
+ } else {
493
+ krate = time ( sess, "maybe creating a macro crate" , || {
494
+ let num_crate_types = crate_types. len ( ) ;
495
+ let is_test_crate = sess. opts . test ;
496
+ syntax_ext:: proc_macro_harness:: inject (
497
+ & sess. parse_sess ,
498
+ & mut resolver,
499
+ krate,
500
+ is_proc_macro_crate,
501
+ has_proc_macro_decls,
502
+ is_test_crate,
503
+ num_crate_types,
504
+ sess. diagnostic ( ) ,
505
+ )
506
+ } ) ;
507
+ }
492
508
493
509
// Done with macro expansion!
494
510
0 commit comments