diff options
| author | Bastian Kauschke <bastian_kauschke@hotmail.de> | 2020-07-15 11:45:01 +0200 |
|---|---|---|
| committer | Bastian Kauschke <bastian_kauschke@hotmail.de> | 2020-07-15 13:06:47 +0200 |
| commit | 2666aed4989c3bec9cf9f94b2d15beda4e5407f7 (patch) | |
| tree | d08c38c3c7a805505226195e7969fd6a2a45290d | |
| parent | e070b45e6acb1cb2bbe06485721cb77de1e2469c (diff) | |
| download | rust-2666aed4989c3bec9cf9f94b2d15beda4e5407f7.tar.gz rust-2666aed4989c3bec9cf9f94b2d15beda4e5407f7.zip | |
unify Instance::resolve
| -rw-r--r-- | src/librustc_middle/mir/interpret/queries.rs | 2 | ||||
| -rw-r--r-- | src/librustc_middle/ty/instance.rs | 25 |
2 files changed, 15 insertions, 12 deletions
diff --git a/src/librustc_middle/mir/interpret/queries.rs b/src/librustc_middle/mir/interpret/queries.rs index 0a9c2ac9475..d7c0be05859 100644 --- a/src/librustc_middle/mir/interpret/queries.rs +++ b/src/librustc_middle/mir/interpret/queries.rs @@ -39,7 +39,7 @@ impl<'tcx> TyCtxt<'tcx> { promoted: Option<mir::Promoted>, span: Option<Span>, ) -> ConstEvalResult<'tcx> { - match ty::Instance::resolve_const_arg(self, param_env, def, substs) { + match ty::Instance::resolve_opt_const_arg(self, param_env, def, substs) { Ok(Some(instance)) => { let cid = GlobalId { instance, promoted }; self.const_eval_global_id(param_env, cid, span) diff --git a/src/librustc_middle/ty/instance.rs b/src/librustc_middle/ty/instance.rs index 1a5c7fe4859..f627d05d3e9 100644 --- a/src/librustc_middle/ty/instance.rs +++ b/src/librustc_middle/ty/instance.rs @@ -339,27 +339,30 @@ impl<'tcx> Instance<'tcx> { def_id: DefId, substs: SubstsRef<'tcx>, ) -> Result<Option<Instance<'tcx>>, ErrorReported> { - // All regions in the result of this query are erased, so it's - // fine to erase all of the input regions. - - // HACK(eddyb) erase regions in `substs` first, so that `param_env.and(...)` - // below is more likely to ignore the bounds in scope (e.g. if the only - // generic parameters mentioned by `substs` were lifetime ones). - let substs = tcx.erase_regions(&substs); - - // FIXME(eddyb) should this always use `param_env.with_reveal_all()`? - tcx.resolve_instance(tcx.erase_regions(¶m_env.and((def_id, substs)))) + Instance::resolve_opt_const_arg( + tcx, + param_env, + ty::WithOptConstParam::unknown(def_id), + substs, + ) } // This should be kept up to date with `resolve`. - pub fn resolve_const_arg( + pub fn resolve_opt_const_arg( tcx: TyCtxt<'tcx>, param_env: ty::ParamEnv<'tcx>, def: ty::WithOptConstParam<DefId>, substs: SubstsRef<'tcx>, ) -> Result<Option<Instance<'tcx>>, ErrorReported> { + // All regions in the result of this query are erased, so it's + // fine to erase all of the input regions. + + // HACK(eddyb) erase regions in `substs` first, so that `param_env.and(...)` + // below is more likely to ignore the bounds in scope (e.g. if the only + // generic parameters mentioned by `substs` were lifetime ones). let substs = tcx.erase_regions(&substs); + // FIXME(eddyb) should this always use `param_env.with_reveal_all()`? if let Some((did, param_did)) = def.as_const_arg() { tcx.resolve_instance_of_const_arg( tcx.erase_regions(¶m_env.and((did, param_did, substs))), |
