Commit graph

10242 commits

Author SHA1 Message Date
Albert Larsan 40ba0e84d5
Change src/test to tests in source files, fix tidy and tests 2023-01-11 09:32:13 +00:00
Yuki Okushi feca61e5eb
Rollup merge of #106662 - Ezrashaw:specialize-bool-tostring, r=cuviper
specialize impl of `ToString` on `bool`

Fixes #106611

Specialize `bool`s `ToString` impl by copying it from `Display`. This is a significant optimization as we avoid lots of dynamic dispatch. AFAIK, this doesn't require a API Change Proposal as this doesn't regress existing code and can be undone without regressing code.
2023-01-11 14:18:56 +09:00
Yuki Okushi 397013dc44
Rollup merge of #106635 - RalfJung:std-test-nits, r=thomcc
std sync tests: better type name, clarifying comment

Just resolving some confusion that I encountered while reading these tests.

r? `@thomcc`
2023-01-11 14:18:54 +09:00
Ezra Shaw 203bbfa2f7
impl: specialize impl of ToString on bool 2023-01-10 15:34:21 +13:00
Yuki Okushi 002eccc752
Rollup merge of #105034 - HintringerFabian:improve_iterator_flatten_doc, r=cuviper
Add example for iterator_flatten

Adds an Example to iterator_flatten
Fixes #82687
2023-01-10 08:05:32 +09:00
Ralf Jung 997101824b std test: better type name, clarifying comment 2023-01-09 16:08:26 +01:00
Fabian Hintringer c364d329dd
Relocate changes 2023-01-09 13:19:41 +01:00
Michael Goulet 70f1566b2b
Rollup merge of #106584 - kpreid:vec-allocator, r=JohnTitor
Document that `Vec::from_raw_parts[_in]` must be given a pointer from the correct allocator.

Currently, the documentation of `Vec::from_raw_parts` and `Vec::from_raw_parts_in` says nothing about what allocator the pointer must come from. This PR adds that missing information explicitly.
2023-01-08 19:57:54 -08:00
Michael Goulet db87e276c4
Rollup merge of #104163 - H4x5:once-repeat-with-debug, r=dtolnay
Don't derive Debug for `OnceWith` & `RepeatWith`

Closures don't impl Debug, so the derived impl is kinda useless. The behavior of not debug-printing closures is consistent with the rest of the iterator adapters/sources.
2023-01-08 19:57:52 -08:00
bors a377893da2 Auto merge of #90291 - geeklint:loosen_weak_debug_bound, r=dtolnay
Loosen the bound on the Debug implementation of Weak.

Both `rc::Weak<T>` and `sync::Weak<T>` currently require `T: Debug` in their own `Debug` implementations, but they don't currently use it;  they only ever print a fixed string.

A general implementation of Debug for Weak that actually attempts to upgrade and rely on the contents is unlikely in the future because it may have unbounded recursion in the presence of reference cycles, which Weak is commonly used in.  (This was the justification for why the current implementation [was implemented the way it is](f0976e2cf3)).

