about summary refs log tree commit diff
path: root/compiler/rustc_ast_passes/src/ast_validation.rs
diff options
context:
space:
mode:
authorLeón Orell Valerian Liehr <me@fmease.dev>2023-11-11 15:30:25 +0100
committerLeón Orell Valerian Liehr <me@fmease.dev>2023-11-11 16:00:13 +0100
commitdf3b981a3a2bc58f01c6c49aeb3cfd01c0fcb316 (patch)
tree9ab4d7b4a501cd634cd95639335d24f3c2203bb0 /compiler/rustc_ast_passes/src/ast_validation.rs
parent9ab0749ce3fe33fdf84ac2f5b6c6e56b78dc10e8 (diff)
downloadrust-df3b981a3a2bc58f01c6c49aeb3cfd01c0fcb316.tar.gz
rust-df3b981a3a2bc58f01c6c49aeb3cfd01c0fcb316.zip
Reject defaultness on free consts
Diffstat (limited to 'compiler/rustc_ast_passes/src/ast_validation.rs')
-rw-r--r--compiler/rustc_ast_passes/src/ast_validation.rs12
1 files changed, 7 insertions, 5 deletions
diff --git a/compiler/rustc_ast_passes/src/ast_validation.rs b/compiler/rustc_ast_passes/src/ast_validation.rs
index 0477c7b2ba9..4c18cdfa2f4 100644
--- a/compiler/rustc_ast_passes/src/ast_validation.rs
+++ b/compiler/rustc_ast_passes/src/ast_validation.rs
@@ -1008,12 +1008,14 @@ impl<'a> Visitor<'a> for AstValidator<'a> {
                     _ => {}
                 }
             }
-            ItemKind::Const(box ConstItem { defaultness, expr: None, .. }) => {
+            ItemKind::Const(box ConstItem { defaultness, expr, .. }) => {
                 self.check_defaultness(item.span, *defaultness);
-                self.session.emit_err(errors::ConstWithoutBody {
-                    span: item.span,
-                    replace_span: self.ending_semi_or_hi(item.span),
-                });
+                if expr.is_none() {
+                    self.session.emit_err(errors::ConstWithoutBody {
+                        span: item.span,
+                        replace_span: self.ending_semi_or_hi(item.span),
+                    });
+                }
             }
             ItemKind::Static(box StaticItem { expr: None, .. }) => {
                 self.session.emit_err(errors::StaticWithoutBody {