Commit Graph

712 Commits

Author SHA1 Message Date
dylni
b96063cf47 Fix soundness issue for replace_range and range 2021-01-18 22:14:38 -05: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
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
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
Dániel Buga
c127ed6e97 Force vec! to expressions only 2021-01-17 12:48:25 +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
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
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
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
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
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
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
Dániel Buga
744f885e2a Remove unreachable panics from VecDeque 2021-01-14 19:31:56 +01: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
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
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
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
Josh Stone
1f1a3b4857 move WriteCloneIntoRaw into alloc::alloc 2021-01-12 12:24:28 -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
CAD97
b5b6760c03 Weak::into_raw shouldn't translate sentinel value 2021-01-10 23:27:32 -05:00
Yuki Okushi
39e1331cfa Add another test case for #79808
Taken from #80293.
2021-01-11 12:10:16 +09:00
Stein Somers
c1dfb4a9c4 BTreeMap: tougher checks on code using raw into_kv_pointers 2021-01-10 14:40:21 +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
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
Stein Somers
26b94626a1 BTreeMap: tougher checks on most uses of copy_nonoverlapping 2021-01-08 19:58:05 +01:00
CAD97
4901c55af7 Replace set_data_ptr with pointer::set_ptr_value 2021-01-07 13:40:57 -05: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
CAD97
f00b458903 Tighten/clarify documentation of rc data_offset 2021-01-07 12:32:42 -05: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
Yuki Okushi
6275a29dbe Update compiler_builtins to 0.1.39 2021-01-07 16:16:36 +09: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
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
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
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