about summary refs log tree commit diff
path: root/library/std/src
AgeCommit message (Collapse)AuthorLines
2020-11-01Rollup merge of #78602 - RalfJung:raw-ptr-aliasing-issues, r=m-ou-seMara Bos-1/+2
fix various aliasing issues in the standard library This fixes various cases where the standard library either used raw pointers after they were already invalidated by using the original reference again, or created raw pointers for one element of a slice and used it to access neighboring elements.
2020-11-01Rollup merge of #78599 - panstromek:master, r=m-ou-seMara Bos-0/+10
Add note to process::arg[s] that args shouldn't be escaped or quoted This came out of discussion on [forum](https://users.rust-lang.org/t/how-to-get-full-output-from-command/50626), where I recently asked a question and it turned out that the problem was redundant quotation: ```rust Command::new("rg") .arg("\"pattern\"") // this will look for "pattern" with quotes included ``` This is something that has bitten me few times already (in multiple languages actually), so It'd be grateful to have it in the docs, even though it's not sctrictly Rust specific problem. Other users also agreed. This can be really annoying to debug, because in many cases (inluding mine), quotes can be legal part of the argument, so the command doesn't fail, it just behaves unexpectedly. Not everybody (including me) knows that quotes around arguments are part of the shell and not part of the called program. Coincidentally, somoene had the same problem [yesterday](https://www.reddit.com/r/rust/comments/jkxelc/going_crazy_over_running_a_curl_process_from_rust/) on reddit. I am not a native speaker, so I welcome any corrections or better formulation, I don't expect this to be merged as is. I was also reminded that this is platform/shell specific behaviour, but I didn't find a good way to formulate that briefly, any ideas welcome. It's also my first PR here, so I am not sure I did everything correctly, I did this just from Github UI.
2020-10-31Apply suggestions from code reviewMatyáš Racek-4/+8
Co-authored-by: Mara Bos <m-ou.se@m-ou.se>
2020-10-31fix aliasing issue in unix sleep functionRalf Jung-1/+2
2020-10-31Add note to process::arg[s] that args shouldn't be escaped or quotedMatyáš Racek-0/+6
2020-10-31Rollup merge of #77099 - tspiteri:exp_m1-examples, r=m-ou-seMara Bos-16/+20
make exp_m1 and ln_1p examples more representative of use With this PR, the examples for `exp_m1` would fail if `x.exp() - 1.0` is used instead of `x.exp_m1()`, and the examples for `ln_1p` would fail if `(x + 1.0).ln()` is used instead of `x.ln_1p()`.
2020-10-31Rollup merge of #74622 - fusion-engineering-forks:panic-box, r=KodrAusMara Bos-0/+14
Add std::panic::panic_any. The discussion of #67984 lead to the conclusion that there should be a macro or function separate from `std::panic!()` for throwing arbitrary payloads, to make it possible to deprecate or disallow (in edition 2021) `std::panic!(arbitrary_payload)`. Alternative names: - `panic_with!(..)` - ~~`start_unwind(..)`~~ (panicking doesn't always unwind) - `throw!(..)` - `panic_throwing!(..)` - `panic_with_value(..)` - `panic_value(..)` - `panic_with(..)` - `panic_box(..)` - `panic(..)` The equivalent (private, unstable) function in `libstd` is called `std::panicking::begin_panic`. I suggest `panic_any`, because it allows for any (`Any + Send`) type. _Tracking issue: #78500_
2020-10-30Rollup merge of #78554 - camelid:improve-drop_in_place-docs-wording, r=jyn514Yuki Okushi-2/+2
Improve wording of `core::ptr::drop_in_place` docs And two small intra-doc link conversions in `std::{f32, f64}`.
2020-10-30Rollup merge of #77921 - wcampbell0x2a:f64-collapsible-if, r=jyn514Yuki Okushi-14/+12
f64: Refactor collapsible_if
2020-10-29Improve wording of `core::ptr::drop_in_place` docsCamelid-2/+2
And two small intra-doc link conversions in `std::{f32, f64}`.
2020-10-28Add tracking issue number for panic_any.Mara Bos-1/+1
2020-10-28Update panic_any feature name.Mara Bos-1/+1
Co-authored-by: Camelid <camelidcamel@gmail.com>
2020-10-27Clean up intra-doc links in `std::path`Camelid-6/+5
2020-10-27Auto merge of #75671 - nathanwhit:cstring-temp-lint, r=oli-obkbors-1/+2
Uplift `temporary-cstring-as-ptr` lint from `clippy` into rustc The general consensus seems to be that this lint covers a common enough mistake to warrant inclusion in rustc. The diagnostic message might need some tweaking, as I'm not sure the use of second-person perspective matches the rest of rustc, but I'd like to hear others' thoughts on that. (cc #53224). r? `@oli-obk`
2020-10-27Auto merge of #78227 - SergioBenitez:test-stdout-threading, r=m-ou-sebors-10/+45
Capture output from threads spawned in tests This is revival of #75172. Original text: > Fixes #42474. > > r? `@​dtolnay` since you expressed interest in this, but feel free to redirect if you aren't the right person anymore. --- Closes #75172.
2020-10-26Fix bootstrap doctest failureNathan Whitaker-1/+1
2020-10-27Rollup merge of #78412 - camelid:cleanup-hash-docs, r=jonas-schievinkYuki Okushi-5/+6
Improve formatting of hash collections docs
2020-10-27Rollup merge of #78394 - rubik:master, r=m-ou-seYuki Okushi-1/+1
fix(docs): typo in BufWriter documentation This PR fixes a small typo in the BufWriter documentation. The current documentation looks like this: ![2020-10-26-111501_438x83_scrot](https://user-images.githubusercontent.com/238549/97160357-83d3a000-177c-11eb-8a35-3cdd3a7d89de.png) The `<u8>` at the end is mangled by Markdown. This PR makes the `BufWriter` documentation like the `BufReader` one: https://github.com/rust-lang/rust/blob/master/library/std/src/io/buffered/bufreader.rs#L16 I'm tagging Steve as per the Rustc dev guide. r? @steveklabnik
2020-10-27Rollup merge of #78375 - taiki-e:question-in-macros, r=kennytmYuki Okushi-5/+2
Use ? in core/std macros
2020-10-26Address review commentsNathan Whitaker-1/+0
2020-10-26Address review commentsNathan Whitaker-0/+2
2020-10-26Change to warn by default / fix typoNathan Whitaker-1/+1
2020-10-26Update doctestNathan Whitaker-1/+1
2020-10-26Improve formatting of hash collections docsCamelid-5/+6
2020-10-26fix(docs): typo in BufWriter documentationMichele Lacchia-1/+1
2020-10-26Rollup merge of #74477 - chansuke:sys-wasm-unsafe-op-in-unsafe-fn, ↵Dylan DPC-15/+38
r=Mark-Simulacrum `#[deny(unsafe_op_in_unsafe_fn)]` in sys/wasm This is part of #73904. This encloses unsafe operations in unsafe fn in `libstd/sys/wasm`. @rustbot modify labels: F-unsafe-block-in-unsafe-fn
2020-10-26Use ? in core/std macrosTaiki Endo-5/+2
2020-10-25Rollup merge of #78208 - liketechnik:issue-69399, r=oli-obkYuki Okushi-1/+3
replace `#[allow_internal_unstable]` with `#[rustc_allow_const_fn_unstable]` for `const fn`s `#[allow_internal_unstable]` is currently used to side-step feature gate and stability checks. While it was originally only meant to be used only on macros, its use was expanded to `const fn`s. This pr adds stricter checks for the usage of `#[allow_internal_unstable]` (only on macros) and introduces the `#[rustc_allow_const_fn_unstable]` attribute for usage on `const fn`s. This pr does not change any of the functionality associated with the use of `#[allow_internal_unstable]` on macros or the usage of `#[rustc_allow_const_fn_unstable]` (instead of `#[allow_internal_unstable]`) on `const fn`s (see https://github.com/rust-lang/rust/issues/69399#issuecomment-712911540). Note: The check for `#[rustc_allow_const_fn_unstable]` currently only validates that the attribute is used on a function, because I don't know how I would check if the function is a `const fn` at the place of the check. I therefore openend this as a 'draft pull request'. Closes rust-lang/rust#69399 r? @oli-obk
2020-10-24Rollup merge of #78119 - fusion-engineering-forks:panic-use-as-str, r=AmanieuJonas Schievink-1/+18
Throw core::panic!("message") as &str instead of String. This makes `core::panic!("message")` consistent with `std::panic!("message")`, which throws a `&str` and not a `String`. This also makes any other panics from `core::panicking::panic` result in a `&str` rather than a `String`, which includes compiler-generated panics such as the panics generated for `mem::zeroed()`. --- Demonstration: ```rust use std::panic; use std::any::Any; fn main() { panic::set_hook(Box::new(|panic_info| check(panic_info.payload()))); check(&*panic::catch_unwind(|| core::panic!("core")).unwrap_err()); check(&*panic::catch_unwind(|| std::panic!("std")).unwrap_err()); } fn check(msg: &(dyn Any + Send)) { if let Some(s) = msg.downcast_ref::<String>() { println!("Got a String: {:?}", s); } else if let Some(s) = msg.downcast_ref::<&str>() { println!("Got a &str: {:?}", s); } } ``` Before: ``` Got a String: "core" Got a String: "core" Got a &str: "std" Got a &str: "std" ``` After: ``` Got a &str: "core" Got a &str: "core" Got a &str: "std" Got a &str: "std" ```
2020-10-24Rollup merge of #77610 - hermitcore:dtors, r=m-ou-seJonas Schievink-163/+182
revise Hermit's mutex interface to support the behaviour of StaticMutex rust-lang/rust#77147 simplifies things by splitting this Mutex type into two types matching the two use cases: StaticMutex and MovableMutex. To support the new behavior of StaticMutex, we move part of the mutex implementation into libstd. The interface to the OS changed. Consequently, I removed a few functions, which aren't longer needed.
2020-10-24Rollup merge of #75115 - chansuke:sys-cloudabi-unsafe, r=KodrAusJonas Schievink-64/+75
`#[deny(unsafe_op_in_unsafe_fn)]` in sys/cloudabi Partial fix of #73904. This encloses unsafe operations in unsafe fn in sys/cloudabi.
2020-10-24Rollup merge of #78274 - Enet4:patch-1, r=jonas-schievinkJonas Schievink-1/+2
Update description of Empty Enum for accuracy An empty enum is similar to the never type `!`, rather than the unit type `()`.
2020-10-24Remove unnecessary unsafe block from condvar_atomics & mutex_atomicschansuke-3/+3
2020-10-24Fix unsafe operation of wasm32::memory_atomic_notifychansuke-1/+2
2020-10-24Add documents for DLMALLOCchansuke-4/+8
2020-10-24Add some description for (malloc/calloc/free/realloc)chansuke-0/+4
2020-10-24`#[deny(unsafe_op_in_unsafe_fn)]` in sys/wasmchansuke-18/+32
2020-10-23Update description of Empty Enum for accuracyEduardo Pinho-1/+2
An empty enum is similar to the never type `!`, rather than the unit type `()`.
2020-10-23Rollup merge of #77918 - wcampbell0x2a:cleanup-network-tests, r=m-ou-seYuki Okushi-12/+5
Cleanup network tests Some cleanup for network related tests
2020-10-22Only load LOCAL_STREAMS if they are being usedSergio Benitez-0/+5
2020-10-22Capture output from threads spawned in testsTyler Mandry-10/+40
Fixes #42474.
2020-10-21switch allow_internal_unstable const fns to rustc_allow_const_fn_unstableFlorian Warzecha-1/+3
2020-10-20Rollup merge of #77923 - wcampbell0x2a:cleanup-net-module, r=scottmcmYuki Okushi-8/+2
[net] apply clippy lints Applied helpful clippy lints to the network std library module.
2020-10-20Rollup merge of #77838 - RalfJung:const-fn, r=kennytmYuki Okushi-3/+18
const keyword: brief paragraph on 'const fn' `const fn` were mentioned in the title, but called "deterministic functions" which is not their main property (though at least currently it is a consequence of being const-evaluable). This adds a brief paragraph discussing them, also in the hopes of clarifying that they do *not* have any effect on run-time uses.
2020-10-20Check that pthread mutex initialization succeededTomasz Miąsko-22/+27
If pthread mutex initialization fails, the failure will go unnoticed unless debug assertions are enabled. Any subsequent use of mutex will also silently fail, since return values from lock & unlock operations are similarly checked only through debug assertions. In some implementations the mutex initialization requires a memory allocation and so it does fail in practice. Check that initialization succeeds to ensure that mutex guarantees mutual exclusion.
2020-10-19Throw core::panic!("message") as &str instead of String.Mara Bos-1/+18
This makes it consistent with std::panic!("message"), which also throws a &str, not a String.
2020-10-19Revert "[net] clippy: needless_update"wcampbell-0/+1
This reverts commit 058699d0a2fca02127761f014d0ecfce1c5541ec.
2020-10-18Add missing punctuationpierwill-1/+1
2020-10-18Remove redundant 'static from library cratesest31-9/+9
2020-10-18Rename panic_box to panic_any.Mara Bos-5/+5