@@ -11,6 +11,7 @@ use rustc_serialize::opaque::{FileEncodeResult, FileEncoder};
1111use parking_lot:: Mutex ;
1212use smallvec:: { smallvec, SmallVec } ;
1313use std:: collections:: hash_map:: Entry ;
14+ use std:: fmt:: Debug ;
1415use std:: hash:: Hash ;
1516use std:: marker:: PhantomData ;
1617use std:: sync:: atomic:: Ordering :: Relaxed ;
@@ -208,7 +209,7 @@ impl<K: DepKind> DepGraph<K> {
208209 /// `arg` parameter.
209210 ///
210211 /// [rustc dev guide]: https://rustc-dev-guide.rust-lang.org/incremental-compilation.html
211- pub fn with_task < Ctxt : HasDepContext < DepKind = K > , A , R > (
212+ pub fn with_task < Ctxt : HasDepContext < DepKind = K > , A : Debug , R > (
212213 & self ,
213214 key : DepNode < K > ,
214215 cx : Ctxt ,
@@ -234,7 +235,7 @@ impl<K: DepKind> DepGraph<K> {
234235 )
235236 }
236237
237- fn with_task_impl < Ctxt : HasDepContext < DepKind = K > , A , R > (
238+ fn with_task_impl < Ctxt : HasDepContext < DepKind = K > , A : Debug , R > (
238239 & self ,
239240 key : DepNode < K > ,
240241 cx : Ctxt ,
@@ -244,6 +245,20 @@ impl<K: DepKind> DepGraph<K> {
244245 hash_result : impl FnOnce ( & mut Ctxt :: StableHashingContext , & R ) -> Option < Fingerprint > ,
245246 ) -> ( R , DepNodeIndex ) {
246247 if let Some ( ref data) = self . data {
248+ // If the following assertion triggers, it can have two reasons:
249+ // 1. Something is wrong with DepNode creation, either here or
250+ // in `DepGraph::try_mark_green()`.
251+ // 2. Two distinct query keys get mapped to the same `DepNode`
252+ // (see for example #48923).
253+ assert ! (
254+ !self . dep_node_exists( & key) ,
255+ "forcing query with already existing `DepNode`\n \
256+ - query-key: {:?}\n \
257+ - dep-node: {:?}",
258+ arg,
259+ key
260+ ) ;
261+
247262 let dcx = cx. dep_context ( ) ;
248263 let task_deps = create_task ( key) . map ( Lock :: new) ;
249264 let result = K :: with_deps ( task_deps. as_ref ( ) , || task ( cx, arg) ) ;
@@ -359,7 +374,7 @@ impl<K: DepKind> DepGraph<K> {
359374
360375 /// Executes something within an "eval-always" task which is a task
361376 /// that runs whenever anything changes.
362- pub fn with_eval_always_task < Ctxt : HasDepContext < DepKind = K > , A , R > (
377+ pub fn with_eval_always_task < Ctxt : HasDepContext < DepKind = K > , A : Debug , R > (
363378 & self ,
364379 key : DepNode < K > ,
365380 cx : Ctxt ,
0 commit comments