Skip to content

Commit 6e43ff5

Browse files
Add check for doc alias on associated const in trait impls
1 parent 6c44bcc commit 6e43ff5

File tree

1 file changed

+11
-1
lines changed

1 file changed

+11
-1
lines changed

compiler/rustc_passes/src/check_attr.rs

+11-1
Original file line numberDiff line numberDiff line change
@@ -250,13 +250,23 @@ impl CheckAttrVisitor<'tcx> {
250250
None
251251
}
252252
}
253+
Target::AssocConst => {
254+
let parent_hir_id = self.tcx.hir().get_parent_item(hir_id);
255+
let containing_item = self.tcx.hir().expect_item(parent_hir_id);
256+
// We can't link to trait impl's consts.
257+
let err = "associated constant in trait implementation block";
258+
match containing_item.kind {
259+
ItemKind::Impl { of_trait: Some(_), .. } => Some(err),
260+
_ => None,
261+
}
262+
}
253263
_ => None,
254264
} {
255265
self.tcx
256266
.sess
257267
.struct_span_err(
258268
meta.span(),
259-
&format!("`#[doc(alias = \"...\")]` isn't allowed on {}", err,),
269+
&format!("`#[doc(alias = \"...\")]` isn't allowed on {}", err),
260270
)
261271
.emit();
262272
}

0 commit comments

Comments
 (0)