The complexities of possible name conflicts here suggest to me that it might be wise to take a totally different strategy: instead of requiring the author to provide a namespace prefix, automatically add namespace prefixes. Note that in particular, an intra-doc link foo::Foo#some-section
already has to be resolved to a specific crate to generate the correct URL, so it's possible to add the ID prefix without needing any more name analysis than is already done.
There might need to be a syntax to distinguish links to rustdoc-generated sections (e.g. some_module#traits
) from user-defined sections, though.
This is more work for rustdoc, but makes it easier and less verbose for authors to write correct documentation.