Auto merge of #36847 - alexcrichton:rustc-macro-doc, r=nrc
rustdoc: Fix documenting rustc-macro crates This commit adds a "hack" to the session to track whether we're a rustdoc session or not. If we're rustdoc then we skip the expansion to add the rustc-macro infrastructure. Closes #36820
This commit is contained in:
commit
ff713464e6
@ -488,7 +488,6 @@ impl<'a> Step<'a> {
|
||||
Source::CheckCodegenUnits { compiler } |
|
||||
Source::CheckIncremental { compiler } |
|
||||
Source::CheckUi { compiler } |
|
||||
Source::CheckRustdoc { compiler } |
|
||||
Source::CheckPretty { compiler } |
|
||||
Source::CheckCFail { compiler } |
|
||||
Source::CheckRPassValgrind { compiler } |
|
||||
@ -511,6 +510,7 @@ impl<'a> Step<'a> {
|
||||
self.debugger_scripts(compiler.stage),
|
||||
]
|
||||
}
|
||||
Source::CheckRustdoc { compiler } |
|
||||
Source::CheckRPassFull { compiler } |
|
||||
Source::CheckRFailFull { compiler } |
|
||||
Source::CheckCFailFull { compiler } |
|
||||
|
@ -288,6 +288,11 @@ top_level_options!(
|
||||
alt_std_name: Option<String> [TRACKED],
|
||||
// Indicates how the compiler should treat unstable features
|
||||
unstable_features: UnstableFeatures [TRACKED],
|
||||
|
||||
// Indicates whether this run of the compiler is actually rustdoc. This
|
||||
// is currently just a hack and will be removed eventually, so please
|
||||
// try to not rely on this too much.
|
||||
actually_rustdoc: bool [TRACKED],
|
||||
}
|
||||
);
|
||||
|
||||
@ -440,6 +445,7 @@ pub fn basic_options() -> Options {
|
||||
libs: Vec::new(),
|
||||
unstable_features: UnstableFeatures::Disallow,
|
||||
debug_assertions: true,
|
||||
actually_rustdoc: false,
|
||||
}
|
||||
}
|
||||
|
||||
@ -1523,6 +1529,7 @@ pub fn build_session_options_and_crate_config(matches: &getopts::Matches)
|
||||
libs: libs,
|
||||
unstable_features: UnstableFeatures::from_environment(),
|
||||
debug_assertions: debug_assertions,
|
||||
actually_rustdoc: false,
|
||||
},
|
||||
cfg)
|
||||
}
|
||||
|
@ -703,10 +703,14 @@ pub fn phase_2_configure_and_expand<'a, F>(sess: &Session,
|
||||
sess.diagnostic())
|
||||
});
|
||||
|
||||
// If we're in rustdoc we're always compiling as an rlib, but that'll trip a
|
||||
// bunch of checks in the `modify` function below. For now just skip this
|
||||
// step entirely if we're rustdoc as it's not too useful anyway.
|
||||
if !sess.opts.actually_rustdoc {
|
||||
krate = time(time_passes, "maybe creating a macro crate", || {
|
||||
let crate_types = sess.crate_types.borrow();
|
||||
let is_rustc_macro_crate = crate_types.contains(&config::CrateTypeRustcMacro);
|
||||
let num_crate_types = crate_types.len();
|
||||
let is_rustc_macro_crate = crate_types.contains(&config::CrateTypeRustcMacro);
|
||||
syntax_ext::rustc_macro_registrar::modify(&sess.parse_sess,
|
||||
&mut resolver,
|
||||
krate,
|
||||
@ -715,6 +719,7 @@ pub fn phase_2_configure_and_expand<'a, F>(sess: &Session,
|
||||
sess.diagnostic(),
|
||||
&sess.features.borrow())
|
||||
});
|
||||
}
|
||||
|
||||
if sess.opts.debugging_opts.input_stats {
|
||||
println!("Post-expansion node count: {}", count_nodes(&krate));
|
||||
|
@ -150,6 +150,7 @@ pub fn run_core(search_paths: SearchPaths,
|
||||
target_triple: triple.unwrap_or(config::host_triple().to_string()),
|
||||
// Ensure that rustdoc works even if rustc is feature-staged
|
||||
unstable_features: UnstableFeatures::Allow,
|
||||
actually_rustdoc: true,
|
||||
..config::basic_options().clone()
|
||||
};
|
||||
|
||||
|
24
src/test/rustdoc/rustc-macro-crate.rs
Normal file
24
src/test/rustdoc/rustc-macro-crate.rs
Normal file
@ -0,0 +1,24 @@
|
||||
// Copyright 2016 The Rust Project Developers. See the COPYRIGHT
|
||||
// file at the top-level directory of this distribution and at
|
||||
// http://rust-lang.org/COPYRIGHT.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
|
||||
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
|
||||
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
|
||||
// option. This file may not be copied, modified, or distributed
|
||||
// except according to those terms.
|
||||
|
||||
// no-prefer-dynamic
|
||||
|
||||
#![feature(rustc_macro)]
|
||||
#![feature(rustc_macro_lib)]
|
||||
#![crate_type = "rustc-macro"]
|
||||
|
||||
extern crate rustc_macro;
|
||||
|
||||
use rustc_macro::TokenStream;
|
||||
|
||||
#[rustc_macro_derive(Foo)]
|
||||
pub fn foo(input: TokenStream) -> TokenStream {
|
||||
input
|
||||
}
|
Loading…
Reference in New Issue
Block a user