diff options
| author | Deadbeef <ent3rm4n@gmail.com> | 2022-07-30 18:01:03 +0000 |
|---|---|---|
| committer | Deadbeef <ent3rm4n@gmail.com> | 2022-09-16 11:48:42 +0800 |
| commit | 81b1810cd7b5f1cb74d498f20fa0ef5887420d33 (patch) | |
| tree | 7dd79d4fc051ce5fdf8f89706ca4b00dba8ff6a7 /compiler/rustc_passes/src/check_const.rs | |
| parent | 22f6aec42de6bce63f8e43f144058428d4dba0f5 (diff) | |
| download | rust-81b1810cd7b5f1cb74d498f20fa0ef5887420d33.tar.gz rust-81b1810cd7b5f1cb74d498f20fa0ef5887420d33.zip | |
Require `#[const_trait]` for `const` `impl`s
Diffstat (limited to 'compiler/rustc_passes/src/check_const.rs')
| -rw-r--r-- | compiler/rustc_passes/src/check_const.rs | 22 |
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); } |
