Auto merge of #75888 - GuillaumeGomez:trait-impl-assoc-const-doc-alias, r=ollie27
Add check for doc alias on assoc const in trait impl Fixes #73721. r? @ollie27
This commit is contained in:
commit
02fe30971e
@ -250,13 +250,23 @@ fn check_doc_alias(&self, attr: &Attribute, hir_id: HirId, target: Target) -> bo
|
||||
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();
|
||||
}
|
||||
|
22
src/test/rustdoc-ui/doc-alias-assoc-const.rs
Normal file
22
src/test/rustdoc-ui/doc-alias-assoc-const.rs
Normal file
@ -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
src/test/rustdoc-ui/doc-alias-assoc-const.stderr
Normal file
8
src/test/rustdoc-ui/doc-alias-assoc-const.stderr
Normal file
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user