Commit graph

5306 commits

Author SHA1 Message Date
bors
6cdd42f9f8 Auto merge of #88988 - Mark-Simulacrum:avoid-into-ok, r=nagisa
Avoid codegen for Result::into_ok in lang_start

This extra codegen seems to be the cause for the regressions in max-rss on #86034. While LLVM will certainly optimize the dead code away, avoiding it's generation in the first place seems good, particularly when it is so simple.

#86034 produced this [diff](https://gist.github.com/Mark-Simulacrum/95c7599883093af3b960c35ffadf4dab#file-86034-diff) for a simple `fn main() {}`. With this PR, that diff [becomes limited to just a few extra IR instructions](https://gist.github.com/Mark-Simulacrum/95c7599883093af3b960c35ffadf4dab#file-88988-from-pre-diff) -- no extra functions.

Note that these are pre-optimization; LLVM surely will eliminate this during optimization. However, that optimization can end up generating more work and bump memory usage, and this eliminates that.
2021-09-18 09:15:40 +00:00
DeveloperC286
05b01cd787 refactor: VecDeques IntoIter fields to private 2021-09-17 21:46:32 +01:00
Sachin Cherian
ec34aa61d6 modify std::os docs to be more consistent
> add intra doc links
> add a usage example for the os::windows module
2021-09-17 23:23:21 +05:30
The8472
57465d9c1b use AtomicU64::fetch_update instead of handrolled RMW-loop 2021-09-17 18:54:24 +02:00
Maybe Waffle
71e2eacc7b Stabilize Iterator::map_while 2021-09-17 19:42:46 +03:00
Guillaume Gomez
eb62779f2d
Rollup merge of #88954 - nbdd0121:panic3, r=oli-obk
Allow `panic!("{}", computed_str)` in const fn.

Special-case `panic!("{}", arg)` and translate it to `panic_display(&arg)`. `panic_display` will behave like `panic_any` in cosnt eval and behave like `panic!(format_args!("{}", arg))` in runtime.

This should bring Rust 2015 and 2021 to feature parity in terms of `const_panic`; and hopefully would unblock the stabilisation of #51999.

`@rustbot` modify labels: +T-compiler +T-libs +A-const-eval +A-const-fn

r? `@oli-obk`
2021-09-17 17:41:19 +02:00
Guillaume Gomez
723d27934b
Rollup merge of #88953 - joshtriplett:chown, r=dtolnay
Add chown functions to std::os::unix::fs to change the owner and group of files

This is a straightforward wrapper that uses the existing helpers for C
string handling and errno handling.

Having this available is convenient for UNIX utility programs written in
Rust, and avoids having to call unsafe functions like `libc::chown`
directly and handle errors manually, in a program that may otherwise be
entirely safe code.

In addition, these functions provide a more Rustic interface by
accepting appropriate traits and using `None` rather than `-1`.
2021-09-17 17:41:18 +02:00
John Paul Adrian Glaubitz
2cef5d8091 library/std/env: Add 'm68k' to comment on ARCH constant 2021-09-17 15:07:14 +00:00
John Paul Adrian Glaubitz
5e56778dc8 libstd: Add m68k for raw type definitions on Linux 2021-09-17 15:07:14 +00:00
Yuki Okushi
5d14396ed0
Rollup merge of #88887 - fee1-dead:const-deref, r=oli-obk
Const Deref

Implements `const Deref`/`const DerefMut` for `&mut T`, `&T`, `Cow<'_, B>` and `ManuallyDrop<T>`
2021-09-17 14:09:48 +09:00
Yuki Okushi
0f06e36603
Rollup merge of #88339 - piegamesde:master, r=joshtriplett
Add TcpListener::into_incoming and IntoIncoming

The `incoming` method is really useful, however for some use cases the borrow
this introduces is needlessly restricting. Thus, an owned variant is added.

