Skip to content

Commit 94b37e5

Browse files
committed
allow registry items to have no body
1 parent e2df1d9 commit 94b37e5

File tree

1 file changed

+11
-4
lines changed

1 file changed

+11
-4
lines changed

compiler/rustc_ast_passes/src/ast_validation.rs

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1084,23 +1084,30 @@ impl<'a> Visitor<'a> for AstValidator<'a> {
10841084
_ => visit::walk_item(self, item),
10851085
}
10861086
}
1087-
ItemKind::Const(box ConstItem { defaultness, expr, .. }) => {
1087+
ItemKind::Const(box ConstItem { defaultness, expr, distributed_slice, .. }) => {
10881088
self.check_defaultness(item.span, *defaultness);
1089-
if expr.is_none() {
1089+
1090+
// declarations of global registries have no body deliberately - items are added
1091+
// later using global registry additions
1092+
if expr.is_none() && !matches!(distributed_slice, DistributedSlice::Declaration(_))
1093+
{
10901094
self.dcx().emit_err(errors::ConstWithoutBody {
10911095
span: item.span,
10921096
replace_span: self.ending_semi_or_hi(item.span),
10931097
});
10941098
}
10951099
visit::walk_item(self, item);
10961100
}
1097-
ItemKind::Static(box StaticItem { expr, safety, .. }) => {
1101+
ItemKind::Static(box StaticItem { expr, safety, distributed_slice, .. }) => {
10981102
self.check_item_safety(item.span, *safety);
10991103
if matches!(safety, Safety::Unsafe(_)) {
11001104
self.dcx().emit_err(errors::UnsafeStatic { span: item.span });
11011105
}
11021106

1103-
if expr.is_none() {
1107+
// declarations of global registries have no body deliberately - items are added
1108+
// later using global registry additions
1109+
if expr.is_none() && !matches!(distributed_slice, DistributedSlice::Declaration(_))
1110+
{
11041111
self.dcx().emit_err(errors::StaticWithoutBody {
11051112
span: item.span,
11061113
replace_span: self.ending_semi_or_hi(item.span),

0 commit comments

Comments
 (0)