diff options
| author | Aaron Hill <aa1ronham@gmail.com> | 2019-08-28 18:00:36 -0400 |
|---|---|---|
| committer | Aaron Hill <aa1ronham@gmail.com> | 2019-08-28 18:00:36 -0400 |
| commit | 4c3e386bd7ee9020407cee4ba120eebfb6373549 (patch) | |
| tree | af353e2a35d0d1038d64e8aa43c71e8e408c4514 | |
| parent | 14986081355db0a2ae67df6a43dd9e6e360d718c (diff) | |
Allow running rustdoc on proc-macro crates without specifying '--crate-type proc-macro'
Add a test to make sure that this works
| -rw-r--r-- | src/librustc_interface/passes.rs | 48 |
1 files changed, 32 insertions, 16 deletions
diff --git a/src/librustc_interface/passes.rs b/src/librustc_interface/passes.rs index 856690903c6..24b44964e4f 100644 --- a/src/librustc_interface/passes.rs +++ b/src/librustc_interface/passes.rs @@ -473,22 +473,38 @@ fn configure_and_expand_inner<'a>( ast_validation::check_crate(sess, &krate) }); - krate = time(sess, "maybe creating a macro crate", || { - let crate_types = sess.crate_types.borrow(); - let num_crate_types = crate_types.len(); - let is_proc_macro_crate = crate_types.contains(&config::CrateType::ProcMacro); - let is_test_crate = sess.opts.test; - syntax_ext::proc_macro_harness::inject( - &sess.parse_sess, - &mut resolver, - krate, - is_proc_macro_crate, - has_proc_macro_decls, - is_test_crate, - num_crate_types, - sess.diagnostic(), - ) - }); + + let crate_types = sess.crate_types.borrow(); + let is_proc_macro_crate = crate_types.contains(&config::CrateType::ProcMacro); + + // For backwards compatibility, we don't try to run proc macro injection + // if rustdoc is run on a proc macro crate without '--crate-type proc-macro' being + // specified. This should only affect users who manually invoke 'rustdoc', as + // 'cargo doc' will automatically pass the proper '--crate-type' flags. + // However, we do emit a warning, to let such users know that they should + // start passing '--crate-type proc-macro' + if has_proc_macro_decls && sess.opts.actually_rustdoc && !is_proc_macro_crate { + let mut msg = sess.diagnostic().struct_warn(&"Trying to document proc macro crate \ + without passing '--crate-type proc-macro to rustdoc"); + + msg.warn("The generated documentation may be incorrect"); + msg.emit() + } else { + krate = time(sess, "maybe creating a macro crate", || { + let num_crate_types = crate_types.len(); + let is_test_crate = sess.opts.test; + syntax_ext::proc_macro_harness::inject( + &sess.parse_sess, + &mut resolver, + krate, + is_proc_macro_crate, + has_proc_macro_decls, + is_test_crate, + num_crate_types, + sess.diagnostic(), + ) + }); + } // Done with macro expansion! |