r? ``@joshtriplett``
2021-09-17 14:09:45 +09:00
Gary Guo
be5a5b70b4 Fix missing no_global_oom_handling cfg-gating 2021-09-17 03:53:18 +01:00
The8472
ca2d2fa283 Don't inline OnceCell initialization closures 2021-09-17 00:24:36 +02:00
Manish Goregaokar
d9fa3561b6
Rollup merge of #89009 - tatami4:master, r=Mark-Simulacrum
Fix typo in `break` docs
2021-09-16 10:57:25 -07:00
Manish Goregaokar
84d384c8c1
Rollup merge of #88986 - hargoniX:master, r=Mark-Simulacrum
Update the backtrace crate

https://github.com/rust-lang/backtrace-rs/pull/437 fixed backtraces in
OpenBSD -> update it here as well so OpenBSD Rust code can produce
proper backtraces.
2021-09-16 10:57:24 -07:00
Manish Goregaokar
06dbc284a8
Rollup merge of #88976 - notriddle:notriddle/cow-from-cstr-docs, r=Mark-Simulacrum
Clean up and add doc comments for CStr

CC #51430
2021-09-16 10:57:21 -07:00
Manish Goregaokar
5b6285e370
Rollup merge of #88928 - lefth:master, r=Mark-Simulacrum
Document the closure arguments for `reduce`.

See issue #88927.
2021-09-16 10:57:20 -07:00
The8472
2b512cc329 fix potential race in AtomicU64 time monotonizer 2021-09-16 18:32:28 +02:00
est31
372711906b Add IntoIterator intra doc link to various collections 2021-09-16 13:55:27 +02:00
tatami4
a452d02636
Fix typo in break docs 2021-09-16 14:51:14 +03:00
est31
a8a829deb4 Add intra-doc-links to BinaryHeap rustdoc 2021-09-16 13:35:54 +02:00
est31
52ab3e8e76 Add intra-doc-links to LinkedList rustdoc 2021-09-16 13:20:36 +02:00
Mark Rousskov
db5ecd539c Avoid codegen for Result::into_ok in lang_start
Otherwise, we end up pulling in an extra module as part of codegen, and that
costs us a sizeable amount of work (both in LLVM and outside).
2021-09-15 21:35:10 -04:00
Michiel De Muynck
77ceb2b5d8 Make Duration's Debug format pad to width
Duration's Debug formatting previously ignored the width parameter.
This commit fixes that.

Fixes issue #88059.
2021-09-16 03:09:31 +02:00
Manish Goregaokar
cad1efae57
Rollup merge of #88915 - joshlf:patch-4, r=kennytm
`Wrapping<T>` has the same layout and ABI as `T`
2021-09-15 14:57:02 -07:00
Gary Guo
11c0e58c74 Allow panic!("{}", computed_str) in const fn. 2021-09-15 21:56:43 +01:00
Josh Triplett
862d89e3b5 Add tracking issue for unix_chown 2021-09-15 13:09:54 -07:00
Henrik Böving
4e61d11a16 Update the backtrace crate
https://github.com/rust-lang/backtrace-rs/pull/437 fixed backtraces in
OpenBSD -> update it here as well so OpenBSD Rust code can produce
proper backtraces.
2021-09-15 20:32:35 +02:00
Michael Howell
cc7929b1bd docs(std): add docs for cof_from_cstr impls
CC #51430
2021-09-15 09:14:20 -07:00
bors
e846f9c44f Auto merge of #88619 - GuillaumeGomez:simplify-std-os-reexports, r=Amanieu
Remove `cfg(doc)` from std::os module reexports to fix rustdoc linking issues

Fixes https://github.com/rust-lang/rust/issues/88304.

I tested it based on https://github.com/rust-lang/rust/pull/88292.

Not sure if it's the best approach, but at least it makes thing a bit simpler.

cc `@jyn514`
2021-09-15 09:30:00 +00:00
Deadbeef
349ac4f6c8
Const Deref 2021-09-15 03:06:53 +00:00
Josh Triplett
4840f67fcb Add chown functions to std::os::unix::fs to change the owner and group of files
This is a straightforward wrapper that uses the existing helpers for C
string handling and errno handling.

Having this available is convenient for UNIX utility programs written in
Rust, and avoids having to call unsafe functions like `libc::chown`
directly and handle errors manually, in a program that may otherwise be
entirely safe code.

