]> git.lizzy.rs Git - rust.git/commitdiff
HACK: Overwrite the MIR's source with the correct const param
authorDylan MacKenzie <ecstaticmorse@gmail.com>
Fri, 2 Oct 2020 01:47:36 +0000 (18:47 -0700)
committerDylan MacKenzie <ecstaticmorse@gmail.com>
Sun, 4 Oct 2020 18:02:16 +0000 (11:02 -0700)
There's a cleaner way of doing this, but it involves passing
`WithOptConstParam` around in more places. We're going to try to explore
different approaches before committing to that.

compiler/rustc_mir_build/src/build/mod.rs

index be1d2696408bf52de07b63c1bc973323a63f8e86..72814e3373bbb8b28b225cd49f63a2ab63fe8e8a 100644 (file)
         return tcx.mir_built(def);
     }
 
-    tcx.alloc_steal_mir(mir_build(tcx, def))
+    let mut body = mir_build(tcx, def);
+    if def.const_param_did.is_some() {
+        assert!(matches!(body.source.instance, ty::InstanceDef::Item(_)));
+        body.source = MirSource::from_instance(ty::InstanceDef::Item(def.to_global()));
+    }
+
+    tcx.alloc_steal_mir(body)
 }
 
 /// Construct the MIR for a given `DefId`.