Skip to content

Commit 3bd09de

Browse files
committed
re-enable mir inlining across trait methods
this fixes #44389
1 parent baa0105 commit 3bd09de

File tree

1 file changed

+23
-8
lines changed

1 file changed

+23
-8
lines changed

src/librustc_mir/transform/inline.rs

+23-8
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ use rustc_data_structures::indexed_vec::{Idx, IndexVec};
1818
use rustc::mir::*;
1919
use rustc::mir::transform::{MirPass, MirSource};
2020
use rustc::mir::visit::*;
21-
use rustc::ty::{self, Ty, TyCtxt};
21+
use rustc::ty::{self, Ty, TyCtxt, Instance};
2222
use rustc::ty::subst::{Subst,Substs};
2323

2424
use std::collections::VecDeque;
@@ -88,13 +88,28 @@ impl<'a, 'tcx> Inliner<'a, 'tcx> {
8888
if let TerminatorKind::Call {
8989
func: Operand::Constant(ref f), .. } = terminator.kind {
9090
if let ty::TyFnDef(callee_def_id, substs) = f.ty.sty {
91-
if self.tcx.trait_of_item(callee_def_id).is_none() {
92-
callsites.push_back(CallSite {
93-
callee: callee_def_id,
94-
substs,
95-
bb,
96-
location: terminator.source_info
97-
});
91+
match self.tcx.trait_of_item(callee_def_id) {
92+
Some(_) => {
93+
match Instance::new(callee_def_id, substs).resolve(self.tcx) {
94+
Some(instance) => {
95+
callsites.push_back(CallSite {
96+
callee: instance.def_id(),
97+
substs: instance.substs,
98+
bb,
99+
location: terminator.source_info
100+
});
101+
},
102+
None => {}
103+
}
104+
}
105+
None => {
106+
callsites.push_back(CallSite {
107+
callee: callee_def_id,
108+
substs,
109+
bb,
110+
location: terminator.source_info
111+
});
112+
}
98113
}
99114
}
100115
}

0 commit comments

Comments
 (0)