diff --git a/compiler/rustc_passes/src/check_attr.rs b/compiler/rustc_passes/src/check_attr.rs index aeaa862f5fd63..420c002c5fc46 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 }