Skip to content

Commit

Permalink
Rollup merge of rust-lang#75888 - GuillaumeGomez:trait-impl-assoc-con…
Browse files Browse the repository at this point in the history
…st-doc-alias, r=ollie27

Add check for doc alias on assoc const in trait impl

Fixes rust-lang#73721.

r? @ollie27
  • Loading branch information
Dylan-DPC authored Sep 4, 2020
2 parents 27a571f + b61eab5 commit 094ef1a
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 1 deletion.
12 changes: 11 additions & 1 deletion compiler/rustc_passes/src/check_attr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -250,13 +250,23 @@ impl CheckAttrVisitor<'tcx> {
None
}
}
Target::AssocConst => {
let parent_hir_id = self.tcx.hir().get_parent_item(hir_id);
let containing_item = self.tcx.hir().expect_item(parent_hir_id);
// We can't link to trait impl's consts.
let err = "associated constant in trait implementation block";
match containing_item.kind {
ItemKind::Impl { of_trait: Some(_), .. } => Some(err),
_ => None,
}
}
_ => None,
} {
self.tcx
.sess
.struct_span_err(
meta.span(),
&format!("`#[doc(alias = \"...\")]` isn't allowed on {}", err,),
&format!("`#[doc(alias = \"...\")]` isn't allowed on {}", err),
)
.emit();
}
Expand Down
22 changes: 22 additions & 0 deletions src/test/rustdoc-ui/doc-alias-assoc-const.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
#![feature(doc_alias)]
#![feature(trait_alias)]

pub struct Foo;

pub trait Bar {
const BAZ: u8;
}

impl Bar for Foo {
#[doc(alias = "CONST_BAZ")] //~ ERROR
const BAZ: u8 = 0;
}

impl Foo {
#[doc(alias = "CONST_FOO")] // ok!
pub const FOO: u8 = 0;

pub fn bar() -> u8 {
Self::FOO
}
}
8 changes: 8 additions & 0 deletions src/test/rustdoc-ui/doc-alias-assoc-const.stderr
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
error: `#[doc(alias = "...")]` isn't allowed on associated constant in trait implementation block
--> $DIR/doc-alias-assoc-const.rs:11:11
|
LL | #[doc(alias = "CONST_BAZ")]
| ^^^^^^^^^^^^^^^^^^^

error: aborting due to previous error

0 comments on commit 094ef1a

Please sign in to comment.