about summary refs log tree commit diff
path: root/library/proc_macro/src
AgeCommit message (Collapse)AuthorLines
2024-07-24Rollup merge of #127733 - GrigorenkoPV:don't-forget, r=AmanieuMatthias Krüger-9/+6
Replace some `mem::forget`'s with `ManuallyDrop` > but I would like to see a larger effort to replace all uses of `mem::forget`. _Originally posted by `@saethlin` in https://github.com/rust-lang/rust/issues/127584#issuecomment-2226087767_ So, r? `@saethlin` Sorry, I have finished writing all of this before I got your response.
2024-07-19Avoid ref when using format! for perfYuri Astrakhan-2/+2
Clean up a few minor refs in `format!` macro, as it has a tiny perf cost. A few more minor related cleanups.
2024-07-15lib: replace some `mem::forget`'s with `ManuallyDrop`Pavel Grigorenko-9/+6
2024-06-19Add a hack to prevent proc_macro misopt in CIGary Guo-1/+3
2024-06-13Remove superfluous escaping from byte, byte str, and c str literalsDavid Tolnay-14/+94
2024-06-05Rollup merge of #123168 - joshtriplett:size-of-prelude, r=AmanieuJubilee-1/+0
Add `size_of` and `size_of_val` and `align_of` and `align_of_val` to the prelude (Note: need to update the PR to add `align_of` and `align_of_val`, and remove the second commit with the myriad changes to appease the lint.) Many, many projects use `size_of` to get the size of a type. However, it's also often equally easy to hardcode a size (e.g. `8` instead of `size_of::<u64>()`). Minimizing friction in the use of `size_of` helps ensure that people use it and make code more self-documenting. The name `size_of` is unambiguous: the name alone, without any prefix or path, is self-explanatory and unmistakeable for any other functionality. Adding it to the prelude cannot produce any name conflicts, as any local definition will silently shadow the one from the prelude. Thus, we don't need to wait for a new edition prelude to add it.
2024-05-30Apply x clippy --fix and x fmtr0cky-4/+4
2024-05-23Rollup merge of #124389 - CensoredUsername:master, r=petrochenkovLeón Orell Valerian Liehr-0/+12
Add a warning to proc_macro::Delimiter::None that rustc currently does not respect it. It does not provide the behaviour it is indicated to provide when used in a proc_macro context. This seems to be a bug, (https://github.com/rust-lang/rust/issues/67062), but it is a long standing one, and hard to discover. This pull request adds a warning to inform users of this issue, with a link to the relevant issue, and a version number of the last known affected rustc version.
2024-05-18Add a warning to Delimiter::None that rustc currently does not respect it.CensoredUsername-0/+12
It does not provide the behaviour it is indicated to provide when used in a proc_macro context.
2024-05-13Add `size_of`, `size_of_val`, `align_of`, and `align_of_val` to the preludeJosh Triplett-1/+0
Many, many projects use `size_of` to get the size of a type. However, it's also often equally easy to hardcode a size (e.g. `8` instead of `size_of::<u64>()`). Minimizing friction in the use of `size_of` helps ensure that people use it and make code more self-documenting. The name `size_of` is unambiguous: the name alone, without any prefix or path, is self-explanatory and unmistakeable for any other functionality. Adding it to the prelude cannot produce any name conflicts, as any local definition will silently shadow the one from the prelude. Thus, we don't need to wait for a new edition prelude to add it. Add `size_of_val`, `align_of`, and `align_of_val` as well, with similar justification: widely useful, self-explanatory, unmistakeable for anything else, won't produce conflicts.
2024-05-01Replace version placeholders for 1.79Mark Rousskov-2/+2
2024-04-22Stabilize generic `NonZero`.Markus Reiter-1/+0
2024-04-16Fix empty-set symbol in commentsDavid Tolnay-1/+1
2024-04-11Call the panic hook for non-unwind panics in proc-macrosBen Kimock-1/+6
2024-04-04Stabilize `Literal::c_string`Slanterns-1/+1
2024-04-04Stabilize `Literal::byte_character`Slanterns-1/+1
2024-03-23proc_macro: simplify bridge statejoboet-135/+61
2024-03-19SeqCst->Relaxed for proc_macro bridge counter.Mara Bos-2/+2
Relaxed is enough here.
2024-03-12Fix typo in lib.rs of proc_macroJonathan Jensen-1/+1
2024-03-04Rollup merge of #120976 - matthiaskrgr:constify_TL_statics, r=lcnrMatthias Krüger-2/+2
constify a couple thread_local statics
2024-03-01Move `HandleStore` into `server.rs`.Nicholas Nethercote-86/+99
This just moves the server-relevant parts of handles into `server.rs`. It introduces a new higher-order macro `with_api_handle_types` to avoid some duplication. This fixes two `FIXME` comments, and makes things clearer, by not having server code in `client.rs`.
2024-02-24Forbid use of `extern "C-unwind"` inside standard libraryGary Guo-0/+1
Those libraries are build with `-C panic=unwind` and is expected to be linkable to `-C panic=abort` library. To ensure unsoundness compiler needs to prevent a `C-unwind` call to exist, as doing so may leak foreign exceptions into `-C panic=abort`.
2024-02-23Auto merge of #121454 - reitermarkus:generic-nonzero-library, r=dtolnaybors-1/+1
Use generic `NonZero` everywhere in `library`. Tracking issue: https://github.com/rust-lang/rust/issues/120257 Use generic `NonZero` everywhere (except stable examples). r? `@dtolnay`
2024-02-22Add `rustc_confusables` annotations to some stdlib APIsEsteban Küber-0/+1
Help with common API confusion, like asking for `push` when the data structure really has `append`. ``` error[E0599]: no method named `size` found for struct `Vec<{integer}>` in the current scope --> $DIR/rustc_confusables_std_cases.rs:17:7 | LL | x.size(); | ^^^^ | help: you might have meant to use `len` | LL | x.len(); | ~~~ help: there is a method with a similar name | LL | x.resize(); | ~~~~~~ ``` #59450
2024-02-22Use generic `NonZero` everywhere else.Markus Reiter-1/+1
2024-02-19Remove `RefMutL` hack in `proc_macro::bridge`Pavel Grigorenko-26/+3
2024-02-16Auto merge of #116385 - kornelski:maybe-rename, r=Amanieubors-1/+1
Rename MaybeUninit::write_slice A step to push #79995 forward. https://github.com/rust-lang/libs-team/issues/122 also suggested to make them inherent methods, but they can't be — they'd conflict with slice's regular methods.
2024-02-16Auto merge of #120486 - reitermarkus:use-generic-nonzero, r=dtolnaybors-10/+11
Use generic `NonZero` internally. Tracking issue: https://github.com/rust-lang/rust/issues/120257
2024-02-15Replace `NonZero::<_>::new` with `NonZero::new`.Markus Reiter-1/+1
2024-02-15Use generic `NonZero` internally.Markus Reiter-10/+11
2024-02-15Add `ErrorGuaranteed` to `ast::LitKind::Err`, `token::LitKind::Err`.Nicholas Nethercote-3/+7
This mostly works well, and eliminates a couple of delayed bugs. One annoying thing is that we should really also add an `ErrorGuaranteed` to `proc_macro::bridge::LitKind::Err`. But that's difficult because `proc_macro` doesn't have access to `ErrorGuaranteed`, so we have to fake it.
2024-02-12constify a couple thread_local staticsMatthias Krüger-2/+2
2024-02-11Rollup merge of #119449 - Nilstrieb:library-clippy, r=cuviperMatthias Krüger-0/+4
Fix `clippy::correctness` in the library needs https://github.com/rust-lang/backtrace-rs/pull/579 to be complete for https://github.com/rust-lang/compiler-team/issues/709
2024-01-31Switch OwnedStore handle count to AtomicU32GnomedDev-10/+10
2024-01-22Document `Token{Stream,Tree}::Display` more thoroughly.Nicholas Nethercote-0/+16
To expressly warn against the kind of proc macro implementation that was broken in #119875.
2024-01-21Fix `clippy::correctness` in the libraryNilstrieb-0/+4
2024-01-16proc_macro_c_str_literals: Implement Literal::c_string constructornovafacing-0/+8
2023-12-11Add support for `--env` on `tracked_env::var`Guillaume Gomez-1/+3
2023-12-11Improve `print_tts` by changing `tokenstream::Spacing`.Nicholas Nethercote-14/+12
`tokenstream::Spacing` appears on all `TokenTree::Token` instances, both punct and non-punct. Its current usage: - `Joint` means "can join with the next token *and* that token is a punct". - `Alone` means "cannot join with the next token *or* can join with the next token but that token is not a punct". The fact that `Alone` is used for two different cases is awkward. This commit augments `tokenstream::Spacing` with a new variant `JointHidden`, resulting in: - `Joint` means "can join with the next token *and* that token is a punct". - `JointHidden` means "can join with the next token *and* that token is a not a punct". - `Alone` means "cannot join with the next token". This *drastically* improves the output of `print_tts`. For example, this: ``` stringify!(let a: Vec<u32> = vec![];) ``` currently produces this string: ``` let a : Vec < u32 > = vec! [] ; ``` With this PR, it now produces this string: ``` let a: Vec<u32> = vec![] ; ``` (The space after the `]` is because `TokenTree::Delimited` currently doesn't have spacing information. The subsequent commit fixes this.) The new `print_tts` doesn't replicate original code perfectly. E.g. multiple space characters will be condensed into a single space character. But it's much improved. `print_tts` still produces the old, uglier output for code produced by proc macros. Because we have to translate the generated code from `proc_macro::Spacing` to the more expressive `token::Spacing`, which results in too much `proc_macro::Along` usage and no `proc_macro::JointHidden` usage. So `space_between` still exists and is used by `print_tts` in conjunction with the `Spacing` field. This change will also help with the removal of `Token::Interpolated`. Currently interpolated tokens are pretty-printed nicely via AST pretty printing. `Token::Interpolated` removal will mean they get printed with `print_tts`. Without this change, that would result in much uglier output for code produced by decl macro expansions. With this change, AST pretty printing and `print_tts` produce similar results. The commit also tweaks the comments on `proc_macro::Spacing`. In particular, it refers to "compound tokens" rather than "multi-char operators" because lifetimes aren't operators.
2023-11-15Bump cfg(bootstrap)sMark Rousskov-2/+2
2023-11-11Rename MaybeUninit::write_sliceKornel-1/+1
#79995
2023-10-08rustdoc: remove rust logo from non-Rust cratesMichael Howell-0/+2
2023-09-26Auto merge of #116124 - WaffleLapkin:fix-proc-macro-literal-to-string, ↵bors-1/+9
r=compiler-errors Properly print cstr literals in `proc_macro::Literal::to_string` Previously we printed the contents of the string, rather than the actual string literal (e.g. `the c string` instead of `c"the c string"`). Fixes #112820 cc #105723
2023-09-24Fix `.to_string()` of `proc_macro::Literal` (properly print cstr literals)Maybe Waffle-1/+9
2023-09-23implement Literal::byte_characterEmil Gardström-0/+7
without this, the only way to create a `LitKind::Byte` is by doing `"b'a'".parse::<Literal>()`, this solves that by enabling `Literal::byte_character(b'a')`
2023-08-23Bump cfg(bootstrap)Mark Rousskov-1/+1
2023-08-16proc_macro: Update docs for `Spacing`Vadim Petrochenkov-13/+25
Brings the docs more in line with reality
2023-08-10Stabilize thread local cell methods.Mara Bos-1/+0
2023-08-03Add `internal_features` lintNilstrieb-0/+1
It lints against features that are inteded to be internal to the compiler and standard library. Implements MCP #596. We allow `internal_features` in the standard library and compiler as those use many features and this _is_ the standard library from the "internal to the compiler and standard library" after all. Marking some features as internal wasn't exactly the most scientific approach, I just marked some mostly obvious features. While there is a categorization in the macro, it's not very well upheld (should probably be fixed in another PR). We always pass `-Ainternal_features` in the testsuite About 400 UI tests and several other tests use internal features. Instead of throwing the attribute on each one, just always allow them. There's nothing wrong with testing internal features^^
2023-07-24Hide `ToString` implementations that specialize the default onesFrank Steffahn-2/+6
The status quo is highly confusing, since the overlap is not apparent, and specialization is not a feature of Rust. This addresses #87545; I'm not certain if it closes it, since that issue might also be trackign a *general* solution for hiding specializing impls automatically.