Backport code from typesafe scala

2.11.4 was just staged: https://groups.google.com/forum/#!topic/scala-internals/y890GcpjONE. Time to backport the changes?