about summary refs log tree commit diff
path: root/library/alloc/src/macros.rs
AgeCommit message (Collapse)AuthorLines
2025-04-28Streamline the `format` macro.Nicholas Nethercote-2/+1
Removing the unnecessary local variable speeds up compilation a little.
2025-03-07Fully test the alloc crate through alloctestsbjorn3-21/+2
For the tests that make use of internal implementation details, we include the module to test using #[path] in alloctests now.
2025-01-12Update the explanation for why we use box_new in vec!Ben Kimock-2/+2
2025-01-03turn rustc_box into an intrinsicRalf Jung-3/+2
2024-07-06Mark format! with must_use hintlukas-4/+8
2024-06-25Remove `__rust_force_expr`.Nicholas Nethercote-14/+4
This was added (with a different name) to improve an error message. It is no longer needed -- removing it changes the error message, but overall I think the new message is no worse: - the mention of `#` in the first line is a little worse, - but the extra context makes it very clear what the problem is, perhaps even clearer than the old message, - and the removal of the note about the `expr` fragment (an internal detail of `__rust_force_expr`) is an improvement. Overall I think the error is quite clear and still far better than the old message that prompted #61933, which didn't even mention patterns. The motivation for this is #124141, which will cause pasted metavariables to be tokenized and reparsed instead of the AST node being cached. This change in behaviour occasionally has a non-zero perf cost, and `__rust_force_expr` causes the tokenize/reparse step to occur twice. Removing `__rust_force_expr` greatly reduces the extra overhead for the `deep-vector` benchmark.
2023-09-06Update doc for `alloc::format!` and `core::concat!`ShE3py-5/+9
2023-08-28format, format_args: Make xref to std::fmt much more prominentIan Jackson-3/+4
That xref contains the actual documentation for what format! does. It should be very prominent - particularly, more so than the other links.
2023-02-27Remove or justify use of #[rustc_box]Ben Kimock-0/+2
2022-08-21Extra documentation for new formatting featureIsaac Cloos-0/+2
High traffic macros should detail this helpful addition.
2022-07-01update cfg(bootstrap)sPietro Albini-19/+1
2022-06-01Use #[rustc_box] in alloc instead of box syntaxest31-2/+23
2022-05-27Finish bumping stage0Mark Rousskov-1/+1
It looks like the last time had left some remaining cfg's -- which made me think that the stage0 bump was actually successful. This brings us to a released 1.62 beta though.
2022-05-05Allow unused rules in some places in the compiler, library and toolsest31-0/+1
2022-04-16`alloc`: make `vec!` unavailable under `no_global_oom_handling`Miguel Ojeda-2/+2
The `vec!` macro has 3 rules, but two are not usable under `no_global_oom_handling` builds of the standard library (even with a zero size): ```rust let _ = vec![42]; // Error: requires `exchange_malloc` lang_item. let _ = vec![42; 0]; // Error: cannot find function `from_elem`. ``` Thus those two rules should not be available to begin with. The remaining one, with an empty matcher, is just a shorthand for `new()` and may not make as much sense to have alone, since the idea behind `vec!` is to enable `Vec`s to be defined with the same syntax as array expressions. Furthermore, the documentation can be confusing since it shows the other rules. Thus perhaps it is better and simpler to disable `vec!` entirely under `no_global_oom_handling` environments, and let users call `new()` instead: ```rust let _: Vec<i32> = vec![]; let _: Vec<i32> = Vec::new(); ``` Notwithstanding this, a `try_vec!` macro would be useful, such as the one introduced in https://github.com/rust-lang/rust/pull/95051. If the shorthand for `new()` is deemed worth keeping on its own, then it may be interesting to have a separate `vec!` macro with a single rule and different, simpler documentation. Signed-off-by: Miguel Ojeda <ojeda@kernel.org>
2022-01-06Add diagnostic items for macrosAlex Macleod-0/+1
2021-06-30Remove alloc/malloc/calloc/realloc doc aliasesAmanieu d'Antras-2/+0
2021-02-14Only define rustc_diagnostic_item format_macro in not(test).Mara Bos-1/+1
2021-02-14Improve suggestion for panic!(format!(..)).Mara Bos-0/+1
2021-01-22Auto merge of #79233 - yoshuawuyts:alloc-doc-alias, r=GuillaumeGomezbors-0/+2
Add doc aliases for memory allocations This patch adds doc aliases for various C allocation functions, making it possible to search for the C-equivalent of a function and finding the (safe) Rust counterpart: - `Vec::with_capacity` / `Box::new` / `vec!` -> alloc + malloc, allocates memory - `Box::new_zeroed` -> calloc, allocates zeroed-out memory - `Vec::{reserve,reserve_exact,try_reserve_exact,shrink_to_fit,shrink_to}` -> realloc, reallocates a previously allocated slice of memory It's worth noting that `Vec::new` does not allocate, so we don't link to it. Instead people are probably looking for `Vec::with_capacity` or `vec!`. I hope this will allow people comfortable with the system allocation APIs to make it easier to find what they may be looking for. Thanks!
2021-01-22Add doc aliases for memory allocationsYoshua Wuyts-0/+2
- Vec::with_capacity / Box::new -> alloc + malloc - Box::new_zeroed -> calloc - Vec::{reserve,reserve_exact,try_reserve_exact,shrink_to_fit,shrink_to} -> realloc
2021-01-21Rename alloc::force_expr to __rust_force_expr.Mara Bos-4/+4
2021-01-21Turn alloc's force_expr macro into a regular macro_rules!{}.Mara Bos-3/+13
Otherwise rust-analyzer doesn't understand vec![].
2021-01-17Force vec! to expressions onlyDániel Buga-4/+4
2020-12-11doc: apply suggestionsWilliam Woodruff-2/+3
2020-12-10doc(array,vec): add notes about side effects when empty-initializingWilliam Woodruff-0/+3
2020-10-31Fix doc links to std::fmtIvan Pavluk-2/+2
std::format and core::write macros' docs linked to core::fmt for format string reference, even though only std::fmt has format string documentation and the link titles were std::fmt.
2020-08-21Use intra-doc-links in `alloc`LeSeulArtichaut-6/+5
2020-07-27mv std libs to library/mark-0/+110