Stream: t-libs

Topic: format! can address named arguments by position


Amanieu (Feb 12 2020 at 10:42, on Zulip):

While implementing asm! I noticed that it is possible for format strings to address named argument by position: println!("{0} {foo}", foo = 2); prints 2 2.

Amanieu (Feb 12 2020 at 10:42, on Zulip):

Is this intentional? The fmt documentation doesn't explicitly say that it isn't allowed, but it feels like it should be...

Amanieu (Feb 12 2020 at 11:09, on Zulip):

cc @Alex Crichton @Esteban Küber

simulacrum (Feb 12 2020 at 14:04, on Zulip):

It is not valid to put positional parameters (those without names) after arguments which have names.

Is the only discussion I see in the docs about this

simulacrum (Feb 12 2020 at 14:04, on Zulip):

My guess is that it's unintentional but also unchangeable at this point

Amanieu (Feb 12 2020 at 14:12, on Zulip):

If it's unintentional then we could add a warning for it (maybe even a deny-by-default lint).

Amanieu (Feb 12 2020 at 14:13, on Zulip):

I'm mainly asking because I'm working on asm! and wondering whether I should emulate this behavior.

simulacrum (Feb 12 2020 at 14:14, on Zulip):

I think we should keep them consistent. I personally think positional arguments were probably a mistake (as a user-facing detail), and we could warn on this I guess, though I don't know that there's much point.

Alex Crichton (Feb 12 2020 at 16:23, on Zulip):

That behavior feels surprising to me, I suspect it was an accident

Amanieu (Feb 12 2020 at 17:05, on Zulip):

A quick bisects shows that this was actually rejected until 1.12.0, which started accepting it.

Amanieu (Feb 12 2020 at 17:07, on Zulip):

Possibly introduced by #33642

Esteban Küber (Feb 12 2020 at 21:11, on Zulip):

I would file a ticket to lint on this, I would assume that starting to reject these outright would lead to widespread breakage

Amanieu (Feb 12 2020 at 21:16, on Zulip):

I opened #69110 for this

Steven Fackler (Feb 12 2020 at 21:40, on Zulip):

seems pretty reasonable to at least run crater to see if changing it's clearly not possible at this point

Last update: Feb 25 2020 at 04:00UTC