- if *locked_dep_idx == this.lock_idx && *locked_dep_idx != locked.lock_idx {
- #[cfg(feature = "backtrace")]
- panic!("Tried to violate existing lockorder.\nMutex that should be locked after the current lock was created at the following backtrace.\nNote that to get a backtrace for the lockorder violation, you should set RUST_BACKTRACE=1\nLock being taken constructed at: {} ({}):\n{:?}\nLock constructed at: {} ({})\n{:?}\n\nLock dep created at:\n{:?}\n\n",
- get_construction_location(&this._lock_construction_bt).0,
- this.lock_idx, this._lock_construction_bt,
- get_construction_location(&locked._lock_construction_bt).0,
- locked.lock_idx, locked._lock_construction_bt,
- _locked_dep._lockdep_trace);
- #[cfg(not(feature = "backtrace"))]
- panic!("Tried to violate existing lockorder. Build with the backtrace feature for more info.");
+ let is_dep_this_lock = *locked_dep_idx == this.lock_idx;
+ let has_same_construction = *locked_dep_idx == locked.lock_idx;
+ if is_dep_this_lock && !has_same_construction {
+ #[allow(unused_mut, unused_assignments)]
+ let mut has_same_callsite = false;
+ #[cfg(feature = "backtrace")] {
+ has_same_callsite = _double_lock_self_allowed &&
+ locate_call_symbol(&_locked_dep._lockdep_trace) ==
+ locate_call_symbol(&Backtrace::new());
+ }
+ if !has_same_callsite {
+ #[cfg(feature = "backtrace")]
+ panic!("Tried to violate existing lockorder.\nMutex that should be locked after the current lock was created at the following backtrace.\nNote that to get a backtrace for the lockorder violation, you should set RUST_BACKTRACE=1\nLock being taken constructed at: {} ({}):\n{:?}\nLock constructed at: {} ({})\n{:?}\n\nLock dep created at:\n{:?}\n\n",
+ locate_call_symbol(&this._lock_construction_bt).0,
+ this.lock_idx, this._lock_construction_bt,
+ locate_call_symbol(&locked._lock_construction_bt).0,
+ locked.lock_idx, locked._lock_construction_bt,
+ _locked_dep._lockdep_trace);
+ #[cfg(not(feature = "backtrace"))]
+ panic!("Tried to violate existing lockorder. Build with the backtrace feature for more info.");
+ }