Rollup merge of #27030 - nrc:save-ctors, r=alexcrichton
This commit is contained in:
commit
77d5fca3ef
4 changed files with 48 additions and 17 deletions
|
|
@ -411,6 +411,13 @@ impl<'ast> Map<'ast> {
|
|||
}
|
||||
}
|
||||
|
||||
pub fn expect_trait_item(&self, id: NodeId) -> &'ast TraitItem {
|
||||
match self.find(id) {
|
||||
Some(NodeTraitItem(item)) => item,
|
||||
_ => panic!("expected trait item, found {}", self.node_to_string(id))
|
||||
}
|
||||
}
|
||||
|
||||
pub fn expect_struct(&self, id: NodeId) -> &'ast StructDef {
|
||||
match self.find(id) {
|
||||
Some(NodeItem(i)) => {
|
||||
|
|
|
|||
|
|
@ -35,7 +35,6 @@ use session::Session;
|
|||
use middle::def;
|
||||
use middle::ty::{self, Ty};
|
||||
|
||||
use std::cell::Cell;
|
||||
use std::fs::File;
|
||||
use std::path::Path;
|
||||
|
||||
|
|
@ -76,14 +75,11 @@ impl <'l, 'tcx> DumpCsvVisitor<'l, 'tcx> {
|
|||
pub fn new(tcx: &'l ty::ctxt<'tcx>,
|
||||
analysis: &'l ty::CrateAnalysis,
|
||||
output_file: Box<File>) -> DumpCsvVisitor<'l, 'tcx> {
|
||||
let span_utils = SpanUtils {
|
||||
sess: &tcx.sess,
|
||||
err_count: Cell::new(0)
|
||||
};
|
||||
let span_utils = SpanUtils::new(&tcx.sess);
|
||||
DumpCsvVisitor {
|
||||
sess: &tcx.sess,
|
||||
tcx: tcx,
|
||||
save_ctxt: SaveContext::new(tcx, span_utils.clone()),
|
||||
save_ctxt: SaveContext::from_span_utils(tcx, span_utils.clone()),
|
||||
analysis: analysis,
|
||||
span: span_utils.clone(),
|
||||
fmt: FmtStrs::new(box Recorder {
|
||||
|
|
|
|||
|
|
@ -163,9 +163,14 @@ pub struct MethodCallData {
|
|||
|
||||
|
||||
impl<'l, 'tcx: 'l> SaveContext<'l, 'tcx> {
|
||||
pub fn new(tcx: &'l ty::ctxt<'tcx>,
|
||||
span_utils: SpanUtils<'l>)
|
||||
-> SaveContext<'l, 'tcx> {
|
||||
pub fn new(tcx: &'l ty::ctxt<'tcx>) -> SaveContext <'l, 'tcx> {
|
||||
let span_utils = SpanUtils::new(&tcx.sess);
|
||||
SaveContext::from_span_utils(tcx, span_utils)
|
||||
}
|
||||
|
||||
pub fn from_span_utils(tcx: &'l ty::ctxt<'tcx>,
|
||||
span_utils: SpanUtils<'l>)
|
||||
-> SaveContext<'l, 'tcx> {
|
||||
SaveContext {
|
||||
tcx: tcx,
|
||||
span_utils: span_utils,
|
||||
|
|
@ -527,7 +532,10 @@ impl<'l, 'tcx: 'l> SaveContext<'l, 'tcx> {
|
|||
ref_id: def.def_id(),
|
||||
})
|
||||
}
|
||||
def::DefStruct(def_id) | def::DefTy(def_id, _) => {
|
||||
def::DefStruct(def_id) |
|
||||
def::DefTy(def_id, _) |
|
||||
def::DefTrait(def_id) |
|
||||
def::DefTyParam(_, _, def_id, _) => {
|
||||
Data::TypeRefData(TypeRefData {
|
||||
span: sub_span.unwrap(),
|
||||
ref_id: def_id,
|
||||
|
|
@ -540,13 +548,12 @@ impl<'l, 'tcx: 'l> SaveContext<'l, 'tcx> {
|
|||
let ti = self.tcx.impl_or_trait_item(decl_id);
|
||||
match provenence {
|
||||
def::FromTrait(def_id) => {
|
||||
Some(self.tcx.trait_items(def_id)
|
||||
.iter()
|
||||
.find(|mr| {
|
||||
mr.name() == ti.name()
|
||||
})
|
||||
.unwrap()
|
||||
.def_id())
|
||||
self.tcx.trait_items(def_id)
|
||||
.iter()
|
||||
.find(|mr| {
|
||||
mr.name() == ti.name() && self.trait_method_has_body(mr)
|
||||
})
|
||||
.map(|mr| mr.def_id())
|
||||
}
|
||||
def::FromImpl(def_id) => {
|
||||
let impl_items = self.tcx.impl_items.borrow();
|
||||
|
|
@ -586,6 +593,20 @@ impl<'l, 'tcx: 'l> SaveContext<'l, 'tcx> {
|
|||
}
|
||||
}
|
||||
|
||||
fn trait_method_has_body(&self, mr: &ty::ImplOrTraitItem) -> bool {
|
||||
let def_id = mr.def_id();
|
||||
if def_id.krate != ast::LOCAL_CRATE {
|
||||
return false;
|
||||
}
|
||||
|
||||
let trait_item = self.tcx.map.expect_trait_item(def_id.node);
|
||||
if let ast::TraitItem_::MethodTraitItem(_, Some(_)) = trait_item.node {
|
||||
true
|
||||
} else {
|
||||
false
|
||||
}
|
||||
}
|
||||
|
||||
pub fn get_field_ref_data(&self,
|
||||
field_ref: &ast::Field,
|
||||
struct_id: DefId,
|
||||
|
|
|
|||
|
|
@ -28,6 +28,13 @@ pub struct SpanUtils<'a> {
|
|||
}
|
||||
|
||||
impl<'a> SpanUtils<'a> {
|
||||
pub fn new(sess: &'a Session) -> SpanUtils<'a> {
|
||||
SpanUtils {
|
||||
sess: sess,
|
||||
err_count: Cell::new(0)
|
||||
}
|
||||
}
|
||||
|
||||
// Standard string for extents/location.
|
||||
pub fn extent_str(&self, span: Span) -> String {
|
||||
let lo_loc = self.sess.codemap().lookup_char_pos(span.lo);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue