Commit graph

2824 commits

Author SHA1 Message Date
bors c6bc46227a Auto merge of #81073 - ssomers:btree_owned_root_vs_dying, r=Mark-Simulacrum
BTreeMap: prevent tree from ever being owned by non-root node

This introduces a new marker type, `Dying`, which is used to note trees which are in the process of deallocation. On such trees, some fields may be in an inconsistent state as we are deallocating the tree. Unfortunately, there's not a great way to express conditional unsafety, so the methods for traversal can cause UB if not invoked correctly, but not marked as such. This is not a regression from the previous state, but rather isolates the destructive methods to solely being called on the dying state.
2021-01-29 04:06:38 +00:00
Yuki Okushi 94e093ab97
Rollup merge of #81306 - SkiFire13:fuse-flatten, r=cuviper
Fuse inner iterator in FlattenCompat and improve related tests

Fixes #81248
2021-01-29 09:17:36 +09:00
Yuki Okushi 70be5cef69
Rollup merge of #81277 - flip1995:from_diag_items, r=matthewjasper
Make more traits of the From/Into family diagnostic items

Following traits are now diagnostic items:
- `From` (unchanged)
- `Into`
- `TryFrom`
- `TryInto`

This also adds symbols for those items:
- `into_trait`
- `try_from_trait`
- `try_into_trait`

Related: https://github.com/rust-lang/rust-clippy/pull/6620#discussion_r562482587
2021-01-28 15:09:08 +09:00
Yuki Okushi 98226638fd
Rollup merge of #80868 - johanngan:should-panic-msg-with-expected, r=m-ou-se
Print failure message on all tests that should panic, but don't

Fixes #80861. Tests with the `#[should_panic]` attribute should always print a failure message if no panic occurs, regardless of whether or not an `expected` panic message is specified.
2021-01-28 15:09:04 +09:00
Yuki Okushi 025a850d21
Rollup merge of #70904 - LukasKalbertodt:stabilize-seek-convenience, r=m-ou-se
Stabilize `Seek::stream_position` (feature `seek_convenience`)

Tracking issue: #59359

