Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 23 additions & 16 deletions compiler/rustc_attr_parsing/src/attributes/doc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@ use super::{AcceptMapping, AttributeParser};
use crate::context::{AcceptContext, FinalizeContext, Stage};
use crate::errors::{
DocAliasDuplicated, DocAutoCfgExpectsHideOrShow, DocAutoCfgHideShowExpectsList,
DocAutoCfgHideShowUnexpectedItem, DocUnknownInclude, IllFormedAttributeInput,
DocAutoCfgHideShowUnexpectedItem, DocAutoCfgWrongLiteral, DocUnknownAny, DocUnknownInclude,
DocUnknownPasses, DocUnknownPlugins, DocUnknownSpotlight, IllFormedAttributeInput,
};
use crate::parser::{ArgParser, MetaItemOrLitParser, MetaItemParser, OwnedPathParser};
use crate::session_diagnostics::{
Expand Down Expand Up @@ -442,9 +443,9 @@ impl DocParser {
ArgParser::NameValue(nv) => {
let MetaItemLit { kind: LitKind::Bool(bool_value), span, .. } = nv.value_as_lit()
else {
cx.emit_lint(
cx.emit_dyn_lint(
rustc_session::lint::builtin::INVALID_DOC_ATTRIBUTES,
AttributeLintKind::DocAutoCfgWrongLiteral,
move |dcx, level| DocAutoCfgWrongLiteral.into_diag(dcx, level),
nv.value_span,
);
return;
Expand Down Expand Up @@ -613,10 +614,11 @@ impl DocParser {
}
}
Some(sym::spotlight) => {
cx.emit_lint(
let span = path.span();
cx.emit_dyn_lint(
rustc_session::lint::builtin::INVALID_DOC_ATTRIBUTES,
AttributeLintKind::DocUnknownSpotlight { span: path.span() },
path.span(),
move |dcx, level| DocUnknownSpotlight { sugg_span: span }.into_diag(dcx, level),
span,
);
}
Some(sym::include) if let Some(nv) = args.name_value() => {
Expand All @@ -640,32 +642,37 @@ impl DocParser {
);
}
Some(name @ (sym::passes | sym::no_default_passes)) => {
cx.emit_lint(
let span = path.span();
cx.emit_dyn_lint(
rustc_session::lint::builtin::INVALID_DOC_ATTRIBUTES,
AttributeLintKind::DocUnknownPasses { name, span: path.span() },
path.span(),
move |dcx, level| {
DocUnknownPasses { name, note_span: span }.into_diag(dcx, level)
},
span,
);
}
Some(sym::plugins) => {
cx.emit_lint(
let span = path.span();
cx.emit_dyn_lint(
rustc_session::lint::builtin::INVALID_DOC_ATTRIBUTES,
AttributeLintKind::DocUnknownPlugins { span: path.span() },
path.span(),
move |dcx, level| DocUnknownPlugins { label_span: span }.into_diag(dcx, level),
span,
);
}
Some(name) => {
cx.emit_lint(
cx.emit_dyn_lint(
rustc_session::lint::builtin::INVALID_DOC_ATTRIBUTES,
AttributeLintKind::DocUnknownAny { name },
move |dcx, level| DocUnknownAny { name }.into_diag(dcx, level),
path.span(),
);
}
None => {
let full_name =
path.segments().map(|s| s.as_str()).intersperse("::").collect::<String>();
cx.emit_lint(
let name = Symbol::intern(&full_name);
cx.emit_dyn_lint(
rustc_session::lint::builtin::INVALID_DOC_ATTRIBUTES,
AttributeLintKind::DocUnknownAny { name: Symbol::intern(&full_name) },
move |dcx, level| DocUnknownAny { name }.into_diag(dcx, level),
path.span(),
);
}
Expand Down
47 changes: 47 additions & 0 deletions compiler/rustc_attr_parsing/src/errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -205,3 +205,50 @@ pub(crate) struct DocUnknownInclude {
)]
pub sugg: (Span, Applicability),
}

#[derive(Diagnostic)]
#[diag("unknown `doc` attribute `spotlight`")]
#[note("`doc(spotlight)` was renamed to `doc(notable_trait)`")]
#[note("`doc(spotlight)` is now a no-op")]
pub(crate) struct DocUnknownSpotlight {
#[suggestion(
"use `notable_trait` instead",
style = "short",
applicability = "machine-applicable",
code = "notable_trait"
)]
pub sugg_span: Span,
}

#[derive(Diagnostic)]
#[diag("unknown `doc` attribute `{$name}`")]
#[note(
"`doc` attribute `{$name}` no longer functions; see issue #44136 <https://github.com/rust-lang/rust/issues/44136>"
)]
#[note("`doc({$name})` is now a no-op")]
pub(crate) struct DocUnknownPasses {
pub name: Symbol,
#[label("no longer functions")]
pub note_span: Span,
}

#[derive(Diagnostic)]
#[diag("unknown `doc` attribute `plugins`")]
#[note(
"`doc` attribute `plugins` no longer functions; see issue #44136 <https://github.com/rust-lang/rust/issues/44136> and CVE-2018-1000622 <https://nvd.nist.gov/vuln/detail/CVE-2018-1000622>"
)]
#[note("`doc(plugins)` is now a no-op")]
pub(crate) struct DocUnknownPlugins {
#[label("no longer functions")]
pub label_span: Span,
}

#[derive(Diagnostic)]
#[diag("unknown `doc` attribute `{$name}`")]
pub(crate) struct DocUnknownAny {
pub name: Symbol,
}

#[derive(Diagnostic)]
#[diag("expected boolean for `#[doc(auto_cfg = ...)]`")]
pub(crate) struct DocAutoCfgWrongLiteral;
20 changes: 0 additions & 20 deletions compiler/rustc_lint/src/early/diagnostics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,26 +43,6 @@ impl<'a> Diagnostic<'a, ()> for DecorateAttrLint<'_, '_, '_> {
.into_diag(dcx, level)
}

