From 885275207810dc0143b56bc4357461aa4c8ed07b Mon Sep 17 00:00:00 2001 From: David Koloski Date: Wed, 23 Feb 2022 04:53:17 +0000 Subject: [PATCH 1/5] Treat unstable lints as unknown This change causes unstable lints to be ignored if the `unknown_lints` lint is allowed. To achieve this, it also changes lints to apply as soon as they are processed. Previously, lints in the same set were processed as a batch and then all simultaneously applied. Implementation of https://github.com/rust-lang/compiler-team/issues/469 --- compiler/rustc_feature/src/active.rs | 2 + compiler/rustc_lint/src/levels.rs | 92 ++++++++++++------- compiler/rustc_lint_defs/src/builtin.rs | 9 ++ compiler/rustc_span/src/symbol.rs | 1 + ...llow-unknown-unstable-lint-command-line.rs | 4 + .../allow-unknown-unstable-lint-inline.rs | 5 + .../unstable-lint-command-line.rs | 5 + .../unstable-lint-command-line.stderr | 11 +++ .../unstable-lint-inline.rs | 6 ++ .../unstable-lint-inline.stderr | 19 ++++ 10 files changed, 119 insertions(+), 35 deletions(-) create mode 100644 src/test/ui/unknown-unstable-lints/allow-unknown-unstable-lint-command-line.rs create mode 100644 src/test/ui/unknown-unstable-lints/allow-unknown-unstable-lint-inline.rs create mode 100644 src/test/ui/unknown-unstable-lints/unstable-lint-command-line.rs create mode 100644 src/test/ui/unknown-unstable-lints/unstable-lint-command-line.stderr create mode 100644 src/test/ui/unknown-unstable-lints/unstable-lint-inline.rs create mode 100644 src/test/ui/unknown-unstable-lints/unstable-lint-inline.stderr diff --git a/compiler/rustc_feature/src/active.rs b/compiler/rustc_feature/src/active.rs index a69d28b184aed..09557332fd725 100644 --- a/compiler/rustc_feature/src/active.rs +++ b/compiler/rustc_feature/src/active.rs @@ -169,6 +169,8 @@ declare_features! ( (active, staged_api, "1.0.0", None, None), /// Added for testing E0705; perma-unstable. (active, test_2018_feature, "1.31.0", None, Some(Edition::Edition2018)), + /// Added for testing unstable lints; perma-unstable. + (active, test_unstable_lint, "1.60.0", None, None), /// Allows non-`unsafe` —and thus, unsound— access to `Pin` constructions. /// Marked `incomplete` since perma-unstable and unsound. (incomplete, unsafe_pin_internals, "1.60.0", None, None), diff --git a/compiler/rustc_lint/src/levels.rs b/compiler/rustc_lint/src/levels.rs index bbfbf61f4869a..a72e0336db915 100644 --- a/compiler/rustc_lint/src/levels.rs +++ b/compiler/rustc_lint/src/levels.rs @@ -93,10 +93,21 @@ impl<'s> LintLevelsBuilder<'s> { self.store } + fn current_specs(&self) -> &FxHashMap { + &self.sets.list[self.cur].specs + } + + fn current_specs_mut(&mut self) -> &mut FxHashMap { + &mut self.sets.list[self.cur].specs + } + fn process_command_line(&mut self, sess: &Session, store: &LintStore) { - let mut specs = FxHashMap::default(); self.sets.lint_cap = sess.opts.lint_cap.unwrap_or(Level::Forbid); + self.cur = self.sets.list.push(LintSet { + specs: FxHashMap::default(), + parent: COMMAND_LINE, + }); for &(ref lint_name, level) in &sess.opts.lint_opts { store.check_lint_name_cmdline(sess, &lint_name, level, self.registered_tools); let orig_level = level; @@ -108,17 +119,16 @@ impl<'s> LintLevelsBuilder<'s> { }; for id in ids { // ForceWarn and Forbid cannot be overriden - if let Some((Level::ForceWarn | Level::Forbid, _)) = specs.get(&id) { + if let Some((Level::ForceWarn | Level::Forbid, _)) = self.current_specs().get(&id) { continue; } - self.check_gated_lint(id, DUMMY_SP); - let src = LintLevelSource::CommandLine(lint_flag_val, orig_level); - specs.insert(id, (level, src)); + if self.check_gated_lint(id, DUMMY_SP) { + let src = LintLevelSource::CommandLine(lint_flag_val, orig_level); + self.current_specs_mut().insert(id, (level, src)); + } } } - - self.cur = self.sets.list.push(LintSet { specs, parent: COMMAND_LINE }); } /// Attempts to insert the `id` to `level_src` map entry. If unsuccessful @@ -126,12 +136,11 @@ impl<'s> LintLevelsBuilder<'s> { /// diagnostic with no change to `specs`. fn insert_spec( &mut self, - specs: &mut FxHashMap, id: LintId, (level, src): LevelAndSource, ) { let (old_level, old_src) = - self.sets.get_lint_level(id.lint, self.cur, Some(&specs), &self.sess); + self.sets.get_lint_level(id.lint, self.cur, Some(self.current_specs()), &self.sess); // Setting to a non-forbid level is an error if the lint previously had // a forbid level. Note that this is not necessarily true even with a // `#[forbid(..)]` attribute present, as that is overriden by `--cap-lints`. @@ -154,7 +163,7 @@ impl<'s> LintLevelsBuilder<'s> { }; debug!( "fcw_warning={:?}, specs.get(&id) = {:?}, old_src={:?}, id_name={:?}", - fcw_warning, specs, old_src, id_name + fcw_warning, self.current_specs(), old_src, id_name ); let decorate_diag = |diag: &mut Diagnostic| { @@ -213,9 +222,9 @@ impl<'s> LintLevelsBuilder<'s> { } } if let Level::ForceWarn = old_level { - specs.insert(id, (old_level, old_src)); + self.current_specs_mut().insert(id, (old_level, old_src)); } else { - specs.insert(id, (level, src)); + self.current_specs_mut().insert(id, (level, src)); } } @@ -239,7 +248,11 @@ impl<'s> LintLevelsBuilder<'s> { is_crate_node: bool, source_hir_id: Option, ) -> BuilderPush { - let mut specs = FxHashMap::default(); + let prev = self.cur; + self.cur = self.sets.list.push(LintSet { + specs: FxHashMap::default(), + parent: prev, + }); let sess = self.sess; let bad_attr = |span| struct_span_err!(sess, span, E0452, "malformed lint attribute input"); for (attr_index, attr) in attrs.iter().enumerate() { @@ -348,8 +361,9 @@ impl<'s> LintLevelsBuilder<'s> { reason, ); for &id in *ids { - self.check_gated_lint(id, attr.span); - self.insert_spec(&mut specs, id, (level, src)); + if self.check_gated_lint(id, attr.span) { + self.insert_spec(id, (level, src)); + } } if let Level::Expect(expect_id) = level { self.lint_expectations @@ -368,7 +382,7 @@ impl<'s> LintLevelsBuilder<'s> { reason, ); for id in ids { - self.insert_spec(&mut specs, *id, (level, src)); + self.insert_spec(*id, (level, src)); } if let Level::Expect(expect_id) = level { self.lint_expectations @@ -378,7 +392,7 @@ impl<'s> LintLevelsBuilder<'s> { Err((Some(ids), ref new_lint_name)) => { let lint = builtin::RENAMED_AND_REMOVED_LINTS; let (lvl, src) = - self.sets.get_lint_level(lint, self.cur, Some(&specs), &sess); + self.sets.get_lint_level(lint, self.cur, Some(self.current_specs()), &sess); struct_lint_level( self.sess, lint, @@ -408,7 +422,7 @@ impl<'s> LintLevelsBuilder<'s> { reason, ); for id in ids { - self.insert_spec(&mut specs, *id, (level, src)); + self.insert_spec(*id, (level, src)); } if let Level::Expect(expect_id) = level { self.lint_expectations @@ -449,7 +463,7 @@ impl<'s> LintLevelsBuilder<'s> { CheckLintNameResult::Warning(msg, renamed) => { let lint = builtin::RENAMED_AND_REMOVED_LINTS; let (renamed_lint_level, src) = - self.sets.get_lint_level(lint, self.cur, Some(&specs), &sess); + self.sets.get_lint_level(lint, self.cur, Some(self.current_specs()), &sess); struct_lint_level( self.sess, lint, @@ -473,7 +487,7 @@ impl<'s> LintLevelsBuilder<'s> { CheckLintNameResult::NoLint(suggestion) => { let lint = builtin::UNKNOWN_LINTS; let (level, src) = - self.sets.get_lint_level(lint, self.cur, Some(&specs), self.sess); + self.sets.get_lint_level(lint, self.cur, Some(self.current_specs()), self.sess); struct_lint_level(self.sess, lint, level, src, Some(sp.into()), |lint| { let name = if let Some(tool_ident) = tool_ident { format!("{}::{}", tool_ident.name, name) @@ -504,8 +518,9 @@ impl<'s> LintLevelsBuilder<'s> { { let src = LintLevelSource::Node(Symbol::intern(&new_name), sp, reason); for &id in ids { - self.check_gated_lint(id, attr.span); - self.insert_spec(&mut specs, id, (level, src)); + if self.check_gated_lint(id, attr.span) { + self.insert_spec(id, (level, src)); + } } if let Level::Expect(expect_id) = level { self.lint_expectations @@ -519,7 +534,7 @@ impl<'s> LintLevelsBuilder<'s> { } if !is_crate_node { - for (id, &(level, ref src)) in specs.iter() { + for (id, &(level, ref src)) in self.current_specs().iter() { if !id.lint.crate_level_only { continue; } @@ -530,7 +545,7 @@ impl<'s> LintLevelsBuilder<'s> { let lint = builtin::UNUSED_ATTRIBUTES; let (lint_level, lint_src) = - self.sets.get_lint_level(lint, self.cur, Some(&specs), self.sess); + self.sets.get_lint_level(lint, self.cur, Some(self.current_specs()), self.sess); struct_lint_level( self.sess, lint, @@ -551,9 +566,9 @@ impl<'s> LintLevelsBuilder<'s> { } } - let prev = self.cur; - if !specs.is_empty() { - self.cur = self.sets.list.push(LintSet { specs, parent: prev }); + if self.current_specs().is_empty() { + self.sets.list.pop(); + self.cur = prev; } BuilderPush { prev, changed: prev != self.cur } @@ -574,18 +589,25 @@ impl<'s> LintLevelsBuilder<'s> { } /// Checks if the lint is gated on a feature that is not enabled. - fn check_gated_lint(&self, lint_id: LintId, span: Span) { + /// + /// Returns `true` if the lint's feature is enabled. + fn check_gated_lint(&self, lint_id: LintId, span: Span) -> bool { if let Some(feature) = lint_id.lint.feature_gate { if !self.sess.features_untracked().enabled(feature) { - feature_err( - &self.sess.parse_sess, - feature, - span, - &format!("the `{}` lint is unstable", lint_id.lint.name_lower()), - ) - .emit(); + let (unknown_lints_level, _) = self.lint_level(builtin::UNKNOWN_LINTS); + if unknown_lints_level != Level::Allow { + feature_err( + &self.sess.parse_sess, + feature, + span, + &format!("the `{}` lint is unstable", lint_id.lint.name_lower()), + ) + .emit(); + } + return false; } } + true } /// Called after `push` when the scope of a set of attributes are exited. diff --git a/compiler/rustc_lint_defs/src/builtin.rs b/compiler/rustc_lint_defs/src/builtin.rs index 04a339f3c95a6..e1c88f74ab33c 100644 --- a/compiler/rustc_lint_defs/src/builtin.rs +++ b/compiler/rustc_lint_defs/src/builtin.rs @@ -3128,6 +3128,7 @@ declare_lint_pass! { SUSPICIOUS_AUTO_TRAIT_IMPLS, UNEXPECTED_CFGS, DEPRECATED_WHERE_CLAUSE_LOCATION, + TEST_UNSTABLE_LINT, ] } @@ -3771,3 +3772,11 @@ declare_lint! { Warn, "deprecated where clause location" } + +declare_lint! { + #[doc(hidden)] + pub TEST_UNSTABLE_LINT, + Deny, + "this unstable lint is only for testing", + @feature_gate = sym::test_unstable_lint; +} diff --git a/compiler/rustc_span/src/symbol.rs b/compiler/rustc_span/src/symbol.rs index 3f44292e03425..24f802c1d4f94 100644 --- a/compiler/rustc_span/src/symbol.rs +++ b/compiler/rustc_span/src/symbol.rs @@ -1383,6 +1383,7 @@ symbols! { test_case, test_removed_feature, test_runner, + test_unstable_lint, then_with, thread, thread_local, diff --git a/src/test/ui/unknown-unstable-lints/allow-unknown-unstable-lint-command-line.rs b/src/test/ui/unknown-unstable-lints/allow-unknown-unstable-lint-command-line.rs new file mode 100644 index 0000000000000..80e30f23993e3 --- /dev/null +++ b/src/test/ui/unknown-unstable-lints/allow-unknown-unstable-lint-command-line.rs @@ -0,0 +1,4 @@ +// check-pass +// compile-flags: -Aunknown_lints -Atest_unstable_lint + +fn main() {} diff --git a/src/test/ui/unknown-unstable-lints/allow-unknown-unstable-lint-inline.rs b/src/test/ui/unknown-unstable-lints/allow-unknown-unstable-lint-inline.rs new file mode 100644 index 0000000000000..992472c894a8c --- /dev/null +++ b/src/test/ui/unknown-unstable-lints/allow-unknown-unstable-lint-inline.rs @@ -0,0 +1,5 @@ +// check-pass + +#![allow(unknown_lints, test_unstable_lint)] + +fn main() {} diff --git a/src/test/ui/unknown-unstable-lints/unstable-lint-command-line.rs b/src/test/ui/unknown-unstable-lints/unstable-lint-command-line.rs new file mode 100644 index 0000000000000..7663abffd9b48 --- /dev/null +++ b/src/test/ui/unknown-unstable-lints/unstable-lint-command-line.rs @@ -0,0 +1,5 @@ +// check-fail +// compile-flags: -Atest_unstable_lint +// error-pattern: the `test_unstable_lint` lint is unstable + +fn main() {} diff --git a/src/test/ui/unknown-unstable-lints/unstable-lint-command-line.stderr b/src/test/ui/unknown-unstable-lints/unstable-lint-command-line.stderr new file mode 100644 index 0000000000000..d088f4c8fe5aa --- /dev/null +++ b/src/test/ui/unknown-unstable-lints/unstable-lint-command-line.stderr @@ -0,0 +1,11 @@ +error[E0658]: the `test_unstable_lint` lint is unstable + | + = help: add `#![feature(test_unstable_lint)]` to the crate attributes to enable + +error[E0658]: the `test_unstable_lint` lint is unstable + | + = help: add `#![feature(test_unstable_lint)]` to the crate attributes to enable + +error: aborting due to 2 previous errors + +For more information about this error, try `rustc --explain E0658`. diff --git a/src/test/ui/unknown-unstable-lints/unstable-lint-inline.rs b/src/test/ui/unknown-unstable-lints/unstable-lint-inline.rs new file mode 100644 index 0000000000000..43789906ed6f0 --- /dev/null +++ b/src/test/ui/unknown-unstable-lints/unstable-lint-inline.rs @@ -0,0 +1,6 @@ +// check-fail +// error-pattern: the `test_unstable_lint` lint is unstable + +#![allow(test_unstable_lint)] + +fn main() {} diff --git a/src/test/ui/unknown-unstable-lints/unstable-lint-inline.stderr b/src/test/ui/unknown-unstable-lints/unstable-lint-inline.stderr new file mode 100644 index 0000000000000..5ec85f346fec5 --- /dev/null +++ b/src/test/ui/unknown-unstable-lints/unstable-lint-inline.stderr @@ -0,0 +1,19 @@ +error[E0658]: the `test_unstable_lint` lint is unstable + --> $DIR/unstable-lint-inline.rs:4:1 + | +LL | #![allow(test_unstable_lint)] + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | + = help: add `#![feature(test_unstable_lint)]` to the crate attributes to enable + +error[E0658]: the `test_unstable_lint` lint is unstable + --> $DIR/unstable-lint-inline.rs:4:1 + | +LL | #![allow(test_unstable_lint)] + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | + = help: add `#![feature(test_unstable_lint)]` to the crate attributes to enable + +error: aborting due to 2 previous errors + +For more information about this error, try `rustc --explain E0658`. From 2677eca237c92877ac8b0aca4cc58f8a14061ab3 Mon Sep 17 00:00:00 2001 From: David Koloski Date: Mon, 28 Feb 2022 20:29:06 +0000 Subject: [PATCH 2/5] Switch the primary diagnostic to `unknown_lints` This also affects the `non_exhaustive_omitted_patterns` and `must_not_suspend` lints as they are not stable. This also changes the diagnostic level to pull from `unknown_lints` instead of always being allow or deny. --- compiler/rustc_lint/src/levels.rs | 67 ++++++++++-------- compiler/rustc_lint_defs/src/builtin.rs | 1 + compiler/rustc_session/src/parse.rs | 21 +++++- ...te-non_exhaustive_omitted_patterns_lint.rs | 23 +++--- ...on_exhaustive_omitted_patterns_lint.stderr | 70 +++++++++++++------ .../feature-gate-test_unstable_lint.rs | 9 +++ .../feature-gate-test_unstable_lint.stderr | 30 ++++++++ src/test/ui/lint/must_not_suspend/gated.rs | 11 +-- .../ui/lint/must_not_suspend/gated.stderr | 43 +++--------- .../deny-unstable-lint-command-line.rs | 6 ++ .../deny-unstable-lint-command-line.stderr | 18 +++++ .../deny-unstable-lint-inline.rs | 9 +++ .../deny-unstable-lint-inline.stderr | 35 ++++++++++ .../unstable-lint-command-line.rs | 5 -- .../unstable-lint-command-line.stderr | 11 --- .../unstable-lint-inline.rs | 6 -- .../unstable-lint-inline.stderr | 19 ----- ...warn-unknown-unstable-lint-command-line.rs | 6 ++ ...-unknown-unstable-lint-command-line.stderr | 18 +++++ .../warn-unknown-unstable-lint-inline.rs | 9 +++ .../warn-unknown-unstable-lint-inline.stderr | 35 ++++++++++ 21 files changed, 310 insertions(+), 142 deletions(-) create mode 100644 src/test/ui/feature-gates/feature-gate-test_unstable_lint.rs create mode 100644 src/test/ui/feature-gates/feature-gate-test_unstable_lint.stderr create mode 100644 src/test/ui/unknown-unstable-lints/deny-unstable-lint-command-line.rs create mode 100644 src/test/ui/unknown-unstable-lints/deny-unstable-lint-command-line.stderr create mode 100644 src/test/ui/unknown-unstable-lints/deny-unstable-lint-inline.rs create mode 100644 src/test/ui/unknown-unstable-lints/deny-unstable-lint-inline.stderr delete mode 100644 src/test/ui/unknown-unstable-lints/unstable-lint-command-line.rs delete mode 100644 src/test/ui/unknown-unstable-lints/unstable-lint-command-line.stderr delete mode 100644 src/test/ui/unknown-unstable-lints/unstable-lint-inline.rs delete mode 100644 src/test/ui/unknown-unstable-lints/unstable-lint-inline.stderr create mode 100644 src/test/ui/unknown-unstable-lints/warn-unknown-unstable-lint-command-line.rs create mode 100644 src/test/ui/unknown-unstable-lints/warn-unknown-unstable-lint-command-line.stderr create mode 100644 src/test/ui/unknown-unstable-lints/warn-unknown-unstable-lint-inline.rs create mode 100644 src/test/ui/unknown-unstable-lints/warn-unknown-unstable-lint-inline.stderr diff --git a/compiler/rustc_lint/src/levels.rs b/compiler/rustc_lint/src/levels.rs index a72e0336db915..2b28fc2c0115e 100644 --- a/compiler/rustc_lint/src/levels.rs +++ b/compiler/rustc_lint/src/levels.rs @@ -17,7 +17,7 @@ use rustc_session::lint::{ builtin::{self, FORBIDDEN_LINT_GROUPS}, Level, Lint, LintExpectationId, LintId, }; -use rustc_session::parse::feature_err; +use rustc_session::parse::{add_feature_diagnostics, feature_err}; use rustc_session::Session; use rustc_span::symbol::{sym, Symbol}; use rustc_span::{source_map::MultiSpan, Span, DUMMY_SP}; @@ -104,10 +104,8 @@ impl<'s> LintLevelsBuilder<'s> { fn process_command_line(&mut self, sess: &Session, store: &LintStore) { self.sets.lint_cap = sess.opts.lint_cap.unwrap_or(Level::Forbid); - self.cur = self.sets.list.push(LintSet { - specs: FxHashMap::default(), - parent: COMMAND_LINE, - }); + self.cur = + self.sets.list.push(LintSet { specs: FxHashMap::default(), parent: COMMAND_LINE }); for &(ref lint_name, level) in &sess.opts.lint_opts { store.check_lint_name_cmdline(sess, &lint_name, level, self.registered_tools); let orig_level = level; @@ -134,11 +132,7 @@ impl<'s> LintLevelsBuilder<'s> { /// Attempts to insert the `id` to `level_src` map entry. If unsuccessful /// (e.g. if a forbid was already inserted on the same scope), then emits a /// diagnostic with no change to `specs`. - fn insert_spec( - &mut self, - id: LintId, - (level, src): LevelAndSource, - ) { + fn insert_spec(&mut self, id: LintId, (level, src): LevelAndSource) { let (old_level, old_src) = self.sets.get_lint_level(id.lint, self.cur, Some(self.current_specs()), &self.sess); // Setting to a non-forbid level is an error if the lint previously had @@ -163,7 +157,10 @@ impl<'s> LintLevelsBuilder<'s> { }; debug!( "fcw_warning={:?}, specs.get(&id) = {:?}, old_src={:?}, id_name={:?}", - fcw_warning, self.current_specs(), old_src, id_name + fcw_warning, + self.current_specs(), + old_src, + id_name ); let decorate_diag = |diag: &mut Diagnostic| { @@ -249,10 +246,8 @@ impl<'s> LintLevelsBuilder<'s> { source_hir_id: Option, ) -> BuilderPush { let prev = self.cur; - self.cur = self.sets.list.push(LintSet { - specs: FxHashMap::default(), - parent: prev, - }); + self.cur = self.sets.list.push(LintSet { specs: FxHashMap::default(), parent: prev }); + let sess = self.sess; let bad_attr = |span| struct_span_err!(sess, span, E0452, "malformed lint attribute input"); for (attr_index, attr) in attrs.iter().enumerate() { @@ -391,8 +386,12 @@ impl<'s> LintLevelsBuilder<'s> { } Err((Some(ids), ref new_lint_name)) => { let lint = builtin::RENAMED_AND_REMOVED_LINTS; - let (lvl, src) = - self.sets.get_lint_level(lint, self.cur, Some(self.current_specs()), &sess); + let (lvl, src) = self.sets.get_lint_level( + lint, + self.cur, + Some(self.current_specs()), + &sess, + ); struct_lint_level( self.sess, lint, @@ -462,8 +461,12 @@ impl<'s> LintLevelsBuilder<'s> { CheckLintNameResult::Warning(msg, renamed) => { let lint = builtin::RENAMED_AND_REMOVED_LINTS; - let (renamed_lint_level, src) = - self.sets.get_lint_level(lint, self.cur, Some(self.current_specs()), &sess); + let (renamed_lint_level, src) = self.sets.get_lint_level( + lint, + self.cur, + Some(self.current_specs()), + &sess, + ); struct_lint_level( self.sess, lint, @@ -486,8 +489,12 @@ impl<'s> LintLevelsBuilder<'s> { } CheckLintNameResult::NoLint(suggestion) => { let lint = builtin::UNKNOWN_LINTS; - let (level, src) = - self.sets.get_lint_level(lint, self.cur, Some(self.current_specs()), self.sess); + let (level, src) = self.sets.get_lint_level( + lint, + self.cur, + Some(self.current_specs()), + self.sess, + ); struct_lint_level(self.sess, lint, level, src, Some(sp.into()), |lint| { let name = if let Some(tool_ident) = tool_ident { format!("{}::{}", tool_ident.name, name) @@ -594,16 +601,14 @@ impl<'s> LintLevelsBuilder<'s> { fn check_gated_lint(&self, lint_id: LintId, span: Span) -> bool { if let Some(feature) = lint_id.lint.feature_gate { if !self.sess.features_untracked().enabled(feature) { - let (unknown_lints_level, _) = self.lint_level(builtin::UNKNOWN_LINTS); - if unknown_lints_level != Level::Allow { - feature_err( - &self.sess.parse_sess, - feature, - span, - &format!("the `{}` lint is unstable", lint_id.lint.name_lower()), - ) - .emit(); - } + let (level, src) = self.lint_level(builtin::UNKNOWN_LINTS); + struct_lint_level(self.sess, lint_id.lint, level, src, Some(span.into()), |lint| { + let mut db = + lint.build(&format!("unknown lint: `{}`", lint_id.lint.name_lower())); + db.note(&format!("the `{}` lint is unstable", lint_id.lint.name_lower(),)); + add_feature_diagnostics(&mut db, &self.sess.parse_sess, feature); + db.emit(); + }); return false; } } diff --git a/compiler/rustc_lint_defs/src/builtin.rs b/compiler/rustc_lint_defs/src/builtin.rs index e1c88f74ab33c..f6ad46cc01888 100644 --- a/compiler/rustc_lint_defs/src/builtin.rs +++ b/compiler/rustc_lint_defs/src/builtin.rs @@ -3775,6 +3775,7 @@ declare_lint! { declare_lint! { #[doc(hidden)] + /// Added for testing unsable lints; perma-unstable. pub TEST_UNSTABLE_LINT, Deny, "this unstable lint is only for testing", diff --git a/compiler/rustc_session/src/parse.rs b/compiler/rustc_session/src/parse.rs index 38ddb841d9656..d34a3360a83e2 100644 --- a/compiler/rustc_session/src/parse.rs +++ b/compiler/rustc_session/src/parse.rs @@ -98,7 +98,26 @@ pub fn feature_err_issue<'a>( explain: &str, ) -> DiagnosticBuilder<'a, ErrorGuaranteed> { let mut err = sess.span_diagnostic.struct_span_err_with_code(span, explain, error_code!(E0658)); + add_feature_diagnostics_for_issue(&mut err, sess, feature, issue); + err +} + +/// Adds the diagnostics for a feature to an existing error. +pub fn add_feature_diagnostics<'a>(err: &mut Diagnostic, sess: &'a ParseSess, feature: Symbol) { + add_feature_diagnostics_for_issue(err, sess, feature, GateIssue::Language); +} +/// Adds the diagnostics for a feature to an existing error. +/// +/// This variant allows you to control whether it is a library or language feature. +/// Almost always, you want to use this for a language feature. If so, prefer +/// `add_feature_diagnostics`. +pub fn add_feature_diagnostics_for_issue<'a>( + err: &mut Diagnostic, + sess: &'a ParseSess, + feature: Symbol, + issue: GateIssue, +) { if let Some(n) = find_feature_issue(feature, issue) { err.note(&format!( "see issue #{} for more information", @@ -110,8 +129,6 @@ pub fn feature_err_issue<'a>( if sess.unstable_features.is_nightly_build() { err.help(&format!("add `#![feature({})]` to the crate attributes to enable", feature)); } - - err } /// Info about a parsing session. diff --git a/src/test/ui/feature-gates/feature-gate-non_exhaustive_omitted_patterns_lint.rs b/src/test/ui/feature-gates/feature-gate-non_exhaustive_omitted_patterns_lint.rs index 2a34ed4d4f644..29a6e1f8a016d 100644 --- a/src/test/ui/feature-gates/feature-gate-non_exhaustive_omitted_patterns_lint.rs +++ b/src/test/ui/feature-gates/feature-gate-non_exhaustive_omitted_patterns_lint.rs @@ -1,9 +1,11 @@ +// check-fail + #![deny(non_exhaustive_omitted_patterns)] -//~^ ERROR the `non_exhaustive_omitted_patterns` lint is unstable -//~| ERROR the `non_exhaustive_omitted_patterns` lint is unstable +//~^ WARNING unknown lint: `non_exhaustive_omitted_patterns` +//~| WARNING unknown lint: `non_exhaustive_omitted_patterns` #![allow(non_exhaustive_omitted_patterns)] -//~^ ERROR the `non_exhaustive_omitted_patterns` lint is unstable -//~| ERROR the `non_exhaustive_omitted_patterns` lint is unstable +//~^ WARNING unknown lint: `non_exhaustive_omitted_patterns` +//~| WARNING unknown lint: `non_exhaustive_omitted_patterns` fn main() { enum Foo { @@ -11,14 +13,15 @@ fn main() { } #[allow(non_exhaustive_omitted_patterns)] + //~^ WARNING unknown lint: `non_exhaustive_omitted_patterns` + //~| WARNING unknown lint: `non_exhaustive_omitted_patterns` + //~| WARNING unknown lint: `non_exhaustive_omitted_patterns` + //~| WARNING unknown lint: `non_exhaustive_omitted_patterns` match Foo::A { Foo::A => {} Foo::B => {} } - //~^^^^^ ERROR the `non_exhaustive_omitted_patterns` lint is unstable - //~| ERROR the `non_exhaustive_omitted_patterns` lint is unstable - //~| ERROR the `non_exhaustive_omitted_patterns` lint is unstable - //~| ERROR the `non_exhaustive_omitted_patterns` lint is unstable + //~^^^^ ERROR non-exhaustive patterns: `C` not covered match Foo::A { Foo::A => {} @@ -26,6 +29,6 @@ fn main() { #[warn(non_exhaustive_omitted_patterns)] _ => {} } - //~^^^ ERROR the `non_exhaustive_omitted_patterns` lint is unstable - //~| ERROR the `non_exhaustive_omitted_patterns` lint is unstable + //~^^^ WARNING unknown lint: `non_exhaustive_omitted_patterns` + //~| WARNING unknown lint: `non_exhaustive_omitted_patterns` } diff --git a/src/test/ui/feature-gates/feature-gate-non_exhaustive_omitted_patterns_lint.stderr b/src/test/ui/feature-gates/feature-gate-non_exhaustive_omitted_patterns_lint.stderr index 691f64cf0addd..94568c96b40a3 100644 --- a/src/test/ui/feature-gates/feature-gate-non_exhaustive_omitted_patterns_lint.stderr +++ b/src/test/ui/feature-gates/feature-gate-non_exhaustive_omitted_patterns_lint.stderr @@ -1,93 +1,119 @@ -error[E0658]: the `non_exhaustive_omitted_patterns` lint is unstable - --> $DIR/feature-gate-non_exhaustive_omitted_patterns_lint.rs:1:1 +warning: unknown lint: `non_exhaustive_omitted_patterns` + --> $DIR/feature-gate-non_exhaustive_omitted_patterns_lint.rs:3:1 | LL | #![deny(non_exhaustive_omitted_patterns)] | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | + = note: `#[warn(non_exhaustive_omitted_patterns)]` on by default + = note: the `non_exhaustive_omitted_patterns` lint is unstable = note: see issue #89554 for more information = help: add `#![feature(non_exhaustive_omitted_patterns_lint)]` to the crate attributes to enable -error[E0658]: the `non_exhaustive_omitted_patterns` lint is unstable - --> $DIR/feature-gate-non_exhaustive_omitted_patterns_lint.rs:4:1 +warning: unknown lint: `non_exhaustive_omitted_patterns` + --> $DIR/feature-gate-non_exhaustive_omitted_patterns_lint.rs:6:1 | LL | #![allow(non_exhaustive_omitted_patterns)] | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | + = note: the `non_exhaustive_omitted_patterns` lint is unstable = note: see issue #89554 for more information = help: add `#![feature(non_exhaustive_omitted_patterns_lint)]` to the crate attributes to enable -error[E0658]: the `non_exhaustive_omitted_patterns` lint is unstable - --> $DIR/feature-gate-non_exhaustive_omitted_patterns_lint.rs:13:5 +warning: unknown lint: `non_exhaustive_omitted_patterns` + --> $DIR/feature-gate-non_exhaustive_omitted_patterns_lint.rs:15:5 | LL | #[allow(non_exhaustive_omitted_patterns)] | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | + = note: the `non_exhaustive_omitted_patterns` lint is unstable = note: see issue #89554 for more information = help: add `#![feature(non_exhaustive_omitted_patterns_lint)]` to the crate attributes to enable -error[E0658]: the `non_exhaustive_omitted_patterns` lint is unstable - --> $DIR/feature-gate-non_exhaustive_omitted_patterns_lint.rs:13:5 +warning: unknown lint: `non_exhaustive_omitted_patterns` + --> $DIR/feature-gate-non_exhaustive_omitted_patterns_lint.rs:15:5 | LL | #[allow(non_exhaustive_omitted_patterns)] | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | + = note: the `non_exhaustive_omitted_patterns` lint is unstable = note: see issue #89554 for more information = help: add `#![feature(non_exhaustive_omitted_patterns_lint)]` to the crate attributes to enable -error[E0658]: the `non_exhaustive_omitted_patterns` lint is unstable - --> $DIR/feature-gate-non_exhaustive_omitted_patterns_lint.rs:26:9 +warning: unknown lint: `non_exhaustive_omitted_patterns` + --> $DIR/feature-gate-non_exhaustive_omitted_patterns_lint.rs:29:9 | LL | #[warn(non_exhaustive_omitted_patterns)] | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | + = note: the `non_exhaustive_omitted_patterns` lint is unstable = note: see issue #89554 for more information = help: add `#![feature(non_exhaustive_omitted_patterns_lint)]` to the crate attributes to enable -error[E0658]: the `non_exhaustive_omitted_patterns` lint is unstable - --> $DIR/feature-gate-non_exhaustive_omitted_patterns_lint.rs:1:1 +warning: unknown lint: `non_exhaustive_omitted_patterns` + --> $DIR/feature-gate-non_exhaustive_omitted_patterns_lint.rs:3:1 | LL | #![deny(non_exhaustive_omitted_patterns)] | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | + = note: the `non_exhaustive_omitted_patterns` lint is unstable = note: see issue #89554 for more information = help: add `#![feature(non_exhaustive_omitted_patterns_lint)]` to the crate attributes to enable -error[E0658]: the `non_exhaustive_omitted_patterns` lint is unstable - --> $DIR/feature-gate-non_exhaustive_omitted_patterns_lint.rs:4:1 +warning: unknown lint: `non_exhaustive_omitted_patterns` + --> $DIR/feature-gate-non_exhaustive_omitted_patterns_lint.rs:6:1 | LL | #![allow(non_exhaustive_omitted_patterns)] | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | + = note: the `non_exhaustive_omitted_patterns` lint is unstable = note: see issue #89554 for more information = help: add `#![feature(non_exhaustive_omitted_patterns_lint)]` to the crate attributes to enable -error[E0658]: the `non_exhaustive_omitted_patterns` lint is unstable - --> $DIR/feature-gate-non_exhaustive_omitted_patterns_lint.rs:13:5 +warning: unknown lint: `non_exhaustive_omitted_patterns` + --> $DIR/feature-gate-non_exhaustive_omitted_patterns_lint.rs:15:5 | LL | #[allow(non_exhaustive_omitted_patterns)] | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | + = note: the `non_exhaustive_omitted_patterns` lint is unstable = note: see issue #89554 for more information = help: add `#![feature(non_exhaustive_omitted_patterns_lint)]` to the crate attributes to enable -error[E0658]: the `non_exhaustive_omitted_patterns` lint is unstable - --> $DIR/feature-gate-non_exhaustive_omitted_patterns_lint.rs:13:5 +warning: unknown lint: `non_exhaustive_omitted_patterns` + --> $DIR/feature-gate-non_exhaustive_omitted_patterns_lint.rs:15:5 | LL | #[allow(non_exhaustive_omitted_patterns)] | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | + = note: the `non_exhaustive_omitted_patterns` lint is unstable = note: see issue #89554 for more information = help: add `#![feature(non_exhaustive_omitted_patterns_lint)]` to the crate attributes to enable -error[E0658]: the `non_exhaustive_omitted_patterns` lint is unstable - --> $DIR/feature-gate-non_exhaustive_omitted_patterns_lint.rs:26:9 +warning: unknown lint: `non_exhaustive_omitted_patterns` + --> $DIR/feature-gate-non_exhaustive_omitted_patterns_lint.rs:29:9 | LL | #[warn(non_exhaustive_omitted_patterns)] | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | + = note: the `non_exhaustive_omitted_patterns` lint is unstable = note: see issue #89554 for more information = help: add `#![feature(non_exhaustive_omitted_patterns_lint)]` to the crate attributes to enable -error: aborting due to 10 previous errors +error[E0004]: non-exhaustive patterns: `C` not covered + --> $DIR/feature-gate-non_exhaustive_omitted_patterns_lint.rs:20:11 + | +LL | / enum Foo { +LL | | A, B, C, + | | - not covered +LL | | } + | |_____- `Foo` defined here +... +LL | match Foo::A { + | ^^^^^^ pattern `C` not covered + | + = help: ensure that all possible cases are being handled, possibly by adding wildcards or more match arms + = note: the matched value is of type `Foo` -For more information about this error, try `rustc --explain E0658`. +error: aborting due to previous error; 10 warnings emitted + +For more information about this error, try `rustc --explain E0004`. diff --git a/src/test/ui/feature-gates/feature-gate-test_unstable_lint.rs b/src/test/ui/feature-gates/feature-gate-test_unstable_lint.rs new file mode 100644 index 0000000000000..c398394cbe1a6 --- /dev/null +++ b/src/test/ui/feature-gates/feature-gate-test_unstable_lint.rs @@ -0,0 +1,9 @@ +// check-pass + +// `test_unstable_lint` is for testing and should never be stabilized. +#![allow(test_unstable_lint)] +//~^ WARNING unknown lint: `test_unstable_lint` +//~| WARNING unknown lint: `test_unstable_lint` +//~| WARNING unknown lint: `test_unstable_lint` + +fn main() {} diff --git a/src/test/ui/feature-gates/feature-gate-test_unstable_lint.stderr b/src/test/ui/feature-gates/feature-gate-test_unstable_lint.stderr new file mode 100644 index 0000000000000..eab89f02018bf --- /dev/null +++ b/src/test/ui/feature-gates/feature-gate-test_unstable_lint.stderr @@ -0,0 +1,30 @@ +warning: unknown lint: `test_unstable_lint` + --> $DIR/feature-gate-test_unstable_lint.rs:4:1 + | +LL | #![allow(test_unstable_lint)] + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | + = note: `#[warn(test_unstable_lint)]` on by default + = note: the `test_unstable_lint` lint is unstable + = help: add `#![feature(test_unstable_lint)]` to the crate attributes to enable + +warning: unknown lint: `test_unstable_lint` + --> $DIR/feature-gate-test_unstable_lint.rs:4:1 + | +LL | #![allow(test_unstable_lint)] + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | + = note: the `test_unstable_lint` lint is unstable + = help: add `#![feature(test_unstable_lint)]` to the crate attributes to enable + +warning: unknown lint: `test_unstable_lint` + --> $DIR/feature-gate-test_unstable_lint.rs:4:1 + | +LL | #![allow(test_unstable_lint)] + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | + = note: the `test_unstable_lint` lint is unstable + = help: add `#![feature(test_unstable_lint)]` to the crate attributes to enable + +warning: 3 warnings emitted + diff --git a/src/test/ui/lint/must_not_suspend/gated.rs b/src/test/ui/lint/must_not_suspend/gated.rs index acb81b0bf9def..b73a76555296f 100644 --- a/src/test/ui/lint/must_not_suspend/gated.rs +++ b/src/test/ui/lint/must_not_suspend/gated.rs @@ -1,12 +1,15 @@ +// check-pass + // edition:2018 -#![deny(must_not_suspend)] //~ ERROR the `must_not_suspend` -//~| ERROR the `must_not_suspend` -//~| ERROR the `must_not_suspend` +#![deny(must_not_suspend)] +//~^ WARNING unknown lint: `must_not_suspend` +//~| WARNING unknown lint: `must_not_suspend` +//~| WARNING unknown lint: `must_not_suspend` async fn other() {} pub async fn uhoh(m: std::sync::Mutex<()>) { - let _guard = m.lock().unwrap(); //~ ERROR `MutexGuard` held across + let _guard = m.lock().unwrap(); other().await; } diff --git a/src/test/ui/lint/must_not_suspend/gated.stderr b/src/test/ui/lint/must_not_suspend/gated.stderr index 0d4319670e662..3d6877045ff78 100644 --- a/src/test/ui/lint/must_not_suspend/gated.stderr +++ b/src/test/ui/lint/must_not_suspend/gated.stderr @@ -1,54 +1,33 @@ -error[E0658]: the `must_not_suspend` lint is unstable - --> $DIR/gated.rs:2:1 +warning: unknown lint: `must_not_suspend` + --> $DIR/gated.rs:4:1 | LL | #![deny(must_not_suspend)] | ^^^^^^^^^^^^^^^^^^^^^^^^^^ | + = note: `#[warn(must_not_suspend)]` on by default + = note: the `must_not_suspend` lint is unstable = note: see issue #83310 for more information = help: add `#![feature(must_not_suspend)]` to the crate attributes to enable -error[E0658]: the `must_not_suspend` lint is unstable - --> $DIR/gated.rs:2:1 +warning: unknown lint: `must_not_suspend` + --> $DIR/gated.rs:4:1 | LL | #![deny(must_not_suspend)] | ^^^^^^^^^^^^^^^^^^^^^^^^^^ | + = note: the `must_not_suspend` lint is unstable = note: see issue #83310 for more information = help: add `#![feature(must_not_suspend)]` to the crate attributes to enable -error[E0658]: the `must_not_suspend` lint is unstable - --> $DIR/gated.rs:2:1 +warning: unknown lint: `must_not_suspend` + --> $DIR/gated.rs:4:1 | LL | #![deny(must_not_suspend)] | ^^^^^^^^^^^^^^^^^^^^^^^^^^ | + = note: the `must_not_suspend` lint is unstable = note: see issue #83310 for more information = help: add `#![feature(must_not_suspend)]` to the crate attributes to enable -error: `MutexGuard` held across a suspend point, but should not be - --> $DIR/gated.rs:9:9 - | -LL | let _guard = m.lock().unwrap(); - | ^^^^^^ -LL | other().await; - | ------ the value is held across this suspend point - | -note: the lint level is defined here - --> $DIR/gated.rs:2:9 - | -LL | #![deny(must_not_suspend)] - | ^^^^^^^^^^^^^^^^ -note: holding a MutexGuard across suspend points can cause deadlocks, delays, and cause Futures to not implement `Send` - --> $DIR/gated.rs:9:9 - | -LL | let _guard = m.lock().unwrap(); - | ^^^^^^ -help: consider using a block (`{ ... }`) to shrink the value's scope, ending before the suspend point - --> $DIR/gated.rs:9:9 - | -LL | let _guard = m.lock().unwrap(); - | ^^^^^^ - -error: aborting due to 4 previous errors +warning: 3 warnings emitted -For more information about this error, try `rustc --explain E0658`. diff --git a/src/test/ui/unknown-unstable-lints/deny-unstable-lint-command-line.rs b/src/test/ui/unknown-unstable-lints/deny-unstable-lint-command-line.rs new file mode 100644 index 0000000000000..dcc06850de174 --- /dev/null +++ b/src/test/ui/unknown-unstable-lints/deny-unstable-lint-command-line.rs @@ -0,0 +1,6 @@ +// check-fail +// compile-flags: -Dunknown_lints -Atest_unstable_lint +// error-pattern: unknown lint: `test_unstable_lint` +// error-pattern: the `test_unstable_lint` lint is unstable + +fn main() {} diff --git a/src/test/ui/unknown-unstable-lints/deny-unstable-lint-command-line.stderr b/src/test/ui/unknown-unstable-lints/deny-unstable-lint-command-line.stderr new file mode 100644 index 0000000000000..c840849a27d9d --- /dev/null +++ b/src/test/ui/unknown-unstable-lints/deny-unstable-lint-command-line.stderr @@ -0,0 +1,18 @@ +error: unknown lint: `test_unstable_lint` + | + = note: `-D test-unstable-lint` implied by `-D unknown-lints` + = note: the `test_unstable_lint` lint is unstable + = help: add `#![feature(test_unstable_lint)]` to the crate attributes to enable + +error: unknown lint: `test_unstable_lint` + | + = note: the `test_unstable_lint` lint is unstable + = help: add `#![feature(test_unstable_lint)]` to the crate attributes to enable + +error: unknown lint: `test_unstable_lint` + | + = note: the `test_unstable_lint` lint is unstable + = help: add `#![feature(test_unstable_lint)]` to the crate attributes to enable + +error: aborting due to 3 previous errors + diff --git a/src/test/ui/unknown-unstable-lints/deny-unstable-lint-inline.rs b/src/test/ui/unknown-unstable-lints/deny-unstable-lint-inline.rs new file mode 100644 index 0000000000000..c6c60b12d83e9 --- /dev/null +++ b/src/test/ui/unknown-unstable-lints/deny-unstable-lint-inline.rs @@ -0,0 +1,9 @@ +// check-fail + +#![deny(unknown_lints)] +#![allow(test_unstable_lint)] +//~^ ERROR unknown lint: `test_unstable_lint` +//~| ERROR unknown lint: `test_unstable_lint` +//~| ERROR unknown lint: `test_unstable_lint` + +fn main() {} diff --git a/src/test/ui/unknown-unstable-lints/deny-unstable-lint-inline.stderr b/src/test/ui/unknown-unstable-lints/deny-unstable-lint-inline.stderr new file mode 100644 index 0000000000000..6e909f9902c4f --- /dev/null +++ b/src/test/ui/unknown-unstable-lints/deny-unstable-lint-inline.stderr @@ -0,0 +1,35 @@ +error: unknown lint: `test_unstable_lint` + --> $DIR/deny-unstable-lint-inline.rs:4:1 + | +LL | #![allow(test_unstable_lint)] + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | +note: the lint level is defined here + --> $DIR/deny-unstable-lint-inline.rs:3:9 + | +LL | #![deny(unknown_lints)] + | ^^^^^^^^^^^^^ + = note: `#[deny(test_unstable_lint)]` implied by `#[deny(unknown_lints)]` + = note: the `test_unstable_lint` lint is unstable + = help: add `#![feature(test_unstable_lint)]` to the crate attributes to enable + +error: unknown lint: `test_unstable_lint` + --> $DIR/deny-unstable-lint-inline.rs:4:1 + | +LL | #![allow(test_unstable_lint)] + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | + = note: the `test_unstable_lint` lint is unstable + = help: add `#![feature(test_unstable_lint)]` to the crate attributes to enable + +error: unknown lint: `test_unstable_lint` + --> $DIR/deny-unstable-lint-inline.rs:4:1 + | +LL | #![allow(test_unstable_lint)] + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | + = note: the `test_unstable_lint` lint is unstable + = help: add `#![feature(test_unstable_lint)]` to the crate attributes to enable + +error: aborting due to 3 previous errors + diff --git a/src/test/ui/unknown-unstable-lints/unstable-lint-command-line.rs b/src/test/ui/unknown-unstable-lints/unstable-lint-command-line.rs deleted file mode 100644 index 7663abffd9b48..0000000000000 --- a/src/test/ui/unknown-unstable-lints/unstable-lint-command-line.rs +++ /dev/null @@ -1,5 +0,0 @@ -// check-fail -// compile-flags: -Atest_unstable_lint -// error-pattern: the `test_unstable_lint` lint is unstable - -fn main() {} diff --git a/src/test/ui/unknown-unstable-lints/unstable-lint-command-line.stderr b/src/test/ui/unknown-unstable-lints/unstable-lint-command-line.stderr deleted file mode 100644 index d088f4c8fe5aa..0000000000000 --- a/src/test/ui/unknown-unstable-lints/unstable-lint-command-line.stderr +++ /dev/null @@ -1,11 +0,0 @@ -error[E0658]: the `test_unstable_lint` lint is unstable - | - = help: add `#![feature(test_unstable_lint)]` to the crate attributes to enable - -error[E0658]: the `test_unstable_lint` lint is unstable - | - = help: add `#![feature(test_unstable_lint)]` to the crate attributes to enable - -error: aborting due to 2 previous errors - -For more information about this error, try `rustc --explain E0658`. diff --git a/src/test/ui/unknown-unstable-lints/unstable-lint-inline.rs b/src/test/ui/unknown-unstable-lints/unstable-lint-inline.rs deleted file mode 100644 index 43789906ed6f0..0000000000000 --- a/src/test/ui/unknown-unstable-lints/unstable-lint-inline.rs +++ /dev/null @@ -1,6 +0,0 @@ -// check-fail -// error-pattern: the `test_unstable_lint` lint is unstable - -#![allow(test_unstable_lint)] - -fn main() {} diff --git a/src/test/ui/unknown-unstable-lints/unstable-lint-inline.stderr b/src/test/ui/unknown-unstable-lints/unstable-lint-inline.stderr deleted file mode 100644 index 5ec85f346fec5..0000000000000 --- a/src/test/ui/unknown-unstable-lints/unstable-lint-inline.stderr +++ /dev/null @@ -1,19 +0,0 @@ -error[E0658]: the `test_unstable_lint` lint is unstable - --> $DIR/unstable-lint-inline.rs:4:1 - | -LL | #![allow(test_unstable_lint)] - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ - | - = help: add `#![feature(test_unstable_lint)]` to the crate attributes to enable - -error[E0658]: the `test_unstable_lint` lint is unstable - --> $DIR/unstable-lint-inline.rs:4:1 - | -LL | #![allow(test_unstable_lint)] - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ - | - = help: add `#![feature(test_unstable_lint)]` to the crate attributes to enable - -error: aborting due to 2 previous errors - -For more information about this error, try `rustc --explain E0658`. diff --git a/src/test/ui/unknown-unstable-lints/warn-unknown-unstable-lint-command-line.rs b/src/test/ui/unknown-unstable-lints/warn-unknown-unstable-lint-command-line.rs new file mode 100644 index 0000000000000..3778291ebb447 --- /dev/null +++ b/src/test/ui/unknown-unstable-lints/warn-unknown-unstable-lint-command-line.rs @@ -0,0 +1,6 @@ +// check-pass +// compile-flags: -Wunknown_lints -Atest_unstable_lint +// error-pattern: unknown lint: `test_unstable_lint` +// error-pattern: the `test_unstable_lint` lint is unstable + +fn main() {} diff --git a/src/test/ui/unknown-unstable-lints/warn-unknown-unstable-lint-command-line.stderr b/src/test/ui/unknown-unstable-lints/warn-unknown-unstable-lint-command-line.stderr new file mode 100644 index 0000000000000..a45bed843c71d --- /dev/null +++ b/src/test/ui/unknown-unstable-lints/warn-unknown-unstable-lint-command-line.stderr @@ -0,0 +1,18 @@ +warning: unknown lint: `test_unstable_lint` + | + = note: `-W test-unstable-lint` implied by `-W unknown-lints` + = note: the `test_unstable_lint` lint is unstable + = help: add `#![feature(test_unstable_lint)]` to the crate attributes to enable + +warning: unknown lint: `test_unstable_lint` + | + = note: the `test_unstable_lint` lint is unstable + = help: add `#![feature(test_unstable_lint)]` to the crate attributes to enable + +warning: unknown lint: `test_unstable_lint` + | + = note: the `test_unstable_lint` lint is unstable + = help: add `#![feature(test_unstable_lint)]` to the crate attributes to enable + +warning: 3 warnings emitted + diff --git a/src/test/ui/unknown-unstable-lints/warn-unknown-unstable-lint-inline.rs b/src/test/ui/unknown-unstable-lints/warn-unknown-unstable-lint-inline.rs new file mode 100644 index 0000000000000..f4247e4569eb7 --- /dev/null +++ b/src/test/ui/unknown-unstable-lints/warn-unknown-unstable-lint-inline.rs @@ -0,0 +1,9 @@ +// check-pass + +#![warn(unknown_lints)] +#![allow(test_unstable_lint)] +//~^ WARNING unknown lint: `test_unstable_lint` +//~| WARNING unknown lint: `test_unstable_lint` +//~| WARNING unknown lint: `test_unstable_lint` + +fn main() {} diff --git a/src/test/ui/unknown-unstable-lints/warn-unknown-unstable-lint-inline.stderr b/src/test/ui/unknown-unstable-lints/warn-unknown-unstable-lint-inline.stderr new file mode 100644 index 0000000000000..ce6bd0f3ef994 --- /dev/null +++ b/src/test/ui/unknown-unstable-lints/warn-unknown-unstable-lint-inline.stderr @@ -0,0 +1,35 @@ +warning: unknown lint: `test_unstable_lint` + --> $DIR/warn-unknown-unstable-lint-inline.rs:4:1 + | +LL | #![allow(test_unstable_lint)] + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | +note: the lint level is defined here + --> $DIR/warn-unknown-unstable-lint-inline.rs:3:9 + | +LL | #![warn(unknown_lints)] + | ^^^^^^^^^^^^^ + = note: `#[warn(test_unstable_lint)]` implied by `#[warn(unknown_lints)]` + = note: the `test_unstable_lint` lint is unstable + = help: add `#![feature(test_unstable_lint)]` to the crate attributes to enable + +warning: unknown lint: `test_unstable_lint` + --> $DIR/warn-unknown-unstable-lint-inline.rs:4:1 + | +LL | #![allow(test_unstable_lint)] + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | + = note: the `test_unstable_lint` lint is unstable + = help: add `#![feature(test_unstable_lint)]` to the crate attributes to enable + +warning: unknown lint: `test_unstable_lint` + --> $DIR/warn-unknown-unstable-lint-inline.rs:4:1 + | +LL | #![allow(test_unstable_lint)] + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | + = note: the `test_unstable_lint` lint is unstable + = help: add `#![feature(test_unstable_lint)]` to the crate attributes to enable + +warning: 3 warnings emitted + From 1593ce8609714f4717a9db964507bf4fdf1e400d Mon Sep 17 00:00:00 2001 From: David Koloski Date: Mon, 28 Feb 2022 22:28:45 +0000 Subject: [PATCH 3/5] Fill out documentation for new lint --- compiler/rustc_lint_defs/src/builtin.rs | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/compiler/rustc_lint_defs/src/builtin.rs b/compiler/rustc_lint_defs/src/builtin.rs index f6ad46cc01888..7f1591a72120b 100644 --- a/compiler/rustc_lint_defs/src/builtin.rs +++ b/compiler/rustc_lint_defs/src/builtin.rs @@ -3774,8 +3774,21 @@ declare_lint! { } declare_lint! { - #[doc(hidden)] - /// Added for testing unsable lints; perma-unstable. + /// The `test_unstable_lint` lint tests unstable lints and is perma-unstable. + /// + /// ### Example + /// + /// ``` + /// #![allow(test_unstable_lint)] + /// ``` + /// + /// {{produces}} + /// + /// ### Explanation + /// + /// In order to test the behavior of unstable traits, a permanently-unstable + /// lint is required. This lint can be used to trigger warnings and errors + /// from the compiler related to unstable lints. pub TEST_UNSTABLE_LINT, Deny, "this unstable lint is only for testing", From fa10d90b9974844790b0ad98fa5c50fae80ee166 Mon Sep 17 00:00:00 2001 From: David Koloski Date: Wed, 2 Mar 2022 00:10:39 +0000 Subject: [PATCH 4/5] Fix docs, fix incorrect lint source in note --- compiler/rustc_lint/src/levels.rs | 5 +++-- compiler/rustc_lint_defs/src/builtin.rs | 2 +- .../feature-gate-non_exhaustive_omitted_patterns_lint.stderr | 2 +- .../ui/feature-gates/feature-gate-test_unstable_lint.stderr | 2 +- src/test/ui/lint/must_not_suspend/gated.stderr | 2 +- .../deny-unstable-lint-command-line.stderr | 2 +- .../unknown-unstable-lints/deny-unstable-lint-inline.stderr | 1 - .../warn-unknown-unstable-lint-command-line.stderr | 2 +- .../warn-unknown-unstable-lint-inline.stderr | 1 - 9 files changed, 9 insertions(+), 10 deletions(-) diff --git a/compiler/rustc_lint/src/levels.rs b/compiler/rustc_lint/src/levels.rs index 2b28fc2c0115e..7b018e7f75fa7 100644 --- a/compiler/rustc_lint/src/levels.rs +++ b/compiler/rustc_lint/src/levels.rs @@ -601,10 +601,11 @@ impl<'s> LintLevelsBuilder<'s> { fn check_gated_lint(&self, lint_id: LintId, span: Span) -> bool { if let Some(feature) = lint_id.lint.feature_gate { if !self.sess.features_untracked().enabled(feature) { + let lint = builtin::UNKNOWN_LINTS; let (level, src) = self.lint_level(builtin::UNKNOWN_LINTS); - struct_lint_level(self.sess, lint_id.lint, level, src, Some(span.into()), |lint| { + struct_lint_level(self.sess, lint, level, src, Some(span.into()), |lint_db| { let mut db = - lint.build(&format!("unknown lint: `{}`", lint_id.lint.name_lower())); + lint_db.build(&format!("unknown lint: `{}`", lint_id.lint.name_lower())); db.note(&format!("the `{}` lint is unstable", lint_id.lint.name_lower(),)); add_feature_diagnostics(&mut db, &self.sess.parse_sess, feature); db.emit(); diff --git a/compiler/rustc_lint_defs/src/builtin.rs b/compiler/rustc_lint_defs/src/builtin.rs index 7f1591a72120b..62eba796eae54 100644 --- a/compiler/rustc_lint_defs/src/builtin.rs +++ b/compiler/rustc_lint_defs/src/builtin.rs @@ -3786,7 +3786,7 @@ declare_lint! { /// /// ### Explanation /// - /// In order to test the behavior of unstable traits, a permanently-unstable + /// In order to test the behavior of unstable lints, a permanently-unstable /// lint is required. This lint can be used to trigger warnings and errors /// from the compiler related to unstable lints. pub TEST_UNSTABLE_LINT, diff --git a/src/test/ui/feature-gates/feature-gate-non_exhaustive_omitted_patterns_lint.stderr b/src/test/ui/feature-gates/feature-gate-non_exhaustive_omitted_patterns_lint.stderr index 94568c96b40a3..7f82fbdea4eba 100644 --- a/src/test/ui/feature-gates/feature-gate-non_exhaustive_omitted_patterns_lint.stderr +++ b/src/test/ui/feature-gates/feature-gate-non_exhaustive_omitted_patterns_lint.stderr @@ -4,7 +4,7 @@ warning: unknown lint: `non_exhaustive_omitted_patterns` LL | #![deny(non_exhaustive_omitted_patterns)] | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | - = note: `#[warn(non_exhaustive_omitted_patterns)]` on by default + = note: `#[warn(unknown_lints)]` on by default = note: the `non_exhaustive_omitted_patterns` lint is unstable = note: see issue #89554 for more information = help: add `#![feature(non_exhaustive_omitted_patterns_lint)]` to the crate attributes to enable diff --git a/src/test/ui/feature-gates/feature-gate-test_unstable_lint.stderr b/src/test/ui/feature-gates/feature-gate-test_unstable_lint.stderr index eab89f02018bf..a29322443ea98 100644 --- a/src/test/ui/feature-gates/feature-gate-test_unstable_lint.stderr +++ b/src/test/ui/feature-gates/feature-gate-test_unstable_lint.stderr @@ -4,7 +4,7 @@ warning: unknown lint: `test_unstable_lint` LL | #![allow(test_unstable_lint)] | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | - = note: `#[warn(test_unstable_lint)]` on by default + = note: `#[warn(unknown_lints)]` on by default = note: the `test_unstable_lint` lint is unstable = help: add `#![feature(test_unstable_lint)]` to the crate attributes to enable diff --git a/src/test/ui/lint/must_not_suspend/gated.stderr b/src/test/ui/lint/must_not_suspend/gated.stderr index 3d6877045ff78..b58ecb55596ab 100644 --- a/src/test/ui/lint/must_not_suspend/gated.stderr +++ b/src/test/ui/lint/must_not_suspend/gated.stderr @@ -4,7 +4,7 @@ warning: unknown lint: `must_not_suspend` LL | #![deny(must_not_suspend)] | ^^^^^^^^^^^^^^^^^^^^^^^^^^ | - = note: `#[warn(must_not_suspend)]` on by default + = note: `#[warn(unknown_lints)]` on by default = note: the `must_not_suspend` lint is unstable = note: see issue #83310 for more information = help: add `#![feature(must_not_suspend)]` to the crate attributes to enable diff --git a/src/test/ui/unknown-unstable-lints/deny-unstable-lint-command-line.stderr b/src/test/ui/unknown-unstable-lints/deny-unstable-lint-command-line.stderr index c840849a27d9d..7e6885bd70646 100644 --- a/src/test/ui/unknown-unstable-lints/deny-unstable-lint-command-line.stderr +++ b/src/test/ui/unknown-unstable-lints/deny-unstable-lint-command-line.stderr @@ -1,6 +1,6 @@ error: unknown lint: `test_unstable_lint` | - = note: `-D test-unstable-lint` implied by `-D unknown-lints` + = note: requested on the command line with `-D unknown-lints` = note: the `test_unstable_lint` lint is unstable = help: add `#![feature(test_unstable_lint)]` to the crate attributes to enable diff --git a/src/test/ui/unknown-unstable-lints/deny-unstable-lint-inline.stderr b/src/test/ui/unknown-unstable-lints/deny-unstable-lint-inline.stderr index 6e909f9902c4f..2d1027dd0e05f 100644 --- a/src/test/ui/unknown-unstable-lints/deny-unstable-lint-inline.stderr +++ b/src/test/ui/unknown-unstable-lints/deny-unstable-lint-inline.stderr @@ -9,7 +9,6 @@ note: the lint level is defined here | LL | #![deny(unknown_lints)] | ^^^^^^^^^^^^^ - = note: `#[deny(test_unstable_lint)]` implied by `#[deny(unknown_lints)]` = note: the `test_unstable_lint` lint is unstable = help: add `#![feature(test_unstable_lint)]` to the crate attributes to enable diff --git a/src/test/ui/unknown-unstable-lints/warn-unknown-unstable-lint-command-line.stderr b/src/test/ui/unknown-unstable-lints/warn-unknown-unstable-lint-command-line.stderr index a45bed843c71d..799d740b00ef2 100644 --- a/src/test/ui/unknown-unstable-lints/warn-unknown-unstable-lint-command-line.stderr +++ b/src/test/ui/unknown-unstable-lints/warn-unknown-unstable-lint-command-line.stderr @@ -1,6 +1,6 @@ warning: unknown lint: `test_unstable_lint` | - = note: `-W test-unstable-lint` implied by `-W unknown-lints` + = note: requested on the command line with `-W unknown-lints` = note: the `test_unstable_lint` lint is unstable = help: add `#![feature(test_unstable_lint)]` to the crate attributes to enable diff --git a/src/test/ui/unknown-unstable-lints/warn-unknown-unstable-lint-inline.stderr b/src/test/ui/unknown-unstable-lints/warn-unknown-unstable-lint-inline.stderr index ce6bd0f3ef994..142558b471b48 100644 --- a/src/test/ui/unknown-unstable-lints/warn-unknown-unstable-lint-inline.stderr +++ b/src/test/ui/unknown-unstable-lints/warn-unknown-unstable-lint-inline.stderr @@ -9,7 +9,6 @@ note: the lint level is defined here | LL | #![warn(unknown_lints)] | ^^^^^^^^^^^^^ - = note: `#[warn(test_unstable_lint)]` implied by `#[warn(unknown_lints)]` = note: the `test_unstable_lint` lint is unstable = help: add `#![feature(test_unstable_lint)]` to the crate attributes to enable From 1c31a95df7de66dc7842b43facf185ef8a776e6f Mon Sep 17 00:00:00 2001 From: David Koloski Date: Tue, 8 Mar 2022 19:57:03 +0000 Subject: [PATCH 5/5] Update for changes to other lints --- ...on_exhaustive_omitted_patterns_lint.stderr | 25 +++++++++++-------- 1 file changed, 15 insertions(+), 10 deletions(-) diff --git a/src/test/ui/feature-gates/feature-gate-non_exhaustive_omitted_patterns_lint.stderr b/src/test/ui/feature-gates/feature-gate-non_exhaustive_omitted_patterns_lint.stderr index 7f82fbdea4eba..dbeef6c2d2ae2 100644 --- a/src/test/ui/feature-gates/feature-gate-non_exhaustive_omitted_patterns_lint.stderr +++ b/src/test/ui/feature-gates/feature-gate-non_exhaustive_omitted_patterns_lint.stderr @@ -102,17 +102,22 @@ LL | #[warn(non_exhaustive_omitted_patterns)] error[E0004]: non-exhaustive patterns: `C` not covered --> $DIR/feature-gate-non_exhaustive_omitted_patterns_lint.rs:20:11 | -LL | / enum Foo { -LL | | A, B, C, - | | - not covered -LL | | } - | |_____- `Foo` defined here -... -LL | match Foo::A { - | ^^^^^^ pattern `C` not covered - | - = help: ensure that all possible cases are being handled, possibly by adding wildcards or more match arms +LL | match Foo::A { + | ^^^^^^ pattern `C` not covered + | +note: `Foo` defined here + --> $DIR/feature-gate-non_exhaustive_omitted_patterns_lint.rs:12:15 + | +LL | enum Foo { + | --- +LL | A, B, C, + | ^ not covered = note: the matched value is of type `Foo` +help: ensure that all possible cases are being handled by adding a match arm with a wildcard pattern or an explicit pattern as shown + | +LL ~ Foo::B => {} +LL + C => todo!() + | error: aborting due to previous error; 10 warnings emitted