Skip to content

Commit

Permalink
Fix def ID mapping for method defs
Browse files Browse the repository at this point in the history
This prevents def IDs with the wrong crate ID from showing up
when using UFCS.  Closes rust-lang#18501
  • Loading branch information
bkoropoff committed Nov 2, 2014
1 parent 39f90ae commit ae92942
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 11 deletions.
16 changes: 5 additions & 11 deletions src/librustc/middle/astencode.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)) }
Expand Down
9 changes: 9 additions & 0 deletions src/librustc/middle/def.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down

0 comments on commit ae92942

Please sign in to comment.