110 Commits

Author SHA1 Message Date
Nicholas Nethercote 3ce3436fd6 Disallow ZST allocations with TypedArena.
`DroplessArena::alloc` already disallows ZST allocation.
`TypedArena::alloc` allows it but:
- (a) it's never used, and
- (b) writing to `NonNull::dangling()` seems dubious, even if the write
  is zero-sized.

This commit just changes it to panic on a ZST. This eliminates an
untested code path, and we shouldn't be allocating ZSTs anyway.
It also eliminates an unused ZST code path in `clear_last_chunk`.
Tests are also updated accordingly.
2026-04-15 20:03:07 +10:00
Ben Kimock ff6191588a Use Vec::push_mut when adding a chunk to arenas 2026-04-11 12:58:21 -04:00
Zalathar 118372ed13 Replace some feature(core_intrinsics) with stable hints 2026-02-08 18:21:47 +11:00
Zalathar e60c475471 Remove unused method DroplessArena::contains_slice 2026-01-31 22:56:49 +11:00
Zalathar 363d3ac438 Document a safety condition for TypedArena::alloc_raw_slice 2026-01-29 23:40:38 +11:00
Zalathar 21c99d3ad9 Fix some typos of "similarity" 2026-01-29 23:40:37 +11:00
Martin Nordholts 8e3d60447c Finish transition from semitransparent to semiopaque for rustc_macro_transparency 2026-01-08 19:14:45 +01:00
Boxy Uwu 2ffb1d55ef Handle bootstrap cfgs 2025-12-19 15:04:30 -08:00
bendn d67f99af2e fix 2025-11-27 17:55:34 +07:00
bjorn3 222480dcb9 Allow internal_features lint in doc tests
Rustdoc forwards -Zcrate-attr=feature(rustdoc_internals) to doc tests,
but deny(warnings) overrides the -Ainternal_features.
2025-11-05 11:25:29 +00:00
bjorn3 973c7527b4 Unify the configuration of the compiler docs
Previously it was rather inconsistent which crates got the rust logo and
which didn't and setting html_root_url was forgotten in many cases.
2025-11-05 11:25:27 +00:00
Kivooeo dc05250c2f some cleanups in compiler 2025-10-12 08:08:30 +00:00
Camille GILLOT d0d3021bf8 Introduce Arena::try_alloc_from_iter. 2025-04-19 01:13:18 +00:00
Nicholas Nethercote ff0a5fe975 Remove #![warn(unreachable_pub)] from all compiler/ crates.
It's no longer necessary now that `-Wunreachable_pub` is being passed.
2025-03-11 13:14:21 +11:00
许杰友 Jieyou Xu (Joe) 063ef18fdc Revert "Use workspace lints for crates in compiler/ #138084"
Revert <https://github.com/rust-lang/rust/pull/138084> to buy time to
consider options that avoids breaking downstream usages of cargo on
distributed `rustc-src` artifacts, where such cargo invocations fail due
to inability to inherit `lints` from workspace root manifest's
`workspace.lints` (this is only valid for the source rust-lang/rust
workspace, but not really the distributed `rustc-src` artifacts).

This breakage was reported in
<https://github.com/rust-lang/rust/issues/138304>.

This reverts commit 48caf81484, reversing
changes made to c6662879b2.
2025-03-10 18:12:47 +08:00
Matthias Krüger 48caf81484 Rollup merge of #138084 - nnethercote:workspace-lints, r=jieyouxu
Use workspace lints for crates in `compiler/`

This is nicer and hopefully less error prone than specifying lints via bootstrap.

r? ``@jieyouxu``
2025-03-09 10:34:50 +01:00
Nicholas Nethercote 8a3e03392e Remove #![warn(unreachable_pub)] from all compiler/ crates.
(Except for `rustc_codegen_cranelift`.)

It's no longer necessary now that `unreachable_pub` is in the workspace
lints.
2025-03-08 08:41:43 +11:00
Nicholas Nethercote beba32cebb Specify rust lints for compiler/ crates via Cargo.
By naming them in `[workspace.lints.rust]` in the top-level
`Cargo.toml`, and then making all `compiler/` crates inherit them with
`[lints] workspace = true`. (I omitted `rustc_codegen_{cranelift,gcc}`,
because they're a bit different.)

The advantages of this over the current approach:
- It uses a standard Cargo feature, rather than special handling in
  bootstrap. So, easier to understand, and less likely to get
  accidentally broken in the future.
- It works for proc macro crates.

It's a shame it doesn't work for rustc-specific lints, as the comments
explain.
2025-03-08 08:41:09 +11:00
Thalia Archibald 38fad984c6 compiler: Use size_of from the prelude instead of imported
Use `std::mem::{size_of, size_of_val, align_of, align_of_val}` from the
prelude instead of importing or qualifying them.

These functions were added to all preludes in Rust 1.80.
2025-03-07 13:37:04 -08:00
Michael Goulet 76d341fa09 Upgrade the compiler to edition 2024 2025-02-22 00:01:48 +00:00
ltdk e37daf0c86 Add inherent versions of MaybeUninit methods for slices 2025-01-11 23:57:00 -05:00
Ralf Jung 56ee492a6e move strict provenance lints to new feature gate, remove old feature gates 2024-10-21 15:22:17 +01:00
Nicholas Nethercote 65863c5e75 Remove unnecessary lifetimes from Arena. 2024-09-13 15:33:19 +10:00
Jubilee Young 2535a0f776 compiler: Remove feature(new_uninit) 2024-08-27 10:17:05 -07:00
Nicholas Nethercote f839309c74 Add warn(unreachable_pub) to rustc_arena. 2024-08-16 08:46:22 +10:00
Nicholas Nethercote 84ac80f192 Reformat use declarations.
The previous commit updated `rustfmt.toml` appropriately. This commit is
the outcome of running `x fmt --all` with the new formatting options.
2024-07-29 08:26:52 +10:00
Nicholas Nethercote 75b164d836 Use tidy to sort crate attributes for all compiler crates.
We already do this for a number of crates, e.g. `rustc_middle`,
`rustc_span`, `rustc_metadata`, `rustc_span`, `rustc_errors`.

For the ones we don't, in many cases the attributes are a mess.
- There is no consistency about order of attribute kinds (e.g.
  `allow`/`deny`/`feature`).
- Within attribute kind groups (e.g. the `feature` attributes),
  sometimes the order is alphabetical, and sometimes there is no
  particular order.
- Sometimes the attributes of a particular kind aren't even grouped
  all together, e.g. there might be a `feature`, then an `allow`, then
  another `feature`.

This commit extends the existing sorting to all compiler crates,
increasing consistency. If any new attribute line is added there is now
only one place it can go -- no need for arbitrary decisions.

Exceptions:
- `rustc_log`, `rustc_next_trait_solver` and `rustc_type_ir_macros`,
  because they have no crate attributes.
- `rustc_codegen_gcc`, because it's quasi-external to rustc (e.g. it's
  ignored in `rustfmt.toml`).
