about summary refs log tree commit diff
path: root/library/std/src
AgeCommit message (Collapse)AuthorLines
2022-01-16Rollup merge of #92619 - Alexendoo:macro-diagnostic-items, r=matthewjasperMatthias Krüger-0/+6
Add diagnostic items for macros For use in Clippy, it adds diagnostic items to all the stable public macros Clippy has lints that look for almost all of these (currently by name or path), but there are a few that aren't currently part of any lint, I could remove those if it's preferred to add them as needed rather than ahead of time
2022-01-16Auto merge of #92598 - Badel2:panic-update-hook, r=yaahcbors-0/+82
Implement `panic::update_hook` Add a new function `panic::update_hook` to allow creating panic hooks that forward the call to the previously set panic hook, without race conditions. It works by taking a closure that transforms the old panic hook into a new one, while ensuring that during the execution of the closure no other thread can modify the panic hook. This is a small function so I hope it can be discussed here without a formal RFC, however if you prefer I can write one. Consider the following example: ```rust let prev = panic::take_hook(); panic::set_hook(Box::new(move |info| { println!("panic handler A"); prev(info); })); ``` This is a common pattern in libraries that need to do something in case of panic: log panic to a file, record code coverage, send panic message to a monitoring service, print custom message with link to github to open a new issue, etc. However it is impossible to avoid race conditions with the current API, because two threads can execute in this order: * Thread A calls `panic::take_hook()` * Thread B calls `panic::take_hook()` * Thread A calls `panic::set_hook()` * Thread B calls `panic::set_hook()` And the result is that the original panic hook has been lost, as well as the panic hook set by thread A. The resulting panic hook will be the one set by thread B, which forwards to the default panic hook. This is not considered a big issue because the panic handler setup is usually run during initialization code, probably before spawning any other threads. Using the new `panic::update_hook` function, this race condition is impossible, and the result will be either `A, B, original` or `B, A, original`. ```rust panic::update_hook(|prev| { Box::new(move |info| { println!("panic handler A"); prev(info); }) }); ``` I found one real world use case here: https://github.com/dtolnay/proc-macro2/blob/988cf403e741aadfd5340bbf67e35e1062a526aa/src/detection.rs#L32 the workaround is to detect the race condition and panic in that case. The pattern of `take_hook` + `set_hook` is very common, you can see some examples in this pull request, so I think it's natural to have a function that combines them both. Also using `update_hook` instead of `take_hook` + `set_hook` reduces the number of calls to `HOOK_LOCK.write()` from 2 to 1, but I don't expect this to make any difference in performance. ### Unresolved questions: * `panic::update_hook` takes a closure, if that closure panics the error message is "panicked while processing panic" which is not nice. This is a consequence of holding the `HOOK_LOCK` while executing the closure. Could be avoided using `catch_unwind`? * Reimplement `panic::set_hook` as `panic::update_hook(|_prev| hook)`?
2022-01-15Rollup merge of #92863 - camelid:read_to_string-rm-mut, r=m-ou-seMatthias Krüger-2/+2
Remove `&mut` from `io::read_to_string` signature ``@m-ou-se`` [realized][1] that because `Read` is implemented for `&mut impl Read`, there's no need to take `&mut` in `io::read_to_string`. Removing the `&mut` from the signature allows users to remove the `&mut` from their calls (and thus pass an owned reader) if they don't use the reader later. r? `@m-ou-se` [1]: https://github.com/rust-lang/rust/issues/80218#issuecomment-874322129
2022-01-15Rollup merge of #92775 - xfix:osstringext-inline, r=m-ou-seMatthias Krüger-0/+2
Inline std::os::unix::ffi::OsStringExt methods Those methods essentially do nothing at assembly level. On Unix systems, `OsString` is represented as a `Vec` without performing any transformations.
2022-01-15Rollup merge of #92684 - ibraheemdev:patch-10, r=m-ou-seMatthias Krüger-0/+2
Export `tcp::IntoIncoming` Added in #88339 but not publicly exported.
2022-01-14Rollup merge of #92768 - ojeda:stabilize-maybe_uninit_extra, r=Mark-SimulacrumMatthias Krüger-1/+0
Partially stabilize `maybe_uninit_extra` This covers: ```rust impl<T> MaybeUninit<T> { pub unsafe fn assume_init_read(&self) -> T { ... } pub unsafe fn assume_init_drop(&mut self) { ... } } ``` It does not cover the const-ness of `write` under `const_maybe_uninit_write` nor the const-ness of `assume_init_read` (this commit adds `const_maybe_uninit_assume_init_read` for that). FCP: https://github.com/rust-lang/rust/issues/63567#issuecomment-958590287. Signed-off-by: Miguel Ojeda <ojeda@kernel.org>
2022-01-13fix stability attribute for `tcp::IntoIncoming`Ibraheem Ahmed-1/+3
2022-01-13Remove `&mut` from `io::read_to_string` signatureNoah Lev-2/+2
`@m-ou-se` [realized][1] that because `Read` is implemented for `&mut impl Read`, there's no need to take `&mut` in `io::read_to_string`. Removing the `&mut` from the signature allows users to remove the `&mut` from their calls (and thus pass an owned reader) if they don't use the reader later. [1]: https://github.com/rust-lang/rust/issues/80218#issuecomment-874322129
2022-01-13Rollup merge of #91938 - yaahc:error-reporter, r=m-ou-seMatthias Krüger-4/+1048
Add `std::error::Report` type This is a continuation of https://github.com/rust-lang/rust/pull/90174, split into a separate PR since I cannot push to ```````@seanchen1991``````` 's fork
2022-01-13Auto merge of #92553 - m-ou-se:thread-join-simplify, r=Mark-Simulacrumbors-9/+9
Simpilfy thread::JoinInner. `JoinInner`'s `native` field was an `Option`, but that's unnecessary. Also, thanks to `Arc::get_mut`, there's no unsafety needed in `JoinInner::join()`.
2022-01-12Rollup merge of #92748 - david-perez:eliminate-boxed-wording-std-error, ↵Matthias Krüger-6/+6
r=Mark-Simulacrum Eliminate "boxed" wording in `std::error::Error` documentation In commit 29403ee, documentation for the methods on `std::any::Any` was modified so that they referred to the concrete value behind the trait object as the "inner" value. This is a more accurate wording than "boxed": while putting trait objects inside boxes is arguably the most common use, they can also be placed behind other pointer types like `&mut` or `std::sync::Arc`. This commit does the same documentation changes for `std::error::Error`.
2022-01-12Rollup merge of #92720 - rosik:patch-1, r=m-ou-seMatthias Krüger-1/+1
Fix doc formatting for time.rs The doc states that instants are not steady, but the word "not" wasn't highlighted in bold.
2022-01-12Rollup merge of #92709 - joshtriplett:file-options-docs, r=Mark-SimulacrumMatthias Krüger-4/+5
Improve documentation for File::options to give a more likely example `File::options().read(true).open(...)` is equivalent to just `File::open`. Change the example to set the `append` flag instead, and then change the filename to something more likely to be written in append mode.
2022-01-11Inline std::os::unix::ffi::OsStringExt methodsKonrad Borowski-0/+2
2022-01-11Partially stabilize `maybe_uninit_extra`Miguel Ojeda-1/+0
This covers: impl<T> MaybeUninit<T> { pub unsafe fn assume_init_read(&self) -> T { ... } pub unsafe fn assume_init_drop(&mut self) { ... } } It does not cover the const-ness of `write` under `const_maybe_uninit_write` nor the const-ness of `assume_init_read` (this commit adds `const_maybe_uninit_assume_init_read` for that). FCP: https://github.com/rust-lang/rust/issues/63567#issuecomment-958590287. Signed-off-by: Miguel Ojeda <ojeda@kernel.org>
2022-01-11Auto merge of #92070 - rukai:replace_vec_into_iter_with_array_into_iter, ↵bors-12/+12
r=Mark-Simulacrum Replace usages of vec![].into_iter with [].into_iter `[].into_iter` is idiomatic over `vec![].into_iter` because its simpler and faster (unless the vec is optimized away in which case it would be the same) So we should change all the implementation, documentation and tests to use it. I skipped: * `src/tools` - Those are copied in from upstream * `src/test/ui` - Hard to tell if `vec![].into_iter` was used intentionally or not here and not much benefit to changing it. * any case where `vec![].into_iter` was used because we specifically needed a `Vec::IntoIter<T>` * any case where it looked like we were intentionally using `vec![].into_iter` to test it.
2022-01-10Improve documentation for File::options to give a more likely exampleJosh Triplett-4/+5
`File::options().read(true).open(...)` is equivalent to just `File::open`. Change the example to set the `append` flag instead, and then change the filename to something more likely to be written in append mode.
2022-01-10Eliminate "boxed" wording in `std::error::Error` documentationdavid-perez-6/+6
In commit 29403ee, documentation for the methods on `std::any::Any` was modified so that they referred to the concrete value behind the trait object as the "inner" value. This is a more accurate wording than "boxed": while putting trait objects inside boxes is arguably the most common use, they can also be placed behind other pointer types like `&mut` or `std::sync::Arc`. This commit does the same documentation changes for `std::error::Error`.
2022-01-10Auto merge of #92719 - matthiaskrgr:rollup-tc7oqys, r=matthiaskrgrbors-2/+2
Rollup of 7 pull requests Successful merges: - #92248 (Normalize struct tail type when checking Pointee trait) - #92357 (Fix invalid removal of newlines from doc comments) - #92602 (Make source links look cleaner) - #92636 (Normalize generator-local types with unevaluated constants) - #92693 (Release notes: add `Result::unwrap_{,err_}unchecked`) - #92702 (Clean up lang_items::extract) - #92717 (update miri) Failed merges: r? `@ghost` `@rustbot` modify labels: rollup
2022-01-10Fix doc formatting for time.rs Yaroslav Dynnikov-1/+1
The doc states that instants are not steady, but the word "not" wasn't highlighted in bold.
2022-01-10Rollup merge of #92602 - jsha:source-link-2, r=GuillaumeGomezMatthias Krüger-2/+2
Make source links look cleaner Change from syntaxy-looking [src] to the plain word "source". Change the syntaxy-looking `[-]` at the top of the page to say "collapse". Reduce opacity of rightside content. Part of #59851 r? `@GuillaumeGomez` Demo: https://rustdoc.crud.net/jsha/source-link-2/std/string/struct.String.html [Discussed on Zulip](https://rust-lang.zulipchat.com/#narrow/stream/266220-rustdoc/topic/display.20of.20source.20link).
2022-01-09Compute most of Public/Exported access level in rustc_resolveLamb-21/+16
Mak DefId to AccessLevel map in resolve for export hir_id to accesslevel in resolve and applied in privacy using local def id removing tracing probes making function not recursive and adding comments Move most of Exported/Public res to rustc_resolve moving public/export res to resolve fix missing stability attributes in core, std and alloc move code to access_levels.rs return for some kinds instead of going through them Export correctness, macro changes, comments add comment for import binding add comment for import binding renmae to access level visitor, remove comments, move fn as closure, remove new_key fmt fix rebase fix rebase fmt fmt fix: move macro def to rustc_resolve fix: reachable AccessLevel for enum variants fmt fix: missing stability attributes for other architectures allow unreachable pub in rustfmt fix: missing impl access level + renaming export to reexport Missing impl access level was found thanks to a test in clippy
2022-01-08export `tcp::IntoIncoming`Ibraheem Ahmed-1/+1
2022-01-09eplace usages of vec![].into_iter with [].into_iterLucas Kent-12/+12
2022-01-08Make source links look cleanerJacob Hoffman-Andrews-2/+2
Change from syntaxy-looking [src] to the plain word "source".
2022-01-07Rollup merge of #92632 - yoshuawuyts:stabilize-available-parallelism, ↵Eric Huss-2/+1
r=joshtriplett Implement stabilization of `#[feature(available_parallelism)]` Stabilized in https://github.com/rust-lang/rust/issues/74479#issuecomment-984379800. Closes https://github.com/rust-lang/rust/issues/74479. Thanks! cc/ ``@rust-lang/libs-api``
2022-01-08Add safety comments to panic::(set/take/update)_hookBadel2-0/+15
2022-01-08Change panic::update_hook to simplify usageBadel2-22/+23
And to remove possibility of panics while changing the panic handler, because that resulted in a double panic.
2022-01-07silence tidy errorsJane Lusby-27/+27
2022-01-07Implement `TryFrom<char>` for `u8`Ian Douglas Scott-0/+3
Previously suggested in https://github.com/rust-lang/rfcs/issues/2854. It makes sense to have this since `char` implements `From<u8>`. Likewise `u32`, `u64`, and `u128` (since #79502) implement `From<char>`.
2022-01-07Implement panic::update_hookBadel2-0/+66
2022-01-07Stabilize `#[feature(available_parallelism)]`Yoshua Wuyts-2/+1
2022-01-06Add diagnostic items for macrosAlex Macleod-0/+6
2022-01-06Rollup merge of #92288 - yescallop:patch-1, r=m-ou-seMatthias Krüger-2/+2
Fix a pair of mistyped test cases in `std::net::ip` These two test cases are not consistent with their comments, which I believe is unintended.
2022-01-05Auto merge of #92587 - matthiaskrgr:rollup-qnwa8qx, r=matthiaskrgrbors-0/+1
Rollup of 7 pull requests Successful merges: - #92092 (Drop guards in slice sorting derive src pointers from &mut T, which is invalidated by interior mutation in comparison) - #92388 (Fix a minor mistake in `String::try_reserve_exact` examples) - #92442 (Add negative `impl` for `Ord`, `PartialOrd` on `LocalDefId`) - #92483 (Stabilize `result_cloned` and `result_copied`) - #92574 (Add RISC-V detection macro and more architecture instructions) - #92575 (ast: Always keep a `NodeId` in `ast::Crate`) - #92583 (:arrow_up: rust-analyzer) Failed merges: r? `@ghost` `@rustbot` modify labels: rollup
2022-01-05Rollup merge of #92517 - ChrisDenton:explicit-path, r=dtolnayMatthias Krüger-33/+37
Explicitly pass `PATH` to the Windows exe resolver This allows for testing different `PATH`s without using the actual environment.
2022-01-05Add is_riscv_feature_detected!; modify impl of hint::spin_loopluojia65-0/+1
Update library/core/src/hint.rs Co-authored-by: Amanieu d'Antras <amanieu@gmail.com> Remove redundant config gate
2022-01-04Rollup merge of #92525 - zohnannor:patch-1, r=camelidMatthias Krüger-1/+2
intra-doc: Make `Receiver::into_iter` into a clickable link The documentation on `std::sync::mpsc::Iter` and `std::sync::mpsc::TryIter` provides links to the corresponding `Receiver` methods, unlike `std::sync::mpsc::IntoIter` does. This was left out in c59b188aaeadea32625534250d1f5120420be000 Related to #29377
2022-01-04Rollup merge of #92456 - danielhenrymantilla:patch-1, r=petrochenkovMatthias Krüger-11/+8
Make the documentation of builtin macro attributes accessible `use ::std::prelude::v1::derive;` compiles on stable, so, AFAIK, there is no reason to have it be `#[doc(hidden)]`. - What it currently looks like for things such as `#[test]`, `#[derive]`, `#[global_allocator]`: https://doc.rust-lang.org/1.57.0/core/prelude/v1/index.html#:~:text=Experimental-,pub,-use%20crate%3A%3Amacros%3A%3Abuiltin%3A%3Aglobal_allocator <img width="767" alt="Screen Shot 2021-12-31 at 17 49 46" src="https://user-images.githubusercontent.com/9920355/147832999-cbd747a6-4607-4df6-8e57-c1675dcbc1c3.png"> and in `::std` they're just straight `hidden`. <img width="452" alt="Screen Shot 2021-12-31 at 17 53 18" src="https://user-images.githubusercontent.com/9920355/147833105-c5ff8cd1-9e4d-4d2b-9621-b36aa3cfcb28.png"> - Here is how it looks like with this PR (assuming the `Rustc{De,En}codable` ones are not reverted): <img width="778" alt="Screen Shot 2021-12-31 at 17 50 55" src="https://user-images.githubusercontent.com/9920355/147833034-84286342-dbf7-4e6e-9062-f39cd6c286a4.png"> <img width="291" alt="Screen Shot 2021-12-31 at 17 52 54" src="https://user-images.githubusercontent.com/9920355/147833109-c92ed55c-51c6-40a2-9205-f834d1e349c0.png"> Since this involves doc people to chime in, and since `jyn` is on vacation, I'll cc `@GuillaumeGomez` and tag the `rustdoc` team as well
2022-01-04Rollup merge of #91754 - Patrick-Poitras:rm-4byte-minimum-stdio-windows, ↵Matthias Krüger-18/+54
r=Mark-Simulacrum Modifications to `std::io::Stdin` on Windows so that there is no longer a 4-byte buffer minimum in read(). This is an attempted fix of issue #91722, where a too-small buffer was passed to the read function of stdio on Windows. This caused an error to be returned when `read_to_end` or `read_to_string` were called. Both delegate to `std::io::default_read_to_end`, which creates a buffer that is of length >0, and forwards it to `std::io::Stdin::read()`. The latter method returns an error if the length of the buffer is less than 4, as there might not be enough space to allocate a UTF-16 character. This creates a problem when the buffer length is in `0 < N < 4`, causing the bug. The current modification creates an internal buffer, much like the one used for the write functions I'd also like to acknowledge the help of ``@agausmann`` and ``@hkratz`` in detecting and isolating the bug, and for suggestions that made the fix possible. Couple disclaimers: - Firstly, I didn't know where to put code to replicate the bug found in the issue. It would probably be wise to add that case to the testing suite, but I'm afraid that I don't know _where_ that test should be added. - Secondly, the code is fairly fundamental to IO operations, so my fears are that this may cause some undesired side effects ~or performance loss in benchmarks.~ The testing suite runs on my computer, and it does fix the issue noted in #91722. - Thirdly, I left the "surrogate" field in the Stdin struct, but from a cursory glance, it seems to be serving the same purpose for other functions. Perhaps merging the two would be appropriate. Finally, this is my first pull request to the rust language, and as such some things may be weird/unidiomatic/plain out bad. If there are any obvious improvements I could do to the code, or any other suggestions, I would appreciate them. Edit: Closes #91722
2022-01-04Simpilfy thread::JoinInner.Mara Bos-9/+9
2022-01-03Make the documentation of builtin macro attributes accessibleDaniel Henry-Mantilla-11/+8
- Do not `#[doc(hidden)]` the `#[derive]` macro attribute - Add a link to the reference section to `derive`'s inherent docs - Do the same for `#[test]` and `#[global_allocator]` - Fix `GlobalAlloc` link (why is it on `core` and not `alloc`?) - Try `no_inline`-ing the `std` reexports from `core` - Revert "Try `no_inline`-ing the `std` reexports from `core`" - Address PR review - Also document the unstable macros
2022-01-03Make `Receiver::into_iter` into a clickable linkzohnannor-1/+2
The documentation on `std::sync::mpsc::Iter` and `std::sync::mpsc::TryIter` provides links to the corresponding `Receiver` methods, unlike `std::sync::mpsc::IntoIter` does. This was left out in c59b188aaeadea32625534250d1f5120420be000 Related to #29377
2022-01-03Explicitly pass `PATH` to the Windows exe resolverChris Denton-33/+37
2022-01-02Auto merge of #92482 - matthiaskrgr:rollup-uso1zi0, r=matthiaskrgrbors-103/+106
Rollup of 7 pull requests Successful merges: - #84083 (Clarify the guarantees that ThreadId does and doesn't make.) - #91593 (Remove unnecessary bounds for some Hash{Map,Set} methods) - #92297 (Reduce compile time of rustbuild) - #92332 (Add test for where clause order) - #92438 (Enforce formatting for rustc_codegen_cranelift) - #92463 (Remove pronunciation guide from Vec<T>) - #92468 (Emit an error for `--cfg=)`) Failed merges: r? `@ghost` `@rustbot` modify labels: rollup
2022-01-01Rollup merge of #91593 - upsuper-forks:hashmap-set-methods-bound, r=dtolnayMatthias Krüger-99/+99
Remove unnecessary bounds for some Hash{Map,Set} methods This PR moves `HashMap::{into_keys,into_values,retain}` and `HashSet::retain` from `impl` blocks with `K: Eq + Hash, S: BuildHasher` into the blocks without them. It doesn't seem to me there is any reason these methods need to be bounded by that. This change brings `HashMap::{into_keys,into_values}` on par with `HashMap::{keys,values,values_mut}` which are not bounded either.
2022-01-01Rollup merge of #84083 - ltratt:threadid_doc_tweak, r=dtolnayMatthias Krüger-4/+7
Clarify the guarantees that ThreadId does and doesn't make. The existing documentation does not spell out whether `ThreadId`s are unique during the lifetime of a thread or of a process. I had to examine the source code to realise (pleasingly!) that they're unique for the lifetime of a process. That seems worth documenting clearly, as it's a strong guarantee. Examining the way `ThreadId`s are created also made me realise that the `as_u64` method on `ThreadId` could be a trap for the unwary on those platforms where the platform's notion of a thread identifier is also a 64 bit integer (particularly if they happen to use a similar identifier scheme to `ThreadId`). I therefore think it's worth being even clearer that there's no relationship between the two.
2022-01-01Auto merge of #92396 - xfix:remove-commandenv-apply, r=Mark-Simulacrumbors-16/+0
Remove CommandEnv::apply It's not being used and uses unsound set_var and remove_var functions. This is an internal function that isn't exported (even with `process_internals` feature), so this shouldn't break anything. Also see #92365. Note that this isn't the only use of those methods in standard library, so that particular pull request will need more changes than just this to work (in particular, `test_capture_env_at_spawn` is using `set_var` and `remove_var`).
2021-12-31Make tidy check for magic numbers that spell thingsJosh Triplett-4/+4
Remove existing problematic cases.
2021-12-30Remove needless allocation from example code of OsStringDavid Tolnay-4/+4