Skip to content

Commit c4c010f

Browse files
Add an error in case the doc alias is the same as the item it's aliasing
1 parent 887398f commit c4c010f

File tree

1 file changed

+12
-1
lines changed

1 file changed

+12
-1
lines changed

compiler/rustc_passes/src/check_attr.rs

+12-1
Original file line numberDiff line numberDiff line change
@@ -310,7 +310,7 @@ impl CheckAttrVisitor<'tcx> {
310310
.sess
311311
.struct_span_err(
312312
meta.name_value_literal_span().unwrap_or_else(|| meta.span()),
313-
&format!("{:?} character isn't allowed in `#[doc(alias = \"...\")]`", c,),
313+
&format!("{:?} character isn't allowed in `#[doc(alias = \"...\")]`", c),
314314
)
315315
.emit();
316316
return false;
@@ -358,6 +358,17 @@ impl CheckAttrVisitor<'tcx> {
358358
.emit();
359359
return false;
360360
}
361+
let item_name = self.tcx.hir().name(hir_id);
362+
if item_name.to_string() == doc_alias {
363+
self.tcx
364+
.sess
365+
.struct_span_err(
366+
meta.span(),
367+
&format!("`#[doc(alias = \"...\")]` is the same as the item's name"),
368+
)
369+
.emit();
370+
return false;
371+
}
361372
true
362373
}
363374

0 commit comments

Comments
 (0)