2024-06-12 15:49:10 +10:00
Ralf Jung b58f647d54 rename ptr::invalid -> ptr::without_provenance
also introduce ptr::dangling matching NonNull::dangling
2024-02-21 20:15:52 +01:00
Nicholas Nethercote 0ac1195ee0 Invert diagnostic lints.
That is, change `diagnostic_outside_of_impl` and
`untranslatable_diagnostic` from `allow` to `deny`, because more than
half of the compiler has be converted to use translated diagnostics.

This commit removes more `deny` attributes than it adds `allow`
attributes, which proves that this change is warranted.
2024-02-06 13:12:33 +11:00
Oli Scherer 61361c16aa Fix Stable trait and its impls to work with the new with_tables 2024-01-19 09:42:51 +00:00
Josh Stone 92bf40ffe3 rustc_arena: add alloc_str
Two places called `from_utf8_unchecked` for strings from `alloc_slice`,
and one's SAFETY comment said this was for lack of `alloc_str` -- so
let's just add that instead!
2023-12-05 17:52:51 -08:00
Nadrieril c1774a137d Document reentrancy in *Arena::alloc_from_iter 2023-12-04 02:24:10 +01:00
Mark Rousskov db3e2bacb6 Bump cfg(bootstrap)s 2023-11-15 19:41:28 -05:00
Nicholas Nethercote 8ff624a9f2 Clean up rustc_*/Cargo.toml.
- Sort dependencies and features sections.
- Add `tidy` markers to the sorted sections so they stay sorted.
- Remove empty `[lib`] sections.
- Remove "See more keys..." comments.

Excluded files:
- rustc_codegen_{cranelift,gcc}, because they're external.
- rustc_lexer, because it has external use.
- stable_mir, because it has external use.
2023-10-30 08:46:02 +11:00
Maybe Waffle e36224118f Stabilize [const_]pointer_byte_offsets 2023-10-25 22:35:12 +00:00
Michael Howell c6e6ecb1af rustdoc: remove rust logo from non-Rust crates 2023-10-08 20:17:53 -07:00
Nicholas Nethercote 816383c60d Remove the TypedArena::alloc_from_iter specialization.
It was added in #78569. It's complicated and doesn't actually help
performance.

Also, add a comment explaining why the two `alloc_from_iter` functions
are so different.
2023-10-03 18:12:08 +11:00
Nicholas Nethercote bb5344a1bf Inline and remove DroplessArena::alloc_raw_without_grow.
It has a single call site. I find the code clearer with it gone.
2023-09-28 17:58:56 +10:00
Nicholas Nethercote 55a1a5223a Reduce grow_and_alloc_raw to a single call site.
The current structure is clumsy, calling `alloc_raw_without_grow` in one
function, and then if that fails, calling another function that calls
`alloc_raw_without_grow` again.
2023-09-28 17:58:54 +10:00
Nicholas Nethercote 25407bc0bb Make DroplessArena::alloc call DroplessArena::alloc_raw.
They're very similar.
2023-09-28 15:44:48 +10:00
Nicholas Nethercote 98d97b7323 Use Layout::new consistently in DroplessArena::alloc. 2023-09-28 15:44:48 +10:00
Nicholas Nethercote 51edc21990 Remove unsafe from TypedArena::alloc_raw_slice.
There's no good reason for it.
2023-09-28 15:44:48 +10:00
Nicholas Nethercote 55de23ed5d Inline and remove TypedArena::ensure_capacity.
It has a single callsite.
2023-09-28 15:44:48 +10:00
Nicholas Nethercote 0001eddb93 Inline and remove DroplessArena::grow_and_alloc.
It has a single callsite.
2023-09-28 15:44:48 +10:00
Nicholas Nethercote a11f7e4c0f Remove some unnecessary lifetimes. 2023-09-28 15:44:48 +10:00
Nicholas Nethercote 79b11f0802 rustc_arena: tweak some comments. 2023-09-28 15:44:48 +10:00
John Kåre Alsaker 2c507cae36 Rename cold_path to outline 2023-09-25 22:54:07 +02:00
Mark Rousskov 0a916062aa Bump cfg(bootstrap) 2023-08-23 20:05:14 -04:00
John Kåre Alsaker 6f86591b87 Address comments 2023-08-14 21:29:19 +02:00
John Kåre Alsaker d5d72168fa Allocate extra space to account for alignment losses 2023-08-14 20:51:58 +02:00