Unresolved questions from tracking issue:
- "Override `stream_len` for `File`?" → we can do that in the future, this does not block stabilization.
- "Rename to `len` and `position`?" → as noted in the tracking issue, both of these shorter names have problems (`len` is usually a cheap getter, `position` clashes with `Cursor`). I do think the current names are perfectly fine.
- "Rename `stream_position` to `tell`?" → as mentioned in [the comment bringing this up](https://github.com/rust-lang/rust/issues/59359#issuecomment-559541545), `stream_position` is more descriptive. I don't think `tell` would be a good name.

What remains to decide, is whether or not adding these methods is worth it.
2021-01-28 15:09:00 +09:00
bors a2f8f62818 Auto merge of #81335 - thomwiggers:no-panic-shrink-to, r=Mark-Simulacrum
Trying to shrink_to greater than capacity should be no-op

Per the discussion in https://github.com/rust-lang/rust/issues/56431, `shrink_to` shouldn't panic if you try to make a vector shrink to a capacity greater than its current capacity.
2021-01-27 18:36:32 +00:00
Yuki Okushi b2f6c2aa9b
Rollup merge of #81412 - hyd-dev:array-assume-init-wrong-assertion, r=m-ou-se
Fix assertion in `MaybeUninit::array_assume_init()` for zero-length arrays

That assertion has a false positive ([playground](https://play.rust-lang.org/?version=nightly&mode=debug&edition=2018&gist=63922b8c897b04112adcdf346deb1d0e)):
```rust
#![feature(maybe_uninit_array_assume_init)]

use std::mem::MaybeUninit;

enum Uninhabited {}

fn main() {
    unsafe {
        // thread 'main' panicked at 'attempted to instantiate uninhabited type `Uninhabited`'
        MaybeUninit::<Uninhabited>::array_assume_init([]);
    }
}
```
*Previously reported in https://github.com/rust-lang/rust/pull/80600#discussion_r564496692.*

This PR makes it ignore zero-length arrays.

cc #80908
2021-01-27 04:43:37 +09:00
Yuki Okushi 8299105821
Rollup merge of #81191 - ssomers:btree_more_order_chaos, r=Mark-Simulacrum
BTreeMap: test all borrowing interfaces and test more chaotic order behavior

Inspired by #81169, test what happens if you mess up order of the type with which you search (as opposed to the key type).

r? `@Mark-Simulacrum`
2021-01-27 04:43:18 +09:00
Yuki Okushi fe6b3a9792
Rollup merge of #80876 - ojeda:option-result-unwrap_unchecked, r=m-ou-se
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.
2021-01-27 04:43:14 +09:00
Stein Somers 417eefedfa BTreeMap: stop tree from being owned by non-root node 2021-01-26 19:32:03 +01:00
Thom Wiggers d069c58e78
shrink_to shouldn't panic on len greater than capacity 2021-01-26 19:25:37 +01:00
hyd-dev f52066726d
Fix assertion in MaybeUninit::array_assume_init() for zero-length arrays 2021-01-27 00:16:58 +08:00
bors 7907345e58 Auto merge of #81217 - ssomers:btree_bring_back_the_slice, r=Mark-Simulacrum
BTreeMap: bring back the key slice for immutable lookup

Pave the way for binary search, by reverting a bit of #73971, which banned `keys` for misbehaving while it was defined for every `BorrowType`. Adding some `debug_assert`s along the way.

r? `@Mark-Simulacrum`
2021-01-26 14:47:51 +00:00
bors 1483e67add Auto merge of #81367 - andersk:join-test-threads, r=dtolnay
libtest: Wait for test threads to exit after they report completion

Otherwise we can miss bugs where a test reports that it succeeded but then panics within a TLS destructor.

Example:

```rust
use std:🧵:sleep;
use std::time::Duration;

struct Foo;

impl Drop for Foo {
    fn drop(&mut self) {
        sleep(Duration::from_secs(1));
        panic!()
    }
}

thread_local!(static FOO: Foo = Foo);

#[test]
pub fn test() {
    FOO.with(|_| {});
}
```

Before this fix, `cargo test` incorrectly reports success.

```console
$ cargo test
    Finished test [unoptimized + debuginfo] target(s) in 0.01s
     Running target/debug/deps/panicking_test-85130fa46b54f758

running 1 test
test test ... ok

test result: ok. 1 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out; finished in 0.00s

$ echo $?
0
```

After this fix, the failure is visible. (The entire process is aborted due to #24479.)

```console
$ cargo test
    Finished test [unoptimized + debuginfo] target(s) in 0.01s
     Running target/debug/deps/panicking_test-76180625bc2ee3c9

running 1 test
thread 'test' panicked at 'explicit panic', src/main.rs:9:9
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
fatal runtime error: failed to initiate panic, error 5
error: test failed, to rerun pass '--bin panicking-test'

Caused by:
  process didn't exit successfully: `/tmp/panicking-test/target/debug/deps/panicking_test-76180625bc2ee3c9 --nocapture` (signal: 6, SIGABRT: process abort signal)

$ echo $?
101
```
2021-01-26 11:15:44 +00:00
bors ff6ee2a702 Auto merge of #79113 - andjo403:raw_vec_ptr, r=m-ou-se
mark raw_vec::ptr with inline

when a lot of vectors is used in a enum as in the example in #66617 if this function is not inlined and multiple cgus is used this results in huge compile times. with this fix the compile time is 6s from minutes for the example in #66617. I did not have the patience to wait for it to compile for more then 3 min.
2021-01-26 02:56:37 +00:00
Anders Kaseorg b05788e859 libtest: Store pending timeouts in a deque
This reduces the total complexity of checking timeouts from quadratic
to linear, and should also fix an unwrap of None on completion of an
already timed-out test.

Signed-off-by: Anders Kaseorg <andersk@mit.edu>
2021-01-25 12:21:33 -08:00
bors f4eb5d9f71 Auto merge of #68828 - oli-obk:inline_cycle, r=wesleywiser
Prevent query cycles in the MIR inliner

r? `@eddyb` `@wesleywiser`

cc `@rust-lang/wg-mir-opt`

The general design is that we have a new query that is run on the `validated_mir` instead of on the `optimized_mir`. That query is forced before going into the optimization pipeline, so as to not try to read from a stolen MIR.

The query should not be cached cross crate, as you should never call it for items from other crates. By its very design calls into other crates can never cause query cycles.

This is a pessimistic approach to inlining, since we strictly have more calls in the `validated_mir` than we have in `optimized_mir`, but that's not a problem imo.
2021-01-25 19:03:37 +00:00
Miguel Ojeda 01250fcec6 Add tracking issue
Signed-off-by: Miguel Ojeda <ojeda@kernel.org>
2021-01-25 14:58:09 +01:00
Miguel Ojeda 0140dacabb Link the reference about undefined behavior
Suggested-by: Mara Bos <m-ou.se@m-ou.se>
Signed-off-by: Miguel Ojeda <ojeda@kernel.org>
2021-01-25 14:53:19 +01:00
Anders Kaseorg 57c72ab846 libtest: Wait for test threads to exit after they report completion
Otherwise we can miss bugs where a test reports that it succeeded but
then panics within a TLS destructor.

Signed-off-by: Anders Kaseorg <andersk@mit.edu>
2021-01-24 19:09:54 -08:00
Jonas Schievink 3ed8a3769a
Rollup merge of #79884 - Digital-Chaos:replace-magic, r=m-ou-se
Replace magic numbers with existing constants

Replaced magic numbers in `library/core/src/time.rs` with predefined constants.
2021-01-24 22:09:51 +01:00
Jonas Schievink 13b88c21d0
Rollup merge of #79174 - taiki-e:std-future, r=Mark-Simulacrum
Make std::future a re-export of core::future

After 1a764a7ef5, there are no `std::future`-specific items (except for `cfg(bootstrap)` items removed in 93eed402ad). So, instead of defining `std` own module, we can re-export the `core::future` directly.
2021-01-24 22:09:49 +01:00
Jonas Schievink 5a1f2ecdd7
Rollup merge of #75180 - KodrAus:feat/error-by-ref, r=m-ou-se
Implement Error for &(impl Error)

Opening this up just to see what it breaks. It's unfortunate that `&(impl Error)` doesn't actually implement `Error`. If this direct approach doesn't work out then I'll try something different, like an `Error::by_ref` method.

**EDIT:** This is a super low-priority experiment so feel free to cancel it for more important crater runs! 🙂

-----

# Stabilization Report

## Why?

We've been working for the last few years to try "fix" the `Error` trait, which is probably one of the most fundamental in the whole standard library. One of its issues is that we commonly expect you to work with abstract errors through `dyn Trait`, but references and smart pointers over `dyn Trait` don't actually implement the `Error` trait. If you have a `&dyn Error` or a `Box<dyn Error>` you simply can't pass it to a method that wants a `impl Error`.

## What does this do?

This stabilizes the following trait impl:

```rust
impl<'a, T: Error + ?Sized + 'static> Error for &'a T;
```

This means that `&dyn Error` will now satisfy a `impl Error` bound.

It doesn't do anything with `Box<dyn Error>` directly. We discussed how we could do `Box<dyn Error>` in the thread here (and elsewhere in the past), but it seems like we need something like lattice-based specialization or a sprinkling of snowflake compiler magic to make that work. Having said that, with this new impl you _can_ now get a `impl Error` from a `Box<dyn Error>`  by dereferencing it.

## What breaks?

A crater run revealed a few crates broke with something like the following:

```rust
// where e: &'short &'long dyn Error
err.source()
```

previously we'd auto-deref that `&'short &'long dyn Error` to return a `Option<&'long dyn Error>` from `source`, but now will call directly on `&'short impl Error`, so will return a `Option<&'short dyn Error>`. The fix is to manually deref:

```rust
// where e: &'short &'long dyn Error
(*err).source()
```

In the recent Libs meeting we considered this acceptable breakage.
2021-01-24 22:09:45 +01:00
bors 9a9477fada Auto merge of #81250 - sivadeilra:remove_xp_compat, r=joshtriplett,m-ou-se
Remove delay-binding for Win XP and Vista

The minimum supported Windows version is now Windows 7. Windows XP
and Windows Vista are no longer supported; both are already broken, and
require extra steps to use.

This commit removes the delayed-binding support for Windows API
functions that are present on all supported Windows targets. This has
several benefits: Removes needless complexity. Removes a load and
dynamic call on hot paths in mutex acquire / release. This may have
performance benefits.

* "Drop official support for Windows XP"
  https://github.com/rust-lang/compiler-team/issues/378

* "Firefox has ended support for Windows XP and Vista"
  https://support.mozilla.org/en-US/kb/end-support-windows-xp-and-vista
2021-01-24 12:34:08 +00:00
Lukas Kalbertodt 8a18fb0f73
Stabilize Seek::stream_position & change feature of Seek::stream_len 2021-01-24 10:14:24 +01:00
Giacomo Stevanato 5aa625b903 Manually fuse the inner iterator in FlattenCompat 2021-01-23 21:33:38 +01:00
Giacomo Stevanato f241c10223 Improve flatten-fuse tests 2021-01-23 21:33:38 +01:00
Jonas Schievink ebeb6b8b26
Rollup merge of #81301 - davidgu:patch-1, r=jonas-schievink
Fix small typo

Fractional part of `12.34e56` seems to be incorrectly stated as '45' and not '34'
2021-01-23 20:16:19 +01:00
Jonas Schievink 44c668cfca
Rollup merge of #81281 - a1phyr:inline_path, r=dtolnay
Inline methods of Path and OsString

These methods are not generic, and therefore aren't candidates for cross-crate inlining without an `#[inline]` attribute.
2021-01-23 20:16:12 +01:00
Jonas Schievink 05a95a4372
Rollup merge of #81170 - xfix:vecdeque-bug-fix, r=sfackler
Avoid hash_slice in VecDeque's Hash implementation

Fixes #80303.
2021-01-23 20:16:02 +01:00
Jonas Schievink 7635462fe8
Rollup merge of #79841 - fintelia:patch-6, r=kennytm
More clear documentation for NonNull<T>

Rephrase and hopefully clarify the discussion of covariance in `NonNull<T>` documentation.

I'm very much not an expert so someone should definitely double check the correctness of what I'm saying. At the same time, the new language makes more sense to me, so hopefully it also is more logical to others whose knowledge of covariance basically begins and ends with the [Rustonomicon chapter](https://doc.rust-lang.org/nomicon/subtyping.html).

Related to #48929.
2021-01-23 20:15:54 +01:00
David 2f5ce8e802
Fix small typo 2021-01-23 12:31:40 -05:00
oli f238148214 Allow libcore to be built with MIR inlining
Inlining caused new lints to get emitted, so we silence those lints now that we actually can.
2021-01-23 16:51:23 +00:00
bors 4153fa82ff Auto merge of #80715 - JulianKnodt:skip_opt, r=nagisa
Change branching in `iter.skip()`

Optimize branching in `Skip`, which was brought up in #80416.
This assumes that if `next` is called, it's likely that there will be more calls to `next`, and the branch for skip will only be hit once thus it's unlikely to take that path. Even w/o the `unlikely` intrinsic, it compiles more efficiently, I believe because the path where `next` is called is always taken.

It should be noted there are very few places in the compiler where `Skip` is used, so probably won't have a noticeable perf impact.

[New impl](https://godbolt.org/z/85rdj4)
[Old impl](https://godbolt.org/z/Wc74rh)

[Some additional asm examples](https://godbolt.org/z/feKzoz) although they really don't have a ton of difference between them.
2021-01-23 09:25:11 +00:00
bors fe0fa59b50 Auto merge of #76391 - danii:master, r=cuviper
Split up core/test/iter.rs into multiple files

This PR removes the `// ignore-tidy-filelength` at the top of [iter.rs](04f44fb923/library/core/tests/iter.rs) by splitting it into several sub files. I have split the file per test, based on what I felt the test was really trying to test.
Addresses issue #60302.
- [associated_util.rs](d29180a8ed/library/core/tests/iter/associated_util.rs) - For testing the module level functions. (Maybe should be renamed?)
- [collection.rs](d29180a8ed/library/core/tests/iter/collection.rs) - For testing methods that use the values of all the items in an iterator, and creates one value from them, whether it be a Vec of all the values, or a number that represents the sum.
- [mod.rs](d29180a8ed/library/core/tests/iter/mod.rs) - For utility structs used in all tests, and other tests I didn't know where to place.
- [range.rs](d29180a8ed/library/core/tests/iter/range.rs) - For testing ranges.
- [transformation.rs](d29180a8ed/library/core/tests/iter/transformation.rs) - For testing methods that transform all the values in an iterator.
- [util.rs](d29180a8ed/library/core/tests/iter/util.rs) - For testing methods that provide utility in more specific use cases.

"Programatically"
-----------------------
You may have noticed I "Programatically" split up the file. [This is how](https://gist.github.com/danii/a58b3bcafa9faf1c3e4b01ad7495baf4) I managed to do that. 😛 Hope that's fine.
2021-01-23 03:33:16 +00:00
Daniel Conley 0c78500426 library/core/tests/iter documentation and cleanup 2021-01-22 17:57:08 -05:00
Daniel Conley bc830a274b library/core/tests/iter rearrange & add back missed doc comments 2021-01-22 17:57:07 -05:00
Daniel Conley 1e3a2def67 library/core/test/iter add newlines between tests 2021-01-22 16:58:21 -05:00
bors 34b3d41e1a Auto merge of #79233 - yoshuawuyts:alloc-doc-alias, r=GuillaumeGomez
Add doc aliases for memory allocations

This patch adds doc aliases for various C allocation functions, making it possible to search for the C-equivalent of a function and finding the (safe) Rust counterpart:

- `Vec::with_capacity` / `Box::new` / `vec!` -> alloc + malloc, allocates memory
- `Box::new_zeroed` -> calloc, allocates zeroed-out memory
- `Vec::{reserve,reserve_exact,try_reserve_exact,shrink_to_fit,shrink_to}` -> realloc, reallocates a previously allocated slice of memory

It's worth noting that `Vec::new` does not allocate, so we don't link to it. Instead people are probably looking for `Vec::with_capacity` or `vec!`. I hope this will allow people comfortable with the system allocation APIs to make it easier to find what they may be looking for.

Thanks!
2021-01-22 21:48:41 +00:00
Jonathan Behrens 0392085f5c More clear documentation for NonNull<T>
Rephrase and hopefully clarify the discussion of covariance in `NonNull<T>` documentation.
2021-01-22 14:46:11 -05:00
bors 22ddcd1a13 Auto merge of #72160 - slo1:libstd-setgroups, r=KodrAus
Add setgroups to std::os::unix::process::CommandExt

Should fix #38527. I'm not sure groups is the greatest name though.
2021-01-22 19:00:11 +00:00
Benoît du Garreau 9880560a1c Inline methods of Path and OsString 2021-01-22 18:46:00 +01:00
Yoshua Wuyts 7d102383f9 Add doc aliases for memory allocations
- Vec::with_capacity / Box::new -> alloc + malloc
- Box::new_zeroed -> calloc
- Vec::{reserve,reserve_exact,try_reserve_exact,shrink_to_fit,shrink_to} -> realloc
2021-01-22 18:15:28 +01:00
flip1995 e25959b417
Make more traits of the From/Into family diagnostic items
Following traits are now diagnostic items:
- `From` (unchanged)
- `Into`
- `TryFrom`
- `TryInto`

This also adds symbols for those items:
- `into_trait`
- `try_from_trait`
- `try_into_trait`
2021-01-22 18:07:00 +01:00
Mara Bos 9c2a5776b2
Rollup merge of #81242 - jyn514:const-cap, r=sfackler
Enforce statically that `MIN_NON_ZERO_CAP` is calculated at compile time

Previously, it would usually get computed by LLVM, but this enforces it. This removes the need for the comment saying "LLVM is smart enough".

I don't expect this to make a performance difference, but I do think it makes the performance properties easier to reason about.
2021-01-22 14:30:22 +00:00
Mara Bos 70597f28f6
Rollup merge of #81241 - m-ou-se:force-expr-macro-rules, r=oli-obk
Turn alloc's force_expr macro into a regular macro_rules.

This turns `alloc`'s `force_expr` macro into a regular `macro_rules`.

Otherwise rust-analyzer doesn't understand `vec![]`. See https://github.com/rust-analyzer/rust-analyzer/issues/7349 and https://github.com/rust-lang/rust/pull/81080#issuecomment-764741721

Edit: See https://github.com/rust-lang/rust/pull/81241#issuecomment-764812660 for a discussion of alternatives.
2021-01-22 14:30:21 +00:00
Mara Bos 81a60b7aa8
Rollup merge of #81233 - lzutao:dbg, r=KodrAus
Document why not use concat! in dbg! macro

Original title: Reduce code generated by `dbg!` macro
The expanded code before/after: <https://rust.godbolt.org/z/hE3j95>.

---

We cannot use `concat!` since `file!` could contains `{` or the expression is a block (`{ .. }`).
Using it will generated malformed format strings.
So let's document this reason why we don't use `concat!` macro at all.
2021-01-22 14:30:17 +00:00
Mara Bos 950ed27e8b
Rollup merge of #81202 - lzutao:dbg_ipv6, r=Amanieu
Don't prefix 0x for each segments in `dbg!(Ipv6)`

Fixes #81182
2021-01-22 14:30:12 +00:00
Mara Bos b59f6e05ef
Rollup merge of #81194 - m-ou-se:stabilize-panic-any, r=m-ou-se
Stabilize std::panic::panic_any.

This stabilizes `std::panic::panic_any`.
2021-01-22 14:30:11 +00:00
Mara Bos 226fe55057
Rollup merge of #81173 - lukaslueg:intersperse_docs, r=m-ou-se
Expand docs on Iterator::intersperse

Unstable feature in #79524. This expands on the docs to bring them more in line with how other methods of `Iterator` are demonstrated.
2021-01-22 14:30:09 +00:00