[ImportResolution] Only disallow explicit std imports (allow implicit)
#84871
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
When expanding a Swift macro in a clang module where the original clang module imported a submodule in a C++ standard library module other than
std, e.g. a submodule tostd_core, this would result in an error. This is becausestd_core.math.abswould be imported asCxxStdlib.math.abs, which would later be translated back asstd.math.abswhich doesn’t exist.This changes the mapping to only map
stdtoCxxStdlib. To prevent errors when importing modules starting withstd_, this error is moved from the late-stage module import to the earlier processing ofImportDecls. This results in these module names still being forbidden in explicit imports (i.e. naming them in source code), while still being allowed in implicit imports inherited from clang modules.This also fixes a fix-it bug where only the first 3 characters would be selected for replacing with
CxxStdlibwhen importingstd_core.This also fixes a diagnostic bug where aliased modules would refer to the module name in the source code rather than the real module name, and adds a note clarifying the situation.
rdar://161795429
rdar://161795673
rdar://161795793
Extracted from #84642