Change:
says: ... which isn't exactly where the was expected. () Another variation is this code: which gives this result: ()
Hello, I am a quite new contributor, and I'd like to tackle this issue. Do you think that is possible? I have looked a bit at the code, and I think this mostly comes from the [] function, more precisely, [this condition][cond] can be tweaked. Is that correct? []: [cond]:
Turns out I was terribly wrong. The problem is that the following snippet: Can be rewritten as: And that the [] function looks for an expression as the first argument ([corresponding code][expression], [code example][snippet]). Consequently, is the said expression, which explain why the error is raised on the first . Now that I know where the error comes from. I think the best way to fix this issue is to check if this expression can be a format string, perhaps with the [] function. I am still unsure about the quality of the emitted error, but at least it would have the correct span. []: [expression]: [snippet]: []:

Discussion:
return Err(ecx.struct_span_err(sp, "requires at least a format string argument")); } <del> let fmtstr = p.parse_expr()?; </del> <ins> let first_token = &p.token; let fmtstr = match first_token.kind { token::TokenKind::Literal(token::Lit { kind: token::LitKind::Str | token::LitKind::StrRaw(_), .. }) => { // If the first token is a string literal, then a format expression // is constructed from it. // // This allows us to properly handle cases when the first comma // after the format string is mistakenly replaced with any operator, // which cause the expression parser to eat too much tokens. p.parse_literal_maybe_minus()? } _ => { // Otherwise, we fall back to the expression parser. p.parse_expr()? } }; </ins> let mut first = true; let mut named = false;

/// Matches `'-' lit | lit` (cf. `ast_validation::AstValidator::check_expr_within_pat`). /// Keep this in sync with `Token::can_begin_literal_maybe_minus`. <del> pub(super) fn parse_literal_maybe_minus(&mut self) -> PResult<'a, P<Expr>> { </del> <ins> pub fn parse_literal_maybe_minus(&mut self) -> PResult<'a, P<Expr>> { </ins> maybe_whole_expr!(self); let lo = self.token.span;

<ins> // Allows to track issue #75492: // https://github.com/rust-lang/rust/issues/75492 use std::iter; fn main() { format!("A number: {}". iter::once(42).next().unwrap()); //~^ ERROR expected token: `,` // Other kind of types are also checked: format!("A number: {}" / iter::once(42).next().unwrap()); //~^ ERROR expected token: `,` format!("A number: {}"; iter::once(42).next().unwrap()); //~^ ERROR expected token: `,` // Note: this character is an COMBINING COMMA BELOW unicode char format!("A number: {}" ̦ iter::once(42).next().unwrap()); //~^ ERROR expected token: `,` //~^^ ERROR unknown start of token: u{326} } </ins>

<ins> error: unknown start of token: u{326} --> $DIR/incorrect-first-separator.rs:19:28 | LL |     format!("A number: {}" ̦ iter::once(42).next().unwrap()); |                            ^ error: expected token: `,` --> $DIR/incorrect-first-separator.rs:7:27 | LL |     format!("A number: {}". iter::once(42).next().unwrap()); |                           ^ expected `,` error: expected token: `,` --> $DIR/incorrect-first-separator.rs:12:28 | LL |     format!("A number: {}" / iter::once(42).next().unwrap()); |                            ^ expected `,` error: expected token: `,` --> $DIR/incorrect-first-separator.rs:15:27 | LL |     format!("A number: {}"; iter::once(42).next().unwrap()); |                           ^ expected `,` error: expected token: `,` --> $DIR/incorrect-first-separator.rs:19:30 | LL |     format!("A number: {}" ̦ iter::once(42).next().unwrap()); |                             ^^^^ expected `,` error: aborting due to 5 previous errors </ins>