about summary refs log tree commit diff
diff options
context:
space:
mode:
authorOli Scherer <git-spam-no-reply9815368754983@oli-obk.de>2022-05-12 07:43:05 +0000
committerOli Scherer <git-spam-no-reply9815368754983@oli-obk.de>2022-05-30 08:52:25 +0000
commitecaf7b7ceeef920f9bb771c383920ae77a63e169 (patch)
tree2ce0507f4a3a19e8f7785fc0570c336f91fd969a
parent4d390de4a3de9e73a51f1edfcecaf8519d94b3ee (diff)
downloadrust-ecaf7b7ceeef920f9bb771c383920ae77a63e169.tar.gz
rust-ecaf7b7ceeef920f9bb771c383920ae77a63e169.zip
Reduce the scope of a mutable variable
-rw-r--r--compiler/rustc_const_eval/src/transform/check_consts/check.rs9
1 files changed, 2 insertions, 7 deletions
diff --git a/compiler/rustc_const_eval/src/transform/check_consts/check.rs b/compiler/rustc_const_eval/src/transform/check_consts/check.rs
index 458f733df10..eea6e2a47a9 100644
--- a/compiler/rustc_const_eval/src/transform/check_consts/check.rs
+++ b/compiler/rustc_const_eval/src/transform/check_consts/check.rs
@@ -711,8 +711,6 @@ impl<'tcx> Visitor<'tcx> for Checker<'_, 'tcx> {
                     }
                 };
 
-                let mut nonconst_call_permission = false;
-
                 // Attempting to call a trait method?
                 if let Some(trait_id) = tcx.trait_of_item(callee) {
                     trace!("attempting to call a trait method");
@@ -776,6 +774,7 @@ impl<'tcx> Visitor<'tcx> for Checker<'_, 'tcx> {
                         _ if !tcx.is_const_fn_raw(callee) => {
                             // At this point, it is only legal when the caller is in a trait
                             // marked with #[const_trait], and the callee is in the same trait.
+                            let mut nonconst_call_permission = false;
                             if let Some(callee_trait) = tcx.trait_of_item(callee)
                                 && tcx.has_attr(callee_trait, sym::const_trait)
                                 && Some(callee_trait) == tcx.trait_of_item(caller)
@@ -872,14 +871,10 @@ impl<'tcx> Visitor<'tcx> for Checker<'_, 'tcx> {
                 let is_intrinsic = tcx.is_intrinsic(callee);
 
                 if !tcx.is_const_fn_raw(callee) {
-                    if tcx.is_const_default_method(callee) {
+                    if !tcx.is_const_default_method(callee) {
                         // To get to here we must have already found a const impl for the
                         // trait, but for it to still be non-const can be that the impl is
                         // using default method bodies.
-                        nonconst_call_permission = true;
-                    }
-
-                    if !nonconst_call_permission {
                         self.check_op(ops::FnCallNonConst {
                             caller,
                             callee,