In addition, these functions provide a more Rustic interface by
accepting appropriate traits and using `None` rather than `-1`.
2021-09-14 19:10:05 -07:00
Dan Zwell
6b7f916008 Document the closure arguments for reduce.
Fixes issue #88927.
2021-09-14 14:22:49 +08:00
Joshua Liebow-Feeser
1053a5bb0f
Wrapping<T> has the same layout and ABI as T 2021-09-13 12:39:45 -07:00
Guillaume Gomez
5eb77838ea
Rollup merge of #88722 - WaffleLapkin:unsafe_cell_const_get_mut, r=dtolnay
Make `UnsafeCell::get_mut` const
2021-09-13 21:20:39 +02:00
Guillaume Gomez
7965a9f143 Move fortanix module position in std::os reexports for alpha sort 2021-09-13 21:00:28 +02:00
Guillaume Gomez
1c4873c81f Remove usage of cfg_if in std/src/os/mod.rs 2021-09-13 21:00:28 +02:00
Guillaume Gomez
8d879aa0f2 Simplify std::os module reexports to fix rustdoc linking issues 2021-09-13 21:00:28 +02:00
Joshua Nelson
7b46920218 Fix linkcheck issues
Most of these are because alloc uses `#[lang_item]` to define methods,
but core documents primitives before those methods are available.

- Fix rustdoc-js-std test

  For some reason this change made CStr not show up in the results for
  `str,u8`. Since it still shows up for str, and since it wasn't a great
  match for that query anyway, I think this is ok to let slide.

- Add test that all primitives can be linked to
- Enable `doc(primitive)` in `core` as well
- Add linkcheck exception specifically for Windows

  Ideally this would be done automatically by the linkchecker by
  replacing `\\` with forward slashes, but this PR is already a ton of
  work ...

- Don't forcibly fail linkchecking if there's a broken intra-doc link on Windows

  Previously, it would exit with a hard error if a missing file had `::`
  in it. This changes it to report a missing file instead, which allows
  adding an exception.
2021-09-12 02:30:24 +00:00
Joshua Nelson
69fe39e8a8 Add primitive documentation to libcore
This works by doing two things:
- Adding links that are specific to the crate. Since not all primitive
  items are defined in `core` (due to lang_items), these need to use
  relative links and not intra-doc links.
- Duplicating `primitive_docs` in both core and std. This allows not needing CARGO_PKG_NAME to build the standard library. It also adds a tidy check to make sure they stay the same.
2021-09-12 02:23:08 +00:00
Jubilee
c2e1097f44
Rollup merge of #88849 - matthiaskrgr:clony_on_copy, r=petrochenkov
don't clone types that are Copy (clippy::clone_on_copy)
2021-09-11 08:23:45 -07:00
Jubilee
95b50eb662
Rollup merge of #87904 - kpreid:unsize, r=jyn514
Reword description of automatic impls of `Unsize`.

The existing documentation felt a little unhelpfully concise, so this change tries to improve it by using longer sentences, each of which specifies which kinds of types it applies to as early as possible. In particular, the third item starts with “Structs ...” instead of saying “Foo is a struct” later.

Also, the previous list items “Only the last field has a type involving `T`” and “`T` is not part of the type of any other fields” are, as far as I see, redundant with each other, so I removed the latter.

I have no particular knowledge of `Unsize`; I have attempted to leave the meaning entirely unchanged but may have missed a nuance.

Markdown preview of the edited documentation:

