Skip to content

Commit 77d5fca

Browse files
committed
Rollup merge of #27030 - nrc:save-ctors, r=alexcrichton
2 parents b8a9c80 + 49d3a93 commit 77d5fca

File tree

4 files changed

+48
-17
lines changed

4 files changed

+48
-17
lines changed

src/librustc/ast_map/mod.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -411,6 +411,13 @@ impl<'ast> Map<'ast> {
411411
}
412412
}
413413

414+
pub fn expect_trait_item(&self, id: NodeId) -> &'ast TraitItem {
415+
match self.find(id) {
416+
Some(NodeTraitItem(item)) => item,
417+
_ => panic!("expected trait item, found {}", self.node_to_string(id))
418+
}
419+
}
420+
414421
pub fn expect_struct(&self, id: NodeId) -> &'ast StructDef {
415422
match self.find(id) {
416423
Some(NodeItem(i)) => {

src/librustc_trans/save/dump_csv.rs

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,6 @@ use session::Session;
3535
use middle::def;
3636
use middle::ty::{self, Ty};
3737

38-
use std::cell::Cell;
3938
use std::fs::File;
4039
use std::path::Path;
4140

@@ -76,14 +75,11 @@ impl <'l, 'tcx> DumpCsvVisitor<'l, 'tcx> {
7675
pub fn new(tcx: &'l ty::ctxt<'tcx>,
7776
analysis: &'l ty::CrateAnalysis,
7877
output_file: Box<File>) -> DumpCsvVisitor<'l, 'tcx> {
79-
let span_utils = SpanUtils {
80-
sess: &tcx.sess,
81-
err_count: Cell::new(0)
82-
};
78+
let span_utils = SpanUtils::new(&tcx.sess);
8379
DumpCsvVisitor {
8480
sess: &tcx.sess,
8581
tcx: tcx,
86-
save_ctxt: SaveContext::new(tcx, span_utils.clone()),
82+
save_ctxt: SaveContext::from_span_utils(tcx, span_utils.clone()),
8783
analysis: analysis,
8884
span: span_utils.clone(),
8985
fmt: FmtStrs::new(box Recorder {

src/librustc_trans/save/mod.rs

Lines changed: 32 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -163,9 +163,14 @@ pub struct MethodCallData {
163163

164164

165165
impl<'l, 'tcx: 'l> SaveContext<'l, 'tcx> {
166-
pub fn new(tcx: &'l ty::ctxt<'tcx>,
167-
span_utils: SpanUtils<'l>)
168-
-> SaveContext<'l, 'tcx> {
166+
pub fn new(tcx: &'l ty::ctxt<'tcx>) -> SaveContext <'l, 'tcx> {
167+
let span_utils = SpanUtils::new(&tcx.sess);
168+
SaveContext::from_span_utils(tcx, span_utils)
169+
}
170+
171+
pub fn from_span_utils(tcx: &'l ty::ctxt<'tcx>,
172+
span_utils: SpanUtils<'l>)
173+
-> SaveContext<'l, 'tcx> {
169174
SaveContext {
170175
tcx: tcx,
171176
span_utils: span_utils,
@@ -527,7 +532,10 @@ impl<'l, 'tcx: 'l> SaveContext<'l, 'tcx> {
527532
ref_id: def.def_id(),
528533
})
529534
}
530-
def::DefStruct(def_id) | def::DefTy(def_id, _) => {
535+
def::DefStruct(def_id) |
536+
def::DefTy(def_id, _) |
537+
def::DefTrait(def_id) |
538+
def::DefTyParam(_, _, def_id, _) => {
531539
Data::TypeRefData(TypeRefData {
532540
span: sub_span.unwrap(),
533541
ref_id: def_id,
@@ -540,13 +548,12 @@ impl<'l, 'tcx: 'l> SaveContext<'l, 'tcx> {
540548
let ti = self.tcx.impl_or_trait_item(decl_id);
541549
match provenence {
542550
def::FromTrait(def_id) => {
543-
Some(self.tcx.trait_items(def_id)
544-
.iter()
545-
.find(|mr| {
546-
mr.name() == ti.name()
547-
})
548-
.unwrap()
549-
.def_id())
551+
self.tcx.trait_items(def_id)
552+
.iter()
553+
.find(|mr| {
554+
mr.name() == ti.name() && self.trait_method_has_body(mr)
555+
})
556+
.map(|mr| mr.def_id())
550557
}
551558
def::FromImpl(def_id) => {
552559
let impl_items = self.tcx.impl_items.borrow();
@@ -586,6 +593,20 @@ impl<'l, 'tcx: 'l> SaveContext<'l, 'tcx> {
586593
}
587594
}
588595

596+
fn trait_method_has_body(&self, mr: &ty::ImplOrTraitItem) -> bool {
597+
let def_id = mr.def_id();
598+
if def_id.krate != ast::LOCAL_CRATE {
599+
return false;
600+
}
601+
602+
let trait_item = self.tcx.map.expect_trait_item(def_id.node);
603+
if let ast::TraitItem_::MethodTraitItem(_, Some(_)) = trait_item.node {
604+
true
605+
} else {
606+
false
607+
}
608+
}
609+
589610
pub fn get_field_ref_data(&self,
590611
field_ref: &ast::Field,
591612
struct_id: DefId,

src/librustc_trans/save/span_utils.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,13 @@ pub struct SpanUtils<'a> {
2828
}
2929

3030
impl<'a> SpanUtils<'a> {
31+
pub fn new(sess: &'a Session) -> SpanUtils<'a> {
32+
SpanUtils {
33+
sess: sess,
34+
err_count: Cell::new(0)
35+
}
36+
}
37+
3138
// Standard string for extents/location.
3239
pub fn extent_str(&self, span: Span) -> String {
3340
let lo_loc = self.sess.codemap().lookup_char_pos(span.lo);

0 commit comments

Comments
 (0)