Commit Graph

244609 Commits

Author SHA1 Message Date
Matthias Krüger
772e80a650
Rollup merge of #119917 - Zalathar:split-off, r=cuviper
Remove special-case handling of `vec.split_off(0)`

#76682 added special handling to `Vec::split_off` for the case where `at == 0`. Instead of copying the vector's contents into a freshly-allocated vector and returning it, the special-case code steals the old vector's allocation, and replaces it with a new (empty) buffer with the same capacity.

That eliminates the need to copy the existing elements, but comes at a surprising cost, as seen in #119913. The returned vector's capacity is no longer determined by the size of its contents (as would be expected for a freshly-allocated vector), and instead uses the full capacity of the old vector.

In cases where the capacity is large but the size is small, that results in a much larger capacity than would be expected from reading the documentation of `split_off`. This is especially bad when `split_off` is called in a loop (to recycle a buffer), and the returned vectors have a wide variety of lengths.

I believe it's better to remove the special-case code, and treat `at == 0` just like any other value:
- The current documentation states that `split_off` returns a “newly allocated vector”, which is not actually true in the current implementation when `at == 0`.
- If the value of `at` could be non-zero at runtime, then the caller has already agreed to the cost of a full memcpy of the taken elements in the general case. Avoiding that copy would be nice if it were close to free, but the different handling of capacity means that it is not.
- If the caller specifically wants to avoid copying in the case where `at == 0`, they can easily implement that behaviour themselves using `mem::replace`.

Fixes #119913.
2024-01-26 14:43:30 +01:00
Matthias Krüger
a5b60c941e
Rollup merge of #117678 - niklasf:stabilize-slice_group_by, r=dtolnay
Stabilize `slice_group_by`

Renamed "group by" to "chunk by" a per #80552.

Newly stable items:

* `core::slice::ChunkBy`
* `core::slice::ChunkByMut`
* `[T]::chunk`
* `[T]::chunk_by`

Closes #80552.
2024-01-26 14:43:29 +01:00
Matthias Krüger
4808aa8872
Rollup merge of #117420 - Jules-Bertholet:internal-unstable-stmt-expr-attributes, r=petrochenkov
Make `#![allow_internal_unstable(..)]` work with `stmt_expr_attributes`

This is a necessary first step to fixing #117304, as explained in https://github.com/rust-lang/rust/issues/117304#issuecomment-1784414453.

`@rustbot` label T-compiler
2024-01-26 14:43:29 +01:00
bors
cdd4ff8d81 Auto merge of #120367 - RalfJung:project_downcast_uninhabited, r=oli-obk
interpret: project_downcast: do not ICE for uninhabited variants

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