> All implementations of `Unsize` are provided automatically by the compiler.
> Those implementations are:
>
> - Arrays `[T; N]` implement `Unsize<[T]>`.
> - Types implementing a trait `Trait` also implement `Unsize<dyn Trait>`.
> - Structs `Foo<..., T, ...>` implement `Unsize<Foo<..., U, ...>>` if all of these conditions
>   are met:
>   - `T: Unsize<U>`.
>   - Only the last field of `Foo` has a type involving `T`.
>   - `Bar<T>: Unsize<Bar<U>>`, where `Bar<T>` stands for the actual type of that last field.
2021-09-11 08:23:38 -07:00
Matthias Krüger
c1e96085d3 don't clone types that are Copy (clippy::clone_on_copy) 2021-09-11 10:18:56 +02:00
Waffle Lapkin
2c30162380
Fill in the tracking issue for #![feature(const_unsafecell_get_mut)] 2021-09-11 00:07:14 +03:00
Manish Goregaokar
00553034db
Rollup merge of #88807 - jruderman:which_reverses, r=joshtriplett
Fix typo in docs for iterators
2021-09-10 08:23:26 -07:00
Manish Goregaokar
8368af060d
Rollup merge of #88667 - kraktus:patch-1, r=dtolnay
Tweak `write_fmt` doc.

Found this weird sentence while reading the docs.
2021-09-10 08:23:21 -07:00
Manish Goregaokar
000dbd27f1
Rollup merge of #86165 - m-ou-se:proc-macro-span-shrink, r=dtolnay
Add proc_macro::Span::{before, after}.

This adds `proc_macro::Span::before()` and `proc_macro::Span::after()` to get a zero width span at the start or end of the span.

These are equivalent to rustc's `Span::shrink_to_lo()` and `Span::shrink_to_hi()` but with a less cryptic name. They are useful when generating diagnostlics like "missing \<thing\> after \<thing\>".

E.g.

```rust
syn::Error::new(ident.span().after(), "missing `:` after field name").into_compile_error()
```
2021-09-10 08:23:14 -07:00
Jesse Ruderman
81ff53fd3e
Fix typo in docs for iterators 2021-09-09 19:21:56 -07:00
Fabian Wolff
79adda930f Ignore automatically derived impls of Clone and Debug in dead code analysis 2021-09-09 19:49:07 +02:00
Mark Rousskov
b4e7649d6d Bump stage0 compiler to 1.56 2021-09-08 20:51:05 -04:00
Jack Huey
bd6ce72ece
Rollup merge of #88712 - jhpratt:fix-int_rounding-docs, r=joshtriplett
Fix docs for `uX::checked_next_multiple_of`

