Skip to content

Support f32/f64 float literals in paste! macro - #27

Draft
AS1100K with Copilot wants to merge 2 commits into
masterfrom
copilot/fix-cannot-generate-f32-f64-values
Draft

Support f32/f64 float literals in paste! macro#27
AS1100K with Copilot wants to merge 2 commits into
masterfrom
copilot/fix-cannot-generate-f32-f64-values

Conversation

Copilot AI commented Mar 30, 2026

Copy link
Copy Markdown
Contributor

The paste! macro failed on float literals with type suffixes ([< 0.0 f32 >] → "unsupported literal") and on negative float literals ([< -0.0 f32 >] → "unexpected punct"), making it impossible to concatenate float values and type suffixes.

Changes

  • src/segment.rs — Accept - punctuation as a valid segment (value "-"), enabling negative numeric literal construction.

  • src/lib.rsparse_bracket_as_segments

    • Introduce is_numeric_literal guard: digit-starting strings without + (e.g. 0.0, 1.5f32) bypass the ./+/\ rejection check. 1e+100 and byte literals still fail as before.
    • Restrict replace('-', "_") to quoted string/char literal content only — prevents the - punct segment from being silently mangled to _.
  • src/lib.rspasted_to_tokens — Handle pasted strings starting with - followed by a digit by emitting a - Punct token + the parsed numeric literal, matching how Rust represents negated literals.

Example

paste! {
    let _ = [< 0.0 f32 >];    // 0.0f32 ✓
    let _ = [< -0.0 f32 >];   // -0.0f32 ✓
    let _ = [< 1.0 f64 >];    // 1.0f64 ✓
}

Copilot AI linked an issue Mar 30, 2026 that may be closed by this pull request
Copilot AI changed the title [WIP] Fix issue with generating f32/f64 values using paste macro Support f32/f64 float literals in paste! macro Mar 30, 2026
Copilot AI requested a review from AS1100K March 30, 2026 18:12
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.

Cannot generate f32/f64 values

2 participants