The std prelude contains quite a number of macros, not all of them frequently used. I believe the reason for this is that prior to Edition 2018 there wasn't a good way to import macros on an as-needed basis.
Some of these macros are widely used and should remain in the prelude:
Other macros are less frequently used, but at least are unlikely to be confused with anything else:
A few are potentially a bit more confusing and not commonly used:
column! may be confused with e.g.
iced::widget::column! (I am planning to introduce a macro by the same to KAS). As a consequence of this existing in the std prelude, attempting to use the widget-constructing macro without a matching import yields a slightly confusing error:
error: column! takes no arguments, while importing the latter macro with a glob-import is insufficient (ambiguous usage).
- Pick a set of confusing rarely used macros for removal from the std prelude.
- Deprecate usage of these macros through the prelude.
- From Edition 2024 (or a later edition if necessary) remove these from the prelude.
These macros technically aren't in the prelude currently. Rather, they're made available by the fact std (or core) is injected with a
I previously filed an ACP to make them also available in the proper prelude, which was accepted, but haven't gotten around to making a PR to do so yet.
It's a conflict, yes, but I don't see why
std is the one who should change. There definitely are uses of
std::column! in the wild -- some prefixed like that, but many not: github search
This is a macro that has been available since Rust 1.0. (And before that, in 0.12 it was called
col!) IMO the onus is on iced and others to differentiate if the overlap is causing problems.
We should absolutely be cautious about adding new macros in privileged prelude/
#[macro_use] positions, but I see no value in churning the old ones out.
I find the argument weird. Not only has the std macros existed since 1.0, iced isn't even some widely used or foundational dependency. Why should std change to accommodate it? The macros you listed aren't very common, but neither are they something super obscure. I've definitely used
column!, for example, in various debug macros.
That said, the diagnostics could indeed be improved. For example, the error could use a fully qualified name
::std::column! instead of just
column!, or suggest using the
iced::widget::column! macro (the latter can be difficult to implement, since in general macros don't provide information on the permissible syntax of their contents).
Thanks folks. I agree that
std should have precedence in case of conflict. On the other hand, I don't know that
column! without prefix is used all that much to refer to
std::column! (in @cuviper's search above, at least half the actual usages appear to be for some form of UI, not position in the source file, while a number just appear to be listings of macros).
I'm more concerned about confusion and agree that an improved diagnostic could help here.
This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.