From b8ebf4431e48abe6f1844b80416c11f7b0ccab0c Mon Sep 17 00:00:00 2001 From: Joshua Nelson Date: Sat, 5 Jun 2021 21:16:19 -0400 Subject: [PATCH] Don't fire `invalid_doc_attributes` on `extern crate` items --- compiler/rustc_passes/src/check_attr.rs | 2 +- src/test/ui/rustdoc/doc-inline-extern-crate.rs | 9 +++++++++ src/test/ui/rustdoc/doc-inline-extern-crate.stderr | 13 +++++++++++++ 3 files changed, 23 insertions(+), 1 deletion(-) create mode 100644 src/test/ui/rustdoc/doc-inline-extern-crate.rs create mode 100644 src/test/ui/rustdoc/doc-inline-extern-crate.stderr diff --git a/compiler/rustc_passes/src/check_attr.rs b/compiler/rustc_passes/src/check_attr.rs index 91b6461151145..b18ef30296237 100644 --- a/compiler/rustc_passes/src/check_attr.rs +++ b/compiler/rustc_passes/src/check_attr.rs @@ -577,7 +577,7 @@ impl CheckAttrVisitor<'tcx> { target: Target, specified_inline: &mut Option<(bool, Span)>, ) -> bool { - if target == Target::Use { + if target == Target::Use || target == Target::ExternCrate { let do_inline = meta.name_or_empty() == sym::inline; if let Some((prev_inline, prev_span)) = *specified_inline { if do_inline != prev_inline { diff --git a/src/test/ui/rustdoc/doc-inline-extern-crate.rs b/src/test/ui/rustdoc/doc-inline-extern-crate.rs new file mode 100644 index 0000000000000..0eb4c149060db --- /dev/null +++ b/src/test/ui/rustdoc/doc-inline-extern-crate.rs @@ -0,0 +1,9 @@ +#[doc(inline)] +//~^ ERROR conflicting +#[doc(no_inline)] +pub extern crate core; + +// no warning +pub extern crate alloc; + +fn main() {} diff --git a/src/test/ui/rustdoc/doc-inline-extern-crate.stderr b/src/test/ui/rustdoc/doc-inline-extern-crate.stderr new file mode 100644 index 0000000000000..41518295b1224 --- /dev/null +++ b/src/test/ui/rustdoc/doc-inline-extern-crate.stderr @@ -0,0 +1,13 @@ +error: conflicting doc inlining attributes + --> $DIR/doc-inline-extern-crate.rs:1:7 + | +LL | #[doc(inline)] + | ^^^^^^ this attribute... +LL | +LL | #[doc(no_inline)] + | ^^^^^^^^^ ...conflicts with this attribute + | + = help: remove one of the conflicting attributes + +error: aborting due to previous error +