about summary refs log tree commit diff
path: root/compiler/rustc_passes/src
diff options
context:
space:
mode:
Diffstat (limited to 'compiler/rustc_passes/src')
-rw-r--r--compiler/rustc_passes/src/check_const.rs22
1 files changed, 22 insertions, 0 deletions
diff --git a/compiler/rustc_passes/src/check_const.rs b/compiler/rustc_passes/src/check_const.rs
index 70518284cf9..4062862ad74 100644
--- a/compiler/rustc_passes/src/check_const.rs
+++ b/compiler/rustc_passes/src/check_const.rs
@@ -192,6 +192,28 @@ impl<'tcx> Visitor<'tcx> for CheckConstVisitor<'tcx> {
     }
 
     fn visit_item(&mut self, item: &'tcx hir::Item<'tcx>) {
+        let tcx = self.tcx;
+        if let hir::ItemKind::Impl(hir::Impl {
+            constness: hir::Constness::Const,
+            of_trait: Some(trait_ref),
+            ..
+        }) = item.kind
+        {
+            let def_id = trait_ref.trait_def_id().unwrap();
+            let source_map = tcx.sess.source_map();
+            if !tcx.has_attr(def_id, sym::const_trait) {
+                tcx.sess
+                    .struct_span_err(
+                        source_map.guess_head_span(item.span),
+                        "const `impl`s must be for traits marked with `#[const_trait]`",
+                    )
+                    .span_note(
+                        source_map.guess_head_span(tcx.def_span(def_id)),
+                        "this trait must be annotated with `#[const_trait]`",
+                    )
+                    .emit();
+            }
+        }
         intravisit::walk_item(self, item);
     }