diff --git a/compiler/rustc_attr_parsing/src/interface.rs b/compiler/rustc_attr_parsing/src/interface.rs index 06738b9c7337..902f2419c46d 100644 --- a/compiler/rustc_attr_parsing/src/interface.rs +++ b/compiler/rustc_attr_parsing/src/interface.rs @@ -10,7 +10,7 @@ use rustc_hir::lints::AttributeLintKind; use rustc_hir::{AttrArgs, AttrItem, AttrPath, Attribute, HashIgnoredAttrId, Target}; use rustc_session::Session; -use rustc_session::lint::{BuiltinLintDiag, LintId}; +use rustc_session::lint::LintId; use rustc_span::{DUMMY_SP, Ident, Span, Symbol, sym}; use crate::context::{AcceptContext, FinalizeContext, FinalizeFn, SharedContext, Stage}; @@ -124,14 +124,7 @@ pub fn parse_limited_all<'a>( target, OmitDoc::Skip, std::convert::identity, - |lint_id, span, kind| { - sess.psess.buffer_lint( - lint_id.lint, - span, - target_node_id, - BuiltinLintDiag::AttributeLint(kind), - ) - }, + |lint_id, span, kind| sess.psess.buffer_lint(lint_id.lint, span, target_node_id, kind), ) } @@ -230,12 +223,7 @@ pub fn parse_single_args( let mut parser = Self { features, tools: None, parse_only: None, sess, stage: Early { emit_errors } }; let mut emit_lint = |lint_id: LintId, span: Span, kind: AttributeLintKind| { - sess.psess.buffer_lint( - lint_id.lint, - span, - target_node_id, - BuiltinLintDiag::AttributeLint(kind), - ) + sess.psess.buffer_lint(lint_id.lint, span, target_node_id, kind) }; if let Some(safety) = attr_safety { parser.check_attribute_safety(&attr_path, inner_span, safety, &mut emit_lint) diff --git a/compiler/rustc_attr_parsing/src/validate_attr.rs b/compiler/rustc_attr_parsing/src/validate_attr.rs index e2521c9abf5f..eb3c4796f02d 100644 --- a/compiler/rustc_attr_parsing/src/validate_attr.rs +++ b/compiler/rustc_attr_parsing/src/validate_attr.rs @@ -14,7 +14,6 @@ use rustc_hir::lints::AttributeLintKind; use rustc_parse::parse_in; use rustc_session::errors::report_lit_error; -use rustc_session::lint::BuiltinLintDiag; use rustc_session::lint::builtin::ILL_FORMED_ATTRIBUTE_INPUT; use rustc_session::parse::ParseSess; use rustc_span::{Span, Symbol, sym}; @@ -208,11 +207,11 @@ fn emit_malformed_attribute( ILL_FORMED_ATTRIBUTE_INPUT, span, ast::CRATE_NODE_ID, - BuiltinLintDiag::AttributeLint(AttributeLintKind::IllFormedAttributeInput { + AttributeLintKind::IllFormedAttributeInput { suggestions: suggestions.clone(), docs: template.docs, help: None, - }), + }, ); } else { suggestions.sort(); diff --git a/compiler/rustc_errors/src/decorate_diag.rs b/compiler/rustc_errors/src/decorate_diag.rs index 321591469889..18c0c571fd1b 100644 --- a/compiler/rustc_errors/src/decorate_diag.rs +++ b/compiler/rustc_errors/src/decorate_diag.rs @@ -5,11 +5,11 @@ use rustc_data_structures::fx::FxIndexMap; use rustc_data_structures::sync::{DynSend, DynSync}; use rustc_error_messages::MultiSpan; -use rustc_lint_defs::{BuiltinLintDiag, Lint, LintId}; +use rustc_lint_defs::{AttributeLintKind, Lint, LintId}; use crate::{Diag, DiagCtxtHandle, Diagnostic, Level}; -/// We can't implement `Diagnostic` for `BuiltinLintDiag`, because decorating some of its +/// We can't implement `Diagnostic` for `AttributeLintKind`, because decorating some of its /// variants requires types we don't have yet. So, handle that case separately. pub enum DecorateDiagCompat { /// The third argument of the closure is a `Session`. However, due to the dependency tree, @@ -22,7 +22,7 @@ pub enum DecorateDiagCompat { + 'static, >, ), - Builtin(BuiltinLintDiag), + Builtin(AttributeLintKind), } impl std::fmt::Debug for DecorateDiagCompat { @@ -38,9 +38,9 @@ fn from(d: D) -> Self { } } -impl From for DecorateDiagCompat { +impl From for DecorateDiagCompat { #[inline] - fn from(b: BuiltinLintDiag) -> Self { + fn from(b: AttributeLintKind) -> Self { Self::Builtin(b) } } diff --git a/compiler/rustc_lint/src/early.rs b/compiler/rustc_lint/src/early.rs index 635185be1cb7..e55cfc052ac4 100644 --- a/compiler/rustc_lint/src/early.rs +++ b/compiler/rustc_lint/src/early.rs @@ -17,7 +17,7 @@ use crate::context::{EarlyContext, LintContext, LintStore}; use crate::passes::{EarlyLintPass, EarlyLintPassObject}; -use crate::{DecorateBuiltinLint, DiagAndSess}; +use crate::{DecorateAttrLint, DiagAndSess}; pub(super) mod diagnostics; @@ -42,10 +42,10 @@ fn check_id(&mut self, id: ast::NodeId) { self.context.opt_span_lint( lint_id.lint, span, - DecorateBuiltinLint { + DecorateAttrLint { sess: self.context.sess(), tcx: self.tcx, - diagnostic: b, + diagnostic: &b, }, ); } diff --git a/compiler/rustc_lint/src/early/diagnostics.rs b/compiler/rustc_lint/src/early/diagnostics.rs index fe1a0bf1394e..0f27e04babd4 100644 --- a/compiler/rustc_lint/src/early/diagnostics.rs +++ b/compiler/rustc_lint/src/early/diagnostics.rs @@ -6,7 +6,6 @@ use rustc_hir::lints::{AttributeLintKind, FormatWarning}; use rustc_middle::ty::TyCtxt; use rustc_session::Session; -use rustc_session::lint::BuiltinLintDiag; use crate::lints; @@ -25,25 +24,6 @@ fn into_diag(self, dcx: DiagCtxtHandle<'a>, level: Level) -> Diag<'a, ()> { } } -/// This is a diagnostic struct that will decorate a `BuiltinLintDiag` -/// Directly creating the lint structs is expensive, using this will only decorate the lint structs when needed. -pub struct DecorateBuiltinLint<'sess, 'tcx> { - pub sess: &'sess Session, - pub tcx: Option>, - pub diagnostic: BuiltinLintDiag, -} - -impl<'a> Diagnostic<'a, ()> for DecorateBuiltinLint<'_, '_> { - fn into_diag(self, dcx: DiagCtxtHandle<'a>, level: Level) -> Diag<'a, ()> { - match self.diagnostic { - BuiltinLintDiag::AttributeLint(kind) => { - DecorateAttrLint { sess: self.sess, tcx: self.tcx, diagnostic: &kind } - .into_diag(dcx, level) - } - } - } -} - /// This is a diagnostic struct that will decorate a `AttributeLintKind` /// Directly creating the lint structs is expensive, using this will only decorate the lint structs when needed. pub struct DecorateAttrLint<'a, 'sess, 'tcx> { diff --git a/compiler/rustc_lint/src/lib.rs b/compiler/rustc_lint/src/lib.rs index c76fafcde2ee..6f6aa0f96e75 100644 --- a/compiler/rustc_lint/src/lib.rs +++ b/compiler/rustc_lint/src/lib.rs @@ -129,7 +129,7 @@ #[rustfmt::skip] pub use builtin::{MissingDoc, SoftLints}; pub use context::{EarlyContext, LateContext, LintContext, LintStore}; -pub use early::diagnostics::{DecorateAttrLint, DecorateBuiltinLint, DiagAndSess}; +pub use early::diagnostics::{DecorateAttrLint, DiagAndSess}; pub use early::{EarlyCheckNode, check_ast_node}; pub use late::{check_crate, late_lint_mod, unerased_lint_store}; pub use levels::LintLevelsBuilder; diff --git a/compiler/rustc_lint_defs/src/lib.rs b/compiler/rustc_lint_defs/src/lib.rs index b24adda06f98..36070dac276f 100644 --- a/compiler/rustc_lint_defs/src/lib.rs +++ b/compiler/rustc_lint_defs/src/lib.rs @@ -652,13 +652,6 @@ pub enum DeprecatedSinceKind { InVersion(String), } -// This could be a closure, but then implementing derive trait -// becomes hacky (and it gets allocated). -#[derive(Debug)] -pub enum BuiltinLintDiag { - AttributeLint(AttributeLintKind), -} - #[derive(Debug, HashStable_Generic)] pub enum AttributeLintKind { UnusedDuplicate {