Pretty printer improvements

Rebasing of #13596, plus some extra fixes.

These commands now execute without error:

```
rustc --pretty expanded src/libcore/lib.rs > core.rs
rustc core.rs
```