This assertion was already under discussion for a bit; I think the [example](https://github.com/rust-lang/rust/issues/120337#issuecomment-1911076292) `@tmiasko` found is the final nail in the coffin. One could argue maybe MIR building should read the discriminant before projecting, but even then MIR optimizations should be allowed to remove that read, so the downcast should still not ICE. Maybe the downcast should be UB, but in this example UB already arises earlier when a value of type `E` is constructed.

r? `@oli-obk`
2024-01-26 12:50:02 +00:00
bjorn3
1f994c7695 Fix outdated comment on Box 2024-01-26 12:15:46 +00:00
bjorn3
dc7ed1680c Update to Cranelift 0.104 2024-01-26 11:18:14 +00:00
bjorn3
1fba58ed94 Update actions/checkout and actions/cache 2024-01-26 11:06:55 +00:00
bors
1fc46f3a8f Auto merge of #120365 - matthiaskrgr:rollup-ly2w0d5, r=matthiaskrgr
Rollup of 8 pull requests

Successful merges:

 - #107464 (Add `str::Lines::remainder`)
 - #118803 (Add the `min_exhaustive_patterns` feature gate)
 - #119466 (Initial implementation of `str::from_raw_parts[_mut]`)
 - #120053 (Specialize `Bytes` on `StdinLock<'_>`)
 - #120124 (Split assembly tests for ELF and MachO)
 - #120204 (Builtin macros effectively have implicit #[collapse_debuginfo(yes)])
 - #120322 (Don't manually resolve async closures in `rustc_resolve`)
 - #120356 (Fix broken markdown in csky-unknown-linux-gnuabiv2.md)

r? `@ghost`
`@rustbot` modify labels: rollup
2024-01-26 10:20:59 +00:00
Ralf Jung
64cd13ff3b add test for GVN issue; cleanup in dataflow_const_prop 2024-01-26 10:40:29 +01:00
Philipp Krones
de8ccdbf80
Clippy: Fix empty suggestion in from_over_into
Co-authored-by: y21 <30553356+y21@users.noreply.github.com>
2024-01-26 09:42:12 +01:00
Ralf Jung
1025a12b64 interpret: project_downcast: do not ICE for uninhabited variants 2024-01-26 09:01:56 +01:00
Ardi
00ada8e30c
Update compiler/rustc_index/src/vec.rs
Co-authored-by: Wesley Wiser <wwiser@gmail.com>
2024-01-26 08:37:37 +01:00
Ralf Jung
5dd6418010 mark a doctest with UB as no_run 2024-01-26 07:44:18 +01:00
David Tolnay
97a720b39b
Rebase slice_group_by stabilization PR 2024-01-25 22:20:59 -08:00
Matthias Krüger
ee2a2a3f31
Rollup merge of #120356 - mbrubeck:patch-2, r=ehuss
Fix broken markdown in csky-unknown-linux-gnuabiv2.md
2024-01-26 06:36:39 +01:00
Matthias Krüger
e400311486
Rollup merge of #120322 - compiler-errors:higher-ranked-async-closures, r=oli-obk
Don't manually resolve async closures in `rustc_resolve`

There's a comment here that talks about doing this "[so] closure [args] are detected as upvars rather than normal closure arg usages", but we do upvar analysis on the HIR now:

cd6d8f2a04/compiler/rustc_passes/src/upvars.rs (L21-L29)

Removing this ad-hoc logic makes it so that `async |x: &str|` now introduces an implicit binder, like regular closures.

r? ```@oli-obk```
2024-01-26 06:36:39 +01:00
Matthias Krüger
626797b61d
Rollup merge of #120204 - azhogin:azhogin/collapse_debuginfo_for_builtin, r=petrochenkov
Builtin macros effectively have implicit #[collapse_debuginfo(yes)]

If collapse_debuginfo attribute for builtin macro is not specified explicitly, it will be effectively set to `#[collapse_debuginfo(yes)]`.
2024-01-26 06:36:38 +01:00
Matthias Krüger
e04cba2724
Rollup merge of #120124 - nikic:fix-assembly-test, r=davidtwco
Split assembly tests for ELF and MachO

On ELF, the text section is opened with ".text", on MachO with ".section __TEXT,__text".

Previously, on ELF this test was actually matching a GNU note section, which is no longer emitted on Solaris starting with LLVM 18.

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

r? ```@davidtwco```
2024-01-26 06:36:38 +01:00
Matthias Krüger
cfa583b388
Rollup merge of #120053 - AldanTanneo:specialize-stdinlock-bytes, r=the8472
Specialize `Bytes` on `StdinLock<'_>`

I noticed recently, while profiling a little project, that I was spending a lot of time reading from stdin (even with locking). I was using the `.bytes()` iterator adaptor; I figured, since `StdinLock` is a `BufReader` internally, it would work just as fast. But this is not the case, as `Bytes` is only specialized for the raw `BufReader`, and not the `StdinLock`/`MutexGuard` wrapper. Performance improved significantly when I wrapped the lock in a new `BufReader`, but I was still a bit sore about the double buffer indirection.

This PR attempts to specialize it, by simply calling the already specialized implementation on `BufReader`.
2024-01-26 06:36:37 +01:00
Matthias Krüger
912877d009
Rollup merge of #119466 - Sky9x:str_from_raw_parts, r=dtolnay
Initial implementation of `str::from_raw_parts[_mut]`

ACP (accepted): rust-lang/libs-team#167
Tracking issue: #119206

Thanks to ``@Kixiron`` for previous work on this (#107207)

``@rustbot`` label +T-libs-api -T-libs
r? ``@thomcc``

Closes #107207.
2024-01-26 06:36:37 +01:00
Matthias Krüger
a37fa37281
Rollup merge of #118803 - Nadrieril:min-exhaustive-patterns, r=compiler-errors
Add the `min_exhaustive_patterns` feature gate

## Motivation

Pattern-matching on empty types is tricky around unsafe code. For that reason, current stable rust conservatively requires arms for empty types in all but the simplest case. It has long been the intention to allow omitting empty arms when it's safe to do so. The [`exhaustive_patterns`](https://github.com/rust-lang/rust/issues/51085) feature allows the omission of all empty arms, but hasn't been stabilized because that was deemed dangerous around unsafe code.

## Proposal

This feature aims to stabilize an uncontroversial subset of exhaustive_patterns. Namely: when `min_exhaustive_patterns` is enabled and the data we're matching on is guaranteed to be valid by rust's operational semantics, then we allow empty arms to be omitted. E.g.:

```rust
let x: Result<T, !> = foo();
match x { // ok
    Ok(y) => ...,
}
let Ok(y) = x; // ok
```

If the place is not guaranteed to hold valid data (namely ptr dereferences, ref dereferences (conservatively) and union field accesses), then we keep stable behavior i.e. we (usually) require arms for the empty cases.

```rust
unsafe {
    let ptr: *const Result<u32, !> = ...;
    match *ptr {
        Ok(x) => { ... }
        Err(_) => { ... } // still required
    }
}
let foo: Result<u32, &!> = ...;
match foo {
    Ok(x) => { ... }
    Err(&_) => { ... } // still required because of the dereference
}
unsafe {
    let ptr: *const ! = ...;
    match *ptr {} // already allowed on stable
}
```

Note that we conservatively consider that a valid reference can point to invalid data, hence we don't allow arms of type `&!` and similar cases to be omitted. This could eventually change depending on [opsem decisions](https://github.com/rust-lang/unsafe-code-guidelines/issues/413). Whenever opsem is undecided on a case, we conservatively keep today's stable behavior.

I proposed this behavior in the [`never_patterns`](https://github.com/rust-lang/rust/issues/118155) feature gate but it makes sense on its own and could be stabilized more quickly. The two proposals nicely complement each other.

## Unresolved Questions

Part of the question is whether this requires an RFC. I'd argue this doesn't need one since there is no design question beyond the intent to omit unreachable patterns, but I'm aware the problem can be framed in ways that require design (I'm thinking of the [original never patterns proposal](https://smallcultfollowing.com/babysteps/blog/2018/08/13/never-patterns-exhaustive-matching-and-uninhabited-types-oh-my/), which would frame this behavior as "auto-nevering" happening).

EDIT: I initially proposed a future-compatibility lint as part of this feature, I don't anymore.
2024-01-26 06:36:36 +01:00
Matthias Krüger
c0992f5ce1
Rollup merge of #107464 - WaffleLapkin:all_that_remains_of_lines, r=dtolnay
Add `str::Lines::remainder`

Based on https://github.com/rust-lang/rust/pull/98453.

This PR adds `str::Lines::remainder` similarly to [other remainder function on str split iterators](https://github.com/rust-lang/rust/issues/77998).
2024-01-26 06:36:36 +01:00
h1467792822
6e53e66bd3 MCP #705: Provide the option -Csymbol-mangling-version=hashed -Z unstable-options to shorten symbol names by replacing them with a digest.
Enrich test cases
2024-01-26 12:39:03 +08:00
bors
69db514ed9 Auto merge of #119968 - clubby789:unused-feature, r=compiler-errors
Remove unused/unnecessary features

~~The bulk of the actual code changes here is replacing try blocks with equivalent closures. I'm not entirely sure that's a good idea since it may have perf impact, happy to revert if that's the case/the change is unwanted.~~

I also removed a lot of `recursion_limit = "256"` since everything seems to build fine without that and most don't have any comment justifying it.
2024-01-26 03:18:34 +00:00
David Tolnay
f94a94227c
Export core::str::from_raw_parts{,_mut} into alloc::str and std::str 2024-01-25 18:11:54 -08:00
Yuri Astrakhan
77f31ef2b2 use checked_add for upper bound 2024-01-25 20:56:52 -05:00
Yuri Astrakhan
8cbff0b426
Update library/core/src/iter/adapters/intersperse.rs
Co-authored-by: Josh Stone <cuviper@gmail.com>
2024-01-25 20:33:06 -05:00
bors
dd2559e08e Auto merge of #116167 - RalfJung:structural-eq, r=lcnr
remove StructuralEq trait

The documentation given for the trait is outdated: *all* function pointers implement `PartialEq` and `Eq` these days. So the `StructuralEq` trait doesn't really seem to have any reason to exist any more.

One side-effect of this PR is that we allow matching on some consts that do not implement `Eq`. However, we already allowed matching on floats and consts containing floats, so this is not new, it is just allowed in more cases now. IMO it makes no sense at all to allow float matching but also sometimes require an `Eq` instance. If we want to require `Eq` we should adjust https://github.com/rust-lang/rust/pull/115893 to check for `Eq`, and rule out float matching for good.

Fixes https://github.com/rust-lang/rust/issues/115881
2024-01-26 00:17:00 +00:00
bors
0c1fb2a1e6 Auto merge of #120341 - matthiaskrgr:rollup-lvm59cj, r=matthiaskrgr
Rollup of 8 pull requests

Successful merges:

 - #118208 (Rewrite the BTreeMap cursor API using gaps)
 - #120099 (linker: Refactor library linking methods in `trait Linker`)
 - #120288 (Bump `askama` version)
 - #120306 (Clean up after clone3 removal from pidfd code (docs and tests))
 - #120316 (Don't call `walk_` functions directly if there is an equivalent `visit_` method)
 - #120330 (Remove coroutine info when building coroutine drop body)
 - #120332 (Remove unused struct)
 - #120338 (Fix links to [strict|exposed] provenance sections of `[std|core]::ptr`)

r? `@ghost`
`@rustbot` modify labels: rollup
2024-01-25 21:59:29 +00:00
bjorn3
7d3b29399d Use sess.cfg_version instead of rustc_version_str()
This makes it easier to patch cg_clif to be statically linked as part of
rustc.
2024-01-25 21:21:27 +00:00
Yuri Astrakhan
f1dbc7b35e fmt 2024-01-25 15:56:57 -05:00
Yuri Astrakhan
b8d245e749 Postpone .next() call until iteration 2024-01-25 15:56:57 -05:00
Yuri Astrakhan
f9259d1b73 Boost intersperse(_with) performance
I did some benchmark digging into the `intersperse` and `intersperse_with` code as part of the https://internals.rust-lang.org/t/add-iterate-with-separators-iterator-function/18781/13 discussion, and as a result I optimized them a bit, without relying on the peekable iterator.
2024-01-25 15:56:57 -05:00
Andrew Zhogin
27717dbd4d Builtin macros effectively have implicit #[collapse_debuginfo(yes)] attribute 2024-01-26 01:45:50 +07:00
Philipp Krones
d7a0182157
Update Cargo.lock 2024-01-25 19:17:52 +01:00
Philipp Krones
41e1231578
Merge commit '66c29b973b3b10278bd39f4e26b08522a379c2c9' into clippy-subtree-update 2024-01-25 19:17:36 +01:00
bors
66c29b973b Auto merge of #12200 - flip1995:rustup, r=flip1995
Rustup

r? `@ghost`

changelog: none
2024-01-25 18:06:39 +00:00
Philipp Krones
c08c756e12
Bump nightly version -> 2024-01-25 2024-01-25 18:39:50 +01:00
Philipp Krones
1534e08250
Merge remote-tracking branch 'upstream/master' into rustup 2024-01-25 18:39:39 +01:00
Matthias Krüger
ea27a57de9
Rollup merge of #120338 - steffahn:provenance_links, r=Nilstrieb
Fix links to [strict|exposed] provenance sections of `[std|core]::ptr`
2024-01-25 17:39:30 +01:00
Matthias Krüger
d7a9f51df7
Rollup merge of #120332 - mu001999:cleanup/dead_code, r=Nilstrieb
Remove unused struct

Detected by #118257
2024-01-25 17:39:30 +01:00
Matthias Krüger
4bca954634
Rollup merge of #120330 - compiler-errors:no-coroutine-info-in-coroutine-drop-body, r=nnethercote
Remove coroutine info when building coroutine drop body

Coroutine drop shims are not themselves coroutines, so erase the "`coroutine`" field from the body so that helper fns like `yield_ty` and `coroutine_kind` properly return `None` for the drop shim.
2024-01-25 17:39:29 +01:00
Matthias Krüger
f7d3a45bb2
Rollup merge of #120316 - GuillaumeGomez:fix-ast-visitor, r=compiler-errors
Don't call `walk_` functions directly if there is an equivalent `visit_` method

I was working on https://github.com/rust-lang/rust/issues/77773 and realized in one of my experiments that the `visit_path` method was not always called whereas it should have. This fixes it.

r? ``@davidtwco``
2024-01-25 17:39:29 +01:00
Matthias Krüger
8750bec42a
Rollup merge of #120306 - safinaskar:clone3-clean-up, r=petrochenkov
Clean up after clone3 removal from pidfd code (docs and tests)

https://github.com/rust-lang/rust/pull/113939 removed clone3 from pidfd code. This patchset does necessary clean up: fixes docs and tests
2024-01-25 17:39:28 +01:00
Matthias Krüger
eeac90cbba
Rollup merge of #120288 - clubby789:bump-askama, r=GuillaumeGomez
Bump `askama` version

Ran into this while looking at #112865 and thought it would be useful to fix it now. Some more details in [Zulip](https://rust-lang.zulipchat.com/#narrow/stream/266220-t-rustdoc/topic/Askama.20parser.20changes)
2024-01-25 17:39:27 +01:00
Matthias Krüger
87448be96f
Rollup merge of #120099 - petrochenkov:linkapi, r=WaffleLapkin
linker: Refactor library linking methods in `trait Linker`

Linkers are not aware of Rust libraries, they look like regular static or dynamic libraries to them, so Rust-specific methods in `trait Linker` do not make much sense.
They can be either removed or renamed to something more suitable.

Commits after the second one are cleanups.
2024-01-25 17:39:27 +01:00
Matthias Krüger
37f02320bc
Rollup merge of #118208 - Amanieu:btree_cursor2, r=dtolnay
Rewrite the BTreeMap cursor API using gaps

Tracking issue: #107540

Currently, a `Cursor` points to a single element in the tree, and allows moving to the next or previous element while mutating the tree. However this was found to be confusing and hard to use.

This PR completely refactors cursors to instead point to a gap between two elements in the tree. This eliminates the need for a "ghost" element that exists after the last element and before the first one. Additionally, `upper_bound` and `lower_bound` now have a much clearer meaning.

The ability to mutate keys is also factored out into a separate `CursorMutKey` type which is unsafe to create. This makes the API easier to use since it avoids duplicated versions of each method with and without key mutation.

API summary:

```rust
impl<K, V> BTreeMap<K, V> {
    fn lower_bound<Q>(&self, bound: Bound<&Q>) -> Cursor<'_, K, V>
    where
        K: Borrow<Q> + Ord,
        Q: Ord;
    fn lower_bound_mut<Q>(&mut self, bound: Bound<&Q>) -> CursorMut<'_, K, V>
    where
        K: Borrow<Q> + Ord,
        Q: Ord;
    fn upper_bound<Q>(&self, bound: Bound<&Q>) -> Cursor<'_, K, V>
    where
        K: Borrow<Q> + Ord,
        Q: Ord;
    fn upper_bound_mut<Q>(&mut self, bound: Bound<&Q>) -> CursorMut<'_, K, V>
    where
        K: Borrow<Q> + Ord,
        Q: Ord;
}

struct Cursor<'a, K: 'a, V: 'a>;

impl<'a, K, V> Cursor<'a, K, V> {
    fn next(&mut self) -> Option<(&'a K, &'a V)>;
    fn prev(&mut self) -> Option<(&'a K, &'a V)>;
    fn peek_next(&self) -> Option<(&'a K, &'a V)>;
    fn peek_prev(&self) -> Option<(&'a K, &'a V)>;
}

struct CursorMut<'a, K: 'a, V: 'a>;

impl<'a, K, V> CursorMut<'a, K, V> {
    fn next(&mut self) -> Option<(&K, &mut V)>;
    fn prev(&mut self) -> Option<(&K, &mut V)>;
    fn peek_next(&mut self) -> Option<(&K, &mut V)>;
    fn peek_prev(&mut self) -> Option<(&K, &mut V)>;

    unsafe fn insert_after_unchecked(&mut self, key: K, value: V);
    unsafe fn insert_before_unchecked(&mut self, key: K, value: V);
    fn insert_after(&mut self, key: K, value: V) -> Result<(), UnorderedKeyError>;
    fn insert_before(&mut self, key: K, value: V) -> Result<(), UnorderedKeyError>;
    fn remove_next(&mut self) -> Option<(K, V)>;
    fn remove_prev(&mut self) -> Option<(K, V)>;

    fn as_cursor(&self) -> Cursor<'_, K, V>;

    unsafe fn with_mutable_key(self) -> CursorMutKey<'a, K, V, A>;
}

struct CursorMutKey<'a, K: 'a, V: 'a>;

impl<'a, K, V> CursorMut<'a, K, V> {
    fn next(&mut self) -> Option<(&mut K, &mut V)>;
    fn prev(&mut self) -> Option<(&mut K, &mut V)>;
    fn peek_next(&mut self) -> Option<(&mut K, &mut V)>;
    fn peek_prev(&mut self) -> Option<(&mut K, &mut V)>;

    unsafe fn insert_after_unchecked(&mut self, key: K, value: V);
    unsafe fn insert_before_unchecked(&mut self, key: K, value: V);
    fn insert_after(&mut self, key: K, value: V) -> Result<(), UnorderedKeyError>;
    fn insert_before(&mut self, key: K, value: V) -> Result<(), UnorderedKeyError>;
    fn remove_next(&mut self) -> Option<(K, V)>;
    fn remove_prev(&mut self) -> Option<(K, V)>;

    fn as_cursor(&self) -> Cursor<'_, K, V>;

    unsafe fn with_mutable_key(self) -> CursorMutKey<'a, K, V, A>;
}

struct UnorderedKeyError;
```
2024-01-25 17:39:26 +01:00
bors
8a17125dd7 Auto merge of #12184 - michaelciraci:merge-deps, r=llogiq
Consolidating rustc Dependencies

changelog: none

For dependencies in rustc where there are multiple versions used, this moves the older dependency to the newer dependency. These are the updates to clippy as mentioned here: https://github.com/rust-lang/rust/pull/120177
2024-01-25 16:31:26 +00:00
Michal Nazarewicz
c4208fad3c bless 2024-01-25 16:41:17 +01:00
Nikita Popov
8866449c66 Split assembly tests for ELF and MachO
On ELF, the text section is opened with ".text", on MachO with
".section __TEXT,__text".

Previously, on ELF this test was actually matching a GNU note
section, which is no longer emitted on Solaris starting with
LLVM 18.

Fixes https://github.com/rust-lang/rust/issues/120105.
2024-01-25 16:17:35 +01:00