Thanks to `@photino` for noticing this [here](https://github.com/rust-lang/rust/issues/88581#issuecomment-913982246).

r? `@joshtriplett`

`@rustbot` label: +A-docs +A-waiting-on-review
2021-09-08 12:24:21 -04:00
Jack Huey
2bbcf929c6
Rollup merge of #88648 - kpreid:option, r=Mark-Simulacrum
Correct “copies” to “moves” in `<Option<T> as From<T>>::from` doc, and other copyediting

The `impl<T> From<T> for Option<T>` has no `Copy` or `Clone` bound, so its operation is guaranteed to be a move. The call site might copy, but the function itself cannot.

Since that would have been a rather small PR, I also reviewed the other documentation in the file and made other improvements (in separate commits): adding periods and commas, linking `Deref::Target`, and clarifying what "a container" is in `FromIterator`.
2021-09-08 12:24:18 -04:00
Jack Huey
b1c782f20b
Rollup merge of #88594 - steffahn:more_symbolic_doc_aliases, r=joshtriplett
More symbolic doc aliases

A bunch of small changes, mostly adding `#[doc(alias = "…")]` entries for symbolic `"…"`.

Also a small change in documentation of `const` keywords.
2021-09-08 12:24:17 -04:00
bors
434cb437b5 Auto merge of #86943 - ptrojahn:suggest_derive, r=estebank
Suggest deriving traits if possible

This only applies to builtin derives as I don't think there is a
clean way to get the available derives in typeck.

Closes #85851
2021-09-08 07:27:41 +00:00
Waffle
efeb461873 Make UnsafeCell::get_mut const 2021-09-07 16:41:15 +03:00
Jacob Pratt
56bb6f5a25
Fix docs for uX::checked_next_multiple_of 2021-09-07 02:14:04 -04:00
bors
ffaf857045 Auto merge of #88448 - xu-cheng:btree-blk-build, r=Mark-Simulacrum
BTreeMap/BTreeSet::from_iter: use bulk building to improve the performance

Bulk building is a common technique to increase the performance of building a fresh btree map. Instead of inserting items one-by-one, we sort all the items beforehand then create the BtreeMap in bulk.

Benchmark
```
./x.py bench library/alloc --test-args btree::map::from_iter
```

* Before
```
test btree::map::from_iter_rand_100                      ... bench:       3,694 ns/iter (+/- 840)
test btree::map::from_iter_rand_10_000                   ... bench:   1,033,446 ns/iter (+/- 192,950)
test btree::map::from_iter_seq_100                       ... bench:       5,689 ns/iter (+/- 1,259)
test btree::map::from_iter_seq_10_000                    ... bench:     861,033 ns/iter (+/- 118,815)
```

* After
```
test btree::map::from_iter_rand_100                      ... bench:       3,033 ns/iter (+/- 707)
test btree::map::from_iter_rand_10_000                   ... bench:     775,958 ns/iter (+/- 105,152)
test btree::map::from_iter_seq_100                       ... bench:       2,969 ns/iter (+/- 336)
test btree::map::from_iter_seq_10_000                    ... bench:     258,292 ns/iter (+/- 29,364)
```
2021-09-07 02:24:11 +00:00
Paul Trojahn
50e5f90c92 Suggest deriving traits if possible
This only applies to builtin derives as I don't think there is a
clean way to get the available derives in typeck.

Closes #85851
2021-09-06 13:18:05 +02:00
Ryan Levick
0d4a51d741
Rollup merge of #88673 - Qwaz:node-typo, r=jyn514
Fix typo: needede -> needed

Fix a typo in library/alloc/src/collections/btree/node.rs
2021-09-06 12:38:57 +02:00
Ryan Levick
29a018def4
Rollup merge of #88647 - ChrisDenton:win-symlink-docs, r=joshtriplett
Document when to use Windows' `symlink_dir` vs. `symlink_file`

It was previously unclear why there are two functions and when they should be used.

Fixes: #88635
2021-09-06 12:38:54 +02:00
lovasoa
f63096e4f2
rust fmt 2021-09-05 22:56:15 +01:00
Yechan Bae
3a105cfcea Fix typo: needede -> needed 2021-09-05 16:04:19 -04:00
Frank Steffahn
5135d86920 Mention usage of const in raw pointer types at the top of the keyword's documentation page. 2021-09-05 19:14:55 +02:00
Frank Steffahn
2b69171dc2 Additional aliases for pointers 2021-09-05 19:14:44 +02:00
kraktus
bfb2b02d61
Tweak write_fmt doc.
Previous version wrongly used `but` while the two parts of the sentence are not contradicting but completing with each other.
2021-09-05 17:23:58 +02:00
Falk Hüffner
d760c33183 Change return type for T::{log,log2,log10} to u32. The value is at
most 128, and this is consistent with using u32 for small values
elsewhere (e.g. BITS, count_ones, leading_zeros).
2021-09-05 17:09:21 +02:00
Mara Bos
22dd6a4e30
Rollup merge of #88432 - terrarier2111:patch-1, r=joshtriplett
Fix a typo in raw_vec
2021-09-05 10:32:21 +02:00
bors
0961e688fd Auto merge of #88469 - patrick-gu:master, r=dtolnay
Add links in docs for some primitive types

This pull request adds additional links in existing documentation of some of the primitive types.

Where items are linked only once, I have used the `[link](destination)` format. For items in `std`, I have linked directly to the HTML, since although the primitives are in `core`, they are not displayed on `core` documentation. I was unsure of what length I should keep lines of documentation to, so I tried to keep them within reason.

Additionally, I have avoided excessively linking to keywords like `self` when they are not relevant to the documentation. I can add these links if it would be an improvement.

I hope this can improve Rust. Please let me know if there's anything I did wrong!
2021-09-05 01:56:25 +00:00
Kevin Reid
9a3a2a1c37 Clarify what “a container” is in FromIterator<Option<A>> for Option<V> doc. 2021-09-04 11:30:14 -07:00
Kevin Reid
c2f432058c Add sentence punctuation and links in Option docs. 2021-09-04 11:30:14 -07:00
Kevin Reid
34c1fce50b “Moves” instead of “copies” in <Option<T> as From<T>>::from doc.
This implementation has no `Copy` or `Clone` bound, so its operation is
guaranteed to be a move. The call site might copy, but the function
itself cannot.

Also linkify `Some` while we're touching the line anyway.
2021-09-04 11:29:55 -07:00
Chris Denton
2d95b5bce7
Document when to use Windows' symlink_dir vs. symlink_file
It was previously unclear which should be used when.
2021-09-04 19:22:34 +01:00
patrick-gu
7c32b58df2
Fix accidentally deleted part 2021-09-03 17:13:42 -07:00
patrick-gu
529abb2fc0 Add a missing backtick 2021-09-03 17:11:57 -07:00
patrick-gu
911d0cbe80 Remove excessive linking 2021-09-03 17:09:37 -07:00
Mara Bos
2ce74b0bc0
Rollup merge of #88613 - m-ou-se:array-docs-2021, r=Amanieu
Update primitive docs for rust 2021.

Fixes https://github.com/rust-lang/rust/issues/87701
2021-09-03 13:30:51 +02:00
Mara Bos
e13b9c90c9
Rollup merge of #88610 - m-ou-se:array-into-iter-docs, r=Amanieu
Update outdated docs of array::IntoIter::new.
2021-09-03 13:30:50 +02:00
Mara Bos
01775b6027
Rollup merge of #88579 - ast-ral:master, r=m-ou-se
remove redundant / misplaced sentence from docs

Removes sentence that seems to have drifted down into the examples section. Luckily, someone already added an explanation of what happens with packed structs back into the initial section of the doc entry and this wayward sentence can likely just be deleted.
2021-09-03 13:30:49 +02:00
Mara Bos
80b572b5e5
Rollup merge of #88507 - atsuzaki:slice-fill-maybeuninit-test, r=RalfJung
Add test case for using `slice::fill` with MaybeUninit

Adds test for #87891

Looks alright? `@RalfJung`
Fixes #87891
2021-09-03 13:30:47 +02:00
Mara Bos
cb2be32dbd
Rollup merge of #88202 - azdavis:master, r=jyn514
Add an example for deriving PartialOrd on enums

For some reason, I always forget which variants are smaller and which
are larger when you derive PartialOrd on an enum. And the wording in the
current docs is not entirely clear to me.

So, I often end up making a small enum, deriving PartialOrd on it, and
then writing a `#[test]` with an assert that the top one is smaller than
the bottom one (or the other way around) to figure out which way the
deriving goes.

So then I figured, it would be great if the standard library docs just
had that example, so if I keep forgetting, at least I can figure it out
quickly by looking at std's docs.
2021-09-03 13:30:46 +02:00
Mara Bos
00c8da145c Update primitive docs for rust 2021. 2021-09-03 12:49:37 +02:00
Ophir LOJKINE
aaa6de7905
Add a better error message for #39364
There is a known bug in the implementation of mpsc channels in rust.
This adds a clearer error message when the bug occurs, so that developers don't lose too much time looking for the origin of the bug.
See https://github.com/rust-lang/rust/issues/39364
2021-09-03 12:14:55 +02:00
Mara Bos
5ea45f35c0 Update outdated docs of array::IntoIter::new. 2021-09-03 11:24:52 +02:00
bors
b834c4c1ba Auto merge of #88596 - m-ou-se:rollup-cidzt4v, r=m-ou-se
Rollup of 12 pull requests

Successful merges:

 - #88177 (Stabilize std::os::unix::fs::chroot)
 - #88505 (Use `unwrap_unchecked` where possible)
 - #88512 (Upgrade array_into_iter lint to include Deref-to-array types.)
 - #88532 (Remove single use variables)
 - #88543 (Improve closure dummy capture suggestion in macros.)
 - #88560 (`fmt::Formatter::pad`: don't call chars().count() more than one time)
 - #88565 (Add regression test for issue 83190)
 - #88567 (Remove redundant `Span` in `QueryJobInfo`)
 - #88573 (rustdoc: Don't panic on ambiguous inherent associated types)
 - #88582 (Implement #88581)
 - #88589 (Correct doc comments inside `use_expr_visitor.rs`)
 - #88592 (Fix ICE in const check)

Failed merges:

r? `@ghost`
`@rustbot` modify labels: rollup
2021-09-02 18:58:12 +00:00
Mara Bos
2159c5db63
Rollup merge of #88582 - jhpratt:int_roundings, r=joshtriplett
Implement #88581

See #88581 for details. This API was discussed on Zulip.

`@rustbot` label: +T-libs-api +S-waiting-on-review

r? `@joshtriplett`
2021-09-02 19:10:22 +02:00
Mara Bos
0d105c0e77
Rollup merge of #88560 - klensy:formatter-pad-shrink, r=m-ou-se
`fmt::Formatter::pad`: don't call chars().count() more than one time

First commit merges two branches of match to call chars().count() only once: that should be faster if this method hits place of 3rd (previous) branch, plus quarter shorter.
Second commit fixes some clippy lints while i'm here (should it be separate PR?).
2021-09-02 19:10:18 +02:00
Mara Bos
8fd1bf3323
Rollup merge of #88505 - ibraheemdev:use-unwrap-unchecked, r=kennytm
Use `unwrap_unchecked` where possible
2021-09-02 19:10:14 +02:00
Mara Bos
e50069ff4f
Rollup merge of #88177 - joshtriplett:stabilize-chroot, r=m-ou-se
Stabilize std::os::unix::fs::chroot

I've verified that this works as documented, and I've tested it in (a nightly
build of) production software as a replacement for an unsafe call to
`libc::chroot`. It's been available in nightly for a few releases. I think it's
ready to stabilize.

---

Tracking issue: https://github.com/rust-lang/rust/issues/84715
2021-09-02 19:10:12 +02:00
bors
1cf8fdd4f0 Auto merge of #87580 - ChrisDenton:win-arg-parse-2008, r=m-ou-se
Update Windows Argument Parsing

Fixes #44650

The Windows command line is passed to applications [as a single string](https://docs.microsoft.com/en-us/archive/blogs/larryosterman/the-windows-command-line-is-just-a-string) which the application then parses to get a list of arguments. The standard rules (as used by C/C++) for parsing the command line have slightly changed over the years, most recently in 2008 which added new escaping rules.

This PR implements the new rules as [described on MSDN](https://docs.microsoft.com/en-us/cpp/cpp/main-function-command-line-args?view=msvc-160#parsing-c-command-line-arguments) and [further detailed here](https://daviddeley.com/autohotkey/parameters/parameters.htm#WIN). It has been tested against the behaviour of C++ by calling a C++ program that outputs its raw command line and the contents of `argv`. See [my repo](https://github.com/ChrisDenton/winarg/tree/std) if anyone wants to reproduce my work.

For an overview of how this PR changes argument parsing behavior and why we feel it is warranted see https://github.com/rust-lang/rust/pull/87580#issuecomment-893833893.

For some examples see: https://github.com/rust-lang/rust/pull/87580#issuecomment-894299249
2021-09-02 16:16:13 +00:00
Frank Steffahn
ab89c88faa Consistent placement of doc alias for primitives below the doc(primitive…) 2021-09-02 17:21:05 +02:00
Frank Steffahn
49c680ada0 Add "!" doc alias for std::ops::Not 2021-09-02 17:19:43 +02:00
bdbai
a8ac6d471e I/O safety for WinUWP 2021-09-02 18:18:00 +08:00
Jacob Pratt
727a4fc7e3
Implement #88581 2021-09-02 01:53:54 -04:00
ast-ral
9da8e2a2fa remove redundant / misplaced sentence from docs 2021-09-01 20:52:30 -07:00
bors
cc9bb1522e Auto merge of #83342 - Count-Count:win-console-incomplete-utf8, r=m-ou-se
Allow writing of incomplete UTF-8 sequences to the Windows console via stdout/stderr

# Problem
Writes of just an incomplete UTF-8 byte sequence (e.g. `b"\xC3"` or `b"\xF0\x9F"`)  to stdout/stderr with a Windows console attached error with `io::ErrorKind::InvalidData, "Windows stdio in console mode does not support writing non-UTF-8 byte sequences"` even though further writes could complete the codepoint. This is currently a rare occurence since the [linewritershim](2c56ea38b0/library/std/src/io/buffered/linewritershim.rs) implementation flushes complete lines immediately and buffers up to 1024 bytes for incomplete lines. It can still happen as described in #83258.

The problem will become more pronounced once the developer can switch stdout/stderr from line-buffered to block-buffered or immediate when the changes in the "Switchable buffering for Stdout" pull request (#78515) get merged.

# Patch description
If there is at least one valid UTF-8 codepoint all valid UTF-8 is passed through to the extracted `write_valid_utf8_to_console()` fn. The new code only comes into play if `write()` is being passed a short byte slice comprising an incomplete UTF-8 codepoint. In this case up to three bytes are buffered in the `IncompleteUtf8` struct associated with `Stdout` / `Stderr`. The bytes are accepted one at a time. As soon as an error can be detected `io::ErrorKind::InvalidData, "Windows stdio in console mode does not support writing non-UTF-8 byte sequences"` is returned. Once a complete UTF-8 codepoint is received it is passed to the `write_valid_utf8_to_console()` and the buffer length is set to zero.

Calling `flush()` will neither error nor write anything if an incomplete codepoint is present in the buffer.

# Tests
Currently there are no Windows-specific tests for console writing code at all. Writing (regression) tests for this problem is a bit challenging since unit tests and UI tests don't run in a console and suddenly popping up another console window might be surprising to developers running the testsuite and it might not work at all in CI builds. To just test the new functionality in unit tests the code would need to be refactored. Some guidance on how to proceed would be appreciated.

# Public API changes
* `std::str::verifications::utf8_char_width()` would be exposed as `std::str::utf8_char_width()` behind the "str_internals" feature gate.

# Related issues
* Fixes #83258.
* PR #78515 will exacerbate the problem.

# Open questions
* Add tests?
* Squash into one commit with better commit message?
2021-09-02 03:31:17 +00:00
klensy
f5f489b945 fix clippy lints 2021-09-01 15:52:29 +03:00
klensy
6c9e708f4b fmt::Formatter::pad: don't call chars().count() more than one time 2021-09-01 15:36:57 +03:00
Mara Bos
d31352961c
Rollup merge of #88551 - inquisitivecrystal:unsafe_cell_raw_get, r=m-ou-se
Stabilize `UnsafeCell::raw_get()`

This PR stabilizes the associated function `UnsafeCell::raw_get()`. The FCP has [already completed](https://github.com/rust-lang/rust/issues/66358#issuecomment-899095068). While there was some discussion about the naming after the close of the FCP, it looks like people have agreed on this name. Still, it would probably be best if a `libs-api` member had a look at this and stated whether more discussion is needed.

While I was at it, I added some tests for `UnsafeCell`, because there were barely any.

Closes #66358.
2021-09-01 09:23:31 +02:00
Mara Bos
f436b6d0a7
Rollup merge of #88548 - inquisitivecrystal:intersperse, r=m-ou-se
Stabilize `Iterator::intersperse()`

This PR stabilizes the methods `Iterator::intersperse()` and `Iterator::intersperse_with()`. The FCP has [already completed](https://github.com/rust-lang/rust/issues/79524#issuecomment-909663616).

Closes #79524.
2021-09-01 09:23:30 +02:00
Mara Bos
59588a9a56
Rollup merge of #88542 - tavianator:readdir_r-errno, r=jyn514
Use the return value of readdir_r() instead of errno

POSIX says:

> If successful, the readdir_r() function shall return zero; otherwise,
> an error number shall be returned to indicate the error.

But we were previously using errno instead of the return value.  This
led to issue #86649.
2021-09-01 09:23:29 +02:00