Fix unsafety in StrInterner

The `StrInterner::clear()` method takes self immutably but can invalidate references returned by `StrInterner::get_ref`. Making it take `&mut self` would cause a lot of cascading code churn, so this PR adds a dynamic borrow check.

`get_ref` is actually unused, so an alternative fix would be to remove it altogether.

Closes #17181

r? @eddyb