Commit Graph

2908 Commits

Author SHA1 Message Date
Mara Bos
8cac04e8b8 Make 'static bound on panic_any explicit.
This was already implied because Any: 'static, but this makes it
explicit.
2021-01-19 21:41:41 +01:00
Mara Bos
230d5b1e5f Stabilize std::panic::panic_any. 2021-01-19 21:30:49 +01:00
Stein Somers
495f7cca85 BTreeMap: compile-test all borrowing interfaces and test more chaotic order 2021-01-19 19:47:31 +01:00
CPerezz
bc6720f872
Add SpecFromIter ref in the comments directly 2021-01-19 18:28:33 +01:00
bors
cf04ae54e6 Auto merge of #79705 - ijackson:bufwriter-disassemble, r=m-ou-se
BufWriter: Provide into_raw_parts

If something goes wrong, one might want to unpeel the layers of nested
Writers to perform recovery actions on the underlying writer, or reuse
its resources.

`into_inner` can be used for this when the inner writer is still
working.  But when the inner writer is broken, and returning errors,
`into_inner` simply gives you the error from flush, and the same
`Bufwriter` back again.

Here I provide the necessary function, which I have chosen to call
`into_raw_parts`.

I had to do something with `panicked`.  Returning it to the caller as
a boolean seemed rather bare.  Throwing the buffered data away in this
situation also seems unfriendly: maybe the programmer knows something
about the underlying writer and can recover somehow.

So I went for a custom Error.  This may be overkill, but it does have
the nice property that a caller who actually wants to look at the
buffered data, rather than simply extracting the inner writer, will be
told by the type system if they forget to handle the panicked case.

If a caller doesn't need the buffer, it can just be discarded.  That
WriterPanicked is a newtype around Vec<u8> means that hopefully the
layouts of the Ok and Err variants can be very similar, with just a
boolean discriminant.  So this custom error type should compile down
to nearly no code.

*If this general idea is felt appropriate, I will open a tracking issue, etc.*
2021-01-19 16:42:19 +00:00
Mara Bos
9272d53c5a Stop fold at first None when iterator yield 2021-01-19 12:17:58 +00:00
Guillaume Gomez
dcb74796c0
Rollup merge of #81168 - soniasingla:doc/sonia, r=jonas-schievink
Fixes #81109 - Typo in pointer::wrapping_sub

Signed-off-by: soniasingla <soniasingla.1812@gmail.com>

Related to issue #81109
2021-01-19 10:28:04 +01:00
Guillaume Gomez
7aa3920488
Rollup merge of #81166 - RalfJung:debug-assert-comments, r=Mark-Simulacrum
remove some outdated comments regarding  debug assertions

https://github.com/rust-lang/rust/pull/79684 removed those debug assertions.
2021-01-19 10:28:03 +01:00
Guillaume Gomez
6af6c40a12
Rollup merge of #81115 - ssomers:btree_drainy_refactor_4, r=Mark-Simulacrum
BTreeMap: prefer bulk_steal functions over specialized ones

The `steal_` functions (apart from their return value) are basically specializations of the more general `bulk_steal_` functions. This PR removes the specializations. The library/alloc benchmarks say this is never slower and up to 6% faster.

r? ``@Mark-Simulacrum``
2021-01-19 10:27:54 +01:00
Guillaume Gomez
de02bf399e
Rollup merge of #81112 - m-ou-se:alloc-std-ops-reexport, r=KodrAus
Remove unused alloc::std::ops re-export.

Removes unused re-export in alloc/lib.rs.
2021-01-19 10:27:53 +01:00
dylni
b96063cf47 Fix soundness issue for replace_range and range 2021-01-18 22:14:38 -05:00
Lzu Tao
20d8478864 Fix intersperse_fold 2021-01-19 00:43:59 +00:00
CPerezz
9abd80c076
Fix internal rustdoc broken links
As it was suggested in #81037 `SpecFromIter` is not
in the scope and therefore (even it should fail),
we get a warning when we try do document private
intems in `rust/library/alloc/`.

This fixes #81037 by adding the trait in the scope
and also adding an `allow(unused_imports)` flag so that
the compiler does not complain, Since the trait is not used
per se in the code, it's just needed to have properly documented
docs.
2021-01-18 23:47:01 +01:00
bors
d98d2f57d9 Auto merge of #80707 - oli-obk:stability_hole_const_intrinsics, r=RalfJung
Stability oddity with const intrinsics

cc `@RalfJung`

In https://github.com/rust-lang/rust/pull/80699#discussion_r551495670 `@usbalbin` realized we accepted some intrinsics as `const` without a `#[rustc_const_(un)stable]` attribute. I did some digging, and that example works because intrinsics inherit their stability from their parents... including `#[rustc_const_(un)stable]` attributes. While we may want to fix that (not sure, wasn't there just a MCPed PR that caused this on purpose?), we definitely want tests for it, thus this PR adding tests and some fun tracing statements.
2021-01-18 20:54:36 +00:00
bors
73f233b3ad Auto merge of #81159 - ssomers:btree_cleanup_search, r=Mark-Simulacrum
BTreeMap: convert search functions to methods

And further tweak the signature of `search_linear`, in preparation of a better #81094.

r? `@Mark-Simulacrum`
2021-01-18 17:30:38 +00:00
Konrad Borowski
ae3a515337 Avoid hash_slice in VecDeque's Hash implementation
Fixes #80303.
2021-01-18 17:56:06 +01:00
Stein Somers
4775334f36 BTreeMap: prefer bulk_steal functions over specialized ones 2021-01-18 17:23:26 +01:00
soniasingla
47c2476c68 Fixes #81109 - Typo in pointer::wrapping_sub
Signed-off-by: soniasingla <soniasingla.1812@gmail.com>
2021-01-18 20:31:47 +05:30
Ralf Jung
712d065061 remove some outdated comments regarding debug assertions 2021-01-18 13:06:01 +01:00
Ashley Mannix
0654e20195
Rollup merge of #81123 - sirh3e:sirh3e-patch-1, r=sfackler
Update cmp.rs

Fixed space
2021-01-18 21:53:33 +10:00
oli
5bac1c9229 Only inherit const stability for methods of impl const Trait blocks 2021-01-18 11:07:35 +00:00
Ralf Jung
dc04ceae71 use raw-ptr-addr-of for slice::swap 2021-01-18 11:24:48 +01:00
Stein Somers
de6e53a327 BTreeMap: convert search functions to methods 2021-01-18 09:31:14 +01:00
bors
93e0aedb07 Auto merge of #81090 - ssomers:btree_drainy_refactor_2, r=Mark-Simulacrum
BTreeMap: offer merge in variants with more clarity

r? `@Mark-Simulacrum`
2021-01-18 02:43:19 +00:00
Nathan Nguyen
829f6bb672 fixed formatting typo in map_while 2021-01-17 18:14:58 -06:00
bors
c4df63f47f Auto merge of #80537 - ehuss:macos-posix-spawn-chdir, r=dtolnay
Don't use posix_spawn_file_actions_addchdir_np on macOS.

There is a bug on macOS where using `posix_spawn_file_actions_addchdir_np` with a relative executable path will cause `posix_spawnp` to return ENOENT, even though it successfully spawned the process in the given directory.

`posix_spawn_file_actions_addchdir_np` was introduced in macOS 10.15 first released in Oct 2019.  I have tested macOS 10.15.7 and 11.0.1.

Example offending program:

```rust
use std::fs;
use std::os::unix::fs::PermissionsExt;
use std::process::*;

fn main() {
    fs::create_dir_all("bar").unwrap();
    fs::create_dir_all("foo").unwrap();
    fs::write("foo/foo.sh", "#!/bin/sh\necho hello ${PWD}\n").unwrap();
    let perms = fs::Permissions::from_mode(0o755);
    fs::set_permissions("foo/foo.sh", perms).unwrap();
    let c = Command::new("../foo/foo.sh").current_dir("bar").spawn();
    eprintln!("{:?}", c);
}
```

This prints:

```
Err(Os { code: 2, kind: NotFound, message: "No such file or directory" })
hello /Users/eric/Temp/bar
```

I wanted to open this PR to get some feedback on possible solutions.  Alternatives:
* Do nothing.
* Document the bug.
* Try to detect if the executable is a relative path on macOS, and avoid using `posix_spawn_file_actions_addchdir_np` only in that case.

