Skip to content

Commit

Permalink
Allow running rustdoc on proc-macro crates without specifying '--crat…
Browse files Browse the repository at this point in the history
…e-type proc-macro'

Add a test to make sure that this works
  • Loading branch information
Aaron1011 committed Aug 28, 2019
1 parent 1498608 commit 4c3e386
Showing 1 changed file with 32 additions and 16 deletions.
48 changes: 32 additions & 16 deletions src/librustc_interface/passes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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!

Expand Down

0 comments on commit 4c3e386

Please sign in to comment.