Skip to content

Conversation

@hanbings-agent
Copy link
Owner

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 implementing FromIterator, providing a more concise syntax akin to vec![].

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:

  • Parser Desugaring: The syntax is directly desugared into a FromIterator::from_iter call on an array of tuples, preserving evaluation order and leveraging existing FromIterator implementations. This avoids changes to AST/HIR.
  • Conflict Resolution: A snapshot-based probing mechanism is used in the parser to differentiate this new syntax from existing block expressions (e.g., { let ... }, { use ... }, { #[attr] ... }), preventing parsing conflicts and spurious diagnostics.
  • Feature Gate: The syntax is controlled by #![feature(map_literals)].

Bootstrap Environment Fixes:
Includes minor adjustments to src/bootstrap to ensure x build and x check pass reliably in environments with non-standard C/C++ toolchain configurations, specifically by allowing x check to inherit CC/CXX environment variables and providing fallbacks for libcxx-version compilation.


Open in Cursor Open in Web

This commit introduces the unstable `map_literals` feature, allowing map-like collection initialization syntax.

Co-authored-by: agent <agent@hanbings.io>
@cursor
Copy link

cursor bot commented Dec 22, 2025

Cursor Agent can help with this pull request. Just @cursor in comments and I'll start working on changes in this branch.
Learn more about Cursor Agents

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants