Matthias Krüger
7dbbffdc67
Rollup merge of #118314 - WaffleLapkin:rename_collectionstests, r=cuviper
...
Rename `{collections=>alloc}{tests,benches}`
The crate is named `alloc` so this makes more sense. Ig this is fallout from #42648 ?
2023-11-28 09:28:37 +01:00
r0cky
c751bfa015
Add proper cfgs
2023-11-28 09:02:34 +08:00
The 8472
40cf1f9257
optimize str::iter::Chars::advance_by
...
this avoids part of the char decoding work by not looking at utf8 continuation bytes
2023-11-27 22:06:35 +01:00
Maybe Waffle
865ab921ab
Rename {collections=>alloc}{tests,benches}
2023-11-26 12:04:56 +00:00
Michael Goulet
fcb9fcc28c
Rollup merge of #117968 - Urgau:stabilize-ptr-addr-eq, r=dtolnay
...
Stabilize `ptr::addr_eq`
This PR stabilize the `ptr_addr_eq` library feature, representing:
```rust
// core::ptr
pub fn addr_eq<T: ?Sized, U: ?Sized>(p: *const T, q: *const U) -> bool;
```
FCP has already started [on the tracking issue](https://github.com/rust-lang/rust/issues/116324#issuecomment-1813008697 ) and is waiting on the final period comment.
Note: stabilizing this feature is somewhat of requirement for a new T-lang lint, cf. https://github.com/rust-lang/rust/pull/117758#issuecomment-1813183686 .
2023-11-25 17:23:33 -05:00
AngelicosPhosphoros
0c6901a487
Add more benchmarks of Vec::dedup
...
They are for more specific cases than old benches.
Also, better usage of blackbox
2023-11-25 02:08:43 +01:00
Amanieu d'Antras
d085f34a2d
Add UnorderedKeyError
2023-11-23 16:05:29 +00:00
Amanieu d'Antras
166e348564
Update library/alloc/src/collections/btree/map.rs
...
Co-authored-by: Joe ST <joe@fbstj.net >
2023-11-23 12:37:20 +00:00
Amanieu d'Antras
8ee9693177
Rewrite the BTreeMap cursor API using gaps
...
Tracking issue: #107540
Currently, a `Cursor` points to a single element in the tree, and allows
moving to the next or previous element while mutating the tree. However
this was found to be confusing and hard to use.
This PR completely refactors cursors to instead point to a gap between
two elements in the tree. This eliminates the need for a "ghost" element
that exists after the last element and before the first one.
Additionally, `upper_bound` and `lower_bound` now have a much clearer
meaning.
The ability to mutate keys is also factored out into a separate
`CursorMutKey` type which is unsafe to create. This makes the API easier
to use since it avoids duplicated versions of each method with and
without key mutation.
API summary:
```rust
impl<K, V> BTreeMap<K, V> {
fn lower_bound<Q>(&self, bound: Bound<&Q>) -> Cursor<'_, K, V>
where
K: Borrow<Q> + Ord,
Q: Ord;
fn lower_bound_mut<Q>(&mut self, bound: Bound<&Q>) -> CursorMut<'_, K, V>
where
K: Borrow<Q> + Ord,
Q: Ord;
fn upper_bound<Q>(&self, bound: Bound<&Q>) -> Cursor<'_, K, V>
where
K: Borrow<Q> + Ord,
Q: Ord;
fn upper_bound_mut<Q>(&mut self, bound: Bound<&Q>) -> CursorMut<'_, K, V>
where
K: Borrow<Q> + Ord,
Q: Ord;
}
struct Cursor<'a, K: 'a, V: 'a>;
impl<'a, K, V> Cursor<'a, K, V> {
fn next(&mut self) -> Option<(&'a K, &'a V)>;
fn prev(&mut self) -> Option<(&'a K, &'a V)>;
fn peek_next(&self) -> Option<(&'a K, &'a V)>;
fn peek_prev(&self) -> Option<(&'a K, &'a V)>;
}
struct CursorMut<'a, K: 'a, V: 'a>;
impl<'a, K, V> CursorMut<'a, K, V> {
fn next(&mut self) -> Option<(&K, &mut V)>;
fn prev(&mut self) -> Option<(&K, &mut V)>;
fn peek_next(&mut self) -> Option<(&K, &mut V)>;
fn peek_prev(&mut self) -> Option<(&K, &mut V)>;
unsafe fn insert_after_unchecked(&mut self, key: K, value: V);
unsafe fn insert_before_unchecked(&mut self, key: K, value: V);
fn insert_after(&mut self, key: K, value: V);
fn insert_before(&mut self, key: K, value: V);
fn remove_next(&mut self) -> Option<(K, V)>;
fn remove_prev(&mut self) -> Option<(K, V)>;
fn as_cursor(&self) -> Cursor<'_, K, V>;
unsafe fn with_mutable_key(self) -> CursorMutKey<'a, K, V, A>;
}
struct CursorMutKey<'a, K: 'a, V: 'a>;
impl<'a, K, V> CursorMut<'a, K, V> {
fn next(&mut self) -> Option<(&mut K, &mut V)>;
fn prev(&mut self) -> Option<(&mut K, &mut V)>;
fn peek_next(&mut self) -> Option<(&mut K, &mut V)>;
fn peek_prev(&mut self) -> Option<(&mut K, &mut V)>;
unsafe fn insert_after_unchecked(&mut self, key: K, value: V);
unsafe fn insert_before_unchecked(&mut self, key: K, value: V);
fn insert_after(&mut self, key: K, value: V);
fn insert_before(&mut self, key: K, value: V);
fn remove_next(&mut self) -> Option<(K, V)>;
fn remove_prev(&mut self) -> Option<(K, V)>;
fn as_cursor(&self) -> Cursor<'_, K, V>;
unsafe fn with_mutable_key(self) -> CursorMutKey<'a, K, V, A>;
}
```
2023-11-23 11:42:55 +00:00
Ralf Jung
74834a9d74
also make 'core_intrinsics' internal
2023-11-22 20:00:56 +01:00
Petr Portnov
72a8633ee8
docs(GH-118094): make docs a bit more explicit
...
Signed-off-by: Petr Portnov <me@progrm-jarvis.ru >
2023-11-20 18:35:04 +03:00
Petr Portnov
91fcdde51b
chore(GH-118094): explicitly mark _elem as unused
...
Signed-off-by: Petr Portnov <me@progrm-jarvis.ru >
2023-11-20 18:33:55 +03:00
Petr Portnov
2fd9442afc
feat: specialize SpecFromElem for ()
...
While a better approach would be to implement it for all ZSTs
which are `Copy` and have trivial `Clone`,
the last property cannot be detected for now.
Signed-off-by: Petr Portnov <me@progrm-jarvis.ru >
2023-11-20 18:29:09 +03:00
Urgau
8d91d6662f
Stabilize ptr_addr_eq library feature
2023-11-16 11:35:59 +01:00
Mark Rousskov
917f6540ed
Re-format code with new rustfmt
2023-11-15 21:45:48 -05:00
Mark Rousskov
db3e2bacb6
Bump cfg(bootstrap)s
2023-11-15 19:41:28 -05:00
bors
2c1b65ee14
Auto merge of #115694 - clarfonthey:std-hash-private, r=dtolnay
...
Add `std:#️⃣ :{DefaultHasher, RandomState}` exports (needs FCP)
This implements rust-lang/libs-team#267 to move the libstd hasher types to `std::hash` where they belong, instead of `std::collections::hash_map`.
<details><summary>The below no longer applies, but is kept for clarity.</summary>
This is a small refactor for #27242 , which moves the definitions of `RandomState` and `DefaultHasher` into `std::hash`, but in a way that won't be noticed in the public API.
I've opened rust-lang/libs-team#267 as a formal ACP to move these directly into the root of `std::hash`, but for now, they're at least separated out from the collections code in a way that will make moving that around easier.
I decided to simply copy the rustdoc for `std::hash` from `core::hash` since I think it would be ideal for the two to diverge longer-term, especially if the ACP is accepted. However, I would be willing to factor them out into a common markdown document if that's preferred.
</details>
2023-11-11 21:12:20 +00:00
John Millikin
82a9f94de5
Closure-consuming helper functions for fmt::Debug helpers
2023-11-10 07:50:11 +09:00
Matt Harding
19caba0008
Remove trailing whitespace
2023-11-09 07:00:31 +00:00
Matt Harding
9bfe49e00a
Add note on how 0 flag overrides fill character
2023-11-09 06:31:50 +00:00
Matt Harding
c493634064
Add link to Formatting traits from alternate forms
2023-11-08 14:56:35 +00:00
Niklas Fiekas
0bccdb34a2
Stabilize slice_group_by
...
Renamed "group by" to "chunk by" a per #80552 .
Newly stable items:
* `core::slice::ChunkBy`
* `core::slice::ChunkByMut`
* `[T]::chunk`
* `[T]::chunk_by`
Closes #80552 .
2023-11-07 17:46:00 +01:00
bors
da1e0d1d75
Auto merge of #116218 - tgross35:const-maybe-uninit-zeroed, r=dtolnay
...
Stabilize `const_maybe_uninit_zeroed` and `const_mem_zeroed`
Make `MaybeUninit::zeroed` and `mem::zeroed` const stable. Newly stable API:
```rust
// core::mem
pub const unsafe fn zeroed<T>() ->;
impl<T> MaybeUninit<T> {
pub const fn zeroed() -> MaybeUninit<T>;
}
```
This relies on features based around `const_mut_refs`. Per `@RalfJung,` this should be OK since we do not leak any `&mut` to the user.
For this to be possible, intrinsics `assert_zero_valid` and `assert_mem_uninitialized_valid` were made const stable.
Tracking issue: #91850
Zulip discussion: https://rust-lang.zulipchat.com/#narrow/stream/146212-t-compiler.2Fconst-eval/topic/.60const_mut_refs.60.20dependents
r? libs-api
`@rustbot` label -T-libs +T-libs-api +A-const-eval
cc `@RalfJung` `@oli-obk` `@rust-lang/wg-const-eval`
2023-11-05 05:56:21 +00:00
bors
f5ca57e153
Auto merge of #117503 - kornelski:hint-try-reserved, r=workingjubilee
...
Hint optimizer about try-reserved capacity
This is #116568 , but limited only to the less-common `try_reserve` functions to reduce bloat in debug binaries from debug info, while still addressing the main use-case #116570
2023-11-05 00:03:41 +00:00
Trevor Gross
f6ce646d3f
Stabilize const_maybe_uninit_zeroed
...
Make `MaybeUninit::zeroed` const stable. Newly stable API:
// core::mem
impl<T> MaybeUninit<T> {
pub const fn zeroed() -> MaybeUninit<T>;
}
Use of `const_mut_refs` should be acceptable since we do not leak the
mutability.
Tracking issue: #91850
2023-11-04 15:27:25 -04:00
alpharush
c7d8c65c1a
docs: clarify explicitly freeing heap allocated memory
2023-11-04 03:00:43 -05:00
ltdk
8337e86b28
Add insta-stable std: #️⃣ :{DefaultHasher, RandomState} exports
2023-11-02 20:35:20 -04:00
Kornel
029fbd67ef
Hint optimizer about reserved capacity
2023-11-02 00:52:06 +00:00
Bugen Zhao
c872ccc510
delegate box error provide
...
Signed-off-by: Bugen Zhao <i@bugenzhao.com >
2023-10-31 16:35:59 +08:00
bors
bcb5798dd8
Auto merge of #117332 - saethlin:panic-immediate-abort, r=workingjubilee
...
Increase the reach of panic_immediate_abort
I wanted to use/abuse this recently as part of another project, and I was surprised how many panic-related things were left in my binaries if I built a large crate with the feature enabled along with LTO. These changes get all the panic-related symbols that I could find out of my set of locally installed Rust utilities.
2023-10-30 00:03:47 +00:00
Ben Kimock
2e7364a586
Increase the reach of panic_immediate_abort
2023-10-29 09:31:07 -04:00
coekjan
4dd7568a97
mark constructor of BinaryHeap as const fn
2023-10-28 21:30:43 +08:00
Maybe Waffle
e36224118f
Stabilize [const_]pointer_byte_offsets
2023-10-25 22:35:12 +00:00
Gimbles
695beca219
Update boxed.rs
2023-10-21 23:41:32 +05:30
Oli Scherer
e96ce20b34
s/generator/coroutine/
2023-10-20 21:14:01 +00:00
Oli Scherer
60956837cf
s/Generator/Coroutine/
2023-10-20 21:10:38 +00:00
Muhammad Hamza
540921e468
Stablize arc_unwrap_or_clone
2023-10-19 22:40:08 +05:00
Ben Kimock
33b0e4be06
Automatically enable cross-crate inlining for small functions
2023-10-17 19:53:51 -04:00
Arthur Carcano
0bcac8a7f2
Add invariant to Vec::pop that len < cap if pop successful
...
Fixes: https://github.com/rust-lang/rust/issues/114334
2023-10-16 18:49:25 +02:00
bors
39acbed8d6
Auto merge of #116407 - Mark-Simulacrum:bootstrap-bump, r=onur-ozkan
...
Bump bootstrap compiler to just-released beta
https://forge.rust-lang.org/release/process.html#master-bootstrap-update-t-2-day-tuesday
2023-10-14 05:44:48 +00:00
bors
6d05c430d2
Auto merge of #115948 - notriddle:notriddle/logo-lockup, r=fmease
...
rustdoc: show crate name beside smaller logo
*Blocked on https://github.com/rust-lang/cargo/pull/12800 *
## Summary
In this PR, the crate name and version are always shown in the sidebar, even in subpages, and the lateral navigation is always shown in the sidebar, even in modules.
Clicking the crate name does the same thing clicking the logo always did: take you to the crate root (the crate's home page, at least within Rustdoc).
The Rust logo is also no longer shown by default for non-Rust docs.
### Screenshots
<details><summary>Before</summary>
| | Macro | Module |
|--|-------|--------|
| In crate |  |
| In module[^1] |  | 
[^1]: This PR also includes a bug fix for derive macros not showing up in the lateral navigation part of the sidebar
</details>
#### Whole sidebar screenshots
| | Macro | Module |
|--|-------|--------|
| In crate |  | 
| In module |  | 
#### Different logo configurations
| | Short crate name | Long crate name |
|---------|------------------|-----------------|
| Root | ![short-root] | ![long-root]
| Subpage | ![short-subpage] | ![long-subpage]
[short-root]: https://github.com/rust-lang/rust/assets/1593513/9e2b4fa8-f581-4106-b562-1e0372c13f79
[short-subpage]: https://github.com/rust-lang/rust/assets/1593513/8331cdb8-fa13-4671-a1e2-dcc1cdca7451
[long-root]: https://github.com/rust-lang/rust/assets/1593513/7d377fec-0f1d-4343-9f82-0e35a8f58056
[long-subpage]: https://github.com/rust-lang/rust/assets/1593513/3b3094a4-63c9-477c-8c15-b6075837df30
##### Without a logo

### Preview pages
https://notriddle.com/rustdoc-html-demo-5/sidebar-layout-rocket/rocket/index.html
https://notriddle.com/rustdoc-html-demo-5/sidebar-layout-rocket/rocket_sync_db_pools/index.html
https://notriddle.com/rustdoc-html-demo-5/sidebar-layout-rust-compiler/index.html
https://notriddle.com/rustdoc-html-demo-5/sidebar-layout-rust/std/index.html
https://notriddle.com/rustdoc-html-demo-5/sidebar-layout-rocket/tokio/index.html
## Motivation
This improves visual information density (the construct with the logo and crate name is *shorter* than the logo on its own, because it's not square) and navigation clarity (we can now see what clicking the Rust logo does, specifically).
Compare this with the layout at [Phoenix's Hexdocs] (which is what this proposal is closely based on), the old proposal on [Internals Discourse] (which always says "Rust standard library" in the sidebar, but doesn't do the side-by-side layout).
[Phoenix's Hexdocs]: https://hexdocs.pm/phoenix/1.7.7/overview.html
[Internals Discourse]: https://internals.rust-lang.org/t/poc-of-a-new-design-for-the-generated-rustdoc/11018
## Guide-level explanation
This PR cleans up some of the sidebar navigation.
It makes the logo in the desktop sidebar a bit smaller, and puts the crate name and version next to it (either beside it, or below it, depending on if there's space), making it clearer what clicking on it does: click the crate name to open the crate's home page. It also removes the Rust logo from non-official-Rust crates, again to make the navigation and supply chain clearer (since the crate name has been added, the logo is no longer necessary for navigation).
It adds a bit more clarifying information for lateral navigation. On items that don't add their own sidebar items, it just shows its siblings directly below the crate name and logo, but for other items, it shows "In crate alloc" instead of just "In alloc". It also shows the lateral navigation tools on module pages, making modules consistent with every other item.
## Drawbacks
While this actually takes up less screen real estate than the old layout on desktop, it takes up more HTML. It's also a bit more visually complex.
## Rationale and alternatives
I could do what the Internals POC did and keep the vertically stacked layout all the time, instead of doing a horizontal stack where possible. It would take up more screen real estate, though.
## Prior art
This design is lifted almost verbatim from Hexdocs. It seems to work for them. [`opentelemetry_process_propagator`], for example, has a long application name.
[`opentelemetry_process_propagator`]: https://hexdocs.pm/opentelemetry_process_propagator/OpentelemetryProcessPropagator.html
## Unresolved questions
Maybe we should encourage crate authors to include their own logo more often? It certainly helps give people a better sense of "place." This seems to be blocked on coming up with an API to do it without requiring them to host the file somewhere.
## Future possibilities
Beyond this, plenty of other changes could be made to improve the layout, like
* Fix things so that clicking an item in the sidebar doesn't cause it to scroll back to the top.
* The [Internals demo](https://utherii.github.io/new.html ) does this right: clicking an item in the sidebar changes the content area, but the sidebar itself does not change. This is nice, because clicking is cheap and I can skim the opening few paragraphs while browsing.
* The layout of the docs sidebar causes trouble to implement this, because it's different on different pages, but at least fix this on the file browser.
* Come up with a less cluttered way to do disclosure. There's a lot of `[-]` on the page.
* We don't lack ideas to fix this one. We have *too many*.
* Do a better job of separating local navigation (vec::Vec links to vec::IntoIter) and the table of contents (vec::Vec links to vec::Vec::new).
* A possibility: add a Back arrow next to the "In [module]" header?

* Give readers more control of how much rustdoc shows them, and giving doc authors more control of how much it generates. Basically, https://github.com/rust-lang/rust/pull/115660 is great, let's do it too.
But those are mostly orthogonal, not future possibilities unlocked by this change.
2023-10-11 06:28:36 +00:00
Ali MJ Al-Nasrawy
38654ad741
Rollup merge of #95967 - CAD97:from-utf16, r=dtolnay
...
Add explicit-endian String::from_utf16 variants
This adds the following APIs under `feature(str_from_utf16_endian)`:
```rust
impl String {
pub fn from_utf16le(v: &[u8]) -> Result<String, FromUtf16Error>;
pub fn from_utf16le_lossy(v: &[u8]) -> String;
pub fn from_utf16be(v: &[u8]) -> Result<String, FromUtf16Error>;
pub fn from_utf16be_lossy(v: &[u8]) -> String;
}
```
These are versions of `String::from_utf16` that explicitly take [UTF-16LE and UTF-16BE](https://unicode.org/faq/utf_bom.html#gen7 ). Notably, we can do better than just the obvious `decode_utf16(v.array_chunks::<2>().copied().map(u16::from_le_bytes)).collect()` in that:
- We handle the case where the byte slice is not an even number of bytes, and
- In the case that the UTF-16 is native endian and the slice is aligned, we can forward to `String::from_utf16`.
If the Unicode Consortium actively defines how to handle character replacement when decoding a UTF-16 bytestream with a trailing odd byte, I was unable to find reference. However, the behavior implemented here is fairly self-evidently correct: replace the single errant byte with the replacement character.
2023-10-11 03:53:16 +03:00
Sven Bartscher
d60b43c06a
Make BTreeSet::new_in const
2023-10-09 11:17:56 +02:00
Sven Bartscher
bbc230478c
Make BTreeMap::new_in const
...
Closes rust-lang/wg-allocators#118
2023-10-09 11:08:48 +02:00
Michael Howell
c6e6ecb1af
rustdoc: remove rust logo from non-Rust crates
2023-10-08 20:17:53 -07:00
Mark Rousskov
ea1066d0be
Bump to latest beta
2023-10-08 19:57:43 -04:00
Jason Newcomb
d464b72970
Add more diagnostic items for clippy
2023-10-05 18:21:47 -04:00
Jubilee
ea3454eabb
Rollup merge of #116223 - catandcoder:master, r=cjgillot
...
Fix misuses of a vs an
Fixes the misuse of "a" vs "an", according to English grammatical
expectations and using https://www.a-or-an.com/
2023-10-05 00:56:29 -07:00
Mark Rousskov
787d32324c
Bump version placeholders
2023-10-03 20:26:36 -04:00
cui fliter
f44d116e1f
Fix misuses of a vs an
...
Signed-off-by: cui fliter <imcusg@gmail.com >
2023-10-04 08:01:11 +08:00