diff --git a/src/bootstrap/step.rs b/src/bootstrap/step.rs index 8a96cd1b4d2..e3567107884 100644 --- a/src/bootstrap/step.rs +++ b/src/bootstrap/step.rs @@ -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 } | diff --git a/src/librustc/session/config.rs b/src/librustc/session/config.rs index f8b06bf2e97..9987fbab389 100644 --- a/src/librustc/session/config.rs +++ b/src/librustc/session/config.rs @@ -288,6 +288,11 @@ top_level_options!( alt_std_name: Option [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) } diff --git a/src/librustc_driver/driver.rs b/src/librustc_driver/driver.rs index f9ac1312d3c..8059ef61eab 100644 --- a/src/librustc_driver/driver.rs +++ b/src/librustc_driver/driver.rs @@ -703,18 +703,23 @@ pub fn phase_2_configure_and_expand<'a, F>(sess: &Session, sess.diagnostic()) }); - 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(); - syntax_ext::rustc_macro_registrar::modify(&sess.parse_sess, - &mut resolver, - krate, - is_rustc_macro_crate, - num_crate_types, - sess.diagnostic(), - &sess.features.borrow()) - }); + // 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 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, + is_rustc_macro_crate, + num_crate_types, + sess.diagnostic(), + &sess.features.borrow()) + }); + } if sess.opts.debugging_opts.input_stats { println!("Post-expansion node count: {}", count_nodes(&krate)); diff --git a/src/librustdoc/core.rs b/src/librustdoc/core.rs index 49e467e5cbe..208819a4a0b 100644 --- a/src/librustdoc/core.rs +++ b/src/librustdoc/core.rs @@ -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() }; diff --git a/src/test/rustdoc/rustc-macro-crate.rs b/src/test/rustdoc/rustc-macro-crate.rs new file mode 100644 index 00000000000..c8bf5b2b912 --- /dev/null +++ b/src/test/rustdoc/rustc-macro-crate.rs @@ -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 or the MIT license +// , 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 +}