Skip to content

Commit 930d3b1

Browse files
committed
Auto merge of #44741 - qmx:trans_fulfill_obligation_should_not_crash, r=nikomatsakis
use param_env on the trait_cache key We bailed from making trans_fulfill_obligation return `Option` or `Result`, just made it less prone to crashing outside trans r? @nikomatsakis
2 parents 1c4510a + 9d52cb2 commit 930d3b1

File tree

3 files changed

+11
-8
lines changed

3 files changed

+11
-8
lines changed

src/librustc/traits/trans/mod.rs

+6-5
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ use std::cell::RefCell;
1919
use std::marker::PhantomData;
2020
use syntax::ast;
2121
use syntax_pos::Span;
22-
use traits::{FulfillmentContext, Obligation, ObligationCause, Reveal, SelectionContext, Vtable};
22+
use traits::{FulfillmentContext, Obligation, ObligationCause, SelectionContext, Vtable};
2323
use ty::{self, Ty, TyCtxt};
2424
use ty::subst::{Subst, Substs};
2525
use ty::fold::{TypeFoldable, TypeFolder};
@@ -31,24 +31,25 @@ impl<'a, 'tcx> TyCtxt<'a, 'tcx, 'tcx> {
3131
/// (necessarily) resolve all nested obligations on the impl. Note
3232
/// that type check should guarantee to us that all nested
3333
/// obligations *could be* resolved if we wanted to.
34+
/// Assumes that this is run after the entire crate has been successfully type-checked.
3435
pub fn trans_fulfill_obligation(self,
3536
span: Span,
37+
param_env: ty::ParamEnv<'tcx>,
3638
trait_ref: ty::PolyTraitRef<'tcx>)
3739
-> Vtable<'tcx, ()>
3840
{
3941
// Remove any references to regions; this helps improve caching.
4042
let trait_ref = self.erase_regions(&trait_ref);
4143

42-
self.trans_trait_caches.trait_cache.memoize(trait_ref, || {
44+
self.trans_trait_caches.trait_cache.memoize((param_env, trait_ref), || {
4345
debug!("trans::fulfill_obligation(trait_ref={:?}, def_id={:?})",
44-
trait_ref, trait_ref.def_id());
46+
(param_env, trait_ref), trait_ref.def_id());
4547

4648
// Do the initial selection for the obligation. This yields the
4749
// shallow result we are looking for -- that is, what specific impl.
4850
self.infer_ctxt().enter(|infcx| {
4951
let mut selcx = SelectionContext::new(&infcx);
5052

51-
let param_env = ty::ParamEnv::empty(Reveal::All);
5253
let obligation_cause = ObligationCause::misc(span,
5354
ast::DUMMY_NODE_ID);
5455
let obligation = Obligation::new(obligation_cause,
@@ -167,7 +168,7 @@ pub struct TraitSelectionCache<'tcx> {
167168
}
168169

169170
impl<'tcx> DepTrackingMapConfig for TraitSelectionCache<'tcx> {
170-
type Key = ty::PolyTraitRef<'tcx>;
171+
type Key = (ty::ParamEnv<'tcx>, ty::PolyTraitRef<'tcx>);
171172
type Value = Vtable<'tcx, ()>;
172173
fn to_dep_kind() -> DepKind {
173174
DepKind::TraitSelect

src/librustc_trans/monomorphize.rs

+4-2
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,8 @@ fn resolve_associated_item<'a, 'tcx>(
112112
def_id, trait_id, rcvr_substs);
113113

114114
let trait_ref = ty::TraitRef::from_method(tcx, trait_id, rcvr_substs);
115-
let vtbl = tcx.trans_fulfill_obligation(DUMMY_SP, ty::Binder(trait_ref));
115+
let vtbl = tcx.trans_fulfill_obligation(
116+
DUMMY_SP, ty::ParamEnv::empty(traits::Reveal::All), ty::Binder(trait_ref));
116117

117118
// Now that we know which impl is being used, we can dispatch to
118119
// the actual function:
@@ -226,7 +227,8 @@ pub fn custom_coerce_unsize_info<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
226227
substs: tcx.mk_substs_trait(source_ty, &[target_ty])
227228
});
228229

229-
match tcx.trans_fulfill_obligation(DUMMY_SP, trait_ref) {
230+
match tcx.trans_fulfill_obligation(
231+
DUMMY_SP, ty::ParamEnv::empty(traits::Reveal::All), trait_ref) {
230232
traits::VtableImpl(traits::VtableImplData { impl_def_id, .. }) => {
231233
tcx.coerce_unsized_info(impl_def_id).custom_kind.unwrap()
232234
}

src/tools/toolstate.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
# Each tool has a list of people to ping
2424

2525
# ping @oli-obk @RalfJung @eddyb
26-
miri = "Testing"
26+
miri = "Broken"
2727

2828
# ping @Manishearth @llogiq @mcarton @oli-obk
2929
clippy = "Broken"

0 commit comments

Comments
 (0)