This function was added in Go 1.19, and covers some corner cases that our custom implementation didn't.