mirror of
https://github.com/rust-lang/rust.git
synced 2025-01-28 15:43:21 +00:00
Do the check even when the feature is not enabled
This commit is contained in:
parent
22a8d46ed3
commit
5e178b29b4
@ -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) {
|
||||
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user