Skip to content

Commit

Permalink
Do the check even when the feature is not enabled
Browse files Browse the repository at this point in the history
  • Loading branch information
fee1-dead committed Jul 1, 2021
1 parent 22a8d46 commit 5e178b2
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions compiler/rustc_passes/src/check_const.rs
Original file line number Diff line number Diff line change
Expand Up @@ -60,9 +60,7 @@ impl NonConstExpr {
fn check_mod_const_bodies(tcx: TyCtxt<'_>, module_def_id: LocalDefId) {
let mut vis = CheckConstVisitor::new(tcx);
tcx.hir().visit_item_likes_in_module(module_def_id, &mut vis.as_deep_visitor());
if tcx.features().enabled(sym::const_trait_impl) {
tcx.hir().visit_item_likes_in_module(module_def_id, &mut CheckConstTraitVisitor::new(tcx));
}
tcx.hir().visit_item_likes_in_module(module_def_id, &mut CheckConstTraitVisitor::new(tcx));
}

pub(crate) fn provide(providers: &mut Providers) {
Expand All @@ -80,6 +78,8 @@ impl<'tcx> CheckConstTraitVisitor<'tcx> {
}

impl<'tcx> hir::itemlikevisit::ItemLikeVisitor<'tcx> for CheckConstTraitVisitor<'tcx> {
/// check for const trait impls, and errors if the impl uses provided/default functions
/// of the trait being implemented; as those provided functions can be non-const.
fn visit_item(&mut self, item: &'hir hir::Item<'hir>) {
let _: Option<_> = try {
if let hir::ItemKind::Impl(ref imp) = item.kind {
Expand All @@ -103,6 +103,9 @@ impl<'tcx> hir::itemlikevisit::ItemLikeVisitor<'tcx> for CheckConstTraitVisitor<
.filter(|it| matches!(it.kind, hir::AssocItemKind::Fn { .. }))
.count();

// number of trait functions unequal to functions in impl,
// meaning that one or more provided/default functions of the
// trait are used.
if trait_fn_cnt != impl_fn_cnt {
self.tcx
.sess
Expand Down

0 comments on commit 5e178b2

Please sign in to comment.