macros_in_submodules
)We propose we re-export the macros exposed in the stdlib's root from their logical sub-modules too. Additionally we define an initial mapping of the macros to submodules.
Right now the Rust stdlib exports over 70 macros, most of which exist only in the crate root - despite providing a wide range of functionality. Ideally this functionality should be exposed from subcrates, but that was not possible up until recently.
This however, recently changed, and it now is possible to expose macros from submodules. This RFC proposed we do exactly that: export macros from submodules.
Explain the proposal as if it was already included in the language and you were teaching it to another Rust programmer. That generally means:
For implementation-oriented RFCs (e.g. for compiler internals), this section should focus on how compiler contributors should think about the change, and give examples of its concrete impact. For policy RFCs, this section should provide an example-driven introduction to the policy, and explain its impact in concrete terms.
This is the technical portion of the RFC. Explain the design in sufficient detail that:
The section should return to the examples given in the previous section, and explain more fully how the detailed proposal makes those examples work.
Why should we not do this?
Discuss prior art, both the good and the bad, in relation to this proposal.
A few examples of what this can include are:
This section is intended to encourage you as an author to think about the lessons from other languages, provide readers of your RFC with a fuller picture.
If there is no prior art, that is fine - your ideas are interesting to us whether they are brand new or if it is an adaptation from other languages.
Note that while precedent set by other languages is some motivation, it does not on its own motivate an RFC.
Please also take into consideration that rust sometimes intentionally diverges from common language features.
Hey all, this is a first stab at mapping the macros on std
root to their respective submodules. I figured if we get to an RFC this might be one of the bigger topics to be discussed, so I figured I'd front load it before writing more of the RFC text.
Roughly my ideas was to try and move as many macros to submodules as possible. The only ones where it doesn't make sense is for items which I'd squarely classify as "lang". But even then there might be some wiggle room (see the "notes" column).
Anyway, feel free to comment on this HackMD!
Macro name | Proposed mod | Notes |
---|---|---|
assert |
std::assert |
New submodule: assert |
assert_eq |
std::assert |
New submodule: assert |
assert_matches::assert_matches |
std::assert |
Unstable, New submodule: assert |
assert_matches::debug_assert_matches |
std::assert |
Unstable, New submodule: assert |
assert_ne |
std::assert |
New submodule: assert |
cfg |
std |
Lang construct |
clone::Clone |
std::clone |
Derive attribute |
cmp::Eq |
std::cmp |
Derive attribute |
cmp::Ord |
std::cmp |
Derive attribute |
cmp::PartialEq |
std::cmp |
Derive attribute |
cmp::PartialOrd |
std::cmp |
Derive attribute |
column |
std |
Should this be std::env ? |
compile_error |
std |
Lang construct |
concat |
std |
Operates on str |
concat_bytes |
std |
Unstable |
concat_idents |
std |
Unstable |
const_format_args |
std |
Unstable |
dbg |
std::io |
Operates on std::io::stdout |
debug_assert |
std::assert |
New submodule: assert |
debug_assert_eq |
std::assert |
New submodule: assert |
debug_assert_ne |
std::assert |
New submodule: assert |
default::Default |
std::default |
Derive attribute |
env |
std::env |
Operates on env during compilation |
eprint |
std::io |
Operates on std::io::stderr |
eprintln |
std::io |
Operates on std::io::stderr |
file |
std::fs |
Should this be in std::env ? |
fmt::Debug |
std |
Proc attribute |
format |
std::fmt |
Formats arguments |
format_args |
std::fmt |
Formats arguments |
format_args_nl |
std::fmt |
Unstable |
future::join |
std |
Unstable, already there! |
hash::Hash |
std |
Derive attribute |
include |
std::fs |
Performs file reads during compilation |
include_bytes |
std::fs |
Performs file reads during compilation |
include_str |
std::fs |
Performs file reads during compilation |
is_aarch64_feature_detected |
std::arch |
Unstable |
is_arm_feature_detected |
std::arch |
Unstable |
is_mips64_feature_detected |
std::arch |
Unstable |
is_mips_feature_detected |
std::arch |
Unstable |
is_powerpc64_feature_detected |
std::arch |
Unstable |
is_powerpc_feature_detected |
std::arch |
Unstable |
is_riscv_feature_detected |
std::arch |
Unstable |
is_x86_feature_detected |
std::arch |
Unstable |
line |
std |
Should this be in std::env ? |
llvm_asm |
std |
Unstable, soon to be removed |
log_syntax |
std |
Unstable |
marker::Copy |
std::marker |
Proc attribute |
matches |
std |
This feels like it's a core thing |
module_path |
std |
Should this be in std::env ? |
option_env |
std::env |
Inspects the env during compilation |
panic |
std::panic |
Panics |
prelude::v1::bench |
std::prelude::v1 |
Prelude |
prelude::v1::cfg_accessible |
std::prelude::v1 |
Prelude |
prelude::v1::cfg_eval |
std::prelude::v1 |
Prelude |
prelude::v1::derive |
std::prelude::v1 |
Prelude |
prelude::v1::global_allocator |
std::prelude::v1 |
Prelude |
prelude::v1::test |
std::prelude::v1 |
Prelude |
prelude::v1::test_case |
std::prelude::v1 |
Prelude |
print |
std::io |
Operates on std::io::stdout |
println |
std::io |
Operates on std::io::stdout |
ptr::addr_of |
std::ptr |
Already there! |
ptr::addr_of_mut |
std::ptr |
Already there! |
simd::simd_swizzle |
std::simd |
Unstable, Already there! |
stringify |
std |
Should this be in proc_macro:: ? |
task::ready |
std::task |
Unstable, likely to be removed |
thread_local |
std::thread |
Operates on threads |
todo |
std::panic |
Panics |
trace_macros |
std |
Unstable |
try |
std |
Lang item, Deprecated |
unimplemented |
std::panic |
Panics |
unreachable |
std::panic |
Panics |
vec |
std::vec |
Creates a vec |
write |
std::io , std::fmt |
Used in both std::fmt and std::io |
writeln |
std::io , std::fmt |
Used in both std::fmt and std::io |
write
/ writeln
. Both are the same, both used in std::fmt
and std::io
.assert
and todo
could potentially be subject to changes, so maybe let's not lock them in?