Do the check even when the feature is not enabled

This commit is contained in:
Deadbeef 2021-06-28 11:13:32 +08:00
parent 22a8d46ed3
commit 5e178b29b4
No known key found for this signature in database
GPG key ID: 6525773485376D92

View file

@ -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));
}
}
pub(crate) fn provide(providers: &mut Providers) {
@ -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 {
@ -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