mirror of
https://github.com/rust-lang/rust.git
synced 2026-04-26 13:01:27 +03:00
Rollup merge of #155590 - GuillaumeGomez:rm-attributelintkind, r=JonathanBrouwer
Remove AttributeLintKind variants - part 5 Part of https://github.com/rust-lang/rust/issues/153099. r? @JonathanBrouwer
This commit is contained in:
@@ -258,11 +258,11 @@ Greg V <greg@unrelenting.technology>
|
||||
Gregor Peach <gregorpeach@gmail.com>
|
||||
Grzegorz Bartoszek <grzegorz.bartoszek@thaumatec.com>
|
||||
Guanqun Lu <guanqun.lu@gmail.com>
|
||||
Guillaume Gomez <guillaume1.gomez@gmail.com>
|
||||
Guillaume Gomez <guillaume1.gomez@gmail.com> ggomez <ggomez@ggo.ifr.lan>
|
||||
Guillaume Gomez <guillaume1.gomez@gmail.com> Guillaume Gomez <ggomez@ggo.ifr.lan>
|
||||
Guillaume Gomez <guillaume1.gomez@gmail.com> Guillaume Gomez <guillaume.gomez@huawei.com>
|
||||
Guillaume Gomez <guillaume1.gomez@gmail.com> Guillaume Gomez <contact@guillaume-gomez.fr>
|
||||
Guillaume Gomez <contact@guillaume-gomez.fr>
|
||||
Guillaume Gomez <contact@guillaume-gomez.fr> Guillaume Gomez <guillaume1.gomez@gmail.com>
|
||||
Guillaume Gomez <contact@guillaume-gomez.fr> ggomez <ggomez@ggo.ifr.lan>
|
||||
Guillaume Gomez <contact@guillaume-gomez.fr> Guillaume Gomez <ggomez@ggo.ifr.lan>
|
||||
Guillaume Gomez <contact@guillaume-gomez.fr> Guillaume Gomez <guillaume.gomez@huawei.com>
|
||||
gnzlbg <gonzalobg88@gmail.com> <gnzlbg@users.noreply.github.com>
|
||||
hamidreza kalbasi <hamidrezakalbasi@protonmail.com>
|
||||
Hanna Kruppe <hanna.kruppe@gmail.com> <robin.kruppe@gmail.com>
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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<S: Stage> SingleAttributeParser<S> for DoNotRecommendParser {
|
||||
fn convert(cx: &mut AcceptContext<'_, '_, S>, args: &ArgParser) -> Option<AttributeKind> {
|
||||
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,
|
||||
);
|
||||
}
|
||||
|
||||
@@ -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<S: Stage>(
|
||||
/// Checks that an attribute is used at the crate level. Returns `true` if valid.
|
||||
fn check_attr_crate_level<S: Stage>(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<S: Stage>(
|
||||
}
|
||||
}
|
||||
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;
|
||||
|
||||
@@ -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 <https://doc.rust-lang.org/nightly/rustdoc/the-doc-attribute.html#at-the-crate-level> 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<UnknownCrateTypesSuggestion>,
|
||||
}
|
||||
|
||||
#[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 {
|
||||
|
||||
@@ -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),
|
||||
|
||||
@@ -3303,46 +3303,6 @@ fn add_to_diag<G: EmissionGuarantee>(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 <https://doc.rust-lang.org/nightly/rustdoc/the-doc-attribute.html#at-the-crate-level> 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<UnknownCrateTypesSuggestion>,
|
||||
}
|
||||
|
||||
#[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(
|
||||
|
||||
@@ -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<Symbol> },
|
||||
MalformedDoc,
|
||||
ExpectedNoArgs,
|
||||
ExpectedNameValue,
|
||||
|
||||
Reference in New Issue
Block a user