diff --git a/.mailmap b/.mailmap index 17232083679c..c29f6a66f5d7 100644 --- a/.mailmap +++ b/.mailmap @@ -258,11 +258,11 @@ Greg V Gregor Peach Grzegorz Bartoszek Guanqun Lu -Guillaume Gomez -Guillaume Gomez ggomez -Guillaume Gomez Guillaume Gomez -Guillaume Gomez Guillaume Gomez -Guillaume Gomez Guillaume Gomez +Guillaume Gomez +Guillaume Gomez Guillaume Gomez +Guillaume Gomez ggomez +Guillaume Gomez Guillaume Gomez +Guillaume Gomez Guillaume Gomez gnzlbg hamidreza kalbasi Hanna Kruppe diff --git a/compiler/rustc_attr_parsing/src/attributes/crate_level.rs b/compiler/rustc_attr_parsing/src/attributes/crate_level.rs index fed4ca7e76ab..3739461c2004 100644 --- a/compiler/rustc_attr_parsing/src/attributes/crate_level.rs +++ b/compiler/rustc_attr_parsing/src/attributes/crate_level.rs @@ -1,10 +1,11 @@ +use rustc_errors::Diagnostic; use rustc_hir::attrs::{CrateType, WindowsSubsystemKind}; -use rustc_hir::lints::AttributeLintKind; use rustc_session::lint::builtin::UNKNOWN_CRATE_TYPES; use rustc_span::Symbol; use rustc_span::edit_distance::find_best_match_for_name; use super::prelude::*; +use crate::errors::{UnknownCrateTypes, UnknownCrateTypesSuggestion}; pub(crate) struct CrateNameParser; @@ -65,13 +66,17 @@ fn extend( crate_type, None, ); - cx.emit_lint( + let span = n.value_span; + cx.emit_dyn_lint( UNKNOWN_CRATE_TYPES, - AttributeLintKind::CrateTypeUnknown { - span: n.value_span, - suggested: candidate, + move |dcx, level| { + UnknownCrateTypes { + sugg: candidate + .map(|s| UnknownCrateTypesSuggestion { span, snippet: s }), + } + .into_diag(dcx, level) }, - n.value_span, + span, ); } return None; diff --git a/compiler/rustc_attr_parsing/src/attributes/diagnostic/do_not_recommend.rs b/compiler/rustc_attr_parsing/src/attributes/diagnostic/do_not_recommend.rs index 8cf6be088a7a..bf811438db93 100644 --- a/compiler/rustc_attr_parsing/src/attributes/diagnostic/do_not_recommend.rs +++ b/compiler/rustc_attr_parsing/src/attributes/diagnostic/do_not_recommend.rs @@ -2,7 +2,6 @@ use rustc_feature::{AttributeTemplate, template}; use rustc_hir::Target; use rustc_hir::attrs::AttributeKind; -use rustc_hir::lints::AttributeLintKind; use rustc_session::lint::builtin::{ MALFORMED_DIAGNOSTIC_ATTRIBUTES, MISPLACED_DIAGNOSTIC_ATTRIBUTES, }; @@ -25,9 +24,9 @@ impl SingleAttributeParser for DoNotRecommendParser { fn convert(cx: &mut AcceptContext<'_, '_, S>, args: &ArgParser) -> Option { let attr_span = cx.attr_span; if !matches!(args, ArgParser::NoArgs) { - cx.emit_lint( + cx.emit_dyn_lint( MALFORMED_DIAGNOSTIC_ATTRIBUTES, - AttributeLintKind::DoNotRecommendDoesNotExpectArgs, + |dcx, level| crate::errors::DoNotRecommendDoesNotExpectArgs.into_diag(dcx, level), attr_span, ); } diff --git a/compiler/rustc_attr_parsing/src/attributes/doc.rs b/compiler/rustc_attr_parsing/src/attributes/doc.rs index 09d474a227fb..2b6d56c41193 100644 --- a/compiler/rustc_attr_parsing/src/attributes/doc.rs +++ b/compiler/rustc_attr_parsing/src/attributes/doc.rs @@ -14,8 +14,9 @@ use super::{AcceptMapping, AttributeParser}; use crate::context::{AcceptContext, FinalizeContext, Stage}; use crate::errors::{ - DocAliasDuplicated, DocAutoCfgExpectsHideOrShow, DocAutoCfgHideShowExpectsList, - DocAutoCfgHideShowUnexpectedItem, DocAutoCfgWrongLiteral, DocUnknownAny, DocUnknownInclude, + AttrCrateLevelOnly, DocAliasDuplicated, DocAutoCfgExpectsHideOrShow, + DocAutoCfgHideShowExpectsList, DocAutoCfgHideShowUnexpectedItem, DocAutoCfgWrongLiteral, + DocTestLiteral, DocTestTakesList, DocTestUnknown, DocUnknownAny, DocUnknownInclude, DocUnknownPasses, DocUnknownPlugins, DocUnknownSpotlight, IllFormedAttributeInput, }; use crate::parser::{ArgParser, MetaItemOrLitParser, MetaItemParser, OwnedPathParser}; @@ -67,9 +68,9 @@ fn check_attr_not_crate_level( /// Checks that an attribute is used at the crate level. Returns `true` if valid. fn check_attr_crate_level(cx: &mut AcceptContext<'_, '_, S>, span: Span) -> bool { if cx.shared.target != Target::Crate { - cx.emit_lint( + cx.emit_dyn_lint( rustc_session::lint::builtin::INVALID_DOC_ATTRIBUTES, - AttributeLintKind::AttrCrateLevelOnly, + |dcx, level| AttrCrateLevelOnly.into_diag(dcx, level), span, ); return false; @@ -216,16 +217,16 @@ fn parse_single_test_doc_attr_item( } } Some(name) => { - cx.emit_lint( + cx.emit_dyn_lint( rustc_session::lint::builtin::INVALID_DOC_ATTRIBUTES, - AttributeLintKind::DocTestUnknown { name }, + move |dcx, level| DocTestUnknown { name }.into_diag(dcx, level), path.span(), ); } None => { - cx.emit_lint( + cx.emit_dyn_lint( rustc_session::lint::builtin::INVALID_DOC_ATTRIBUTES, - AttributeLintKind::DocTestLiteral, + |dcx, level| DocTestLiteral.into_diag(dcx, level), path.span(), ); } @@ -587,9 +588,9 @@ macro_rules! string_arg_and_crate_level { Some(sym::auto_cfg) => self.parse_auto_cfg(cx, path, args), Some(sym::test) => { let Some(list) = args.list() else { - cx.emit_lint( + cx.emit_dyn_lint( rustc_session::lint::builtin::INVALID_DOC_ATTRIBUTES, - AttributeLintKind::DocTestTakesList, + |dcx, level| DocTestTakesList.into_diag(dcx, level), args.span().unwrap_or(path.span()), ); return; diff --git a/compiler/rustc_attr_parsing/src/errors.rs b/compiler/rustc_attr_parsing/src/errors.rs index 8e4dfb40ad86..96a4c473c3ae 100644 --- a/compiler/rustc_attr_parsing/src/errors.rs +++ b/compiler/rustc_attr_parsing/src/errors.rs @@ -253,6 +253,46 @@ pub(crate) struct DocUnknownAny { #[diag("expected boolean for `#[doc(auto_cfg = ...)]`")] pub(crate) struct DocAutoCfgWrongLiteral; +#[derive(Diagnostic)] +#[diag("`#[doc(test(...)]` takes a list of attributes")] +pub(crate) struct DocTestTakesList; + +#[derive(Diagnostic)] +#[diag("unknown `doc(test)` attribute `{$name}`")] +pub(crate) struct DocTestUnknown { + pub name: Symbol, +} + +#[derive(Diagnostic)] +#[diag("`#![doc(test(...)]` does not take a literal")] +pub(crate) struct DocTestLiteral; + +#[derive(Diagnostic)] +#[diag("this attribute can only be applied at the crate level")] +#[note( + "read for more information" +)] +pub(crate) struct AttrCrateLevelOnly; + +#[derive(Diagnostic)] +#[diag("`#[diagnostic::do_not_recommend]` does not expect any arguments")] +pub(crate) struct DoNotRecommendDoesNotExpectArgs; + +#[derive(Diagnostic)] +#[diag("invalid `crate_type` value")] +pub(crate) struct UnknownCrateTypes { + #[subdiagnostic] + pub sugg: Option, +} + +#[derive(Subdiagnostic)] +#[suggestion("did you mean", code = r#""{snippet}""#, applicability = "maybe-incorrect")] +pub(crate) struct UnknownCrateTypesSuggestion { + #[primary_span] + pub span: Span, + pub snippet: Symbol, +} + #[derive(Diagnostic)] #[diag("`#[diagnostic::on_const]` can only be applied to non-const trait implementations")] pub(crate) struct DiagnosticOnConstOnlyForTraitImpls { diff --git a/compiler/rustc_lint/src/early/diagnostics.rs b/compiler/rustc_lint/src/early/diagnostics.rs index 4a0320cbaf80..60bfdd689609 100644 --- a/compiler/rustc_lint/src/early/diagnostics.rs +++ b/compiler/rustc_lint/src/early/diagnostics.rs @@ -43,27 +43,6 @@ fn into_diag(self, dcx: DiagCtxtHandle<'a>, level: Level) -> Diag<'a, ()> { .into_diag(dcx, level) } - &AttributeLintKind::DocTestTakesList => lints::DocTestTakesList.into_diag(dcx, level), - - &AttributeLintKind::DocTestUnknown { name } => { - lints::DocTestUnknown { name }.into_diag(dcx, level) - } - - &AttributeLintKind::DocTestLiteral => lints::DocTestLiteral.into_diag(dcx, level), - - &AttributeLintKind::AttrCrateLevelOnly => { - lints::AttrCrateLevelOnly.into_diag(dcx, level) - } - - &AttributeLintKind::DoNotRecommendDoesNotExpectArgs => { - lints::DoNotRecommendDoesNotExpectArgs.into_diag(dcx, level) - } - - &AttributeLintKind::CrateTypeUnknown { span, suggested } => lints::UnknownCrateTypes { - sugg: suggested.map(|s| lints::UnknownCrateTypesSuggestion { span, snippet: s }), - } - .into_diag(dcx, level), - &AttributeLintKind::MalformedDoc => lints::MalformedDoc.into_diag(dcx, level), &AttributeLintKind::ExpectedNoArgs => lints::ExpectedNoArgs.into_diag(dcx, level), diff --git a/compiler/rustc_lint/src/lints.rs b/compiler/rustc_lint/src/lints.rs index 19fabc51ae53..ccbc325648e3 100644 --- a/compiler/rustc_lint/src/lints.rs +++ b/compiler/rustc_lint/src/lints.rs @@ -3303,46 +3303,6 @@ fn add_to_diag(self, diag: &mut Diag<'_, G>) { )] pub(crate) struct ExpectedNameValue; -#[derive(Diagnostic)] -#[diag("`#[doc(test(...)]` takes a list of attributes")] -pub(crate) struct DocTestTakesList; - -#[derive(Diagnostic)] -#[diag("unknown `doc(test)` attribute `{$name}`")] -pub(crate) struct DocTestUnknown { - pub name: Symbol, -} - -#[derive(Diagnostic)] -#[diag("`#![doc(test(...)]` does not take a literal")] -pub(crate) struct DocTestLiteral; - -#[derive(Diagnostic)] -#[diag("this attribute can only be applied at the crate level")] -#[note( - "read for more information" -)] -pub(crate) struct AttrCrateLevelOnly; - -#[derive(Diagnostic)] -#[diag("`#[diagnostic::do_not_recommend]` does not expect any arguments")] -pub(crate) struct DoNotRecommendDoesNotExpectArgs; - -#[derive(Diagnostic)] -#[diag("invalid `crate_type` value")] -pub(crate) struct UnknownCrateTypes { - #[subdiagnostic] - pub sugg: Option, -} - -#[derive(Subdiagnostic)] -#[suggestion("did you mean", code = r#""{snippet}""#, applicability = "maybe-incorrect")] -pub(crate) struct UnknownCrateTypesSuggestion { - #[primary_span] - pub span: Span, - pub snippet: Symbol, -} - #[derive(Diagnostic)] #[diag("positional format arguments are not allowed here")] #[help( diff --git a/compiler/rustc_lint_defs/src/lib.rs b/compiler/rustc_lint_defs/src/lib.rs index 96c7dec3d818..45ac2c59b04e 100644 --- a/compiler/rustc_lint_defs/src/lib.rs +++ b/compiler/rustc_lint_defs/src/lib.rs @@ -656,12 +656,6 @@ pub enum DeprecatedSinceKind { pub enum AttributeLintKind { UnexpectedCfgName((Symbol, Span), Option<(Symbol, Span)>), UnexpectedCfgValue((Symbol, Span), Option<(Symbol, Span)>), - DocTestTakesList, - DocTestUnknown { name: Symbol }, - DocTestLiteral, - AttrCrateLevelOnly, - DoNotRecommendDoesNotExpectArgs, - CrateTypeUnknown { span: Span, suggested: Option }, MalformedDoc, ExpectedNoArgs, ExpectedNameValue,