Allow running rustdoc on proc-macro crates without specifying '--crate-type proc-macro'

Add a test to make sure that this works
This commit is contained in:
Aaron Hill 2019-08-28 18:00:36 -04:00
parent 1498608135
commit 4c3e386bd7
No known key found for this signature in database
GPG key ID: B4087E510E98B164

View file

@ -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!