diff options
| author | Joshua Nelson <jyn514@gmail.com> | 2020-10-10 14:27:52 -0400 |
|---|---|---|
| committer | Joshua Nelson <jyn514@gmail.com> | 2020-11-07 13:45:11 -0500 |
| commit | 622c48e4f1a5bc3727f8ead89767c8a9e367a77e (patch) | |
| tree | 559b4777071477577cca6b704a6e5f70deca06e7 /src/librustdoc | |
| parent | dc06a36074f04c6a77b5834f2950011d49607898 (diff) | |
| download | rust-622c48e4f1a5bc3727f8ead89767c8a9e367a77e.tar.gz rust-622c48e4f1a5bc3727f8ead89767c8a9e367a77e.zip | |
Allow making `RUSTC_BOOTSTRAP` conditional on the crate name
The main change is that `UnstableOptions::from_environment` now requires an (optional) crate name. If the crate name is unknown (`None`), then the new feature is not available and you still have to use `RUSTC_BOOTSTRAP=1`. In practice this means the feature is only available for `--crate-name`, not for `#![crate_name]`; I'm interested in supporting the second but I'm not sure how. Other major changes: - Added `Session::is_nightly_build()`, which uses the `crate_name` of the session - Added `nightly_options::match_is_nightly_build`, a convenience method for looking up `--crate-name` from CLI arguments. `Session::is_nightly_build()`should be preferred where possible, since it will take into account `#![crate_name]` (I think). - Added `unstable_features` to `rustdoc::RenderOptions` There is a user-facing change here: things like `RUSTC_BOOTSTRAP=0` no longer active nightly features. In practice this shouldn't be a big deal, since `RUSTC_BOOTSTRAP` is the opposite of stable and everyone uses `RUSTC_BOOTSTRAP=1` anyway. - Add tests Check against `Cheat`, not whether nightly features are allowed. Nightly features are always allowed on the nightly channel. - Only call `is_nightly_build()` once within a function - Use booleans consistently for rustc_incremental Sessions can't be passed through threads, so `read_file` couldn't take a session. To be consistent, also take a boolean in `write_file_header`.
Diffstat (limited to 'src/librustdoc')
| -rw-r--r-- | src/librustdoc/clean/types.rs | 4 | ||||
| -rw-r--r-- | src/librustdoc/config.rs | 16 | ||||
| -rw-r--r-- | src/librustdoc/core.rs | 2 | ||||
| -rw-r--r-- | src/librustdoc/doctest.rs | 3 | ||||
| -rw-r--r-- | src/librustdoc/externalfiles.rs | 4 | ||||
| -rw-r--r-- | src/librustdoc/html/render/mod.rs | 4 | ||||
| -rw-r--r-- | src/librustdoc/markdown.rs | 5 | ||||
| -rw-r--r-- | src/librustdoc/passes/doc_test_lints.rs | 4 | ||||
| -rw-r--r-- | src/librustdoc/passes/html_tags.rs | 3 | ||||
| -rw-r--r-- | src/librustdoc/passes/non_autolinks.rs | 3 |
10 files changed, 26 insertions, 22 deletions
diff --git a/src/librustdoc/clean/types.rs b/src/librustdoc/clean/types.rs index 32b3f69ecd4..5f5deebca65 100644 --- a/src/librustdoc/clean/types.rs +++ b/src/librustdoc/clean/types.rs @@ -681,7 +681,9 @@ impl Attributes { } Some(&(_, _, ExternalLocation::Remote(ref s))) => s.to_string(), Some(&(_, _, ExternalLocation::Unknown)) | None => String::from( - if UnstableFeatures::from_environment().is_nightly_build() { + // NOTE: intentionally doesn't pass crate name to avoid having + // different primitive links between crates + if UnstableFeatures::from_environment(None).is_nightly_build() { "https://doc.rust-lang.org/nightly" } else { "https://doc.rust-lang.org" diff --git a/src/librustdoc/config.rs b/src/librustdoc/config.rs index 02885f51936..b7db665147e 100644 --- a/src/librustdoc/config.rs +++ b/src/librustdoc/config.rs @@ -253,6 +253,7 @@ pub struct RenderOptions { pub document_private: bool, /// Document items that have `doc(hidden)`. pub document_hidden: bool, + pub unstable_features: rustc_feature::UnstableFeatures, } /// Temporary storage for data obtained during `RustdocVisitor::clean()`. @@ -295,7 +296,7 @@ impl Options { println_condition(p.condition); } - if nightly_options::is_nightly_build() { + if nightly_options::match_is_nightly_build(matches) { println!("\nPasses run with `--show-coverage`:"); for p in passes::COVERAGE_PASSES { print!("{:>20}", p.pass.name); @@ -479,6 +480,7 @@ impl Options { &matches.opt_strs("html-after-content"), &matches.opt_strs("markdown-before-content"), &matches.opt_strs("markdown-after-content"), + nightly_options::match_is_nightly_build(&matches), &diag, &mut id_map, edition, @@ -535,7 +537,9 @@ impl Options { let output_format = match matches.opt_str("output-format") { Some(s) => match OutputFormat::try_from(s.as_str()) { Ok(o) => { - if o.is_json() && !(show_coverage || nightly_options::is_nightly_build()) { + if o.is_json() + && !(show_coverage || nightly_options::match_is_nightly_build(matches)) + { diag.struct_err("json output format isn't supported for doc generation") .emit(); return Err(1); @@ -586,7 +590,6 @@ impl Options { Ok(Options { input, - crate_name, proc_macro_crate, error_format, libs, @@ -637,7 +640,11 @@ impl Options { generate_search_filter, document_private, document_hidden, + unstable_features: rustc_feature::UnstableFeatures::from_environment( + crate_name.as_deref(), + ), }, + crate_name, output_format, }) } @@ -655,7 +662,8 @@ fn check_deprecated_options(matches: &getopts::Matches, diag: &rustc_errors::Han for flag in deprecated_flags.iter() { if matches.opt_present(flag) { if *flag == "output-format" - && (matches.opt_present("show-coverage") || nightly_options::is_nightly_build()) + && (matches.opt_present("show-coverage") + || nightly_options::match_is_nightly_build(matches)) { continue; } diff --git a/src/librustdoc/core.rs b/src/librustdoc/core.rs index 5eca54199d6..4cfc0a10c00 100644 --- a/src/librustdoc/core.rs +++ b/src/librustdoc/core.rs @@ -370,7 +370,7 @@ pub fn run_core( cg: codegen_options, externs, target_triple: target, - unstable_features: UnstableFeatures::from_environment(), + unstable_features: UnstableFeatures::from_environment(crate_name.as_deref()), actually_rustdoc: true, debugging_opts, error_format, diff --git a/src/librustdoc/doctest.rs b/src/librustdoc/doctest.rs index eb33890fb5f..5e40e6b151d 100644 --- a/src/librustdoc/doctest.rs +++ b/src/librustdoc/doctest.rs @@ -1,7 +1,6 @@ use rustc_ast as ast; use rustc_data_structures::sync::Lrc; use rustc_errors::ErrorReported; -use rustc_feature::UnstableFeatures; use rustc_hir as hir; use rustc_hir::intravisit; use rustc_hir::{HirId, CRATE_HIR_ID}; @@ -70,7 +69,7 @@ pub fn run(options: Options) -> Result<(), ErrorReported> { lint_cap: Some(options.lint_cap.clone().unwrap_or_else(|| lint::Forbid)), cg: options.codegen_options.clone(), externs: options.externs.clone(), - unstable_features: UnstableFeatures::from_environment(), + unstable_features: options.render_options.unstable_features, actually_rustdoc: true, debugging_opts: config::DebuggingOptions { ..config::basic_debugging_options() }, edition: options.edition, diff --git a/src/librustdoc/externalfiles.rs b/src/librustdoc/externalfiles.rs index c8121d39d0f..900821dbf4a 100644 --- a/src/librustdoc/externalfiles.rs +++ b/src/librustdoc/externalfiles.rs @@ -1,6 +1,5 @@ use crate::html::markdown::{ErrorCodes, IdMap, Markdown, Playground}; use crate::rustc_span::edition::Edition; -use rustc_feature::UnstableFeatures; use std::fs; use std::path::Path; use std::str; @@ -25,12 +24,13 @@ impl ExternalHtml { after_content: &[String], md_before_content: &[String], md_after_content: &[String], + nightly_build: bool, diag: &rustc_errors::Handler, id_map: &mut IdMap, edition: Edition, playground: &Option<Playground>, ) -> Option<ExternalHtml> { - let codes = ErrorCodes::from(UnstableFeatures::from_environment().is_nightly_build()); + let codes = ErrorCodes::from(nightly_build); let ih = load_external_files(in_header, diag)?; let bc = load_external_files(before_content, diag)?; let m_bc = load_external_files(md_before_content, diag)?; diff --git a/src/librustdoc/html/render/mod.rs b/src/librustdoc/html/render/mod.rs index 5ac0ffcfbf1..b3bfa7138a0 100644 --- a/src/librustdoc/html/render/mod.rs +++ b/src/librustdoc/html/render/mod.rs @@ -52,7 +52,6 @@ use rustc_ast_pretty::pprust; use rustc_attr::StabilityLevel; use rustc_data_structures::flock; use rustc_data_structures::fx::{FxHashMap, FxHashSet}; -use rustc_feature::UnstableFeatures; use rustc_hir as hir; use rustc_hir::def_id::{DefId, LOCAL_CRATE}; use rustc_hir::Mutability; @@ -397,6 +396,7 @@ impl FormatRenderer for Context { resource_suffix, static_root_path, generate_search_filter, + unstable_features, .. } = options; @@ -466,7 +466,7 @@ impl FormatRenderer for Context { static_root_path, fs: DocFS::new(sender), edition, - codes: ErrorCodes::from(UnstableFeatures::from_environment().is_nightly_build()), + codes: ErrorCodes::from(unstable_features.is_nightly_build()), playground, }; diff --git a/src/librustdoc/markdown.rs b/src/librustdoc/markdown.rs index 3a87e1c46a6..33bd57223b8 100644 --- a/src/librustdoc/markdown.rs +++ b/src/librustdoc/markdown.rs @@ -2,7 +2,6 @@ use std::fs::{create_dir_all, read_to_string, File}; use std::io::prelude::*; use std::path::Path; -use rustc_feature::UnstableFeatures; use rustc_span::edition::Edition; use rustc_span::source_map::DUMMY_SP; @@ -66,7 +65,7 @@ pub fn render<P: AsRef<Path>>( let title = metadata[0]; let mut ids = IdMap::new(); - let error_codes = ErrorCodes::from(UnstableFeatures::from_environment().is_nightly_build()); + let error_codes = ErrorCodes::from(options.unstable_features.is_nightly_build()); let text = if !options.markdown_no_toc { MarkdownWithToc(text, &mut ids, error_codes, edition, &playground).into_string() } else { @@ -131,7 +130,7 @@ pub fn test(mut options: Options) -> Result<(), String> { options.enable_per_target_ignores, ); collector.set_position(DUMMY_SP); - let codes = ErrorCodes::from(UnstableFeatures::from_environment().is_nightly_build()); + let codes = ErrorCodes::from(options.render_options.unstable_features.is_nightly_build()); find_testable_code(&input_str, &mut collector, codes, options.enable_per_target_ignores, None); diff --git a/src/librustdoc/passes/doc_test_lints.rs b/src/librustdoc/passes/doc_test_lints.rs index 686ec51fb06..5fd7f5f81f7 100644 --- a/src/librustdoc/passes/doc_test_lints.rs +++ b/src/librustdoc/passes/doc_test_lints.rs @@ -92,9 +92,7 @@ pub fn look_for_tests<'tcx>(cx: &DocContext<'tcx>, dox: &str, item: &Item) { find_testable_code(&dox, &mut tests, ErrorCodes::No, false, None); - if tests.found_tests == 0 - && rustc_feature::UnstableFeatures::from_environment().is_nightly_build() - { + if tests.found_tests == 0 && cx.tcx.sess.is_nightly_build() { if should_have_doc_example(cx, &item) { debug!("reporting error for {:?} (hir_id={:?})", item, hir_id); let sp = span_of_attrs(&item.attrs).unwrap_or(item.source.span()); diff --git a/src/librustdoc/passes/html_tags.rs b/src/librustdoc/passes/html_tags.rs index 1d9be619ec9..26b64b4905e 100644 --- a/src/librustdoc/passes/html_tags.rs +++ b/src/librustdoc/passes/html_tags.rs @@ -5,7 +5,6 @@ use crate::fold::DocFolder; use crate::html::markdown::opts; use core::ops::Range; use pulldown_cmark::{Event, Parser}; -use rustc_feature::UnstableFeatures; use rustc_session::lint; use std::iter::Peekable; use std::str::CharIndices; @@ -27,7 +26,7 @@ impl<'a, 'tcx> InvalidHtmlTagsLinter<'a, 'tcx> { } pub fn check_invalid_html_tags(krate: Crate, cx: &DocContext<'_>) -> Crate { - if !UnstableFeatures::from_environment().is_nightly_build() { + if !cx.tcx.sess.is_nightly_build() { krate } else { let mut coll = InvalidHtmlTagsLinter::new(cx); diff --git a/src/librustdoc/passes/non_autolinks.rs b/src/librustdoc/passes/non_autolinks.rs index 4a8fc7fc618..964773dc055 100644 --- a/src/librustdoc/passes/non_autolinks.rs +++ b/src/librustdoc/passes/non_autolinks.rs @@ -7,7 +7,6 @@ use core::ops::Range; use pulldown_cmark::{Event, LinkType, Parser, Tag}; use regex::Regex; use rustc_errors::Applicability; -use rustc_feature::UnstableFeatures; use rustc_session::lint; pub const CHECK_NON_AUTOLINKS: Pass = Pass { @@ -54,7 +53,7 @@ impl<'a, 'tcx> NonAutolinksLinter<'a, 'tcx> { } pub fn check_non_autolinks(krate: Crate, cx: &DocContext<'_>) -> Crate { - if !UnstableFeatures::from_environment().is_nightly_build() { + if !cx.tcx.sess.is_nightly_build() { krate } else { let mut coll = NonAutolinksLinter::new(cx); |
