Rollup merge of #82708 - GuillaumeGomez:doc-test-attr-check, r=Manishearth
Warn on `#![doc(test(...))]` on items other than the crate root and use future incompatible lint Part of #82672. This PR does multiple things: * Create a new `INVALID_DOC_ATTRIBUTE` lint which is also "future incompatible", allowing us to use it as a warning for the moment until it turns (eventually) into a hard error. * Use this link when `#![doc(test(...))]` isn't used at the crate level. * Make #82702 use this new lint as well. r? ``@jyn514``
This commit is contained in:
commit
8867f7f650
10 changed files with 143 additions and 23 deletions
|
@ -3059,3 +3059,33 @@ declare_lint! {
|
|||
Allow,
|
||||
"No declared ABI for extern declaration"
|
||||
}
|
||||
|
||||
declare_lint! {
|
||||
/// The `invalid_doc_attributes` lint detects when the `#[doc(...)]` is
|
||||
/// misused.
|
||||
///
|
||||
/// ### Example
|
||||
///
|
||||
/// ```rust,compile_fail
|
||||
/// #![deny(warnings)]
|
||||
///
|
||||
/// pub mod submodule {
|
||||
/// #![doc(test(no_crate_inject))]
|
||||
/// }
|
||||
/// ```
|
||||
///
|
||||
/// {{produces}}
|
||||
///
|
||||
/// ### Explanation
|
||||
///
|
||||
/// Previously, there were very like checks being performed on `#[doc(..)]`
|
||||
/// unlike the other attributes. It'll now catch all the issues that it
|
||||
/// silently ignored previously.
|
||||
pub INVALID_DOC_ATTRIBUTES,
|
||||
Warn,
|
||||
"detects invalid `#[doc(...)]` attributes",
|
||||
@future_incompatible = FutureIncompatibleInfo {
|
||||
reference: "issue #82730 <https://github.com/rust-lang/rust/issues/82730>",
|
||||
edition: None,
|
||||
};
|
||||
}
|
||||
|
|
|
@ -17,7 +17,9 @@ use rustc_hir::{
|
|||
self, FnSig, ForeignItem, ForeignItemKind, HirId, Item, ItemKind, TraitItem, CRATE_HIR_ID,
|
||||
};
|
||||
use rustc_hir::{MethodKind, Target};
|
||||
use rustc_session::lint::builtin::{CONFLICTING_REPR_HINTS, UNUSED_ATTRIBUTES};
|
||||
use rustc_session::lint::builtin::{
|
||||
CONFLICTING_REPR_HINTS, INVALID_DOC_ATTRIBUTES, UNUSED_ATTRIBUTES,
|
||||
};
|
||||
use rustc_session::parse::feature_err;
|
||||
use rustc_span::symbol::{sym, Symbol};
|
||||
use rustc_span::{Span, DUMMY_SP};
|
||||
|
@ -544,6 +546,21 @@ impl CheckAttrVisitor<'tcx> {
|
|||
{
|
||||
return false;
|
||||
}
|
||||
} else if meta.has_name(sym::test) {
|
||||
if CRATE_HIR_ID != hir_id {
|
||||
self.tcx.struct_span_lint_hir(
|
||||
INVALID_DOC_ATTRIBUTES,
|
||||
hir_id,
|
||||
meta.span(),
|
||||
|lint| {
|
||||
lint.build(
|
||||
"`#![doc(test(...)]` is only allowed as a crate level attribute"
|
||||
)
|
||||
.emit();
|
||||
},
|
||||
);
|
||||
return false;
|
||||
}
|
||||
} else if let Some(i_meta) = meta.meta_item() {
|
||||
if ![
|
||||
sym::cfg,
|
||||
|
@ -568,7 +585,7 @@ impl CheckAttrVisitor<'tcx> {
|
|||
.any(|m| i_meta.has_name(*m))
|
||||
{
|
||||
self.tcx.struct_span_lint_hir(
|
||||
UNUSED_ATTRIBUTES,
|
||||
INVALID_DOC_ATTRIBUTES,
|
||||
hir_id,
|
||||
i_meta.span,
|
||||
|lint| {
|
||||
|
@ -576,11 +593,6 @@ impl CheckAttrVisitor<'tcx> {
|
|||
"unknown `doc` attribute `{}`",
|
||||
i_meta.name_or_empty()
|
||||
))
|
||||
.warn(
|
||||
"this was previously accepted by the compiler but is \
|
||||
being phased out; it will become a hard error in \
|
||||
a future release!",
|
||||
)
|
||||
.emit();
|
||||
},
|
||||
);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue