Commit Graph

191 Commits

Author SHA1 Message Date
Yuri Astrakhan
91275b2c2b Avoid ref when using format! for perf
Clean up a few minor refs in `format!` macro, as it has a tiny perf
cost. A few more minor related cleanups.
2024-07-19 12:23:49 -04:00
Gary Guo
da8ac73d91 Add a hack to prevent proc_macro misopt in CI 2024-06-19 13:54:55 +01:00
David Tolnay
7ddc89e893
Remove superfluous escaping from byte, byte str, and c str literals 2024-06-13 09:49:15 -07:00
Jubilee
9ccc7b78ec
Rollup merge of #123168 - joshtriplett:size-of-prelude, r=Amanieu
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-06-05 01:14:29 -07:00
r0cky
dabd05bbab Apply x clippy --fix and x fmt 2024-05-30 09:51:27 +08:00
León Orell Valerian Liehr
f862f6d292
Rollup merge of #124389 - CensoredUsername:master, r=petrochenkov
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-23 20:09:08 +02:00
CensoredUsername
c2d2df182a Add a warning to 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.
2024-05-18 01:41:45 +02:00
Josh Triplett
a5a60d75a8 Add size_of, size_of_val, align_of, and align_of_val to the prelude
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-13 15:11:28 +02:00
Mark Rousskov
bd7d328807 Replace version placeholders for 1.79 2024-05-01 21:01:51 -04:00
Markus Reiter
33e68aadc9
Stabilize generic NonZero. 2024-04-22 18:48:47 +02:00
David Tolnay
e480cabe3a
Fix empty-set symbol in comments 2024-04-16 18:19:27 -07:00
Ben Kimock
d8dc28b93e Call the panic hook for non-unwind panics in proc-macros 2024-04-11 17:46:12 -04:00
Slanterns
fbc56dfac1
Stabilize Literal::c_string 2024-04-04 05:04:27 +08:00
Slanterns
61ac7812c6
Stabilize Literal::byte_character 2024-04-04 05:00:49 +08:00
joboet
ac770f7bd5
proc_macro: simplify bridge state 2024-03-23 12:15:11 +01:00
Mara Bos
bf3debe9d7 SeqCst->Relaxed for proc_macro bridge counter.
Relaxed is enough here.
2024-03-19 15:27:11 +01:00
Jonathan Jensen
34e59f49d5 Fix typo in lib.rs of proc_macro 2024-03-12 13:35:14 +01:00
Matthias Krüger
706fe0b7d8
Rollup merge of #120976 - matthiaskrgr:constify_TL_statics, r=lcnr
constify a couple thread_local statics
2024-03-04 22:16:30 +01:00
Nicholas Nethercote
392159b561 Move HandleStore into server.rs.
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-03-01 16:30:26 +11:00
Gary Guo
f08e2d4137 Forbid use of extern "C-unwind" inside standard library
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-24 14:53:04 +00:00
bors
b6a23b8537 Auto merge of #121454 - reitermarkus:generic-nonzero-library, r=dtolnay
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-23 14:27:33 +00:00
Esteban Küber
e5b3c7ef14 Add rustc_confusables annotations to some stdlib APIs
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-22 18:04:55 +00:00
Markus Reiter
0c474acdfa
Use generic NonZero everywhere else. 2024-02-22 15:17:34 +01:00
Pavel Grigorenko
5be3d4bee4
Remove RefMutL hack in proc_macro::bridge 2024-02-19 17:39:25 +03:00
bors
ae9d7b0c64 Auto merge of #116385 - kornelski:maybe-rename, r=Amanieu
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-16 14:11:10 +00:00
bors
1be468815c Auto merge of #120486 - reitermarkus:use-generic-nonzero, r=dtolnay
Use generic `NonZero` internally.

Tracking issue: https://github.com/rust-lang/rust/issues/120257
2024-02-16 07:46:31 +00:00
Markus Reiter
a90cc05233
Replace NonZero::<_>::new with NonZero::new. 2024-02-15 08:09:42 +01:00
Markus Reiter
746a58d435
Use generic NonZero internally. 2024-02-15 08:09:42 +01:00
Nicholas Nethercote
25ed6e43b0 Add ErrorGuaranteed to ast::LitKind::Err, token::LitKind::Err.
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-15 14:46:08 +11:00
Matthias Krüger
d0873c7a11 constify a couple thread_local statics 2024-02-12 16:25:39 +01:00
Matthias Krüger
0c5d8d3d3e
Rollup merge of #119449 - Nilstrieb:library-clippy, r=cuviper
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-02-11 08:25:42 +01:00
GnomedDev
3cc601ac7e
Switch OwnedStore handle count to AtomicU32 2024-01-31 13:36:37 +00:00
Nicholas Nethercote
c4fc9ff0d3 Document Token{Stream,Tree}::Display more thoroughly.
To expressly warn against the kind of proc macro implementation that was
broken in #119875.
2024-01-22 13:31:52 +11:00
Nilstrieb
e55716e20e Fix clippy::correctness in the library 2024-01-21 14:14:10 +01:00
novafacing
ee007ab187 proc_macro_c_str_literals: Implement Literal::c_string constructor 2024-01-16 13:27:58 -08:00
Guillaume Gomez
6ce2fefea6 Add support for --env on tracked_env::var 2023-12-11 16:44:33 +01:00
Nicholas Nethercote
925f7fad57 Improve print_tts by changing tokenstream::Spacing.
`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-12-11 09:19:09 +11:00
Mark Rousskov
db3e2bacb6 Bump cfg(bootstrap)s 2023-11-15 19:41:28 -05:00
Kornel
da3db9a4f7 Rename MaybeUninit::write_slice
#79995
2023-11-11 22:54:07 +00:00
Michael Howell
c6e6ecb1af rustdoc: remove rust logo from non-Rust crates 2023-10-08 20:17:53 -07:00
bors
a6dce3bac5 Auto merge of #116124 - WaffleLapkin:fix-proc-macro-literal-to-string, 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-26 03:39:25 +00:00
Maybe Waffle
285e574b8e Fix .to_string() of proc_macro::Literal (properly print cstr literals) 2023-09-24 20:05:27 +00:00
Emil Gardström
74f5261345
implement Literal::byte_character
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-09-23 23:29:47 +02:00
Mark Rousskov
0a916062aa Bump cfg(bootstrap) 2023-08-23 20:05:14 -04:00
Vadim Petrochenkov
176a9392d1 proc_macro: Update docs for Spacing
Brings the docs more in line with reality
2023-08-16 19:00:51 +08:00
Mara Bos
dc3cbc1e56 Stabilize thread local cell methods. 2023-08-10 17:33:40 +02:00
Nilstrieb
5830ca216d Add internal_features lint
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-08-03 14:50:50 +02:00
Frank Steffahn
3911a63b77 Hide ToString implementations that specialize the default ones
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.
2023-07-24 23:37:35 +09:00
Jacob Pratt
abd0677d2f
Merge proc_macro_span_shrink and proc_macro_span 2023-06-20 19:40:26 -04:00
Jacob Pratt
a1cd8c3a28
Add Span::{line, column} 2023-06-20 19:40:25 -04:00