Rebase of #7036 against latest 3.0.0-wip

In light of @vilius having had to wait ~4 months for @fat to respond to his pull request, I've taken the liberty of rebasing #7036 against the current latest `3.0.0-wip`, to save him the trouble.