validate doc(masked)
This commit is contained in:
parent
237ed1630f
commit
637ea3f746
@ -211,6 +211,17 @@ passes_doc_keyword_not_mod =
|
||||
passes_doc_keyword_only_impl =
|
||||
`#[doc(keyword = "...")]` should be used on impl blocks
|
||||
|
||||
passes_doc_masked_not_extern_crate_self =
|
||||
this attribute cannot be applied to an `extern crate self` item
|
||||
.label = not applicable on `extern crate self` items
|
||||
.extern_crate_self_label = `extern crate self` defined here
|
||||
|
||||
passes_doc_masked_only_extern_crate =
|
||||
this attribute can only be applied to an `extern crate` item
|
||||
.label = only applicable on `extern crate` items
|
||||
.not_an_extern_crate_label = not an `extern crate` item
|
||||
.note = read <https://doc.rust-lang.org/unstable-book/language-features/doc-masked.html> for more information
|
||||
|
||||
passes_doc_test_literal = `#![doc(test(...)]` does not take a literal
|
||||
|
||||
passes_doc_test_takes_list =
|
||||
|
@ -878,6 +878,44 @@ fn check_doc_inline(
|
||||
}
|
||||
}
|
||||
|
||||
fn check_doc_masked(
|
||||
&self,
|
||||
attr: &Attribute,
|
||||
meta: &NestedMetaItem,
|
||||
hir_id: HirId,
|
||||
target: Target,
|
||||
) -> bool {
|
||||
if target != Target::ExternCrate {
|
||||
self.tcx.emit_spanned_lint(
|
||||
INVALID_DOC_ATTRIBUTES,
|
||||
hir_id,
|
||||
meta.span(),
|
||||
errors::DocMaskedOnlyExternCrate {
|
||||
attr_span: meta.span(),
|
||||
item_span: (attr.style == AttrStyle::Outer)
|
||||
.then(|| self.tcx.hir().span(hir_id)),
|
||||
},
|
||||
);
|
||||
return false;
|
||||
}
|
||||
|
||||
if self.tcx.extern_mod_stmt_cnum(hir_id.owner).is_none() {
|
||||
self.tcx.emit_spanned_lint(
|
||||
INVALID_DOC_ATTRIBUTES,
|
||||
hir_id,
|
||||
meta.span(),
|
||||
errors::DocMaskedNotExternCrateSelf {
|
||||
attr_span: meta.span(),
|
||||
item_span: (attr.style == AttrStyle::Outer)
|
||||
.then(|| self.tcx.hir().span(hir_id)),
|
||||
},
|
||||
);
|
||||
return false;
|
||||
}
|
||||
|
||||
true
|
||||
}
|
||||
|
||||
/// Checks that an attribute is *not* used at the crate level. Returns `true` if valid.
|
||||
fn check_attr_not_crate_level(
|
||||
&self,
|
||||
@ -1048,6 +1086,17 @@ fn check_doc_attrs(
|
||||
is_valid = false;
|
||||
}
|
||||
|
||||
sym::masked
|
||||
if !self.check_doc_masked(
|
||||
attr,
|
||||
meta,
|
||||
hir_id,
|
||||
target,
|
||||
) =>
|
||||
{
|
||||
is_valid = false;
|
||||
}
|
||||
|
||||
// no_default_passes: deprecated
|
||||
// passes: deprecated
|
||||
// plugins: removed, but rustdoc warns about it itself
|
||||
|
@ -267,6 +267,25 @@ pub struct DocInlineOnlyUse {
|
||||
pub item_span: Option<Span>,
|
||||
}
|
||||
|
||||
#[derive(LintDiagnostic)]
|
||||
#[diag(passes_doc_masked_only_extern_crate)]
|
||||
#[note]
|
||||
pub struct DocMaskedOnlyExternCrate {
|
||||
#[label]
|
||||
pub attr_span: Span,
|
||||
#[label(passes_not_an_extern_crate_label)]
|
||||
pub item_span: Option<Span>,
|
||||
}
|
||||
|
||||
#[derive(LintDiagnostic)]
|
||||
#[diag(passes_doc_masked_not_extern_crate_self)]
|
||||
pub struct DocMaskedNotExternCrateSelf {
|
||||
#[label]
|
||||
pub attr_span: Span,
|
||||
#[label(passes_extern_crate_self_label)]
|
||||
pub item_span: Option<Span>,
|
||||
}
|
||||
|
||||
#[derive(Diagnostic)]
|
||||
#[diag(passes_doc_attr_not_crate_level)]
|
||||
pub struct DocAttrNotCrateLevel<'a> {
|
||||
|
@ -1,5 +1,10 @@
|
||||
#![crate_type = "lib"]
|
||||
#![deny(warnings)]
|
||||
#![feature(doc_masked)]
|
||||
|
||||
#![doc(masked)]
|
||||
//~^ ERROR this attribute can only be applied to an `extern crate` item
|
||||
//~| WARN is being phased out
|
||||
|
||||
#[doc(test(no_crate_inject))]
|
||||
//~^ ERROR can only be applied at the crate level
|
||||
@ -30,3 +35,13 @@ pub fn baz() {}
|
||||
//~^^ ERROR conflicting doc inlining attributes
|
||||
//~| HELP remove one of the conflicting attributes
|
||||
pub use bar::baz;
|
||||
|
||||
#[doc(masked)]
|
||||
//~^ ERROR this attribute can only be applied to an `extern crate` item
|
||||
//~| WARN is being phased out
|
||||
pub struct Masked;
|
||||
|
||||
#[doc(masked)]
|
||||
//~^ ERROR this attribute cannot be applied to an `extern crate self` item
|
||||
//~| WARN is being phased out
|
||||
pub extern crate self as reexport;
|
||||
|
@ -1,5 +1,5 @@
|
||||
error: this attribute can only be applied at the crate level
|
||||
--> $DIR/invalid-doc-attr.rs:4:7
|
||||
--> $DIR/invalid-doc-attr.rs:9:7
|
||||
|
|
||||
LL | #[doc(test(no_crate_inject))]
|
||||
| ^^^^^^^^^^^^^^^^^^^^^
|
||||
@ -19,7 +19,7 @@ LL | #![doc(test(no_crate_inject))]
|
||||
| +
|
||||
|
||||
error: this attribute can only be applied to a `use` item
|
||||
--> $DIR/invalid-doc-attr.rs:9:7
|
||||
--> $DIR/invalid-doc-attr.rs:14:7
|
||||
|
|
||||
LL | #[doc(inline)]
|
||||
| ^^^^^^ only applicable on `use` items
|
||||
@ -32,7 +32,7 @@ LL | pub fn foo() {}
|
||||
= note: read <https://doc.rust-lang.org/nightly/rustdoc/the-doc-attribute.html#inline-and-no_inline> for more information
|
||||
|
||||
error: this attribute can only be applied at the crate level
|
||||
--> $DIR/invalid-doc-attr.rs:15:12
|
||||
--> $DIR/invalid-doc-attr.rs:20:12
|
||||
|
|
||||
LL | #![doc(test(no_crate_inject))]
|
||||
| ^^^^^^^^^^^^^^^^^^^^^
|
||||
@ -42,7 +42,7 @@ LL | #![doc(test(no_crate_inject))]
|
||||
= note: read <https://doc.rust-lang.org/nightly/rustdoc/the-doc-attribute.html#at-the-crate-level> for more information
|
||||
|
||||
error: conflicting doc inlining attributes
|
||||
--> $DIR/invalid-doc-attr.rs:28:7
|
||||
--> $DIR/invalid-doc-attr.rs:33:7
|
||||
|
|
||||
LL | #[doc(inline)]
|
||||
| ^^^^^^ this attribute...
|
||||
@ -51,8 +51,43 @@ LL | #[doc(no_inline)]
|
||||
|
|
||||
= help: remove one of the conflicting attributes
|
||||
|
||||
error: this attribute can only be applied to an `extern crate` item
|
||||
--> $DIR/invalid-doc-attr.rs:39:7
|
||||
|
|
||||
LL | #[doc(masked)]
|
||||
| ^^^^^^ only applicable on `extern crate` items
|
||||
...
|
||||
LL | pub struct Masked;
|
||||
| ----------------- not an `extern crate` item
|
||||
|
|
||||
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
|
||||
= note: for more information, see issue #82730 <https://github.com/rust-lang/rust/issues/82730>
|
||||
= note: read <https://doc.rust-lang.org/unstable-book/language-features/doc-masked.html> for more information
|
||||
|
||||
error: this attribute cannot be applied to an `extern crate self` item
|
||||
--> $DIR/invalid-doc-attr.rs:44:7
|
||||
|
|
||||
LL | #[doc(masked)]
|
||||
| ^^^^^^ not applicable on `extern crate self` items
|
||||
...
|
||||
LL | pub extern crate self as reexport;
|
||||
| --------------------------------- `extern crate self` defined here
|
||||
|
|
||||
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
|
||||
= note: for more information, see issue #82730 <https://github.com/rust-lang/rust/issues/82730>
|
||||
|
||||
error: this attribute can only be applied to an `extern crate` item
|
||||
--> $DIR/invalid-doc-attr.rs:5:8
|
||||
|
|
||||
LL | #![doc(masked)]
|
||||
| ^^^^^^ only applicable on `extern crate` items
|
||||
|
|
||||
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
|
||||
= note: for more information, see issue #82730 <https://github.com/rust-lang/rust/issues/82730>
|
||||
= note: read <https://doc.rust-lang.org/unstable-book/language-features/doc-masked.html> for more information
|
||||
|
||||
error: this attribute can only be applied at the crate level
|
||||
--> $DIR/invalid-doc-attr.rs:19:11
|
||||
--> $DIR/invalid-doc-attr.rs:24:11
|
||||
|
|
||||
LL | #[doc(test(no_crate_inject))]
|
||||
| ^^^^^^^^^^^^^^^^^^^^^
|
||||
@ -62,7 +97,7 @@ LL | #[doc(test(no_crate_inject))]
|
||||
= note: read <https://doc.rust-lang.org/nightly/rustdoc/the-doc-attribute.html#at-the-crate-level> for more information
|
||||
|
||||
error: this attribute can only be applied to a `use` item
|
||||
--> $DIR/invalid-doc-attr.rs:22:11
|
||||
--> $DIR/invalid-doc-attr.rs:27:11
|
||||
|
|
||||
LL | #[doc(inline)]
|
||||
| ^^^^^^ only applicable on `use` items
|
||||
@ -74,5 +109,5 @@ LL | pub fn baz() {}
|
||||
= note: for more information, see issue #82730 <https://github.com/rust-lang/rust/issues/82730>
|
||||
= note: read <https://doc.rust-lang.org/nightly/rustdoc/the-doc-attribute.html#inline-and-no_inline> for more information
|
||||
|
||||
error: aborting due to 6 previous errors
|
||||
error: aborting due to 9 previous errors
|
||||
|
||||
|
@ -1,32 +0,0 @@
|
||||
#![crate_type = "lib"]
|
||||
#![deny(warnings)]
|
||||
|
||||
#[doc(test(no_crate_inject))]
|
||||
//~^ ERROR can only be applied at the crate level
|
||||
//~| WARN is being phased out
|
||||
//~| HELP to apply to the crate, use an inner attribute
|
||||
//~| SUGGESTION !
|
||||
#[doc(inline)]
|
||||
//~^ ERROR can only be applied to a `use` item
|
||||
//~| WARN is being phased out
|
||||
pub fn foo() {}
|
||||
|
||||
pub mod bar {
|
||||
#![doc(test(no_crate_inject))]
|
||||
//~^ ERROR can only be applied at the crate level
|
||||
//~| WARN is being phased out
|
||||
|
||||
#[doc(test(no_crate_inject))]
|
||||
//~^ ERROR can only be applied at the crate level
|
||||
//~| WARN is being phased out
|
||||
#[doc(inline)]
|
||||
//~^ ERROR can only be applied to a `use` item
|
||||
//~| WARN is being phased out
|
||||
pub fn baz() {}
|
||||
}
|
||||
|
||||
#[doc(inline)]
|
||||
#[doc(no_inline)]
|
||||
//~^^ ERROR conflicting doc inlining attributes
|
||||
//~| HELP remove one of the conflicting attributes
|
||||
pub use bar::baz;
|
@ -1,78 +0,0 @@
|
||||
error: this attribute can only be applied at the crate level
|
||||
--> $DIR/invalid-doc-attr.rs:4:7
|
||||
|
|
||||
LL | #[doc(test(no_crate_inject))]
|
||||
| ^^^^^^^^^^^^^^^^^^^^^
|
||||
|
|
||||
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
|
||||
= note: for more information, see issue #82730 <https://github.com/rust-lang/rust/issues/82730>
|
||||
= note: read <https://doc.rust-lang.org/nightly/rustdoc/the-doc-attribute.html#at-the-crate-level> for more information
|
||||
note: the lint level is defined here
|
||||
--> $DIR/invalid-doc-attr.rs:2:9
|
||||
|
|
||||
LL | #![deny(warnings)]
|
||||
| ^^^^^^^^
|
||||
= note: `#[deny(invalid_doc_attributes)]` implied by `#[deny(warnings)]`
|
||||
help: to apply to the crate, use an inner attribute
|
||||
|
|
||||
LL | #![doc(test(no_crate_inject))]
|
||||
| +
|
||||
|
||||
error: this attribute can only be applied to a `use` item
|
||||
--> $DIR/invalid-doc-attr.rs:9:7
|
||||
|
|
||||
LL | #[doc(inline)]
|
||||
| ^^^^^^ only applicable on `use` items
|
||||
...
|
||||
LL | pub fn foo() {}
|
||||
| ------------ not a `use` item
|
||||
|
|
||||
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
|
||||
= note: for more information, see issue #82730 <https://github.com/rust-lang/rust/issues/82730>
|
||||
= note: read <https://doc.rust-lang.org/nightly/rustdoc/the-doc-attribute.html#inline-and-no_inline> for more information
|
||||
|
||||
error: this attribute can only be applied at the crate level
|
||||
--> $DIR/invalid-doc-attr.rs:15:12
|
||||
|
|
||||
LL | #![doc(test(no_crate_inject))]
|
||||
| ^^^^^^^^^^^^^^^^^^^^^
|
||||
|
|
||||
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
|
||||
= note: for more information, see issue #82730 <https://github.com/rust-lang/rust/issues/82730>
|
||||
= note: read <https://doc.rust-lang.org/nightly/rustdoc/the-doc-attribute.html#at-the-crate-level> for more information
|
||||
|
||||
error: conflicting doc inlining attributes
|
||||
--> $DIR/invalid-doc-attr.rs:28:7
|
||||
|
|
||||
LL | #[doc(inline)]
|
||||
| ^^^^^^ this attribute...
|
||||
LL | #[doc(no_inline)]
|
||||
| ^^^^^^^^^ ...conflicts with this attribute
|
||||
|
|
||||
= help: remove one of the conflicting attributes
|
||||
|
||||
error: this attribute can only be applied at the crate level
|
||||
--> $DIR/invalid-doc-attr.rs:19:11
|
||||
|
|
||||
LL | #[doc(test(no_crate_inject))]
|
||||
| ^^^^^^^^^^^^^^^^^^^^^
|
||||
|
|
||||
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
|
||||
= note: for more information, see issue #82730 <https://github.com/rust-lang/rust/issues/82730>
|
||||
= note: read <https://doc.rust-lang.org/nightly/rustdoc/the-doc-attribute.html#at-the-crate-level> for more information
|
||||
|
||||
error: this attribute can only be applied to a `use` item
|
||||
--> $DIR/invalid-doc-attr.rs:22:11
|
||||
|
|
||||
LL | #[doc(inline)]
|
||||
| ^^^^^^ only applicable on `use` items
|
||||
...
|
||||
LL | pub fn baz() {}
|
||||
| ------------ not a `use` item
|
||||
|
|
||||
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
|
||||
= note: for more information, see issue #82730 <https://github.com/rust-lang/rust/issues/82730>
|
||||
= note: read <https://doc.rust-lang.org/nightly/rustdoc/the-doc-attribute.html#inline-and-no_inline> for more information
|
||||
|
||||
error: aborting due to 6 previous errors
|
||||
|
Loading…
Reference in New Issue
Block a user