about summary refs log tree commit diff
path: root/compiler
diff options
context:
space:
mode:
authorbors <bors@rust-lang.org>2021-01-05 08:47:46 +0000
committerbors <bors@rust-lang.org>2021-01-05 08:47:46 +0000
commitf4b9d32ef53c0629732ee131b640920ae12d1edb (patch)
tree7e424be67db46374cd2ede1be8cea521b9c32baa /compiler
parentf412fb56b8d11c168e7ee49ee74e79c4ab2e5637 (diff)
parent9714ac08a5476ccfbbce859d3fb69905a64668e1 (diff)
downloadrust-f4b9d32ef53c0629732ee131b640920ae12d1edb.tar.gz
rust-f4b9d32ef53c0629732ee131b640920ae12d1edb.zip
Auto merge of #80686 - GuillaumeGomez:error-doc-alias-same-name, r=jyn514
Error when #[doc(alias)] has same name as the item

Something I came across when reviewing some doc alias PRs.

r? `@jyn514`
Diffstat (limited to 'compiler')
-rw-r--r--compiler/rustc_passes/src/check_attr.rs13
1 files changed, 12 insertions, 1 deletions
diff --git a/compiler/rustc_passes/src/check_attr.rs b/compiler/rustc_passes/src/check_attr.rs
index aeaa862f5fd..420c002c5fc 100644
--- a/compiler/rustc_passes/src/check_attr.rs
+++ b/compiler/rustc_passes/src/check_attr.rs
@@ -310,7 +310,7 @@ impl CheckAttrVisitor<'tcx> {
                 .sess
                 .struct_span_err(
                     meta.name_value_literal_span().unwrap_or_else(|| meta.span()),
-                    &format!("{:?} character isn't allowed in `#[doc(alias = \"...\")]`", c,),
+                    &format!("{:?} character isn't allowed in `#[doc(alias = \"...\")]`", c),
                 )
                 .emit();
             return false;
@@ -358,6 +358,17 @@ impl CheckAttrVisitor<'tcx> {
                 .emit();
             return false;
         }
+        let item_name = self.tcx.hir().name(hir_id);
+        if item_name.to_string() == doc_alias {
+            self.tcx
+                .sess
+                .struct_span_err(
+                    meta.span(),
+                    &format!("`#[doc(alias = \"...\")]` is the same as the item's name"),
+                )
+                .emit();
+            return false;
+        }
         true
     }