Map literal syntax sugar #5
Draft
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.
feat: Introduce feature-gated map literal syntax sugar
This PR introduces a new feature-gated syntax sugar for initializing map-like collections, addressing long-standing requests (e.g., RFCs rust-lang#1420, rust-lang#542, rust-lang#1602).
Why this change?
To simplify the initialization of
HashMap,BTreeMap, and other types implementingFromIterator, providing a more concise syntax akin tovec![].What does it do?
It allows initializing collections using
{ k1, v1, k2, v2, ... }syntax, which desugars in the parser to::core::iter::FromIterator::from_iter([(k1, v1), (k2, v2), ...]).Key implementation details:
FromIterator::from_itercall on an array of tuples, preserving evaluation order and leveraging existingFromIteratorimplementations. This avoids changes to AST/HIR.{ let ... },{ use ... },{ #[attr] ... }), preventing parsing conflicts and spurious diagnostics.#![feature(map_literals)].Bootstrap Environment Fixes:
Includes minor adjustments to
src/bootstrapto ensurex buildandx checkpass reliably in environments with non-standard C/C++ toolchain configurations, specifically by allowingx checkto inherit CC/CXX environment variables and providing fallbacks forlibcxx-versioncompilation.