There was a pitch recently in on the Swift Evolution open source forums by Ashley Garland that related to this kind of setup - the idea being the documentation catalog could contain a specific set of swift snippets, and the compiler (or SwiftPM in this case I think) could/would build those to verify that everything kept working, no warnings, etc.
I don't know the current state of that pitch, but I think it's nearly exactly what you're after here.
(and I'm doing the same right now - including snippets in two places, one in my tests, and another in the doc comments)
Topic:
Developer Tools & Services
SubTopic:
General
Tags: