-/// 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!")
- }
- }
-}
-