Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 16 additions & 7 deletions src/librustc_mir/transform/inline.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ use rustc_data_structures::indexed_vec::{Idx, IndexVec};

use rustc::mir::*;
use rustc::mir::visit::*;
use rustc::ty::{self, Instance, Ty, TyCtxt};
use rustc::ty::{self, Instance, InstanceDef, Ty, TyCtxt};
use rustc::ty::subst::{Subst,Substs};

use std::collections::VecDeque;
Expand Down Expand Up @@ -100,12 +100,21 @@ impl<'a, 'tcx> Inliner<'a, 'tcx> {
param_env,
callee_def_id,
substs) {
callsites.push_back(CallSite {
callee: instance.def_id(),
substs: instance.substs,
bb,
location: terminator.source_info
});
let is_virtual =
if let InstanceDef::Virtual(..) = instance.def {
true
} else {
false
};

if !is_virtual {
callsites.push_back(CallSite {
callee: instance.def_id(),
substs: instance.substs,
bb,
location: terminator.source_info
});
}
}
}
}
Expand Down
31 changes: 31 additions & 0 deletions src/test/mir-opt/inline-trait-method.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
// compile-flags: -Z span_free_formats

fn main() {
println!("{}", test(&()));
}

fn test(x: &dyn X) -> u32 {
x.y()
}

trait X {
fn y(&self) -> u32 {
1
}
}

impl X for () {
fn y(&self) -> u32 {
2
}
}

// END RUST SOURCE
// START rustc.test.Inline.after.mir
// ...
// bb0: {
// ...
// _0 = const X::y(move _2) -> bb1;
// }
// ...
// END rustc.test.Inline.after.mir