Skip to content
Draft
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
59 changes: 35 additions & 24 deletions compiler/rustc_attr_parsing/src/attributes/doc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,9 @@ use crate::diagnostics::{
DocAliasStartEnd, DocAttrNotCrateLevel, DocAttributeNotAttribute, DocAutoCfgExpectsHideOrShow,
DocAutoCfgHideShowExpectsList, DocAutoCfgHideShowNoIdentBeforeValues,
DocAutoCfgHideShowUnexpectedItem, DocAutoCfgHideShowUnexpectedItemAfterValues,
DocAutoCfgHideShowValuesMix, DocAutoCfgWrongLiteral, DocKeywordNotKeyword, DocTestLiteral,
DocTestTakesList, DocTestUnknown, DocUnknownAny, DocUnknownInclude, DocUnknownPasses,
DocUnknownPlugins, DocUnknownSpotlight, ExpectedNameValue, ExpectedNoArgs,
DocAutoCfgHideShowValuesMix, DocAutoCfgWrongLiteral, DocKeywordNotKeyword, DocReserved,
DocTestLiteral, DocTestTakesList, DocTestUnknown, DocUnknownAny, DocUnknownInclude,
DocUnknownPasses, DocUnknownPlugins, DocUnknownSpotlight, ExpectedNameValue, ExpectedNoArgs,
IllFormedAttributeInput, MalformedDoc, UnusedDuplicate,
};
use crate::parser::{
Expand Down Expand Up @@ -625,13 +625,11 @@ impl DocParser {
no_args_and_not_crate_level!(search_unbox)
}
Some(sym::rust_logo) => {
// FIXME: Only feature gated at the crate level (!!)
if cx.target == Target::Crate {
gated!(
rustdoc_internals,
"the `#[doc(rust_logo)]` attribute is used for Rust branding"
);
}
gated!(
rustdoc_internals,
"the `#[doc(rust_logo)]` attribute is used for Rust branding"
);

no_args_and_crate_level!(rust_logo)
}
Some(sym::auto_cfg) => {
Expand Down Expand Up @@ -666,18 +664,30 @@ impl DocParser {
let span = path.span();
cx.emit_lint(INVALID_DOC_ATTRIBUTES, DocUnknownSpotlight { sugg_span: span }, span);
}
Some(sym::include) if let Some(nv) = args.as_name_value() => {
let inner = match cx.attr_style {
AttrStyle::Outer => "",
AttrStyle::Inner => "!",
};
let value = nv.value_as_lit().symbol;
let span = path.span();
cx.emit_lint(
INVALID_DOC_ATTRIBUTES,
DocUnknownInclude { inner, value, sugg: (span, Applicability::MaybeIncorrect) },
span,
);
Some(sym::include) => {
if let Some(nv) = args.as_name_value() {
let inner = match cx.attr_style {
AttrStyle::Outer => "",
AttrStyle::Inner => "!",
};
let value = nv.value_as_lit().symbol;
let span = path.span();
cx.emit_lint(
INVALID_DOC_ATTRIBUTES,
DocUnknownInclude {
inner,
value,
sugg: (span, Applicability::MaybeIncorrect),
},
span,
);
} else {
cx.emit_lint(
INVALID_DOC_ATTRIBUTES,
DocUnknownAny { name: sym::include },
path.span(),
);
}
}
Some(name @ (sym::passes | sym::no_default_passes)) => {
let span = path.span();
Expand All @@ -692,13 +702,14 @@ impl DocParser {
cx.emit_lint(INVALID_DOC_ATTRIBUTES, DocUnknownPlugins { label_span: span }, span);
}
Some(name) => {
cx.emit_lint(INVALID_DOC_ATTRIBUTES, DocUnknownAny { name }, path.span());
cx.emit_err(DocReserved { name, span: path.span() });
}
None => {
let full_name =
path.segments().map(|s| s.as_str()).intersperse("::").collect::<String>();
let name = Symbol::intern(&full_name);
cx.emit_lint(INVALID_DOC_ATTRIBUTES, DocUnknownAny { name }, path.span());

cx.emit_err(DocReserved { name, span: path.span() });
}
}
}
Expand Down
8 changes: 8 additions & 0 deletions compiler/rustc_attr_parsing/src/diagnostics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -263,6 +263,14 @@ pub(crate) struct DocUnknownAny {
pub name: Symbol,
}

#[derive(Diagnostic)]
#[diag("reserved `doc` attribute `{$name}`")]
pub(crate) struct DocReserved {
pub name: Symbol,
#[primary_span]
pub span: Span,
}

#[derive(Diagnostic)]
#[diag("expected boolean for `#[doc(auto_cfg = ...)]`")]
pub(crate) struct DocAutoCfgWrongLiteral;
Expand Down
9 changes: 4 additions & 5 deletions tests/rustdoc-ui/lints/doc-attr-2.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
#![deny(invalid_doc_attributes)]
#![doc(as_ptr)]
//~^ ERROR unknown `doc` attribute `as_ptr`
//~^ ERROR reserved `doc` attribute `as_ptr`

#[doc(as_ptr)]
//~^ ERROR unknown `doc` attribute `as_ptr`
//~^ ERROR reserved `doc` attribute `as_ptr`
pub fn foo() {}

#[doc(foo::bar, crate::bar::baz = "bye")]
//~^ ERROR unknown `doc` attribute `foo::bar`
//~| ERROR unknown `doc` attribute `crate::bar::baz`
//~^ ERROR reserved `doc` attribute `foo::bar`
//~| ERROR reserved `doc` attribute `crate::bar::baz`
fn bar() {}
22 changes: 8 additions & 14 deletions tests/rustdoc-ui/lints/doc-attr-2.stderr
Original file line number Diff line number Diff line change
@@ -1,29 +1,23 @@
error: unknown `doc` attribute `as_ptr`
--> $DIR/doc-attr-2.rs:2:8
error: reserved `doc` attribute `as_ptr`
--> $DIR/doc-attr-2.rs:1:8
|
LL | #![doc(as_ptr)]
| ^^^^^^
|
note: the lint level is defined here
--> $DIR/doc-attr-2.rs:1:9
|
LL | #![deny(invalid_doc_attributes)]
| ^^^^^^^^^^^^^^^^^^^^^^

error: unknown `doc` attribute `as_ptr`
--> $DIR/doc-attr-2.rs:5:7
error: reserved `doc` attribute `as_ptr`
--> $DIR/doc-attr-2.rs:4:7
|
LL | #[doc(as_ptr)]
| ^^^^^^

error: unknown `doc` attribute `foo::bar`
--> $DIR/doc-attr-2.rs:9:7
error: reserved `doc` attribute `foo::bar`
--> $DIR/doc-attr-2.rs:8:7
|
LL | #[doc(foo::bar, crate::bar::baz = "bye")]
| ^^^^^^^^

error: unknown `doc` attribute `crate::bar::baz`
--> $DIR/doc-attr-2.rs:9:17
error: reserved `doc` attribute `crate::bar::baz`
--> $DIR/doc-attr-2.rs:8:17
|
LL | #[doc(foo::bar, crate::bar::baz = "bye")]
| ^^^^^^^^^^^^^^^
Expand Down
8 changes: 4 additions & 4 deletions tests/ui/attributes/doc-attr.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
#![deny(invalid_doc_attributes)]
#![crate_type = "lib"]
#![doc(as_ptr)]
//~^ ERROR unknown `doc` attribute
//~^ ERROR reserved `doc` attribute

#[doc(as_ptr)]
//~^ ERROR unknown `doc` attribute
//~^ ERROR reserved `doc` attribute
pub fn foo() {}

#[doc(123)]
Expand All @@ -16,6 +16,6 @@ pub fn foo() {}
//~| WARN
//~| WARN
#[doc(foo::bar, crate::bar::baz = "bye")]
//~^ ERROR unknown `doc` attribute
//~| ERROR unknown `doc` attribute
//~^ ERROR reserved `doc` attribute
//~| ERROR reserved `doc` attribute
fn bar() {}
39 changes: 19 additions & 20 deletions tests/ui/attributes/doc-attr.stderr
Original file line number Diff line number Diff line change
@@ -1,28 +1,39 @@
error: unknown `doc` attribute `as_ptr`
error: reserved `doc` attribute `as_ptr`
--> $DIR/doc-attr.rs:3:8
|
LL | #![doc(as_ptr)]
| ^^^^^^
|
note: the lint level is defined here
--> $DIR/doc-attr.rs:1:9
|
LL | #![deny(invalid_doc_attributes)]
| ^^^^^^^^^^^^^^^^^^^^^^

error: unknown `doc` attribute `as_ptr`
error: reserved `doc` attribute `as_ptr`
--> $DIR/doc-attr.rs:6:7
|
LL | #[doc(as_ptr)]
| ^^^^^^

error: reserved `doc` attribute `foo::bar`
--> $DIR/doc-attr.rs:18:7
|
LL | #[doc(foo::bar, crate::bar::baz = "bye")]
| ^^^^^^^^

error: reserved `doc` attribute `crate::bar::baz`
--> $DIR/doc-attr.rs:18:17
|
LL | #[doc(foo::bar, crate::bar::baz = "bye")]
| ^^^^^^^^^^^^^^^

error: expected this to be of the form `... = "..."`
--> $DIR/doc-attr.rs:10:7
|
LL | #[doc(123)]
| ^^^
|
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
note: the lint level is defined here
--> $DIR/doc-attr.rs:1:9
|
LL | #![deny(invalid_doc_attributes)]
| ^^^^^^^^^^^^^^^^^^^^^^

error: expected this to be of the form `... = "..."`
--> $DIR/doc-attr.rs:13:7
Expand All @@ -40,17 +51,5 @@ LL | #[doc("hello", "bar")]
|
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!

error: unknown `doc` attribute `foo::bar`
--> $DIR/doc-attr.rs:18:7
|
LL | #[doc(foo::bar, crate::bar::baz = "bye")]
| ^^^^^^^^

error: unknown `doc` attribute `crate::bar::baz`
--> $DIR/doc-attr.rs:18:17
|
LL | #[doc(foo::bar, crate::bar::baz = "bye")]
| ^^^^^^^^^^^^^^^

error: aborting due to 7 previous errors

3 changes: 2 additions & 1 deletion tests/ui/feature-gates/doc-rust-logo.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,6 @@
//! This is not an official rust crate

#[doc(rust_logo)]
//~^ WARN this attribute can only be applied at the crate level
//~^ ERROR this subset of the `doc` attribute is meant for internal use only
//~| WARN this attribute can only be applied at the crate level
fn main() {}
13 changes: 12 additions & 1 deletion tests/ui/feature-gates/doc-rust-logo.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,17 @@ LL | #![doc(rust_logo)]
= note: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date
= note: the `#[doc(rust_logo)]` attribute is used for Rust branding

error[E0658]: this subset of the `doc` attribute is meant for internal use only
--> $DIR/doc-rust-logo.rs:5:7
|
LL | #[doc(rust_logo)]
| ^^^^^^^^^
|
= note: see issue #90418 <https://github.com/rust-lang/rust/issues/90418> for more information
= help: add `#![feature(rustdoc_internals)]` to the crate attributes to enable
= note: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date
= note: the `#[doc(rust_logo)]` attribute is used for Rust branding

warning: this attribute can only be applied at the crate level
--> $DIR/doc-rust-logo.rs:5:7
|
Expand All @@ -18,6 +29,6 @@ LL | #[doc(rust_logo)]
= note: read <https://doc.rust-lang.org/nightly/rustdoc/the-doc-attribute.html#at-the-crate-level> for more information
= note: `#[warn(invalid_doc_attributes)]` on by default

error: aborting due to 1 previous error; 1 warning emitted
error: aborting due to 2 previous errors; 1 warning emitted

For more information about this error, try `rustc --explain E0658`.
2 changes: 1 addition & 1 deletion tests/ui/repr/invalid_repr_list_help.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,5 +18,5 @@ pub enum OwO4 {
}

#[repr(uwu)] //~ERROR: malformed `repr` attribute input
#[doc(owo)] //~ERROR: unknown `doc` attribute
#[doc(owo)] //~ERROR: reserved `doc` attribute
pub struct Owo5;
8 changes: 1 addition & 7 deletions tests/ui/repr/invalid_repr_list_help.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -48,17 +48,11 @@ LL | #[repr(uwu)]
|
= note: for more information, visit <https://doc.rust-lang.org/reference/type-layout.html#representations>

error: unknown `doc` attribute `owo`
error: reserved `doc` attribute `owo`
--> $DIR/invalid_repr_list_help.rs:21:7
|
LL | #[doc(owo)]
| ^^^
|
note: the lint level is defined here
--> $DIR/invalid_repr_list_help.rs:1:9
|
LL | #![deny(invalid_doc_attributes)]
| ^^^^^^^^^^^^^^^^^^^^^^

error: aborting due to 6 previous errors

Expand Down
4 changes: 1 addition & 3 deletions tests/ui/rustdoc/deny-invalid-doc-attrs.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
#![deny(invalid_doc_attributes)]
//~^ NOTE defined here
#![doc(x)]
//~^ ERROR unknown `doc` attribute `x`
//~^ ERROR reserved `doc` attribute `x`
fn main() {}
10 changes: 2 additions & 8 deletions tests/ui/rustdoc/deny-invalid-doc-attrs.stderr
Original file line number Diff line number Diff line change
@@ -1,14 +1,8 @@
error: unknown `doc` attribute `x`
--> $DIR/deny-invalid-doc-attrs.rs:3:8
error: reserved `doc` attribute `x`
--> $DIR/deny-invalid-doc-attrs.rs:1:8
|
LL | #![doc(x)]
| ^
|
note: the lint level is defined here
--> $DIR/deny-invalid-doc-attrs.rs:1:9
|
LL | #![deny(invalid_doc_attributes)]
| ^^^^^^^^^^^^^^^^^^^^^^

error: aborting due to 1 previous error

2 changes: 1 addition & 1 deletion tests/ui/rustdoc/doc-primitive.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#![deny(invalid_doc_attributes)]

#[doc(primitive = "foo")]
//~^ ERROR unknown `doc` attribute `primitive`
//~^ ERROR reserved `doc` attribute `primitive`
mod bar {}

fn main() {}
8 changes: 1 addition & 7 deletions tests/ui/rustdoc/doc-primitive.stderr
Original file line number Diff line number Diff line change
@@ -1,14 +1,8 @@
error: unknown `doc` attribute `primitive`
error: reserved `doc` attribute `primitive`
--> $DIR/doc-primitive.rs:3:7
|
LL | #[doc(primitive = "foo")]
| ^^^^^^^^^
|
note: the lint level is defined here
--> $DIR/doc-primitive.rs:1:9
|
LL | #![deny(invalid_doc_attributes)]
| ^^^^^^^^^^^^^^^^^^^^^^

error: aborting due to 1 previous error

Loading