Scala REPL: There were deprecation warnings, re-run with -deprecation

Whenever I used to get the Scala REPL warning message, “There were deprecation warnings, re-run with -deprecation,” I used to have to restart the REPL with the -deprecation flag to see the warning message, like this:

$ scala -deprecation

That works, but sadly, you had to lose your entire REPL session to run it.

Solution: Use “:warnings”

Thanks to the Scala gods, this is no longer necessary in Scala 2.10 (and newer). Now, when you get the REPL “deprecation” warning message, like this:

scala> val x = <pizza><topping>cheese</topping><topping>sausage</topping></pizza>
x: scala.xml.Elem = <pizza><topping>cheese</topping><topping>sausage</topping></pizza>

scala> scala.xml.Utility.toXML(x, minimizeTags = true)
warning: there were 1 deprecation warnings; re-run with -deprecation for details
res0: StringBuilder = <pizza><topping>cheese</topping><topping>sausage</topping></pizza>

Just type :warnings to see the actual deprecation message, like so:

scala> :warnings
<console>:9: warning: method toXML in object Utility is deprecated: 
Please use `serialize` instead and specify a `minimizeTags` parameter
              scala.xml.Utility.toXML(x, minimizeTags = true)
                                ^

*I bow to the Scala gods in thanks.*