Skip to content

Commit ecaf7b7

Browse files
committedMay 30, 2022
Reduce the scope of a mutable variable
1 parent 4d390de commit ecaf7b7

File tree

1 file changed

+2
-7
lines changed
  • compiler/rustc_const_eval/src/transform/check_consts

1 file changed

+2
-7
lines changed
 

‎compiler/rustc_const_eval/src/transform/check_consts/check.rs

+2-7
Original file line numberDiff line numberDiff line change
@@ -711,8 +711,6 @@ impl<'tcx> Visitor<'tcx> for Checker<'_, 'tcx> {
711711
}
712712
};
713713

714-
let mut nonconst_call_permission = false;
715-
716714
// Attempting to call a trait method?
717715
if let Some(trait_id) = tcx.trait_of_item(callee) {
718716
trace!("attempting to call a trait method");
@@ -776,6 +774,7 @@ impl<'tcx> Visitor<'tcx> for Checker<'_, 'tcx> {
776774
_ if !tcx.is_const_fn_raw(callee) => {
777775
// At this point, it is only legal when the caller is in a trait
778776
// marked with #[const_trait], and the callee is in the same trait.
777+
let mut nonconst_call_permission = false;
779778
if let Some(callee_trait) = tcx.trait_of_item(callee)
780779
&& tcx.has_attr(callee_trait, sym::const_trait)
781780
&& Some(callee_trait) == tcx.trait_of_item(caller)
@@ -872,14 +871,10 @@ impl<'tcx> Visitor<'tcx> for Checker<'_, 'tcx> {
872871
let is_intrinsic = tcx.is_intrinsic(callee);
873872

874873
if !tcx.is_const_fn_raw(callee) {
875-
if tcx.is_const_default_method(callee) {
874+
if !tcx.is_const_default_method(callee) {
876875
// To get to here we must have already found a const impl for the
877876
// trait, but for it to still be non-const can be that the impl is
878877
// using default method bodies.
879-
nonconst_call_permission = true;
880-
}
881-
882-
if !nonconst_call_permission {
883878
self.check_op(ops::FnCallNonConst {
884879
caller,
885880
callee,

0 commit comments

Comments
 (0)
Please sign in to comment.