1
Fork 0

Add an error in case the doc alias is the same as the item it's aliasing

This commit is contained in:
Guillaume Gomez 2021-01-04 15:05:36 +01:00
parent 887398ff68
commit c4c010f534

View file

@ -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
}