Suppose I have an object `foo` of some type that implements the trait
`Foo { fn blah() {} }`, and I see an ExprMethodCall `foo.blah()`, how
do I get the DefId of the trait method `blah`?
The following is what I have tried so far. The particular part I'm
concerned about is the match arm for `typeck::method_param` and
`typeck::method_object`.
```
let id = match e.node {
ast::ExprPath(..) | ast::ExprStruct(..) => {
match cx.tcx.def_map.find(&e.id) {
Some(&def) => ast_util::def_id_of_def(def),
None => return
}
}
ast::ExprMethodCall(..) => {
match cx.method_map.find(&e.id) {
Some(&typeck::method_map_entry { origin, .. }) => {
match origin {
typeck::method_static(def_id) => def_id,
typeck::method_param(typeck::method_param {
trait_id: trait_id,
method_num: index,
..
})
| typeck::method_object(typeck::method_object {
trait_id: trait_id,
method_num: index,
..
}) => {
ty::trait_method(cx.tcx, trait_id, index).def_id
}
}
}
None => return
}
}
_ => return
};
```
I thought the above would work, but when I try to look up `id.node` in
the `ty::ctxt.items` map, it does not return any entry. I have also
tried replacing the line `ty::trait_method(cx.tcx, trait_id,
index).def_id` with
```
let method = ty::trait_method(cx.tcx, trait_id, index);
method.provided_source.unwrap_or(method.def_id)
```
but it doesn't work. I'm now out of idea and would like some help.
_______________________________________________
Rust-dev mailing list
[email protected]
https://mail.mozilla.org/listinfo/rust-dev