X-Git-Url: https://git.lizzy.rs/?a=blobdiff_plain;f=compiler%2Frustc_mir_transform%2Fsrc%2Fdeduce_param_attrs.rs;h=ddab7bbb2e3016a29fb23d9259c66a4064d9eac2;hb=f02439dea78e5c2df42198c7a03e2db6002ff263;hp=28b1c5a48099bc9d8c14d9b1456b263ea568f531;hpb=1b91bdfda995fa21b3019a85e12a063f32cd62af;p=rust.git diff --git a/compiler/rustc_mir_transform/src/deduce_param_attrs.rs b/compiler/rustc_mir_transform/src/deduce_param_attrs.rs index 28b1c5a4809..ddab7bbb2e3 100644 --- a/compiler/rustc_mir_transform/src/deduce_param_attrs.rs +++ b/compiler/rustc_mir_transform/src/deduce_param_attrs.rs @@ -110,15 +110,16 @@ fn visit_terminator(&mut self, terminator: &Terminator<'tcx>, location: Location if let TerminatorKind::Call { ref args, .. } = terminator.kind { for arg in args { - if let Operand::Move(_) = *arg { - // ArgumentChecker panics if a direct move of an argument from a caller to a - // callee was detected. - // - // If, in the future, MIR optimizations cause arguments to be moved directly - // from callers to callees, change the panic to instead add the argument in - // question to `mutating_uses`. - ArgumentChecker::new(self.mutable_args.domain_size()) - .visit_operand(arg, location) + if let Operand::Move(place) = *arg { + let local = place.local; + if place.is_indirect() + || local == RETURN_PLACE + || local.index() > self.mutable_args.domain_size() + { + continue; + } + + self.mutable_args.insert(local.index() - 1); } } }; @@ -127,37 +128,8 @@ fn visit_terminator(&mut self, terminator: &Terminator<'tcx>, location: Location } } -/// A visitor that simply panics if a direct move of an argument from a caller to a callee was -/// detected. -struct ArgumentChecker { - /// The number of arguments to the calling function. - arg_count: usize, -} - -impl ArgumentChecker { - /// Creates a new ArgumentChecker. - fn new(arg_count: usize) -> Self { - Self { arg_count } - } -} - -impl<'tcx> Visitor<'tcx> for ArgumentChecker { - fn visit_local(&mut self, local: Local, context: PlaceContext, _: Location) { - // Check to make sure that, if this local is an argument, we didn't move directly from it. - if matches!(context, PlaceContext::NonMutatingUse(NonMutatingUseContext::Move)) - && local != RETURN_PLACE - && local.index() <= self.arg_count - { - // If, in the future, MIR optimizations cause arguments to be moved directly from - // callers to callees, change this panic to instead add the argument in question to - // `mutating_uses`. - panic!("Detected a direct move from a caller's argument to a callee's argument!") - } - } -} - /// Returns true if values of a given type will never be passed indirectly, regardless of ABI. -fn type_will_always_be_passed_directly<'tcx>(ty: Ty<'tcx>) -> bool { +fn type_will_always_be_passed_directly(ty: Ty<'_>) -> bool { matches!( ty.kind(), ty::Bool