When I brought it up [on the forum](https://internals.rust-lang.org/t/could-the-bound-on-weak-debug-be-relaxed/15504), it was suggested that, even if an implementation is specialized in the future that relies on the data stored within the Weak, it would likely rely on specialization anyway, and could therefore easily specialize on the Debug bound as well.
2023-01-08 22:40:38 +00:00
Yuki Okushi 14ce60333d
Rollup merge of #106562 - clubby789:vec-deque-example, r=Mark-Simulacrum
Clarify examples for `VecDeque::get/get_mut`

Closes #106114

``@rustbot`` label +A-docs
2023-01-08 17:01:48 +09:00
Yuki Okushi ed77ffe166
Rollup merge of #103104 - SUPERCILEX:sep-ref, r=dtolnay
Stabilize `main_separator_str`

See reasoning here: https://github.com/rust-lang/rust/issues/94071#issuecomment-1279872605. Closes #94071.
2023-01-08 17:01:46 +09:00
bors 2afe58571e Auto merge of #104658 - thomcc:rand-update-and-usable-no_std, r=Mark-Simulacrum
Update `rand` in the stdlib tests, and remove the `getrandom` feature from it.

The main goal is actually removing `getrandom`, so that eventually we can allow running the stdlib test suite on tier3 targets which don't have `getrandom` support. Currently those targets can only run the subset of stdlib tests that exist in uitests, and (generally speaking), we prefer not to test libstd functionality in uitests, which came up recently in https://github.com/rust-lang/rust/pull/104095 and https://github.com/rust-lang/rust/pull/104185. Additionally, the fact that we can't update `rand`/`getrandom` means we're stuck with the old set of tier3 targets, so can't test new ones.

~~Anyway, I haven't checked that this actually does allow use on tier3 targets (I think it does not, as some work is needed in stdlib submodules) but it moves us slightly closer to this, and seems to allow at least finally updating our `rand` dep, which definitely improves the status quo.~~ Checked and works now.

For the most part, our tests and benchmarks are fine using hard-coded seeds. A couple tests seem to fail with this (stuff manipulating the environment expecting no collisions, for example), or become pointless (all inputs to a function become equivalent). In these cases I've done a (gross) dance (ab)using `RandomState` and `Location::caller()` for some extra "entropy".

Trying to share that code seems *way* more painful than it's worth given that the duplication is a 7-line function, even if the lines are quite gross. (Keeping in mind that sharing it would require adding `rand` as a non-dev dep to std, and exposing a type from it publicly, all of which sounds truly awful, even if done behind a perma-unstable feature).

See also some previous attempts:
- https://github.com/rust-lang/rust/pull/86963 (in particular https://github.com/rust-lang/rust/pull/86963#issuecomment-885438936 which explains why this is non-trivial)
- https://github.com/rust-lang/rust/pull/89131
- https://github.com/rust-lang/rust/pull/96626#issuecomment-1114562857 (I tried in that PR at the same time, but settled for just removing the usage of `thread_rng()` from the benchmarks, since that was the main goal).
- https://github.com/rust-lang/rust/pull/104185
- Probably more. It's very tempting of a thing to "just update".

r? `@Mark-Simulacrum`
2023-01-08 01:34:05 +00:00
Kevin Reid 288e89bf76 Document that Vec::from_raw_parts[_in] must be given a pointer from the correct allocator. 2023-01-07 15:56:36 -08:00
Matthias Krüger 3076f26988
Rollup merge of #106564 - Folyd:feat-repeatn, r=scottmcm
Change to immutable borrow when cloning element of RepeatN
2023-01-07 20:43:23 +01:00
Matthias Krüger ee1992c695
Rollup merge of #106553 - Ezrashaw:fix-hashset-doctest, r=JohnTitor
docs: make `HashSet::retain` doctest more clear

Fixes #106535

Extremely simple fix suggested by ``@compiler-errors`` in the linked issue.
2023-01-07 20:43:22 +01:00
Matthias Krüger d7519c3639
Rollup merge of #105128 - Sp00ph:vec_vec_deque_conversion, r=dtolnay
Add O(1) `Vec -> VecDeque` conversion guarantee

(See #105072)
2023-01-07 20:43:20 +01:00
Matthias Krüger 08653c8c57
Rollup merge of #104081 - joshlf:patch-6, r=dtolnay
PhantomData layout guarantees
2023-01-07 20:43:19 +01:00
Sky eddb479ad3
Don't derive Debug for OnceWith & RepeatWith 2023-01-07 14:28:44 -05:00
Folyd a139fd0627 Change to immutable borrow when cloning element of RepeatN 2023-01-07 23:50:07 +08:00
clubby789 fed349957d Clarify examples for VecDeque::get/get_mut 2023-01-07 14:38:21 +00:00
Ezra Shaw 43bec83266
docs: make HashSet::retain doctest more clear 2023-01-07 17:08:07 +13:00
Matthias Krüger 72d650f47a
Rollup merge of #106453 - coastalwhite:master, r=GuillaumeGomez
Improve include macro documentation

As outlined in #106118, the `include!` macro is a SEO problem when it comes to the Rust documentation. Beginners may see it as a replacement to `include` syntax in other languages. I feel like this documentation should quite explicitly link to the modules' documentation.

The primary goal of this PR is to address that issue by adding a warning to the documentation. While I was here, I also added some other parts. This included a `Uses` section and some (intra doc) links to other relevant topics.

I hope this can help beginners to Rust more quickly understand some multi-file project intricacies.

# References
- Syntax for the warning: 58accc6da3/tracing/src/lib.rs (L55)
2023-01-06 21:26:10 +01:00
Gijs Burghoorn ae667be0f6 Remove HTML tags around warning 2023-01-06 13:20:58 +01:00
Gijs Burghoorn c30f7c9980 Better phrasing for hygiene of include macro 2023-01-05 17:09:11 +01:00
Thom Chiovoloni a4bf36e87b
Update rand in the stdlib tests, and remove the getrandom feature from it 2023-01-04 14:52:41 -08:00
Matthias Krüger 06b2df4706
Rollup merge of #106461 - notriddle:notriddle/window-searchstate-focus, r=GuillaumeGomez
docs: fix broken link "search bar"

Regression introduced by #84150
2023-01-04 23:39:52 +01:00
Matthias Krüger 5eb9698b4e
Rollup merge of #106398 - jyn514:fix-clippy, r=thomcc
Fix a few clippy lints in libtest

- Remove unnecessary references and dereferences
- Use `.contains` instead of `a <= x && x <= b`
- Use `mem::take` instead of `mem::replace` where possible

cc https://github.com/rust-lang/rust/pull/106394 :)
2023-01-04 23:39:49 +01:00
Michael Howell 854082c218 docs: fix broken link "search bar" 2023-01-04 12:47:24 -07:00
Gijs Burghoorn eb2980c7f1 Tidy up whitespace 2023-01-04 16:18:34 +01:00
Gijs Burghoorn 0c43b42b0c Improve include macro documentation 2023-01-04 16:07:33 +01:00
bors df756439df Auto merge of #106239 - LegionMammal978:thin-box-drop-guard, r=Amanieu
Deallocate ThinBox even if the value unwinds on drop

This makes it match the behavior of an ordinary `Box`.
2023-01-04 12:55:22 +00:00
Matthias Krüger d24b229072
Rollup merge of #106327 - gimbles:dbg, r=jyn514
Add tidy check for dbg

Fixes #106169
2023-01-04 07:28:55 +01:00
Matthias Krüger 70468af591
Rollup merge of #106200 - compiler-errors:suggest-impl-trait, r=estebank
Suggest `impl Fn*` and `impl Future` in `-> _` return suggestions

Follow-up to #106172, only the last commit is relevant. Can rebase once that PR is landed for easier review.

Suggests `impl Future` and `impl Fn{,Mut,Once}` in `-> _` return suggestions.

r? `@estebank`
2023-01-04 07:28:54 +01:00
Michael Goulet f6b0f4707b
Rollup merge of #106045 - RalfJung:oom-nounwind-panic, r=Amanieu
default OOM handler: use non-unwinding panic, to match std handler

The OOM handler in std will by default abort. This adjusts the default in liballoc to do the same, using the `can_unwind` flag on the panic info to indicate a non-unwinding panic.

In practice this probably makes little difference since the liballoc default will only come into play in no-std situations where people write a custom panic handler, which most likely will not implement unwinding. But still, this seems more consistent.

Cc `@rust-lang/wg-allocators,` https://github.com/rust-lang/rust/issues/66741
2023-01-03 17:19:26 -08:00
Michael Goulet a0390463fc Suggest more impl Trait on -> _ 2023-01-03 23:50:31 +00:00
Joshua Nelson 3534e0a393 Fix a few clippy lints in libtest
- Remove unnecessary references and dereferences
- Use `.contains` instead of `a <= x && x <= b`
- Use `mem::take` instead of `mem::replace` where possible
2023-01-03 18:55:03 +00:00
bors b435960c4c Auto merge of #95644 - WaffleLapkin:str_split_as_str_refactor_take2, r=Amanieu
`Split*::as_str` refactor

I've made this patch almost a year ago, so the rename and the behavior change are in one commit, sorry 😅

This fixes #84974, as it's required to make other changes work.

This PR
- Renames `as_str` method of string `Split*` iterators to `remainder` (it seems like the `as_str` name was confusing to users)
- Makes `remainder` return `Option<&str>`, to distinguish between "the iterator is exhausted" and "the tail is empty", this was [required on the tracking issue](https://github.com/rust-lang/rust/issues/77998#issuecomment-832696619)

r? `@m-ou-se`
2023-01-03 11:06:08 +00:00
Michael Goulet da1ca5df6e
Rollup merge of #104298 - tbu-:pr_set_extension_caveats, r=m-ou-se
Add notes and examples about non-intuitive `PathBuf::set_extension` behavior

Basically, passing the empty string will actually remove the extension instead of setting it to the empty string. This might change what is considered to be an extension. Additionally, passing an extension that contains dots will make the path only consider the last part of it to be the new extension.
2023-01-02 15:39:16 -08:00
David Tolnay 257e766c0c
Remove test of static Context
Context is no longer Sync so this doesn't work.

    error[E0277]: `*mut ()` cannot be shared between threads safely
      --> library/core/tests/task.rs:24:21
       |
    24 |     static CONTEXT: Context<'static> = Context::from_waker(&WAKER);
       |                     ^^^^^^^^^^^^^^^^ `*mut ()` cannot be shared between threads safely
       |
       = help: within `Context<'static>`, the trait `Sync` is not implemented for `*mut ()`
       = note: required because it appears within the type `PhantomData<*mut ()>`
       = note: required because it appears within the type `Context<'static>`
       = note: shared static variables must have a type that implements `Sync`
2023-01-02 10:33:23 -08:00
James Higgins fd59b628ea
Add PhantomData marker to Context to make Context !Send and !Sync 2023-01-02 10:20:59 -08:00
Ralf Jung 5974f6f0a5 default OOM handler: use non-unwinding panic (unless -Zoom=panic is set), to match std handler 2023-01-02 16:35:14 +01:00
LegionMammal978 ce28b4d408 Deallocate ThinBox even if the value unwinds on drop 2023-01-01 13:48:18 -05:00
Kornel 3a6ceeb18f Document a way to limit read_line length 2023-01-01 18:04:26 +00:00
Kornel 1a983536f3 Document read_line gotcha 2023-01-01 17:49:05 +00:00
Matthias Krüger 4bf9cae080
Rollup merge of #106280 - Ezrashaw:path-join-docs-better, r=thomcc
docs: add link to `Path::join` in `PathBuf::push`

Fixes #106219

Hopefully my wording is alright.
2022-12-31 23:51:34 +01:00
bors dd01a163c1 Auto merge of #106275 - Nilstrieb:const-eval-select-me-some-compile-time, r=thomcc
Use some more `const_eval_select` in pointer methods for compile times

Builds on top of #105435

`is_aligned_to` is _huge_ with calling `align_offset`, so this should cut it down a lot.

This shows up in https://github.com/rust-lang/rust/issues/65031#issuecomment-1367574340
2022-12-31 17:19:10 +00:00
gimbles cc2881391a Add tidy check for dbg 2022-12-31 15:32:09 +05:30
Michael Goulet 5b74a33b8d
Rollup merge of #106248 - dtolnay:revertupcastlint, r=jackh726
Revert "Implement allow-by-default `multiple_supertrait_upcastable` lint"

This is a clean revert of #105484.

I confirmed that reverting that PR fixes the regression reported in #106247. ~~I can't say I understand what this code is doing, but maybe it can be re-landed with a different implementation.~~ **Edit:** https://github.com/rust-lang/rust/issues/106247#issuecomment-1367174384 has an explanation of why #105484 ends up surfacing spurious `where_clause_object_safety` errors. The implementation of `where_clause_object_safety` assumes we only check whether a trait is object safe when somebody actually uses that trait with `dyn`. However the implementation of `multiple_supertrait_upcastable` added in the problematic PR involves checking *every* trait for whether it is object-safe.

FYI `@nbdd0121` `@compiler-errors`
2022-12-30 21:26:34 -08:00
Michael Goulet ff3326d925
Rollup merge of #105903 - joboet:unify_parking, r=m-ou-se
Unify id-based thread parking implementations

Multiple platforms currently use thread-id-based parking implementations (NetBSD and SGX[^1]). Even though the strategy does not differ, these are duplicated for each platform, as the id is encoded into an atomic thread variable in different ways for each platform.

Since `park` is only called by one thread, it is possible to move the thread id into a separate field. By ensuring that the field is only written to once, before any other threads access it, these accesses can be unsynchronized, removing any restrictions on the size and niches of the thread id.

This PR also renames the internal `thread_parker` modules to `thread_parking`, as that name now better reflects their contents. I hope this does not add too much reviewing noise.

r? `@m-ou-se`

`@rustbot` label +T-libs

[^1]: SOLID supports this as well, I will switch it over in a follow-up PR.
2022-12-30 21:26:33 -08:00