Commit graph

1804 commits

Author SHA1 Message Date
Nika Layzell
00f32e6631 Add fetch_update methods to AtomicBool and AtomicPtr
These methods were stabilized for the integer atomics in #71843, but the methods
were not added for the non-integer atomics `AtomicBool` and `AtomicPtr`.
2020-11-01 13:57:45 -05:00
Mara Bos
97678b8358
Rollup merge of #78621 - solson:inline, r=m-ou-se
Inline Default::default() for atomics

Functions like `AtomicUsize::default()` are not cross-crate inlineable before this PR ([see assembly output here](https://play.rust-lang.org/?version=stable&mode=release&edition=2018&gist=e353321766418f759c69fb141d3732f8)), which can lead to unexpected performance issues when initializing a large array using this function, e.g. as seen [here](d513996a85/src/histogram.rs (L53)) which should turn into a simple loop writing zeroes but doesn't.

r? @m-ou-se
2020-11-01 11:53:39 +01:00
Mara Bos
8ed31d2782
Rollup merge of #78602 - RalfJung:raw-ptr-aliasing-issues, r=m-ou-se
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-01 11:53:36 +01:00
Mara Bos
f281a76f83
Rollup merge of #78599 - panstromek:master, r=m-ou-se
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-11-01 11:53:34 +01:00
Mara Bos
25eac92987
Rollup merge of #78596 - pavlukivan:master, r=m-ou-se
Fix doc links to std::fmt

`std::format` and `core::write` macros' docs linked to `core::fmt` for format string reference, even though only `std::fmt` has format string documentation (and the link titles were `std::fmt`)
2020-11-01 11:53:33 +01:00
Mara Bos
835310e3cc
Rollup merge of #78073 - fusion-engineering-forks:inline, r=eddyb
Add #[inline] to some functions in core::str.

Almost all str functions already had #[inline].
2020-11-01 11:53:29 +01:00
Scott Olson
e5b1f69d63 Inline Default::default() for atomics 2020-11-01 04:38:41 +00:00
Matyáš Racek
db416b232c
Apply suggestions from code review
Co-authored-by: Mara Bos <m-ou.se@m-ou.se>
2020-10-31 17:28:44 +01:00
Ralf Jung
9749eb72af fix aliasing issues in SipHasher 2020-10-31 16:26:06 +01:00
Ralf Jung
607076e209 fix aliasing issue in binary_heap 2020-10-31 16:26:06 +01:00
Ralf Jung
9f630af930 fix aliasing issue in unix sleep function 2020-10-31 16:26:06 +01:00
Ralf Jung
ed96321e7e fix aliasing issues in u128 formatting code 2020-10-31 16:26:06 +01:00
Matyáš Racek
d417bbef95
Add note to process::arg[s] that args shouldn't be escaped or quoted 2020-10-31 14:40:36 +01:00
Ivan Pavluk
3baf6a4a74 Fix doc links to std::fmt
std::format and core::write macros' docs linked to core::fmt for format string reference, even though only std::fmt has format string documentation and the link titles were std::fmt.
2020-10-31 18:02:55 +07:00
Mara Bos
3601f9d40b
Rollup merge of #78581 - a1phyr:const_btree_more, r=dtolnay
Constantify more BTreeMap and BTreeSet functions

Just because we can:

- `BTreeMap::len`
- `BTreeMap::is_empty`
- `BTreeSet::len`
- `BTreeSet::is_empty`

Note that I put the `const` under `const_btree_new`, because I don't think their is a need to create another feature flag for that.

cc #71835
2020-10-31 09:49:39 +01:00
Mara Bos
4ebd5536b4
Rollup merge of #77099 - tspiteri:exp_m1-examples, r=m-ou-se
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-31 09:49:32 +01:00
Mara Bos
76b8b00b4f
Rollup merge of #74622 - fusion-engineering-forks:panic-box, r=KodrAus
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-31 09:49:28 +01:00
Benoît du Garreau
307cc11beb Constantify more BTreeMap and BTreeSet functions
- BTreeMap::len
- BTreeMap::is_empty
- BTreeSet::len
- BTreeSet::is_empty
2020-10-30 19:24:08 +01:00
Yuki Okushi
73d0340fd5
Rollup merge of #78554 - camelid:improve-drop_in_place-docs-wording, r=jyn514
Improve wording of `core::ptr::drop_in_place` docs

And two small intra-doc link conversions in `std::{f32, f64}`.
2020-10-30 18:00:58 +09:00
Yuki Okushi
02a4b58a3f
Rollup merge of #77921 - wcampbell0x2a:f64-collapsible-if, r=jyn514
f64: Refactor collapsible_if
2020-10-30 18:00:49 +09:00
Yuki Okushi
0723b274d2
Rollup merge of #77334 - pickfire:patch-4, r=jyn514
Reorder benches const variable

Move LEN so it is is read in order.
2020-10-30 18:00:41 +09:00
Camelid
fee4f8feb0 Improve wording of core::ptr::drop_in_place docs
And two small intra-doc link conversions in `std::{f32, f64}`.
2020-10-29 20:09:29 -07:00
Jonas Schievink
48c4afbf9c
Rollup merge of #78499 - SkiFire13:fix-string-retain, r=m-ou-se
Prevent String::retain from creating non-utf8 strings when abusing panic

Fixes #78498

The idea is the same as `Vec::drain`, set the len to 0 so that nobody can observe the broken invariant if it escapes the function (in this case if `f` panics)
2020-10-29 17:05:28 +01:00
Jonas Schievink
a384a5866b
Rollup merge of #76138 - camelid:rc-fully-qualified-syntax, r=steveklabnik
Explain fully qualified syntax for `Rc` and `Arc`

Also cleaned up some other small things.

@rustbot modify labels: T-doc
2020-10-29 17:05:08 +01:00
Jonas Schievink
2168210961
Rollup merge of #75078 - ijackson:slice-strip, r=steveklabnik
Improve documentation for slice strip_* functions

Prompted by the stabilisation tracking issue #73413 I looked at the docs for `strip_prefix` and `strip_suffix` for both `str` and `slice`, and I felt they could be slightly improved.

Thanks for your attention.
2020-10-29 17:05:00 +01:00
bors
a53fb30e3b Auto merge of #78446 - RalfJung:box, r=Amanieu
fix Box::into_unique

https://github.com/rust-lang/rust/pull/77187/ broke Stacked Borrows pointer tagging around `Box::into_unique` (this is caused by `Box` being a special case in the type system, which box-internal code needs to account for). This PR fixes that.

r? `@Amanieu` Cc `@TimDiekmann`

Fixes https://github.com/rust-lang/rust/issues/78419.
2020-10-29 12:08:16 +00:00
Giacomo Stevanato
1f6f917f73 Added test for issue #78498 2020-10-29 12:25:02 +01:00
Giacomo Stevanato
e83666f45e Prevent String::retain from creating non-utf8 strings when abusing panic 2020-10-29 11:58:12 +01:00
Yuki Okushi
c7792230c0
Rollup merge of #78491 - petertodd:2020-inline-from-nonzero, r=sfackler
Inline NonZeroN::from(n)

Currently this results in the generated assembly having a function call for this trivial conversion.
2020-10-29 12:08:59 +09:00
Yuki Okushi
7eb7b5a4af
Rollup merge of #78470 - camelid:fixup-std-path-intra-doc, r=jyn514
Clean up intra-doc links in `std::path`
2020-10-29 12:08:53 +09:00
Camelid
4e30e10f25 Don't say you "should" use fully qualified syntax
That recommendation was removed last year; there isn't a particular
style that is officially recommended anymore.
2020-10-28 16:49:30 -07:00
Camelid
e0eed3c558 Fix broken intra-doc link 2020-10-28 16:31:45 -07:00
Camelid
bd7cbaecd3 Explain fully qualified syntax for Rc and Arc 2020-10-28 16:31:44 -07:00
Mara Bos
b48fee010c Add tracking issue number for panic_any. 2020-10-28 21:23:45 +01:00
Mara Bos
a9d334d386
Update panic_any feature name.
Co-authored-by: Camelid <camelidcamel@gmail.com>
2020-10-28 21:21:41 +01:00
Peter Todd
061715604a
Inline NonZeroN::from(n) 2020-10-28 13:26:44 -04:00
Camelid
0217edbd29
Clean up intra-doc links in std::path 2020-10-27 20:54:30 -07:00
bors
db241bb0c8 Auto merge of #78458 - Dylan-DPC:rollup-tan044s, r=Dylan-DPC
Rollup of 10 pull requests

Successful merges:

 - #78152 (Separate unsized locals)
 - #78297 (Suggest calling await on method call and field access)
 - #78351 (Move "mutable thing in const" check from interning to validity)
 - #78365 (check object safety of generic constants)
 - #78379 (Tweak invalid `fn` header and body parsing)
 - #78391 (Add const_fn in generics test)
 - #78401 (resolve: private fields in tuple struct ctor diag)
 - #78408 (Remove tokens from foreign items in `TokenStripper`)
 - #78447 (Fix typo in  comment)
 - #78453 (Fix typo in comments)

Failed merges:

r? `@ghost`
2020-10-28 01:40:06 +00:00
Dylan DPC
346aeef496
Rollup merge of #78152 - spastorino:separate-unsized-locals, r=oli-obk
Separate unsized locals

Closes #71694

Takes over again #72029 and #74971

cc @RalfJung @oli-obk @pnkfelix @eddyb as they've participated in previous reviews of this PR.
2020-10-28 01:21:08 +01:00
bors
90e6d0d46b Auto merge of #75671 - nathanwhit:cstring-temp-lint, r=oli-obk
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-27 22:59:13 +00:00
Santiago Pastorino
ba59aa2b77
Do not depend on except for bootstrap 2020-10-27 14:45:36 -03:00
Santiago Pastorino
708fc3b1a2
Add unsized_fn_params feature 2020-10-27 14:45:02 -03:00
Ralf Jung
ab374dc37c fix Box::into_unique 2020-10-27 17:02:42 +01:00
Ayrton
511fe048b4 Changed lint to check for std::fmt::Pointer and transmute
The lint checks arguments in calls to `transmute` or functions that have
`Pointer` as a trait bound and displays a warning if the argument is a function
reference. Also checks for `std::fmt::Pointer::fmt` to handle formatting macros
although it doesn't depend on the exact expansion of the macro or formatting
internals. `std::fmt::Pointer` and `std::fmt::Pointer::fmt` were also added as
diagnostic items and symbols.
2020-10-27 11:04:04 -04:00
bors
56d288fa46 Auto merge of #78227 - SergioBenitez:test-stdout-threading, r=m-ou-se
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-27 11:43:18 +00:00
bors
c9b606ed67 Auto merge of #78359 - ssomers:btree_cleanup_mem, r=Mark-Simulacrum
BTreeMap: move generic support functions out of navigate.rs

A preparatory step chipped off #78104, useful in general (if at all).

r? `@Mark-Simulacrum`
2020-10-27 04:01:52 +00:00
Nathan Whitaker
39941e6281 Fix bootstrap doctest failure 2020-10-26 22:09:47 -04:00
Yuki Okushi
4236d27c9b
Rollup merge of #78412 - camelid:cleanup-hash-docs, r=jonas-schievink
Improve formatting of hash collections docs
2020-10-27 08:45:30 +09:00
Yuki Okushi
f6f8764b25
Rollup merge of #78394 - rubik:master, r=m-ou-se
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-27 08:45:20 +09:00
Yuki Okushi
5a33fa5179
Rollup merge of #78375 - taiki-e:question-in-macros, r=kennytm
Use ? in core/std macros
2020-10-27 08:45:10 +09:00