Skip to content

Commit 7218836

Browse files
committed
Fix mozjs crater failure
1 parent 134c291 commit 7218836

File tree

2 files changed

+48
-3
lines changed

2 files changed

+48
-3
lines changed

src/librustc_mir/interpret/eval_context.rs

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -246,7 +246,10 @@ impl<'a, 'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> EvalContext<'a, 'mir, 'tcx, M
246246
}
247247

248248
pub(super) fn resolve(&self, def_id: DefId, substs: &'tcx Substs<'tcx>) -> EvalResult<'tcx, ty::Instance<'tcx>> {
249-
let substs = self.tcx.trans_apply_param_substs(self.substs(), &substs);
249+
trace!("resolve: {:?}, {:#?}", def_id, substs);
250+
trace!("substs: {:#?}", self.substs());
251+
trace!("param_env: {:#?}", self.param_env);
252+
let substs = self.tcx.trans_apply_param_substs_env(self.substs(), self.param_env, &substs);
250253
ty::Instance::resolve(
251254
*self.tcx,
252255
self.param_env,
@@ -690,8 +693,13 @@ impl<'a, 'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> EvalContext<'a, 'mir, 'tcx, M
690693
bug!("reifying a fn ptr that requires \
691694
const arguments");
692695
}
693-
let instance = self.resolve(def_id, substs)?;
694-
let fn_ptr = self.memory.create_fn_alloc(instance);
696+
let instance: EvalResult<'tcx, _> = ty::Instance::resolve(
697+
*self.tcx,
698+
self.param_env,
699+
def_id,
700+
substs,
701+
).ok_or(EvalErrorKind::TypeckError.into());
702+
let fn_ptr = self.memory.create_fn_alloc(instance?);
695703
let valty = ValTy {
696704
value: Value::ByVal(PrimVal::Ptr(fn_ptr)),
697705
ty: dest_ty,

src/test/run-pass/ctfe/mozjs-error.rs

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
// Copyright 2018 The Rust Project Developers. See the COPYRIGHT
2+
// file at the top-level directory of this distribution and at
3+
// http://rust-lang.org/COPYRIGHT.
4+
//
5+
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6+
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7+
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8+
// option. This file may not be copied, modified, or distributed
9+
// except according to those terms.
10+
11+
struct CustomAutoRooterVFTable {
12+
trace: unsafe extern "C" fn(this: *mut i32, trc: *mut u32),
13+
}
14+
15+
unsafe trait CustomAutoTraceable: Sized {
16+
const vftable: CustomAutoRooterVFTable = CustomAutoRooterVFTable {
17+
trace: Self::trace,
18+
};
19+
20+
unsafe extern "C" fn trace(this: *mut i32, trc: *mut u32) {
21+
let this = this as *const Self;
22+
let this = this.as_ref().unwrap();
23+
Self::do_trace(this, trc);
24+
}
25+
26+
fn do_trace(&self, trc: *mut u32);
27+
}
28+
29+
unsafe impl CustomAutoTraceable for () {
30+
fn do_trace(&self, _: *mut u32) {
31+
// nop
32+
}
33+
}
34+
35+
fn main() {
36+
let _ = <()>::vftable;
37+
}

0 commit comments

Comments
 (0)