&AttributeLintKind::DocUnknownSpotlight { span } => {
lints::DocUnknownSpotlight { sugg_span: span }.into_diag(dcx, level)
}

&AttributeLintKind::DocUnknownPasses { name, span } => {
lints::DocUnknownPasses { name, note_span: span }.into_diag(dcx, level)
}

&AttributeLintKind::DocUnknownPlugins { span } => {
lints::DocUnknownPlugins { label_span: span }.into_diag(dcx, level)
}

&AttributeLintKind::DocUnknownAny { name } => {
lints::DocUnknownAny { name }.into_diag(dcx, level)
}

&AttributeLintKind::DocAutoCfgWrongLiteral => {
lints::DocAutoCfgWrongLiteral.into_diag(dcx, level)
}

&AttributeLintKind::DocTestTakesList => lints::DocTestTakesList.into_diag(dcx, level),

&AttributeLintKind::DocTestUnknown { name } => {
Expand Down
47 changes: 0 additions & 47 deletions compiler/rustc_lint/src/lints.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3303,53 +3303,6 @@ pub(crate) struct ExpectedNoArgs;
)]
pub(crate) struct ExpectedNameValue;

#[derive(Diagnostic)]
#[diag("unknown `doc` attribute `spotlight`")]
#[note("`doc(spotlight)` was renamed to `doc(notable_trait)`")]
#[note("`doc(spotlight)` is now a no-op")]
pub(crate) struct DocUnknownSpotlight {
#[suggestion(
"use `notable_trait` instead",
style = "short",
applicability = "machine-applicable",
code = "notable_trait"
)]
pub sugg_span: Span,
}

#[derive(Diagnostic)]
#[diag("unknown `doc` attribute `{$name}`")]
#[note(
"`doc` attribute `{$name}` no longer functions; see issue #44136 <https://github.com/rust-lang/rust/issues/44136>"
)]
#[note("`doc({$name})` is now a no-op")]
pub(crate) struct DocUnknownPasses {
pub name: Symbol,
#[label("no longer functions")]
pub note_span: Span,
}

#[derive(Diagnostic)]
#[diag("unknown `doc` attribute `plugins`")]
#[note(
"`doc` attribute `plugins` no longer functions; see issue #44136 <https://github.com/rust-lang/rust/issues/44136> and CVE-2018-1000622 <https://nvd.nist.gov/vuln/detail/CVE-2018-1000622>"
)]
#[note("`doc(plugins)` is now a no-op")]
pub(crate) struct DocUnknownPlugins {
#[label("no longer functions")]
pub label_span: Span,
}

#[derive(Diagnostic)]
#[diag("unknown `doc` attribute `{$name}`")]
pub(crate) struct DocUnknownAny {
pub name: Symbol,
}

#[derive(Diagnostic)]
#[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;
Expand Down
5 changes: 0 additions & 5 deletions compiler/rustc_lint_defs/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -656,11 +656,6 @@ pub enum DeprecatedSinceKind {
pub enum AttributeLintKind {
UnexpectedCfgName((Symbol, Span), Option<(Symbol, Span)>),
UnexpectedCfgValue((Symbol, Span), Option<(Symbol, Span)>),
DocUnknownSpotlight { span: Span },
DocUnknownPasses { name: Symbol, span: Span },
DocUnknownPlugins { span: Span },
DocUnknownAny { name: Symbol },
DocAutoCfgWrongLiteral,
DocTestTakesList,
DocTestUnknown { name: Symbol },
DocTestLiteral,
Expand Down
Loading