]> git.lizzy.rs Git - rust.git/blobdiff - compiler/rustc_passes/src/check_attr.rs
Auto merge of #80790 - JohnTitor:rollup-js1noez, r=JohnTitor
[rust.git] / compiler / rustc_passes / src / check_attr.rs
index 73fb28e5c9aa68eafacd3ec875fb0638d4c23d88..a6a61ffc5dae509e52e67f2705266452be1401ba 100644 (file)
@@ -310,7 +310,7 @@ fn check_doc_alias(&self, meta: &NestedMetaItem, hir_id: HirId, target: Target)
                 .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 @@ fn check_doc_alias(&self, meta: &NestedMetaItem, hir_id: HirId, target: Target)
                 .emit();
             return false;
         }
+        let item_name = self.tcx.hir().name(hir_id);
+        if &*item_name.as_str() == 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
     }
 
@@ -882,6 +893,18 @@ fn visit_item(&mut self, item: &'tcx Item<'tcx>) {
         intravisit::walk_item(self, item)
     }
 
+    fn visit_generic_param(&mut self, generic_param: &'tcx hir::GenericParam<'tcx>) {
+        let target = Target::from_generic_param(generic_param);
+        self.check_attributes(
+            generic_param.hir_id,
+            generic_param.attrs,
+            &generic_param.span,
+            target,
+            None,
+        );
+        intravisit::walk_generic_param(self, generic_param)
+    }
+
     fn visit_trait_item(&mut self, trait_item: &'tcx TraitItem<'tcx>) {
         let target = Target::from_trait_item(trait_item);
         self.check_attributes(trait_item.hir_id, &trait_item.attrs, &trait_item.span, target, None);