Skip to content

Conversation

jieyouxu
Copy link
Member

@jieyouxu jieyouxu commented Aug 19, 2025

Caution

This should only be merged after FCP on rust-lang/rust#145463 passes and the PR is itself merged.

This is being proposed to be removed in rust-lang/rust#145463 as we never intended for this to be valid syntax. The concrete example forms are in the nomination report in rust-lang/rust#145463 (comment).

Outdated discussion on the grammar

Note on TUPLE_INDEX

This production looks wrong to me

TUPLE_INDEX -> INTEGER_LITERAL

INTEGER_LITERAL covers all the decimal, binary, octal and hex literal forms, but AFAICT TUPLE_INDEX as implemented does not even accept the full range of decimal syntax. I.e.

DEC_LITERAL -> DEC_DIGIT (DEC_DIGIT|`_`)*

but e.g.

fn main() {
    let x = (1,);
    println!("{}", x.0_0); //~ ERROR no field `0_0` on type `({integer},)`
}

I believe the accepted TUPLE_INDEX grammar here is only

DEC_LITERAL -> DEC_DIGIT+

Let me know if that sounds right.

@ehuss
Copy link
Contributor

ehuss commented Aug 19, 2025

The grammar is defined by the AST. It is essentially the pre-expansion accepted text, or to think of it another way, it is the valid input to a macro metavariable.

I haven't looked at your PR to determine exactly what it does, but from what I can tell it rejects the suffix at parsing time. So I think the new grammar is something like:

TUPLE_INDEX -> DEC_LITERAL | BIN_LITERAL | OCT_LITERAL | HEX_LITERAL

Personally I think that is weird, and would be simpler if it could just be DEC_LITERAL. However, since it is an exact textual match, it still has the oddity that 04 is not the same as 4, so 🤷 .

@jieyouxu
Copy link
Member Author

jieyouxu commented Aug 19, 2025

It really does feel weird, because e.g.

let _x = (4,).0x0;
              ^^^

clearly does not work... before or after my PR.

@ehuss
Copy link
Contributor

ehuss commented Aug 19, 2025

To be clear, that does parse successfully. For example:

// Parse, but don't process:
#[cfg(false)]
fn f()  {
    let _x = (4,).0x0;
}

// Or via a macro:
macro_rules! m {
    ($e:expr) => {};
}

fn main() {
    m!((4,).0x0);
}

0x0 gives the same error message as 00. Neither is a textual match for 0.

@jieyouxu
Copy link
Member Author

Right... I'll update it to

TUPLE_INDEX -> DEC_LITERAL | BIN_LITERAL | OCT_LITERAL | HEX_LITERAL

like you suggested.

@traviscross traviscross added the S-waiting-on-stabilization Waiting for a stabilization PR to be merged in the main Rust repository label Aug 19, 2025
@traviscross traviscross removed the S-waiting-on-review Status: The marked PR is awaiting review from a maintainer label Aug 19, 2025
This is being proposed to be removed in
<rust-lang/rust#145463> as we never intended for
this to be valid syntax.

Also include an invalid tuple index with underscore example.
@jieyouxu
Copy link
Member Author

Included

let underscore = example.0_0; // ERROR no field `0_0` on type `(&str, &str, &str)`

example.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
S-waiting-on-stabilization Waiting for a stabilization PR to be merged in the main Rust repository
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants