Navigation Menu

Skip to content

Commit

Permalink
Add an error in case the doc alias is the same as the item it's aliasing
Browse files Browse the repository at this point in the history
  • Loading branch information
GuillaumeGomez committed Jan 4, 2021
1 parent 887398f commit c4c010f
Showing 1 changed file with 12 additions and 1 deletion.
13 changes: 12 additions & 1 deletion compiler/rustc_passes/src/check_attr.rs
Expand Up @@ -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;
Expand Down Expand Up @@ -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
}

Expand Down

0 comments on commit c4c010f

Please sign in to comment.