Skip to content

Commit d05a286

Browse files
committed
Iterate through impls only when permitted
1 parent 77d1559 commit d05a286

File tree

1 file changed

+11
-8
lines changed

1 file changed

+11
-8
lines changed

compiler/rustc_mir/src/transform/check_consts/validation.rs

+11-8
Original file line numberDiff line numberDiff line change
@@ -897,16 +897,19 @@ impl Visitor<'tcx> for Validator<'mir, 'tcx> {
897897
permitted = true;
898898
}
899899
}
900-
let mut const_impls = true;
901-
tcx.for_each_relevant_impl(trait_id, substs.type_at(0), |imp| {
902-
if const_impls {
903-
if let hir::Constness::NotConst = tcx.impl_constness(imp) {
904-
const_impls = false;
900+
if !permitted {
901+
// if trait's impls are all const, permit the call.
902+
let mut const_impls = true;
903+
tcx.for_each_relevant_impl(trait_id, substs.type_at(0), |imp| {
904+
if const_impls {
905+
if let hir::Constness::NotConst = tcx.impl_constness(imp) {
906+
const_impls = false;
907+
}
905908
}
909+
});
910+
if const_impls {
911+
permitted = true;
906912
}
907-
});
908-
if const_impls {
909-
permitted = true;
910913
}
911914
}
912915

0 commit comments

Comments
 (0)