From e221be89e0772de3ff2999921b6a89005f19bafd Mon Sep 17 00:00:00 2001 From: Guillaume Gomez Date: Sat, 23 Jun 2018 15:09:21 +0200 Subject: [PATCH 1/2] Add command line lint manipulation in rustdoc --- src/librustc/session/config.rs | 41 ++++++++++++++++++++-------------- src/librustdoc/core.rs | 9 ++++++-- src/librustdoc/lib.rs | 28 ++++++++++++++++++++++- 3 files changed, 58 insertions(+), 20 deletions(-) diff --git a/src/librustc/session/config.rs b/src/librustc/session/config.rs index f831b006642bb..89945a29e9b0a 100644 --- a/src/librustc/session/config.rs +++ b/src/librustc/session/config.rs @@ -1747,6 +1747,29 @@ pub fn parse_cfgspecs(cfgspecs: Vec) -> ast::CrateConfig { .collect::() } +pub fn get_cmd_lint_options(matches: &getopts::Matches, + error_format: ErrorOutputType) + -> (Vec<(String, lint::Level)>, bool, Option) { + let mut lint_opts = vec![]; + let mut describe_lints = false; + + for &level in &[lint::Allow, lint::Warn, lint::Deny, lint::Forbid] { + for lint_name in matches.opt_strs(level.as_str()) { + if lint_name == "help" { + describe_lints = true; + } else { + lint_opts.push((lint_name.replace("-", "_"), level)); + } + } + } + + let lint_cap = matches.opt_str("cap-lints").map(|cap| { + lint::Level::from_str(&cap) + .unwrap_or_else(|| early_error(error_format, &format!("unknown lint level: `{}`", cap))) + }); + (lint_opts, describe_lints, lint_cap) +} + pub fn build_session_options_and_crate_config( matches: &getopts::Matches, ) -> (Options, ast::CrateConfig) { @@ -1824,23 +1847,7 @@ pub fn build_session_options_and_crate_config( let crate_types = parse_crate_types_from_list(unparsed_crate_types) .unwrap_or_else(|e| early_error(error_format, &e[..])); - let mut lint_opts = vec![]; - let mut describe_lints = false; - - for &level in &[lint::Allow, lint::Warn, lint::Deny, lint::Forbid] { - for lint_name in matches.opt_strs(level.as_str()) { - if lint_name == "help" { - describe_lints = true; - } else { - lint_opts.push((lint_name.replace("-", "_"), level)); - } - } - } - - let lint_cap = matches.opt_str("cap-lints").map(|cap| { - lint::Level::from_str(&cap) - .unwrap_or_else(|| early_error(error_format, &format!("unknown lint level: `{}`", cap))) - }); + let (lint_opts, describe_lints, lint_cap) = get_cmd_lint_options(matches, error_format); let mut debugging_opts = build_debugging_options(matches, error_format); diff --git a/src/librustdoc/core.rs b/src/librustdoc/core.rs index 53ebb3a12f527..527ad08d7f2fe 100644 --- a/src/librustdoc/core.rs +++ b/src/librustdoc/core.rs @@ -178,7 +178,10 @@ pub fn run_core(search_paths: SearchPaths, force_unstable_if_unmarked: bool, edition: Edition, cg: CodegenOptions, - error_format: ErrorOutputType) -> (clean::Crate, RenderInfo) + error_format: ErrorOutputType, + cmd_lints: Vec<(String, lint::Level)>, + lint_cap: Option, + describe_lints: bool) -> (clean::Crate, RenderInfo) { // Parse, resolve, and typecheck the given crate. @@ -200,6 +203,7 @@ pub fn run_core(search_paths: SearchPaths, Some((lint.name_lower(), lint::Allow)) } }) + .chain(cmd_lints.into_iter()) .collect::>(); let host_triple = TargetTriple::from_triple(config::host_triple()); @@ -213,7 +217,7 @@ pub fn run_core(search_paths: SearchPaths, } else { vec![] }, - lint_cap: Some(lint::Forbid), + lint_cap: Some(lint_cap.unwrap_or_else(|| lint::Forbid)), cg, externs, target_triple: triple.unwrap_or(host_triple), @@ -226,6 +230,7 @@ pub fn run_core(search_paths: SearchPaths, }, error_format, edition, + describe_lints, ..config::basic_options() }; driver::spawn_thread_pool(sessopts, move |sessopts| { diff --git a/src/librustdoc/lib.rs b/src/librustdoc/lib.rs index 566e2f1ed498c..029be7dc805c6 100644 --- a/src/librustdoc/lib.rs +++ b/src/librustdoc/lib.rs @@ -68,6 +68,7 @@ use rustc::session::search_paths::SearchPaths; use rustc::session::config::{ErrorOutputType, RustcOptGroup, Externs, CodegenOptions}; use rustc::session::config::{nightly_options, build_codegen_options}; use rustc_target::spec::TargetTriple; +use rustc::session::config::get_cmd_lint_options; #[macro_use] pub mod externalfiles; @@ -304,6 +305,28 @@ pub fn opts() -> Vec { "disable-minification", "Disable minification applied on JS files") }), + unstable("warn", |o| { + o.optmulti("W", "warn", "Set lint warnings", "OPT") + }), + unstable("allow", |o| { + o.optmulti("A", "allow", "Set lint allowed", "OPT") + }), + unstable("deny", |o| { + o.optmulti("D", "deny", "Set lint denied", "OPT") + }), + unstable("forbid", |o| { + o.optmulti("F", "forbid", "Set lint forbidden", "OPT") + }), + unstable("cap-lints", |o| { + o.optmulti( + "", + "cap-lints", + "Set the most restrictive lint level. \ + More restrictive lints are capped at this \ + level. By default, it is at `forbid` level.", + "LEVEL", + ) + }), ] } @@ -636,6 +659,8 @@ where R: 'static + Send, *x == "force-unstable-if-unmarked" }); + let (lint_opts, describe_lints, lint_cap) = get_cmd_lint_options(matches, error_format); + let (tx, rx) = channel(); rustc_driver::monitor(move || syntax::with_globals(move || { @@ -644,7 +669,8 @@ where R: 'static + Send, let (mut krate, renderinfo) = core::run_core(paths, cfgs, externs, Input::File(cratefile), triple, maybe_sysroot, display_warnings, crate_name.clone(), - force_unstable_if_unmarked, edition, cg, error_format); + force_unstable_if_unmarked, edition, cg, error_format, + lint_opts, lint_cap, describe_lints); info!("finished with rustc"); From 23fbfb57cfbfa24325046cadb50518eed262695c Mon Sep 17 00:00:00 2001 From: Alex Crichton Date: Thu, 5 Jul 2018 18:16:17 -0700 Subject: [PATCH 2/2] rustc: Update tracking issue for wasm_import_module It's now https://github.com/rust-lang/rust/issues/52090 --- src/libsyntax/feature_gate.rs | 2 +- src/test/ui/feature-gate-wasm_import_module.stderr | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/libsyntax/feature_gate.rs b/src/libsyntax/feature_gate.rs index 2ae0e669fd031..4c88325378793 100644 --- a/src/libsyntax/feature_gate.rs +++ b/src/libsyntax/feature_gate.rs @@ -421,7 +421,7 @@ declare_features! ( (active, wasm_custom_section, "1.26.0", Some(51088), None), // The #![wasm_import_module] attribute - (active, wasm_import_module, "1.26.0", Some(51088), None), + (active, wasm_import_module, "1.26.0", Some(52090), None), // Allows keywords to be escaped for use as identifiers (active, raw_identifiers, "1.26.0", Some(48589), None), diff --git a/src/test/ui/feature-gate-wasm_import_module.stderr b/src/test/ui/feature-gate-wasm_import_module.stderr index 02830a49f530f..5430f6b5825eb 100644 --- a/src/test/ui/feature-gate-wasm_import_module.stderr +++ b/src/test/ui/feature-gate-wasm_import_module.stderr @@ -1,4 +1,4 @@ -error[E0658]: experimental attribute (see issue #51088) +error[E0658]: experimental attribute (see issue #52090) --> $DIR/feature-gate-wasm_import_module.rs:11:1 | LL | #[wasm_import_module = "test"] //~ ERROR: experimental