I looked at the [XNU source code](https://opensource.apple.com/source/xnu/xnu-6153.141.1/bsd/kern/kern_exec.c.auto.html), but I didn't see anything obvious that would explain the behavior.  The actual chdir succeeds, it is something else further down that fails, but I couldn't see where.

EDIT: I forgot to mention, relative exe paths with `current_dir` in general are discouraged (see #37868).  I don't know if #37868 is fixable, since normalizing it would change the semantics for some platforms. Another option is to convert the executable to an absolute path with something like joining the cwd with the new cwd and the executable, but I'm uncertain about that.
2021-01-17 23:44:46 +00:00
bors
1f0fc02cc8 Auto merge of #80524 - jyn514:unknown-tool-lints, r=flip1995,matthewjasper
Don't make tools responsible for checking unknown and renamed lints

Previously, clippy (and any other tool emitting lints) had to have their
own separate UNKNOWN_LINTS pass, because the compiler assumed any tool
lint could be valid. Now, as long as any lint starting with the tool
prefix exists, the compiler will warn when an unknown lint is present.

This may interact with the unstable `tool_lint` feature, which I don't entirely understand, but it will take the burden off those external tools to add their own lint pass, which seems like a step in the right direction to me.

- Don't mark `ineffective_unstable_trait_impl` as an internal lint
- Use clippy's more advanced lint suggestions
- Deprecate the `UNKNOWN_CLIPPY_LINTS` pass (and make it a no-op)
- Say 'unknown lint `clippy::x`' instead of 'unknown lint x'

This is tested by existing clippy tests. When https://github.com/rust-lang/rust/pull/80527 merges, it will also be tested in rustdoc tests. AFAIK there is no way to test this with rustc directly.
2021-01-17 17:52:01 +00:00
Eric Huss
a938725ef7 Don't use posix_spawn_file_actions_addchdir_np on macOS. 2021-01-17 09:51:02 -08:00
Marvin Huber
7276b6c328
Update cmp.rs
Fixed space
2021-01-17 16:11:48 +01:00
bors
edeb631ad0 Auto merge of #81113 - m-ou-se:rollup-a1unz4x, r=m-ou-se
Rollup of 13 pull requests

Successful merges:

 - #79298 (correctly deal with late-bound lifetimes in anon consts)
 - #80031 (resolve: Reject ambiguity built-in attr vs different built-in attr)
 - #80201 (Add benchmark and fast path for BufReader::read_exact)
 - #80635 (Improve diagnostics when closure doesn't meet trait bound)
 - #80765 (resolve: Simplify collection of traits in scope)
 - #80932 (Allow downloading LLVM on Windows and MacOS)
 - #80983 (Remove is_dllimport_foreign_item definition from cg_ssa)
 - #81064 (Support non-stage0 check)
 - #81080 (Force vec![] to expression position only)
 - #81082 (BTreeMap: clean up a few more comments)
 - #81084 (Use Option::map instead of open-coding it)
 - #81095 (Use Option::unwrap_or instead of open-coding it)
 - #81107 (Add NonZeroUn::is_power_of_two)

Failed merges:

r? `@ghost`
`@rustbot` modify labels: rollup
2021-01-17 14:50:24 +00:00
Mara Bos
801684620b
Rollup merge of #81107 - scottmcm:nonzero-is_power_of_two, r=kennytm
Add NonZeroUn::is_power_of_two

This saves instructions on both new and old machines <https://rust.godbolt.org/z/4fjTMz>
- On the default x64 target (with no fancy instructions available) it saves a few instructions by not needing to also check for zero.
- On newer targets (with BMI1) it uses `BLSR` for super-short assembly.

This can be used for things like checks against alignments stored in `NonZeroUsize`.
2021-01-17 12:25:01 +00:00
Mara Bos
366f97bf8c
Rollup merge of #81082 - ssomers:btree_cleanup_comments, r=Mark-Simulacrum
BTreeMap: clean up a few more comments

And mark `pop` as unsafe.
r? ```@Mark-Simulacrum```
2021-01-17 12:24:56 +00:00
Mara Bos
19370a4860
Rollup merge of #81080 - bugadani:vec-diag, r=oli-obk,m-ou-se
Force vec![] to expression position only

r? `@oli-obk`

I went with the lazy way of only changing what broke. I moved the test to ui/macros because the diagnostics no longer give suggestions.

Closes #61933
2021-01-17 12:24:54 +00:00
Mara Bos
152f425dcb
Rollup merge of #80201 - saethlin:bufreader-read-exact, r=KodrAus
Add benchmark and fast path for BufReader::read_exact

At work, we have a wrapper type that implements this optimization. It would be nice if the standard library were faster.

Before:
```
test io::buffered::tests::bench_buffered_reader_small_reads       ... bench:       7,670 ns/iter (+/- 45)
```
After:
```
test io::buffered::tests::bench_buffered_reader_small_reads       ... bench:       4,457 ns/iter (+/- 41)
```
2021-01-17 12:24:42 +00:00
bors
7d3818152d Auto merge of #81058 - Smittyvb:wasm-num-tests, r=Mark-Simulacrum
Re-enable all num tests on WASM

This was partially done by #47365, but a few tests were missed in that PR.
2021-01-17 11:51:47 +00:00
Dániel Buga
c127ed6e97 Force vec! to expressions only 2021-01-17 12:48:25 +01:00
Mara Bos
ff5dcc2438 Remove unused alloc::std::ops re-export. 2021-01-17 12:08:38 +01:00
bors
d51cf9601c Auto merge of #81083 - ssomers:btree_drainy_refactor_1, r=Mark-Simulacrum
BTreeMap: expose new_internal function and sanitize from_new_internal

`new_internal` is the functional core of the imperative `push_internal_level`, and `from_new_internal` can easily do a proper job instead of returning a half-baked node.

r? `@Mark-Simulacrum`
2021-01-17 08:44:12 +00:00
bors
49d7889da4 Auto merge of #78818 - scottmcm:as_rchunks, r=KodrAus
Add `as_rchunks` (and friends) to slices

`@est31` mentioned (https://github.com/rust-lang/rust/issues/76354#issuecomment-717027175) that, for completeness, there needed to be an `as_chunks`-like method that chunks from the end (with the remainder at the beginning) like `rchunks` does.

So here's a PR for `as_rchunks: &[T] -> (&[T], &[[T; N]])` and `as_rchunks_mut: &mut [T] -> (&mut [T], &mut [[T; N]])`.

But as I was doing this and copy-pasting `from_raw_parts` calls, I thought that I should extract that into an unsafe method.  It started out a private helper, but it seemed like `as_chunks_unchecked` could be reasonable as a "real" method, so I added docs and made it public.  Let me know if you think it doesn't pull its weight.
2021-01-17 05:43:55 +00:00
Scott McMurray
3e16e9211e Add NonZeroUn::is_power_of_two
This saves instructions on both new and old machines.
2021-01-16 19:27:51 -08:00
Ben Kimock
4e27ed3af1 Add benchmark and fast path for BufReader::read_exact 2021-01-17 12:10:39 +10:00
bors
8a6518427e Auto merge of #81089 - m-ou-se:rollup-z7iac6i, r=m-ou-se
Rollup of 17 pull requests

Successful merges:

 - #78455 (Introduce {Ref, RefMut}::try_map for optional projections in RefCell)
 - #80144 (Remove giant badge in README)
 - #80614 (Explain why borrows can't be held across yield point in async blocks)
 - #80670 (TrustedRandomAaccess specialization composes incorrectly for nested iter::Zips)
 - #80681 (Clarify what the effects of a 'logic error' are)
 - #80764 (Re-stabilize Weak::as_ptr and friends for unsized T)
 - #80901 (Make `x.py --color always` apply to logging too)
 - #80902 (Add a regression test for #76281)
 - #80941 (Do not suggest invalid code in pattern with loop)
 - #80968 (Stabilize the poll_map feature)
 - #80971 (Put all feature gate tests under `feature-gates/`)
 - #81021 (Remove doctree::Import)
 - #81040 (doctest: Reset errors before dropping the parse session)
 - #81060 (Add a regression test for #50041)
 - #81065 (codegen_cranelift: Fix redundant semicolon warn)
 - #81069 (Add sample code for Rc::new_cyclic)
 - #81081 (Add test for #34792)

Failed merges:

r? `@ghost`
`@rustbot` modify labels: rollup
2021-01-16 20:26:20 +00:00
Stein Somers
bb61cc48b3 BTreeMap: offer merge in variants with more clarity 2021-01-16 18:56:03 +01:00
Mara Bos
dd86fc6228
Rollup merge of #81069 - ogoffart:rc_new_cyclic_doc, r=Mark-Simulacrum
Add sample code for Rc::new_cyclic
2021-01-16 17:30:15 +00:00
Mara Bos
dba6c9c6d1
Rollup merge of #80968 - KodrAus:stabilize/poll_map, r=Mark-Simulacrum
Stabilize the poll_map feature

Stabilizes the `poll_map` feature as tracked by #63514 (with a completed FCP).
2021-01-16 17:30:04 +00:00
Mara Bos
5702cfa255
Rollup merge of #80764 - CAD97:weak-unsized-as-ptr-again, r=RalfJung
Re-stabilize Weak::as_ptr and friends for unsized T

As per [T-lang consensus](https://hackmd.io/7r3_is6uTz-163fsOV8Vfg), this uses a branch to handle the dangling case. The discussed optimization of only doing the branch in the T: ?Sized case is left for a followup patch, as doing so is not trivial (as it requires specialization) and not _obviously_ better (as it requires using `wrapping_offset` rather than `offset` more).

<details><summary>Basically said optimization</summary>

Specialize on `T: Sized`:

```rust
fn as_ptr(&self) -> *const T {
    if [ T is Sized ] || !is_dangling(ptr) {
        (ptr as *mut T).set_ptr_value( (ptr as *mut u8).wrapping_offset(data_offset) )
    } else {
        ptr::null()
    }
}

fn from_raw(*const T) -> Self {
    if [ T is Sized ] || !ptr.is_null() {
        let ptr = (ptr as *mut RcBox).set_ptr_value( (ptr as *mut u8).wrapping_offset(-data_offset) );
        Weak { ptr }
    } else {
        Weak::new()
    }
}
```

(but with more `set_ptr_value` to avoid `Sized` restrictions and maintain metadata.)

Written in this fashion, this is not a correctness-critical specialization (i.e. so long as `[ T is Sized ]` is false for unsized `T`, it can be `rand()` for sized `T` without breaking correctness), but it's still touchy, so I'd rather do it in another PR with separate review.

---
</details>

This effectively reverts #80422 and re-establishes #74160. T-libs [previously signed off](https://github.com/rust-lang/rust/pull/74160#issuecomment-660539373) on this stable API change in #74160.
2021-01-16 17:29:56 +00:00
Mara Bos
40d2506cab
Rollup merge of #80681 - ChrisJefferson:logic-error-doc, r=m-ou-se
Clarify what the effects of a 'logic error' are

This clarifies what a 'logic error' is (which is a term used to describe what happens if you put things in a hash table or btree and then use something like a refcell to break the internal ordering). This tries to be as vague as possible, as we don't really want to promise what happens, except "bad things, but not UB". This was discussed in #80657
2021-01-16 17:29:53 +00:00
Mara Bos
d8843d9d82
Rollup merge of #80670 - the8472:fix-zip-trusted-random-access-composition, r=m-ou-se
TrustedRandomAaccess specialization composes incorrectly for nested iter::Zips

I found this while working on improvements for TRA.

After partially consuming a Zip adapter and then wrapping it into another Zip where the adapters use their `TrustedRandomAccess` specializations leads to the outer adapter returning elements which should have already been consumed.

If the optimizer gets tripped up by the addition this might affect performance for chained `zip()` iterators even when the inner one is not partially advanced but it would require more extensive fixes to `TrustedRandomAccess` to communicate those offsets earlier.

Included test fails on nightly, [playground link](https://play.rust-lang.org/?version=nightly&mode=debug&edition=2018&gist=24fa1edf8a104ff31f5a24830593b01f)
2021-01-16 17:29:51 +00:00
Mara Bos
6bb06f4f23
Rollup merge of #78455 - udoprog:refcell-opt-map, r=KodrAus
Introduce {Ref, RefMut}::try_map for optional projections in RefCell

This fills a usability gap of `RefCell` I've personally encountered to perform optional projections, mostly into collections such as `RefCell<Vec<T>>` or `RefCell<HashMap<U, T>>`:

> This kind of API was briefly featured under Open questions in #10514 back in 2013 (!)

```rust
let values = RefCell::new(vec![1, 2, 3, 4]);
let b = Ref::opt_map(values.borrow(), |vec| vec.get(2));
```

It primarily avoids this alternative approach to accomplish the same kind of projection which is both rather noisy and panicky:
```rust
let values = RefCell::new(vec![1, 2, 3, 4]);

let b = if values.get(2).is_some() {
    Some(Ref::map(values.borrow(), |vec| vec.get(2).unwrap()))
} else {
    None
};
```

### Open questions

The naming `opt_map` is preliminary. I'm not aware of prior art in std to lean on here, but this name should probably be improved if this functionality is desirable.

Since `opt_map` consumes the guard, and alternative syntax might be more appropriate which instead *tries* to perform the projection, allowing the original borrow to be recovered in case it fails:

```rust
pub fn try_map<U: ?Sized, F>(orig: Ref<'b, T>, f: F) -> Result<Ref<'b, U>, Self>
where
    F: FnOnce(&T) -> Option<&U>;
```

This would be more in line with the `try_map` method [provided by parking lot](https://docs.rs/lock_api/0/lock_api/struct.RwLockWriteGuard.html#method.try_map).
2021-01-16 17:29:45 +00:00
bors
492b83c697 Auto merge of #80290 - RalfJung:less-intrinsic-write, r=lcnr
implement ptr::write without dedicated intrinsic

This makes `ptr::write` more consistent with `ptr::write_unaligned`, `ptr::read`, `ptr::read_unaligned`, all of which are implemented in terms of `copy_nonoverlapping`.

This means we can also remove `move_val_init` implementations in codegen and Miri, and its special handling in the borrow checker.

Also see [this Zulip discussion](https://rust-lang.zulipchat.com/#narrow/stream/131828-t-compiler/topic/ptr.3A.3Aread.20vs.20ptr.3A.3Awrite).
2021-01-16 17:28:32 +00:00
Stein Somers
d199c5b020 BTreeMap: expose new_internal function and sanitize from_new_internal 2021-01-16 17:07:38 +01:00
Stein Somers
50ee0b2986 BTreeMap: clean up a few more comments 2021-01-16 16:20:00 +01:00
bors
410a546fc5 Auto merge of #77435 - hanmertens:binary_heap_append, r=scottmcm
Always use extend in BinaryHeap::append

This is faster, see #77433.

Fixes #77433
2021-01-16 11:10:13 +00:00
Chris Jefferson
78d919280d Clarify what the effects of a 'logic error' are 2021-01-16 09:36:28 +00:00
Olivier Goffart
9952632a2f Add sample code for Rc::new_cyclic 2021-01-16 10:29:21 +01:00
bors
efdb859dcd Auto merge of #80873 - ssomers:btree_cleanup_slices_4, r=Mark-Simulacrum
BTreeMap: tougher checks on code using raw into_kv_pointers

r? `@Mark-Simulacrum`
2021-01-16 07:12:12 +00:00
Scott McMurray
132307c685 Rename as_chunks_mut_unchecked -> as_chunks_unchecked_mut 2021-01-15 21:25:30 -08:00
Scott McMurray
ae4b5a21e6 Add as_rchunks (and friends) to slices 2021-01-15 21:24:38 -08:00
Ashley Mannix
c625b979ae
add tracking issue to cell_filter_map 2021-01-16 10:40:36 +10:00
Joshua Nelson
c819a4c025 Don't mark ineffective_unstable_trait_impl as an internal lint
It's not an internal lint:
- It's not in the rustc::internal lint group
- It's on unconditionally, because it actually lints `staged_api`, not
  the compiler

This fixes a bug where `#[deny(rustc::internal)]` would warn that
`rustc::internal` was an unknown lint.
2021-01-15 17:31:10 -05:00
Smitty
e10555c658 Re-enable all num tests on WASM
This was partially done by #47365, but a few tests
were missed in that PR.
2021-01-15 16:58:44 -05:00
Han Mertens
32a20f4433 Change rebuild heuristic in BinaryHeap::append
See #77433 for why the new heuristic was chosen.

Fixes #77433
2021-01-15 21:50:05 +01:00
Yoshua Wuyts
b50df6d31c Stabilize core::slice::fill_with 2021-01-15 18:51:09 +01:00
John-John Tedro
e8757af311 Use Result and rename to filter_map
The use of Result allows for making use of a reconstructed original value on failed
projections.
2021-01-15 17:52:48 +01:00
John-John Tedro
0660b8b5a5 Introduce {Ref, RefMut}::try_map for optional projections 2021-01-15 13:47:00 +01:00
Yuki Okushi
1b8fd02daa
Rollup merge of #80834 - bugadani:vecdeque, r=oli-obk
Remove unreachable panics from VecDeque::{front/back}[_mut]

`VecDeque`'s `front`, `front_mut`, `back` and `back_mut` methods are implemented in terms of the index operator, which causes these functions to contain [unreachable panic calls](https://rust.godbolt.org/z/MTnq1o).

This PR reimplements these methods in terms of `get[_mut]` instead.
2021-01-15 18:26:11 +09:00
Alex Crichton
5756bd7f2d std: Update wasi-libc commit of the wasm32-wasi target
This brings in an implementation of `current_dir` and `set_current_dir`
(emulation in `wasi-libc`) as well as an updated version of finding
relative paths. This also additionally updates clang to the latest
release to build wasi-libc with.
2021-01-14 10:40:10 -08:00
Dániel Buga
744f885e2a Remove unreachable panics from VecDeque 2021-01-14 19:31:56 +01:00
Mara Bos
9c75ee6b3b
Rollup merge of #80991 - calebsander:fix/fmt-link, r=m-ou-se
Fix formatting specifiers doc links

d36e3e23a8 seems to have inadvertently changed many of these links to point to `core::fmt` instead of `std::fmt`. The information about formatting specifiers is only documented in [`std::fmt`](https://doc.rust-lang.org/std/fmt/); [`core::fmt`](https://doc.rust-lang.org/core/fmt/) is empty. 3baf6a4a74 seems to have already fixed a couple of these links to point back to `std::fmt`.
2021-01-14 18:00:31 +00:00
Mara Bos
c504e89bc7
Rollup merge of #80985 - ijackson:slice-strip-fix, r=jyn514
Fix stabilisation version of slice_strip

See https://github.com/rust-lang/rust/pull/77853#pullrequestreview-564921079

Signed-off-by: Ian Jackson <ijackson@chiark.greenend.org.uk>
2021-01-14 18:00:27 +00:00
Mara Bos
d5e55cee99
Rollup merge of #80980 - trevarj:patch-1, r=nagisa
Fixed incorrect doc comment

">" is right alignment, not left
2021-01-14 18:00:22 +00:00
Mara Bos
9bfe6f1b2c
Rollup merge of #80972 - KodrAus:deprecate/remove_item, r=nagisa
Remove unstable deprecated Vec::remove_item

Closes #40062

The `Vec::remove_item` method was deprecated in `1.46.0` (in August of 2020). This PR now removes that unstable method entirely.
2021-01-14 18:00:18 +00:00
Mara Bos
7855a730b9
Rollup merge of #80966 - KodrAus:deprecate/spin_loop_hint, r=m-ou-se
Deprecate atomic::spin_loop_hint in favour of hint::spin_loop

For https://github.com/rust-lang/rust/issues/55002

We wanted to leave `atomic::spin_loop_hint` alone when stabilizing `hint::spin_loop` so folks had some time to migrate. This now deprecates `atomic_spin_loop_hint`.
2021-01-14 18:00:14 +00:00
Mara Bos
ce48709405
Rollup merge of #80895 - sfackler:read-to-end-ub, r=m-ou-se
Fix handling of malicious Readers in read_to_end

A malicious `Read` impl could return overly large values from `read`, which would result in the guard's drop impl setting the buffer's length to greater than its capacity! ~~To fix this, the drop impl now uses the safe `truncate` function instead of `set_len` which ensures that this will not happen. The result of calling the function will be nonsensical, but that's fine given the contract violation of the `Read` impl.~~

~~The `Guard` type is also used by `append_to_string` which does not pass untrusted values into the length field, so I've copied the guard type into each function and only modified the one used by `read_to_end`. We could just keep a single one and modify it, but it seems a bit cleaner to keep the guard code close to the functions and related specifically to them.~~

To fix this, we now assert that the returned length is not larger than the buffer passed to the method.

For reference, this bug has been present for ~2.5 years since 1.20: ecbb896b9e.

Closes #80894.
2021-01-14 18:00:11 +00:00
Mara Bos
446ed77124
Rollup merge of #80567 - lukaslueg:intersperse_with, r=m-ou-se
Add Iterator::intersperse_with

This is a follow-up to #79479, tracking in #79524, as discussed https://github.com/rust-lang/rust/pull/79479#issuecomment-752671731.

~~Note that I had to manually implement `Clone` and `Debug` because `derive` insists on placing a `Clone`-bound on the struct-definition, which is too narrow. There is a long-standing issue # for this somewhere around here :-)~~

Also, note that I refactored the guts of `Intersperse` into private functions and re-used them in `IntersperseWith`, so I also went light on duplicating all the tests.

If this is suitable to be merged, the tracking issue should be updated, since it only mentions `intersperse`.

Happy New Year!

r? ``@m-ou-se``
2021-01-14 18:00:06 +00:00
Mara Bos
3308b43ba1
Rollup merge of #80444 - glittershark:bound-as-ref, r=dtolnay
Add as_ref and as_mut methods for Bound

Add as_ref and as_mut method for std::ops::range::Bound, patterned off
of the methods of the same name on Option.

I'm not quite sure what the process is for introducing new feature gates (this is my first contribution) so I've left these ungated, but happy to do whatever is necessary to gate them.
2021-01-14 18:00:02 +00:00
Mara Bos
9fc298ca89
Rollup merge of #80217 - camelid:io-read_to_string, r=m-ou-se
Add a `std::io::read_to_string` function

I recognize that you're usually supposed to open an issue first, but the
implementation is very small so it's okay if this is closed and it was 'wasted
work' :)

-----

The equivalent of `std::fs::read_to_string`, but generalized to all
`Read` impls.

As the documentation on `std::io::read_to_string` says, the advantage of
this function is that it means you don't have to create a variable first
and it provides more type safety since you can only get the buffer out
if there were no errors. If you use `Read::read_to_string`, you have to
remember to check whether the read succeeded because otherwise your
buffer will be empty.

It's friendlier to newcomers and better in most cases to use an explicit
return value instead of an out parameter.
2021-01-14 18:00:00 +00:00
Mara Bos
930371b3ae
Rollup merge of #80169 - frewsxcv:frewsxcv-docs-fix, r=jyn514
Recommend panic::resume_unwind instead of panicking.

Fixes https://github.com/rust-lang/rust/issues/79950.
2021-01-14 17:59:57 +00:00
Mara Bos
8ac21fb201
Rollup merge of #79982 - ijackson:exit-status, r=dtolnay
Add missing methods to unix ExitStatusExt

These are the methods corresponding to the remaining exit status examination macros from `wait.h`.  `WCOREDUMP` isn't in SuS but is it is very standard.  I have not done portability testing to see if this builds everywhere, so I may need to Do Something if it doesn't.

There is also a bugfix and doc improvement to `.signal()`, and an `.into_raw()` accessor.

This would fix #73128 and fix #73129.  Please let me know if you like this direction, and if so I will open the tracking issue and so on.

If this MR goes well, I may tackle #73125 next - I have an idea for how to do it.
2021-01-14 17:59:53 +00:00
David Tolnay
a8d0161960
Fix typos in Fuchsia unix_process_wait_more 2021-01-13 22:13:45 -08:00
Philippe Laflamme
64d695b753
Adds tests to ensure some base op traits exist.
These tests invoke the various op traits using all accepted types they
are implemented for as well as for references to those types.

This fixes #49660 and ensures the following implementations exist:

* `Add`, `Sub`, `Mul`, `Div`, `Rem`
  * `T op T`, `T op &T`, `&T op T` and `&T op &T`
  * for all integer and floating point types
* `AddAssign`, `SubAssign`, `MulAssign`, `DivAssign`, `RemAssign`
  * `&mut T op T` and `&mut T op &T`
  * for all integer and floating point types
* `Neg`
  * `op T` and `op &T`
  * for all signed integer and floating point types
* `Not`
  * `op T` and `op &T`
  * for `bool`
* `BitAnd`, `BitOr`, `BitXor`
  * `T op T`, `T op &T`, `&T op T` and `&T op &T`
  * for all integer types and bool
* `BitAndAssign`, `BitOrAssign`, `BitXorAssign`
  * `&mut T op T` and `&mut T op &T`
  * for all integer types and bool
* `Shl`, `Shr`
  * `L op R`, `L op &R`, `&L op R` and `&L op &R`
  * for all pairs of integer types
* `ShlAssign`, `ShrAssign`
  * `&mut L op R`, `&mut L op &R`
  * for all pairs of integer types
2021-01-13 23:14:00 -05:00
Philippe Laflamme
8ddad18283
Avoid ident concatenation in macro.
AFAIK it isn't currently possible to do this. It is also more in line with other tests in the surrounding modules.
2021-01-13 23:13:55 -05:00
Philippe Laflamme
872dc60ed2
Fix missing mod declaration for Wrapping tests. 2021-01-13 23:13:49 -05:00
Griffin Smith
eb72dc5d40 Add as_ref and as_mut methods for Bound
Add as_ref and as_mut method for std::ops::range::Bound, patterned off
of the methods of the same name on Option.
2021-01-13 21:16:26 -05:00
Jacob Pratt
edf2e3725e
Use unsigned_abs throughout repository 2021-01-13 17:58:08 -05:00
Christopher Durham
c14e919f1e
Apply suggestions from code review
Co-authored-by: Ralf Jung <post@ralfj.de>
2021-01-13 17:21:23 -05:00
bors
a62a76047e Auto merge of #77524 - Patryk27:fixes/66228, r=estebank
Rework diagnostics for wrong number of generic args (fixes #66228 and #71924)

This PR reworks the `wrong number of {} arguments` message, so that it provides more details and contextual hints.
2021-01-13 20:35:58 +00:00
Lukas Lueg
9b2f085110 Improve Iterator::intersperse_ docs 2021-01-13 21:07:59 +01:00
Caleb Sander
391b4cc378 Fix formatting specifiers doc link
Was incorrectly linked to `core::fmt`, which is empty, in d36e3e23a8
Some of the links were fixed already in 3baf6a4a74
2021-01-13 15:05:39 -05:00
Lukas Lueg
95289889fe Add doc intralinks 2021-01-13 19:47:41 +01:00
Ian Jackson
b59fa3d634 Fix stabilisation version of slice_strip
See https://github.com/rust-lang/rust/pull/77853#pullrequestreview-564921079

Signed-off-by: Ian Jackson <ijackson@chiark.greenend.org.uk>
2021-01-13 14:21:18 +00:00
bors
fd2df74902 Auto merge of #76219 - Mark-Simulacrum:extern-require-abi, r=estebank
Add allow-by-default lint on implicit ABI in extern function pointers and items

This adds a new lint, missing_abi, which lints on omitted ABIs on extern blocks, function declarations, and function pointers.

It is currently not emitting the best possible diagnostics -- we need to track the span of "extern" at least or do some heuristic searching based on the available spans -- but seems good enough for an initial pass than can be expanded in future PRs.

This is a pretty large PR, but mostly due to updating a large number of tests to include ABIs; I can split that into a separate PR if it would be helpful, but test updates are already in dedicated commits.
2021-01-13 13:56:15 +00:00
Ian Jackson
05a88aabc1 ExitStatusExt: Fix build on Fuchsia
This is not particularly pretty but the current situation is a mess
and I don't think I'm making it significantly worse.

Signed-off-by: Ian Jackson <ijackson@chiark.greenend.org.uk>
2021-01-13 13:27:30 +00:00
David Tolnay
efddf5949f Fix typo saeled -> sealed 2021-01-13 12:50:29 +00:00
Ian Jackson
f3e7199a79 ExitStatusExt windows: Retrospectively seal this trait
Signed-off-by: Ian Jackson <ijackson@chiark.greenend.org.uk>
2021-01-13 12:50:29 +00:00
Ian Jackson
70121941ff ExitStatusExt unix: Retrospectively seal this trait
As discussed in #79982.

I think the "new interfaces", ie the new trait and impl, must be
insta-stable.  This seems OK because we are, in fact, adding a new
restriction to the stable API.

Signed-off-by: Ian Jackson <ijackson@chiark.greenend.org.uk>
2021-01-13 12:50:29 +00:00
Ian Jackson
fa68567a1f unix ExitStatus: Add tracking issue to new methods
Signed-off-by: Ian Jackson <ijackson@chiark.greenend.org.uk>
2021-01-13 12:50:29 +00:00
Ian Jackson
06a405c49c Replace Ie with In other words
Co-authored-by: Joshua Nelson <joshua@yottadb.com>
2021-01-13 12:50:29 +00:00
Ian Jackson
29c851aef6 Replace Ie with In other words
Co-authored-by: Joshua Nelson <joshua@yottadb.com>
2021-01-13 12:50:29 +00:00
Ian Jackson
42ea8f6434 unix ExitStatus: Provide .continued()
Signed-off-by: Ian Jackson <ijackson@chiark.greenend.org.uk>
2021-01-13 12:50:29 +00:00
Ian Jackson
f060b9e0d9 unix ExitStatus: Provide .stopped_signal()
Necessary to handle WIFSTOPPED.

Signed-off-by: Ian Jackson <ijackson@chiark.greenend.org.uk>
2021-01-13 12:50:29 +00:00
Ian Jackson
3f05051d6b unix ExitStatus: Provide .core_dumped
This is essential for proper reporting of child process status on Unix.

Signed-off-by: Ian Jackson <ijackson@chiark.greenend.org.uk>
2021-01-13 12:50:29 +00:00
Ian Jackson
530270f94a unix ExitStatus: Provide .into_raw()
Signed-off-by: Ian Jackson <ijackson@chiark.greenend.org.uk>
2021-01-13 12:50:29 +00:00
Ian Jackson
12d62aa436 unix ExitStatus: Clarify docs for .signal()
We need to be clear that this never returns WSTOPSIG.  That is, if
WIFSTOPPED, the return value is None.

Signed-off-by: Ian Jackson <ijackson@chiark.greenend.org.uk>
2021-01-13 12:50:29 +00:00
Ian Jackson
5b1316f781 unix ExitStatus: Do not treat WIFSTOPPED as WIFSIGNALED
A unix wait status can contain, at least, exit statuses, termination
signals, and stop signals.

WTERMSIG is only valid if WIFSIGNALED.

https://pubs.opengroup.org/onlinepubs/9699919799/functions/wait.html

It will not be easy to experience this bug with `Command`, because
that doesn't pass WUNTRACED.  But you could make an ExitStatus
containing, say, a WIFSTOPPED, from a call to one of the libc wait
functions.

(In the WIFSTOPPED case, there is WSTOPSIG.  But a stop signal is
encoded differently to a termination signal, so WTERMSIG and WSTOPSIG
are by no means the same.)

Signed-off-by: Ian Jackson <ijackson@chiark.greenend.org.uk>
2021-01-13 12:50:29 +00:00
Mark Rousskov
4614671cae Update code to account for extern ABI requirement 2021-01-13 07:49:45 -05:00
Mark Rousskov
8a3edb1d66 Update tests for extern block linting 2021-01-13 07:49:16 -05:00
bors
116d1a7056 Auto merge of #80824 - cuviper:heap-clones, r=kennytm
Try to avoid locals when cloning into Box/Rc/Arc

For generic `T: Clone`, we can allocate an uninitialized box beforehand,
which gives the optimizer a chance to create the clone directly in the
heap. For `T: Copy`, we can go further and do a simple memory copy,
regardless of optimization level.

The same applies to `Rc`/`Arc::make_mut` when they must clone the data.
2021-01-13 11:11:34 +00:00
trevor arjeski
697b20ff08
Fixed incorrect doc comment
">" is right alignment, not left
2021-01-13 13:49:46 +03:00
bors
9f3998b4aa Auto merge of #77858 - ijackson:split-inclusive, r=KodrAus
Stabilize split_inclusive

### Contents of this MR

This stabilises:

 * `slice::split_inclusive`
 * `slice::split_inclusive_mut`
 * `str::split_inclusive`

Closes #72360.

### A possible concern

The proliferation of `split_*` methods is not particularly pretty.  The existence of `split_inclusive` seems to invite the addition of `rsplit_inclusive`, `splitn_inclusive`, etc.  We could instead have a more general API, along these kinds of lines maybe:
```
   pub fn split_generic('a,P,H>(&'a self, pat: P, how: H) -> ...
       where P: Pattern
       where H: SplitHow;

   pub fn split_generic_mut('a,P,H>(&'a mut self, pat: P, how: H) -> ...
       where P: Pattern
       where H: SplitHow;

   trait SplitHow {
       fn reverse(&self) -> bool;
       fn inclusive -> bool;
       fn limit(&self) -> Option<usize>;
   }

   pub struct SplitFwd;
   ...
   pub struct SplitRevInclN(pub usize);
```
But maybe that is worse.

### Let us defer that? ###

This seems like a can of worms.  I think we can defer opening it now; if and when we have something more general, these two methods can become convenience aliases.  But I thought I would mention it so the lang API team can consider it and have an opinion.
2021-01-13 07:38:58 +00:00
Ashley Mannix
d65cb6ebce deprecate atomic::spin_loop_hint in favour of hint::spin_loop 2021-01-13 16:30:29 +10:00
Ashley Mannix
7e83fece91 remove unstable deprecated Vec::remove_item 2021-01-13 15:14:11 +10:00
Ashley Mannix
b2f504801c stabilize the poll_map feature 2021-01-13 14:51:27 +10:00
Ashley Mannix
5584224fda
bump split_inclusive stabilization to 1.51.0 2021-01-13 13:51:37 +10:00
Ashley Mannix
e4a2f33360
bump split_inclusive stabilization to 1.51.0 2021-01-13 13:50:39 +10:00
Ashley Mannix
0620514094
bump split_inclusive stabilization to 1.51.0 2021-01-13 13:49:34 +10:00
Ashley Mannix
bd2c072b9b
bump split_inclusive stabilization to 1.51.0 2021-01-13 13:48:36 +10:00
Dylan DPC
e73ee1dde2
Rollup merge of #80736 - KodrAus:feat/lazy-resolve, r=dtolnay
use Once instead of Mutex to manage capture resolution

For #78299

This allows us to return borrows of the captured backtrace frames that are tied to a borrow of the Backtrace itself, instead of to some short-lived Mutex guard.

We could alternatively share `&Mutex<Capture>`s and lock on-demand, but then we could potentially forget to call `resolve()` before working with the capture. It also makes it semantically clearer what synchronization is needed on the capture.

cc `@seanchen1991` `@rust-lang/project-error-handling`
2021-01-13 03:20:17 +01:00
Jacob Pratt
85394252e6
Stabilize unsigned_abs 2021-01-12 20:07:34 -05:00
Josh Stone
1f1a3b4857 move WriteCloneIntoRaw into alloc::alloc 2021-01-12 12:24:28 -08:00
Sebastian Dröge
12014d29b8 Add Box::downcast() for dyn Any + Send + Sync 2021-01-12 16:37:20 +02:00
Yuki Okushi
961a4386cd
Rollup merge of #80917 - epilys:patch-1, r=jyn514
core/slice: remove doc comment about scoped borrow

There's no need to scope the borrow in the doc example due to NLL.

[Playground link](https://play.rust-lang.org/?version=stable&mode=debug&edition=2018&code=fn%20main()%20%7B%0A%20%20%20%20let%20mut%20v%20%3D%20%5B1%2C%200%2C%203%2C%200%2C%205%2C%206%5D%3B%0A%0A%20%20%20%20let%20(left%2C%20right)%20%3D%20v.split_at_mut(2)%3B%0A%20%20%20%20assert_eq!(left%2C%20%5B1%2C%200%5D)%3B%0A%20%20%20%20assert_eq!(right%2C%20%5B3%2C%200%2C%205%2C%206%5D)%3B%0A%20%20%20%20left%5B1%5D%20%3D%202%3B%0A%20%20%20%20right%5B1%5D%20%3D%204%3B%0A%0A%20%20%20%20assert_eq!(v%2C%20%5B1%2C%202%2C%203%2C%204%2C%205%2C%206%5D)%3B%0A%7D%0A) where changed code compiles
2021-01-12 16:13:31 +09:00
Yuki Okushi
a9e3125f13
Rollup merge of #80898 - JohnTitor:vecdeque-another-case, r=lcnr
Add another test case for #79808

Taken from #80293.
Closes #80293

r? `@lcnr`
2021-01-12 16:13:29 +09:00
Yuki Okushi
babfdafb10
Rollup merge of #80600 - CoffeeBlend:maybe_uninit_array_assume_init, r=dtolnay
Add `MaybeUninit` method `array_assume_init`

When initialising an array element-by-element, the conversion to the initialised array is done through `mem::transmute`, which is both ugly and does not work with const generics (see #61956). This PR proposes the associated method `array_assume_init`, matching the style of `slice_assume_init_*`:

```rust
unsafe fn array_assume_init<T, const N: usize>(array: [MaybeUninit<T>; N]) -> [T; N];
```

Example:
```rust
let mut array: [MaybeUninit<i32>; 3] = MaybeUninit::uninit_array();
array[0].write(0);
array[1].write(1);
array[2].write(2);

// SAFETY: Now safe as we initialised all elements
let array: [i32; 3] = unsafe {
     MaybeUninit::array_assume_init(array)
};
```

Things I'm unsure about:
* Should this be a method of array instead?
* Should the function be const?
2021-01-12 16:13:24 +09:00
Camelid
7463292015 Add docs on performance 2021-01-11 19:18:39 -08:00
Josh Stone
f89f30fb2c Move directly when Rc/Arc::make_mut splits from Weak
When only other `Weak` references remain, we can directly move the data
into the new unique allocation as a plain memory copy.
2021-01-11 17:46:49 -08:00
Josh Stone
d85df44e8d Specialize Rc/Arc::make_mut clones to try to avoid locals
As we did with `Box`, we can allocate an uninitialized `Rc` or `Arc`
beforehand, giving the optimizer a chance to skip the local value for
regular clones, or avoid any local altogether for `T: Copy`.
2021-01-11 17:43:10 -08:00
Josh Stone
9aa7dd1e6a Specialize Box clones to try to avoid locals
For generic `T: Clone`, we can allocate an uninitialized box beforehand,
which gives the optimizer a chance to create the clone directly in the
heap. For `T: Copy`, we can go further and do a simple memory copy,
regardless of optimization level.
2021-01-11 17:43:10 -08:00
CoffeeBlend
985071b08f
Fix implementation 2021-01-12 01:39:10 +01:00
Yuki Okushi
4646eac08e
Rollup merge of #80864 - ericseppanen:master, r=jyn514
std/core docs: fix wrong link in PartialEq

PartialEq doc was attempting to link to ``[`Eq`]`` but instead we got a link to `` `eq` ``. Disambiguate with `trait@Eq`.

You can see the bad link [here](https://doc.rust-lang.org/std/cmp/trait.PartialEq.html) (Second sentence, "floating point types implement PartialEq but not Eq").
2021-01-12 07:59:11 +09:00
CoffeeBlend
5d65b7e055
Simplify array_assume_init 2021-01-11 23:32:03 +01:00
Steven Fackler
e6c07b0628 clarify docs a bit 2021-01-11 17:16:44 -05:00
Steven Fackler
5cb830397e make check a bit more clear 2021-01-11 17:13:50 -05:00
Manos Pitsidianakis
0be9d39336
core/slice: remove doc comment about scoped borrow
There's no need to scope the borrow in the doc example due to NLL.

Playground link where changed code compiles
https://play.rust-lang.org/?version=stable&mode=debug&edition=2018&code=fn%20main()%20%7B%0A%20%20%20%20let%20mut%20v%20%3D%20%5B1%2C%200%2C%203%2C%200%2C%205%2C%206%5D%3B%0A%0A%20%20%20%20let%20(left%2C%20right)%20%3D%20v.split_at_mut(2)%3B%0A%20%20%20%20assert_eq!(left%2C%20%5B1%2C%200%5D)%3B%0A%20%20%20%20assert_eq!(right%2C%20%5B3%2C%200%2C%205%2C%206%5D)%3B%0A%20%20%20%20left%5B1%5D%20%3D%202%3B%0A%20%20%20%20right%5B1%5D%20%3D%204%3B%0A%0A%20%20%20%20assert_eq!(v%2C%20%5B1%2C%202%2C%203%2C%204%2C%205%2C%206%5D)%3B%0A%7D%0A
2021-01-11 18:55:35 +02:00
Steven Fackler
a9ef7983a6 clean up control flow 2021-01-11 07:48:24 -05:00
Steven Fackler
ebe402dc9e Fix handling of malicious Readers in read_to_end 2021-01-11 07:27:03 -05:00
Lukas Kalbertodt
4038042eb0
Add [T; N]::each_ref and [T; N]::each_mut
These methods work very similarly to `Option`'s methods `as_ref` and
`as_mut`. They are useful in several situation, particularly when
calling other array methods (like `map`) on the result. Unfortunately,
we can't easily call them `as_ref` and `as_mut` as that would shadow
those methods on slices, thus being a breaking change (that is likely
to affect a lot of code).
2021-01-11 01:09:22 -08:00
CoffeeBlend
dec8c033a3
Add tracking issue for array_assume_init 2021-01-11 10:07:29 +01:00
CAD97
b5b6760c03 Weak::into_raw shouldn't translate sentinel value 2021-01-10 23:27:32 -05:00
bors
00c5c3922f Auto merge of #80818 - 12101111:system-libunwind, r=Mark-Simulacrum
Don't build in-tree llvm-libunwind if system-llvm-libunwind is enable

When "system-llvm-libunwind" is enabled, some target eg. musl still build in-tree llvm-libunwind which is useless.
2021-01-11 03:24:14 +00:00
Yuki Okushi
39e1331cfa Add another test case for #79808
Taken from #80293.
2021-01-11 12:10:16 +09:00
Miguel Ojeda
76299b3f42 Add SAFETY annotations
Signed-off-by: Miguel Ojeda <ojeda@kernel.org>
2021-01-10 15:59:58 +01:00
Miguel Ojeda
679f6f3473 Add unwrap_unchecked() methods for Option and Result
In particular:
  - `unwrap_unchecked()` for `Option`.
  - `unwrap_unchecked()` and `unwrap_err_unchecked()` for `Result`.

These complement other `*_unchecked()` methods in `core` etc.

Currently there are a couple of places it may be used inside rustc
(`LinkedList`, `BTree`). It is also easy to find other repositories
with similar functionality.

Fixes #48278.

Signed-off-by: Miguel Ojeda <ojeda@kernel.org>
2021-01-10 15:14:38 +01:00
Stein Somers
c1dfb4a9c4 BTreeMap: tougher checks on code using raw into_kv_pointers 2021-01-10 14:40:21 +01:00
Patryk Wychowaniec
d2f8e398f1
Rework diagnostics for wrong number of generic args 2021-01-10 13:07:40 +01:00
bors
fd34606ddf Auto merge of #80391 - ssomers:btree_cleanup_slices_3, r=Mark-Simulacrum
BTreeMap: tougher checking on most uses of copy_nonoverlapping

Miri checks pointer provenance and destination, but we can check it in debug builds already.
Also, we can let Miri confirm we don't mistake imprints of moved keys and values as genuine.
r? `@Mark-Simulacrum`
2021-01-10 10:48:55 +00:00
bors
34628e5b53 Auto merge of #80867 - JohnTitor:rollup-tvqw555, r=JohnTitor
Rollup of 9 pull requests

Successful merges:

 - #79502 (Implement From<char> for u64 and u128.)
 - #79968 (Improve core::ptr::drop_in_place debuginfo)
 - #80774 (Fix safety comment)
 - #80801 (Use correct span for structured suggestion)
 - #80803 (Remove useless `fill_in` function)
 - #80820 (Support `download-ci-llvm` on NixOS)
 - #80825 (Remove under-used ImplPolarity enum)
 - #80850 (Allow #[rustc_builtin_macro = "name"])
 - #80857 (Add comment to `Vec::truncate` explaining `>` vs `>=`)

Failed merges:

r? `@ghost`
`@rustbot` modify labels: rollup
2021-01-10 08:01:12 +00:00
Yuki Okushi
19b8c65e4e
Rollup merge of #80857 - camelid:vec-truncate-comment, r=scottmcm
Add comment to `Vec::truncate` explaining `>` vs `>=`

Hopefully this will prevent people from continuing to ask about this
over and over again :)

See [this Zulip discussion][1] for more.

[1]: https://rust-lang.zulipchat.com/#narrow/stream/219381-t-libs/topic/Vec.3A.3Atruncate.20implementation

r? ``@scottmcm``
2021-01-10 16:56:07 +09:00
Yuki Okushi
d64356f06c
Rollup merge of #80774 - LingMan:patch-1, r=nagisa
Fix safety comment

The size assertion in the comment was inverted compared to the code. After fixing that the implication that `(new_size >= old_size) => new_size != 0` still doesn't hold so explain why `old_size != 0` at this point.
2021-01-10 16:55:57 +09:00
Yuki Okushi
5c0f5b69c2
Rollup merge of #79502 - Julian-Wollersberger:from_char_for_u64, r=withoutboats
Implement From<char> for u64 and u128.

With this PR you can write
```
let u = u64::from('👤');
let u = u128::from('👤');
```

Previously, you could already write `as` conversions ([Playground link](https://play.rust-lang.org/?version=stable&mode=debug&edition=2018&gist=cee18febe28e69024357d099f07ca081)):
```
// Lossless conversions
dbg!('👤' as u32);    // Prints 128100
dbg!('👤' as u64);    // Prints 128100
dbg!('👤' as u128);   // Prints 128100

// truncates, thus no `From` impls.
dbg!('👤' as u8);     // Prints 100
dbg!('👤' as u16);    // Prints 62564

// These `From` impls already exist.
dbg!(u32::from('👤'));               // Prints 128100
dbg!(u64::from(u32::from('👤')));    // Prints 128100
```

The idea is from ``@gendx`` who opened [this Internals thread](https://internals.rust-lang.org/t/implement-from-char-for-u64/13454), and ``@withoutboats`` responded that someone should open a PR for it.
Some people mentioned `From<char>` impls for `f32` and `f64`, but that doesn't seem correct to me, so I didn't include them here.

I don't know what the feature should be named. Must it be registered somewhere, like unstable features?

r? ``@withoutboats``
2021-01-10 16:55:53 +09:00
johanngan
b43aa960d0 Print failure message on all tests that should panic, but don't
This already happens with should_panic tests without an expected
message. This commit fixes should_panic tests with an expected message
to have the same behavior.
2021-01-10 01:18:23 -06:00
Eric Seppanen
eef95871a4 fix broken link in PartialEq doc
PartialEq doc was attempting to link to [`Eq`] but instead we got a link
to `eq`. Disambiguate with "trait@Eq".
2021-01-09 22:40:48 -08:00
bors
7a193921a0 Auto merge of #77862 - danielhenrymantilla:rustdoc/fix-macros_2_0-paths, r=jyn514,petrochenkov
Rustdoc: Fix macros 2.0 and built-in derives being shown at the wrong path

Fixes #74355

  - ~~waiting on author + draft PR since my code ought to be cleaned up _w.r.t._ the way I avoid the `.unwrap()`s:~~

      - ~~dummy items may avoid the first `?`,~~

      - ~~but within the module traversal some tests did fail (hence the second `?`), meaning the crate did not possess the exact path of the containing module (`extern` / `impl` blocks maybe? I'll look into that).~~

r? `@jyn514`
2021-01-10 05:15:01 +00:00
Camelid
befd153098
Add comment to Vec::truncate explaining > vs >=
Hopefully this will prevent people from continuing to ask about this
over and over again :)

See [this Zulip discussion][1] for more.

[1]: https://rust-lang.zulipchat.com/#narrow/stream/219381-t-libs/topic/Vec.3A.3Atruncate.20implementation
2021-01-09 12:35:47 -08:00
CAD97
747dbcb325 Provide reasoning for rc data_offset safety 2021-01-09 14:32:55 -05:00
bors
ef589490a7 Auto merge of #80808 - CAD97:patch-3, r=nagisa
Fix typo in Step trait

... I don't know how this major typo happened, whoops 🙃

`@bors` rollup=always
(comment only change)
2021-01-09 13:56:15 +00:00
Julian Wollersberger
e8cb72c503 Update the stabilisation version. 2021-01-09 12:31:30 +01:00
bors
1f9dc9a182 Auto merge of #80755 - sunfishcode:path-cleanup/copy, r=nagisa
Optimize away some path lookups in the generic `fs::copy` implementation

This also eliminates a use of a `Path` convenience function, in support
of #80741, refactoring `std::path` to focus on pure data structures and
algorithms.
2021-01-09 07:48:53 +00:00
12101111
5de06800c7 Don't build in-tree llvm-libunwind if system-llvm-libunwind is enable 2021-01-09 12:50:08 +08:00
Stein Somers
26b94626a1 BTreeMap: tougher checks on most uses of copy_nonoverlapping 2021-01-08 19:58:05 +01:00
kadmin
e5094a2851 Add more benchmarks 2021-01-08 09:50:35 +00:00
kadmin
fb8cc7bd99 Clean up branching in skip 2021-01-08 08:05:31 +00:00
Christopher Durham
02850d3f30
Fix typo in Step trait 2021-01-07 21:29:17 -05:00
Yuki Okushi
1ed90e4f06
Rollup merge of #80791 - mrcz:master, r=jyn514
Fix type name in doc example for Iter and IterMut
2021-01-08 11:11:47 +09:00
CAD97
4901c55af7 Replace set_data_ptr with pointer::set_ptr_value 2021-01-07 13:40:57 -05:00
bors
c8915eebea Auto merge of #80790 - JohnTitor:rollup-js1noez, r=JohnTitor
Rollup of 10 pull requests

Successful merges:

 - #80012 (Add pointing const identifier when emitting E0435)
 - #80521 (MIR Inline is incompatible with coverage)
 - #80659 (Edit rustc_ast::tokenstream docs)
 - #80660 (Properly handle primitive disambiguators in rustdoc)
 - #80738 (Remove bottom margin from crate version when the docs sidebar is collapsed)
 - #80744 (rustdoc: Turn `next_def_id` comments into docs)
 - #80750 (Don't use to_string on Symbol in rustc_passes/check_attr.rs)
 - #80769 (Improve wording of parse doc)
 - #80780 (Return EOF_CHAR constant instead of magic char.)
 - #80784 (rustc_parse: Better spans for synthesized token streams)

Failed merges:

 - #80785 (rustc_ast_pretty: Remove `PrintState::insert_extra_parens`)

r? `@ghost`
`@rustbot` modify labels: rollup
2021-01-07 18:20:12 +00:00
CAD97
1e578c9fb0 Reclarify Weak<->raw pointer safety comments 2021-01-07 12:53:04 -05:00
CAD97
b10b9e25ff Remove "pointer describes" terminology 2021-01-07 12:41:58 -05:00
Marcus Svensson
358ef56216 Enclose types in comments in backticks 2021-01-07 18:36:25 +01:00
CAD97
f00b458903 Tighten/clarify documentation of rc data_offset 2021-01-07 12:32:42 -05:00
Marcus Svensson
10180b4c53 Fix type name in doc example for Iter and IterMut 2021-01-07 18:22:37 +01:00
Yuki Okushi
a97dc5f103
Rollup merge of #80769 - ejez:patch-1, r=jonas-schievink
Improve wording of parse doc

Change:
```
`parse` can parse any type that...
```
to:
```
`parse` can parse into any type that...
```
Word `into` added to be more precise and in coherence with other parts of the doc.
2021-01-08 02:06:16 +09:00
bors
8f0b945cfc Auto merge of #77853 - ijackson:slice-strip-stab, r=Amanieu
Stabilize slice::strip_prefix and slice::strip_suffix

These two methods are useful.  The corresponding methods on `str` are already stable.

I believe that stablising these now would not get in the way of, in the future, extending these to take a richer pattern API a la `str`'s patterns.

Tracking PR: #73413.  I also have an outstanding PR to improve the docs for these two functions and the corresponding ones on `str`: #75078

I have tried to follow the [instructions in the dev guide](https://rustc-dev-guide.rust-lang.org/stabilization_guide.html#stabilization-pr).  The part to do with `compiler/rustc_feature` did not seem applicable.  I assume that's because these are just library features, so there is no corresponding machinery in rustc.
2021-01-07 15:21:30 +00:00
bors
b5c496de37 Auto merge of #79863 - JohnTitor:compiler-builtins, r=bjorn3
Update `compiler_builtins` to 0.1.39

This version contains the fixes of https://github.com/rust-lang/compiler-builtins/issues/390 and https://github.com/rust-lang/compiler-builtins/issues/391.
Also, rename features following https://github.com/rust-lang/compiler-builtins/pull/386.
2021-01-07 11:22:42 +00:00
LingMan
769fb8a8b7
Fix safety comment
The size assertion in the comment was inverted compared to the code. After fixing that the implication that `(new_size >= old_size) => new_size != 0` still doesn't hold so explain why `old_size != 0` at this point.
2021-01-07 09:13:21 +01:00
Yuki Okushi
6275a29dbe Update compiler_builtins to 0.1.39 2021-01-07 16:16:36 +09:00
Ejez
2b8109f229
Improve wording of parse doc
Change:
```
`parse` can parse any type that...
```
to:
```
`parse` can parse into any type that...
```
Word `into` added to be more precise and in coherence with other parts of the doc.
2021-01-07 07:47:03 +03:00
CAD97
6bc772cdc0 Re-stabilize Weak::as_ptr &friends for unsized T
As per T-lang consensus, this uses a branch to handle the dangling case.
The discussed optimization of only doing the branch in the T: ?Sized
case is left for a followup patch, as doing so is not trivial
(as it requires specialization for correctness, not just optimization).
2021-01-06 19:30:22 -05:00
Lukas Lueg
7a0ada0427 Remove FIXME-notes 2021-01-07 00:45:47 +01:00
Dan Gohman
97baac4184 Optimize away some path lookups in the generic fs::copy implementation.
This also eliminates a use of a `Path` convenience function, in support
of #80741, refactoring `std::path` to focus on pure data structures and
algorithms.
2021-01-06 08:36:31 -08:00
Daniel Henry-Mantilla
aa863caebe Style nit: replace for_each & return with for & continue
Co-Authored-By: Joshua Nelson <jyn514@gmail.com>
2021-01-06 15:13:38 +01:00
Camelid
25a4964191 Use heading for std::prelude and not io::prelude
The heading style for `std::prelude` is to be consistent with the
headings for `std` and `core`: `# The Rust Standard Library` and
`# The Rust Core Library`, respectively.
2021-01-05 17:52:24 -08:00
Camelid
4274ba40bd Use lowercase for prelude items 2021-01-05 17:51:27 -08:00
Ashley Mannix
db4585aa3b use Once instead of Mutex to manage capture resolution
This allows us to return borrows of the captured backtrace frames
that are tied to a borrow of the Backtrace itself, instead of to
some short-lived Mutex guard.

It also makes it semantically clearer what synchronization is needed
on the capture.
2021-01-06 10:44:06 +10:00
bors
da305a2b00 Auto merge of #80711 - camelid:intrinsic-of-val-safety, r=oli-obk
Make `size_of_val` and `min_align_of_val` intrinsics unsafe

Fixes #80668.

r? `@oli-obk`
2021-01-05 17:07:25 +00:00
bors
3b63e16552 Auto merge of #80717 - mbartlett21:patch-2, r=dtolnay
Add more code spans to docs in intrinsics.rs

I have added some more code spans in core/src/intrinsics.rs, changing some `=` to `==`, etc. I also changed the wording in some sections.
2021-01-05 14:15:49 +00:00
bors
68ec332611 Auto merge of #80699 - usbalbin:const_copy_tracking_issue, r=oli-obk
const_intrinsic_copy - Add Reference to tracking issue

Add reference to tracking issue #80697 for feature gate added in previous PR #79684
2021-01-05 11:29:27 +00:00
mbartlett21
63dd00b97b
Add code spans to docs in intrinsics.rs 2021-01-05 17:27:10 +10:00
Camelid
bbf175df3c Make size_of_val and min_align_of_val intrinsics unsafe 2021-01-04 19:23:55 -08:00
Yuki Okushi
ee94d9d690
Rollup merge of #80677 - kw-fn:patch-2, r=jyn514
doc -- list edit for consistency
2021-01-05 09:52:50 +09:00
Yuki Okushi
cda26a6b15
Rollup merge of #80666 - jjlin:master, r=Dylan-DPC
Fix missing link for "fully qualified syntax"

This issue can currently be seen at https://doc.rust-lang.org/stable/std/rc/index.html#toggle-all-docs:~:text=%5B-,fully%20qualified%20syntax

It originates from #76138, where the link was added to `library/alloc/src/sync.rs`, but not `library/alloc/src/rc.rs`.
2021-01-05 09:52:47 +09:00
Yuki Okushi
cbdc24174b
Rollup merge of #80656 - booleancoercion:master, r=sfackler
Fixed documentation error for `std::hint::spin_loop`

Fixes #80644.
2021-01-05 09:52:45 +09:00
Yuki Okushi
bdf8bbde1d
Rollup merge of #80442 - steffahn:mention_arc_in_cow, r=Mark-Simulacrum
Mention Arc::make_mut and Rc::make_mut in the documentation of Cow

Following this discussion: https://users.rust-lang.org/t/should-the-cow-documentation-mention-arc/53341

_Rendered (the last paragraph is new):_

![Screenshot_20201228_171551](https://user-images.githubusercontent.com/3986214/103228135-5d72e200-4930-11eb-89e1-38b5c86b08c7.png)

`@rustbot` modify labels: T-doc, T-libs
2021-01-05 09:52:33 +09:00
Albin Hedman
63f5d6111a Added reference to tracking issue and removed unneeded line 2021-01-04 19:36:25 +01:00
Ian Jackson
2c1d6557c9 Remove two obsolete uses of #![feature(split_inclusive)]
Signed-off-by: Ian Jackson <ijackson@chiark.greenend.org.uk>
2021-01-04 16:29:12 +00:00
Ian Jackson
be226e49e4 Stabilize split_inclusive
Closes #72360.

Signed-off-by: Ian Jackson <ijackson@chiark.greenend.org.uk>
2021-01-04 16:20:08 +00:00
Ian Jackson
dea6d6c909 BufWriter::into_raw_parts: Add tracking issue number
Signed-off-by: Ian Jackson <ijackson@chiark.greenend.org.uk>
2021-01-04 15:35:28 +00:00
oliver
e152582a2b
doc -- list edit for consistency 2021-01-04 04:50:24 +00:00
The8472
af2983a912 TrustedRandomAaccess spec composes incorrectly for nested iter::Zips
After partially consuming a Zip adapter and then wrapping it into
another Zip where the adapters use their TrustedRandomAccess specializations
leads to the outer adapter returning elements which should have already been
consumed.
2021-01-04 01:12:21 +01:00
Jeremy Lin
6d45d055a1 Fix missing link for "fully qualified syntax" 2021-01-03 13:59:02 -08:00