diff options
| author | Matthias Krüger <matthias.krueger@famsik.de> | 2022-03-14 17:24:58 +0100 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2022-03-14 17:24:58 +0100 |
| commit | 6548a368c8c66c802ba710dd9fede228dc65587e (patch) | |
| tree | e16d7650112a4673530e53023d13536dd8450215 /compiler/rustc_errors/src | |
| parent | 774655da5fabdef01f862c50d1796abbe59efb7d (diff) | |
| parent | be84049570d5be6d6e76e471ef88a11ae46292ad (diff) | |
| download | rust-6548a368c8c66c802ba710dd9fede228dc65587e.tar.gz rust-6548a368c8c66c802ba710dd9fede228dc65587e.zip | |
Rollup merge of #94670 - xFrednet:rfc-2383-expect-impl-after-party, r=flip1995,wesleywiser
Improve `expect` impl and handle `#[expect(unfulfilled_lint_expectations)]` (RFC 2383) This PR updates unstable `ExpectationIds` in stashed diagnostics and adds some asserts to ensure that the stored expectations are really empty in the end. Additionally, it handles the `#[expect(unfulfilled_lint_expectations)]` case. According to the [Errors and lints docs](https://rustc-dev-guide.rust-lang.org/diagnostics.html#diagnostic-levels) the `error` level should only be used _"when the compiler detects a problem that makes it unable to compile the program"_. As this isn't the case with `#[expect(unfulfilled_lint_expectations)]` I decided to only create a warning. To avoid adding a new lint only for this case, I simply emit a `unfulfilled_lint_expectations` diagnostic with an additional note. --- r? `@wesleywiser` I'm requesting a review from you since you reviewed the previous PR https://github.com/rust-lang/rust/pull/87835. You are welcome to reassign it if you're busy :upside_down_face: rfc: [RFC-2383](https://rust-lang.github.io/rfcs/2383-lint-reasons.html) tracking issue: https://github.com/rust-lang/rust/issues/85549 cc: `@flip1995` In case you're also interested in this :)
Diffstat (limited to 'compiler/rustc_errors/src')
| -rw-r--r-- | compiler/rustc_errors/src/diagnostic.rs | 25 | ||||
| -rw-r--r-- | compiler/rustc_errors/src/lib.rs | 30 |
2 files changed, 42 insertions, 13 deletions
diff --git a/compiler/rustc_errors/src/diagnostic.rs b/compiler/rustc_errors/src/diagnostic.rs index 39ebd57b4b2..5c36c3c55b5 100644 --- a/compiler/rustc_errors/src/diagnostic.rs +++ b/compiler/rustc_errors/src/diagnostic.rs @@ -5,7 +5,8 @@ use crate::Substitution; use crate::SubstitutionPart; use crate::SuggestionStyle; use crate::ToolMetadata; -use rustc_lint_defs::Applicability; +use rustc_data_structures::stable_map::FxHashMap; +use rustc_lint_defs::{Applicability, LintExpectationId}; use rustc_serialize::json::Json; use rustc_span::edition::LATEST_STABLE_EDITION; use rustc_span::{MultiSpan, Span, DUMMY_SP}; @@ -138,6 +139,28 @@ impl Diagnostic { } } + pub fn update_unstable_expectation_id( + &mut self, + unstable_to_stable: &FxHashMap<LintExpectationId, LintExpectationId>, + ) { + if let Level::Expect(expectation_id) = &mut self.level { + if expectation_id.is_stable() { + return; + } + + // The unstable to stable map only maps the unstable `AttrId` to a stable `HirId` with an attribute index. + // The lint index inside the attribute is manually transferred here. + let lint_index = expectation_id.get_lint_index(); + expectation_id.set_lint_index(None); + let mut stable_id = *unstable_to_stable + .get(&expectation_id) + .expect("each unstable `LintExpectationId` must have a matching stable id"); + + stable_id.set_lint_index(lint_index); + *expectation_id = stable_id; + } + } + pub fn has_future_breakage(&self) -> bool { match self.code { Some(DiagnosticId::Lint { has_future_breakage, .. }) => has_future_breakage, diff --git a/compiler/rustc_errors/src/lib.rs b/compiler/rustc_errors/src/lib.rs index 3641c38f9dc..345247b0700 100644 --- a/compiler/rustc_errors/src/lib.rs +++ b/compiler/rustc_errors/src/lib.rs @@ -522,6 +522,11 @@ impl Drop for HandlerInner { "no warnings or errors encountered even though `delayed_good_path_bugs` issued", ); } + + assert!( + self.unstable_expect_diagnostics.is_empty(), + "all diagnostics with unstable expectations should have been converted", + ); } } @@ -942,29 +947,30 @@ impl Handler { let mut inner = self.inner.borrow_mut(); for mut diag in diags.into_iter() { - let mut unstable_id = diag + diag.update_unstable_expectation_id(unstable_to_stable); + + let stable_id = diag .level .get_expectation_id() .expect("all diagnostics inside `unstable_expect_diagnostics` must have a `LintExpectationId`"); - - // The unstable to stable map only maps the unstable `AttrId` to a stable `HirId` with an attribute index. - // The lint index inside the attribute is manually transferred here. - let lint_index = unstable_id.get_lint_index(); - unstable_id.set_lint_index(None); - let mut stable_id = *unstable_to_stable - .get(&unstable_id) - .expect("each unstable `LintExpectationId` must have a matching stable id"); - - stable_id.set_lint_index(lint_index); - diag.level = Level::Expect(stable_id); inner.fulfilled_expectations.insert(stable_id); (*TRACK_DIAGNOSTICS)(&diag); } + + inner + .stashed_diagnostics + .values_mut() + .for_each(|diag| diag.update_unstable_expectation_id(unstable_to_stable)); + inner + .future_breakage_diagnostics + .iter_mut() + .for_each(|diag| diag.update_unstable_expectation_id(unstable_to_stable)); } /// This methods steals all [`LintExpectationId`]s that are stored inside /// [`HandlerInner`] and indicate that the linked expectation has been fulfilled. + #[must_use] pub fn steal_fulfilled_expectation_ids(&self) -> FxHashSet<LintExpectationId> { assert!( self.inner.borrow().unstable_expect_diagnostics.is_empty(), |
