Rewrite the coercion code to be more readable, more sound, and to reborrow when needed.

The first few commits are all refactorings that should not affect anything.  The last commit is the important part.  There is one caveat, which is that it was a bit hard for me to test some of the method stuff: it seems to do the right thing, but the current code also passes the tests, though it shouldn't, I think due to various bugs in the mode.rs code.  So I may have some more patches coming along.

r? @brson