Not sure if this is completely correct. I essentially copied what's done here: https://github.com/mozilla/rust/blob/master/src/librustc/middle/typeck/check/method.rs#L500-L503