Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

rustdoc: Fix documenting rustc-macro crates #36847

Merged
merged 1 commit into from
Oct 3, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/bootstrap/step.rs
Original file line number Diff line number Diff line change
Expand Up @@ -486,7 +486,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 } |
Expand All @@ -509,6 +508,7 @@ impl<'a> Step<'a> {
self.debugger_scripts(compiler.stage),
]
}
Source::CheckRustdoc { compiler } |
Source::CheckRPassFull { compiler } |
Source::CheckRFailFull { compiler } |
Source::CheckCFailFull { compiler } |
Expand Down
7 changes: 7 additions & 0 deletions src/librustc/session/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -287,6 +287,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],
}
);

Expand Down Expand Up @@ -439,6 +444,7 @@ pub fn basic_options() -> Options {
libs: Vec::new(),
unstable_features: UnstableFeatures::Disallow,
debug_assertions: true,
actually_rustdoc: false,
}
}

Expand Down Expand Up @@ -1536,6 +1542,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)
}
Expand Down
29 changes: 17 additions & 12 deletions src/librustc_driver/driver.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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));
Expand Down
1 change: 1 addition & 0 deletions src/librustdoc/core.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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()
};

Expand Down
24 changes: 24 additions & 0 deletions src/test/rustdoc/rustc-macro-crate.rs
Original file line number Diff line number Diff line change
@@ -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
}