Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error when #[doc(alias)] has same name as the item #80686

Merged
merged 2 commits into from
Jan 5, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 12 additions & 1 deletion compiler/rustc_passes/src/check_attr.rs
Original file line number Diff line number Diff line change
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 {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does it really need to_string to compare between an Symbol and a string?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You're absolutely right, I opened #80750 to fix it.

self.tcx
.sess
.struct_span_err(
meta.span(),
&format!("`#[doc(alias = \"...\")]` is the same as the item's name"),
)
.emit();
return false;
}
GuillaumeGomez marked this conversation as resolved.
Show resolved Hide resolved
true
}

Expand Down
4 changes: 4 additions & 0 deletions src/test/rustdoc-ui/doc-alias-same-name.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#![crate_type = "lib"]

#[doc(alias = "Foo")] //~ ERROR
pub struct Foo;
8 changes: 8 additions & 0 deletions src/test/rustdoc-ui/doc-alias-same-name.stderr
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
error: `#[doc(alias = "...")]` is the same as the item's name
--> $DIR/doc-alias-same-name.rs:3:7
|
LL | #[doc(alias = "Foo")]
| ^^^^^^^^^^^^^

error: aborting due to previous error

4 changes: 4 additions & 0 deletions src/test/ui/doc-alias-same-name.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#![crate_type = "lib"]

#[doc(alias = "Foo")] //~ ERROR
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm, I didn't realize this runs in rustc_attr itself. It shouldn't be changed here, but I wonder if it makes sense to run those checks in rustdoc instead?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's scheduled for later. :)

pub struct Foo;
8 changes: 8 additions & 0 deletions src/test/ui/doc-alias-same-name.stderr
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
error: `#[doc(alias = "...")]` is the same as the item's name
--> $DIR/doc-alias-same-name.rs:3:7
|
LL | #[doc(alias = "Foo")]
| ^^^^^^^^^^^^^

error: aborting due to previous error