Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Named format arguments introduce implicit positional arguments #93378

Closed
Veetaha opened this issue Jan 27, 2022 · 9 comments · Fixed by #93394
Closed

Named format arguments introduce implicit positional arguments #93378

Veetaha opened this issue Jan 27, 2022 · 9 comments · Fixed by #93394
Assignees
Labels
A-fmt Area: `std::fmt` C-bug Category: This is a bug. P-critical Critical priority T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. T-lang Relevant to the language team, which will review and decide on the PR/issue. T-libs-api Relevant to the library API team, which will review and decide on the PR/issue.

Comments

@Veetaha
Copy link
Contributor

Veetaha commented Jan 27, 2022

I tried this code:

fn main() {
    let a = "a";
    let b = "b";
    
    println!("{a} {b} {} {} {c} {}", c = "c");
}

I expected to see a compile error that says that there are missing positional arguments or that it is prohibited to mix positional and named parameters.

Instead, this compiles and prints the following:

a b c a c b

This code is available on the playground.

Meta

rustc --version --verbose:

rustc 1.58.1 (db9d1b20b 2022-01-20)
binary: rustc
commit-hash: db9d1b20bba1968c1ec1fc49616d4742c1725b4b
commit-date: 2022-01-20
host: x86_64-unknown-linux-gnu
release: 1.58.1
LLVM version: 13.0.0
@Veetaha Veetaha added the C-bug Category: This is a bug. label Jan 27, 2022
@matthiaskrgr
Copy link
Member

@rustbot prioritize

@rustbot rustbot added the I-prioritize Issue: Indicates that prioritization has been requested for this issue. label Jan 27, 2022
@camelid camelid added A-fmt Area: `std::fmt` T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. T-lang Relevant to the language team, which will review and decide on the PR/issue. T-libs-api Relevant to the library API team, which will review and decide on the PR/issue. I-lang-nominated Nominated for discussion during a lang team meeting. labels Jan 27, 2022
@m-ou-se
Copy link
Member

m-ou-se commented Jan 27, 2022

Oh dear. We should fix this quickly, before any code starts depending on this.

@KamilaBorowska
Copy link
Contributor

println!("{c} {}", c = "c") appears to be valid since Rust 1.12.

@m-ou-se m-ou-se self-assigned this Jan 27, 2022
@m-ou-se
Copy link
Member

m-ou-se commented Jan 27, 2022

println!("{c} {}", c = "c") appears to be valid since Rust 1.12.

Yes, but that's not as bad, and arguably the right thing. The problem we should fix is the implicit captures getting used for {}.

@m-ou-se
Copy link
Member

m-ou-se commented Jan 27, 2022

This should fix it: #93394

@CAD97
Copy link
Contributor

CAD97 commented Jan 28, 2022

I just ran into this as well and reported #93415; I've tightened that one to just the fact that named arguments count as positional, so discussion on that can happen there.

@Nemo157
Copy link
Member

Nemo157 commented Jan 28, 2022

Also see previously #69110 and #45256 for discussion about non-capture named arguments introducing positional arguments.

@camelid camelid added P-critical Critical priority and removed I-prioritize Issue: Indicates that prioritization has been requested for this issue. labels Jan 29, 2022
@camelid
Copy link
Member

camelid commented Jan 29, 2022

Assigning priority as discussed in the prioritization working group.

@joshtriplett
Copy link
Member

We discussed this in today's @rust-lang/lang meeting, and we agreed that 1) we'd like this to stop being accepted, ASAP, and 2) we don't consider the PR fixing this to need T-lang review or approval.

@Mark-Simulacrum Mark-Simulacrum removed the I-lang-nominated Nominated for discussion during a lang team meeting. label Feb 1, 2022
m-ou-se added a commit to m-ou-se/rust that referenced this issue Feb 7, 2022
Don't allow {} to refer to implicit captures in format_args.

Fixes rust-lang#93378
@bors bors closed this as completed in 4445a8f Feb 7, 2022
ehuss pushed a commit to ehuss/rust that referenced this issue Feb 10, 2022
Don't allow {} to refer to implicit captures in format_args.

Fixes rust-lang#93378
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-fmt Area: `std::fmt` C-bug Category: This is a bug. P-critical Critical priority T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. T-lang Relevant to the language team, which will review and decide on the PR/issue. T-libs-api Relevant to the library API team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

10 participants