Fix def ID mapping for method defs

This prevents def IDs with the wrong crate ID from showing up
when using UFCS.  Closes #18501
This commit is contained in:
Brian Koropoff 2014-11-01 18:49:48 -07:00
parent 39f90aead4
commit ae92942758
2 changed files with 14 additions and 11 deletions

View File

@ -441,19 +441,13 @@ impl tr for def::Def {
fn tr(&self, dcx: &DecodeContext) -> def::Def {
match *self {
def::DefFn(did, is_ctor) => def::DefFn(did.tr(dcx), is_ctor),
def::DefStaticMethod(did, wrapped_did2) => {
def::DefStaticMethod(did.tr(dcx),
match wrapped_did2 {
def::FromTrait(did2) => {
def::FromTrait(did2.tr(dcx))
}
def::FromImpl(did2) => {
def::FromImpl(did2.tr(dcx))
}
})
def::DefStaticMethod(did, p) => {
def::DefStaticMethod(did.tr(dcx), p.map(|did2| did2.tr(dcx)))
}
def::DefMethod(did0, did1, p) => {
def::DefMethod(did0.tr(dcx), did1.map(|did1| did1.tr(dcx)), p)
def::DefMethod(did0.tr(dcx),
did1.map(|did1| did1.tr(dcx)),
p.map(|did2| did2.tr(dcx)))
}
def::DefSelfTy(nid) => { def::DefSelfTy(dcx.tr_id(nid)) }
def::DefMod(did) => { def::DefMod(did.tr(dcx)) }

View File

@ -55,6 +55,15 @@ pub enum MethodProvenance {
FromImpl(ast::DefId),
}
impl MethodProvenance {
pub fn map(self, f: |ast::DefId| -> ast::DefId) -> MethodProvenance {
match self {
FromTrait(did) => FromTrait(f(did)),
FromImpl(did) => FromImpl(f(did))
}
}
}
impl Def {
pub fn def_id(&self) -> ast::DefId {
match *self {