Commit Graph

244691 Commits

Author SHA1 Message Date
Matthias Krüger 8ec883856d
Rollup merge of #120277 - compiler-errors:normalize-before-validating, r=oli-obk
Normalize field types before checking validity

I forgot to normalize field types when checking ADT-like aggregates in the MIR validator.

This normalization is needed due to a crude check for opaque types in `mir_assign_valid_types` which prevents opaque type cycles -- if we pass in an unnormalized type, we may not detect that the destination type is an opaque, and therefore will call `type_of(opaque)` later on, which causes a cycle error -> ICE.

Fixes #120253
2024-01-26 23:15:51 +01:00
Matthias Krüger 975a82b4e2
Rollup merge of #120205 - Berrysoft:windows-alloc-init, r=ChrisDenton
std: make `HEAP` initializer never inline

The system allocator for Windows calls `init_or_get_process_heap` every time allocating. It generates very much useless code and makes the binary larger. The `HEAP` only needs to initialize once before the main fn.

Concerns:
* I'm not sure if `init` will be properly called in cdylib.
* Do we need to ensure the allocator works if the user enables `no_main`?
* Should we panic if `GetProcessHeap` returns null?
2024-01-26 23:15:50 +01:00
Matthias Krüger b31bf24908
Rollup merge of #119800 - dev-ardi:tmp, r=wesleywiser
Document `rustc_index::vec::IndexVec`

Document a few of the methods.

Part of https://github.com/rust-lang/rust/issues/93792.
2024-01-26 23:15:50 +01:00
Matthias Krüger 346397d081
Rollup merge of #119562 - LegionMammal978:rename-pin-pointer, r=Amanieu,dtolnay
Rename `pointer` field on `Pin`

A few days ago, I was helping another user create a self-referential type using `PhantomPinned`. However, I noticed an odd behavior when I tried to access one of the type's fields via `Pin`'s `Deref` impl:

```rust
use std::{marker::PhantomPinned, ptr};

struct Pinned {
    data: i32,
    pointer: *const i32,
    _pin: PhantomPinned,
}

fn main() {
    let mut b = Box::pin(Pinned {
        data: 42,
        pointer: ptr::null(),
        _pin: PhantomPinned,
    });
    {
        let pinned = unsafe { b.as_mut().get_unchecked_mut() };
        pinned.pointer = &pinned.data;
    }
    println!("{}", unsafe { *b.pointer });
}
```

```rust
error[E0658]: use of unstable library feature 'unsafe_pin_internals'
  --> <source>:19:30
   |
19 |     println!("{}", unsafe { *b.pointer });
   |                              ^^^^^^^^^

error[E0277]: `Pinned` doesn't implement `std::fmt::Display`
  --> <source>:19:20
   |
19 |     println!("{}", unsafe { *b.pointer });
   |                    ^^^^^^^^^^^^^^^^^^^^^ `Pinned` cannot be formatted with the default formatter
   |
   = help: the trait `std::fmt::Display` is not implemented for `Pinned`
   = note: in format strings you may be able to use `{:?}` (or {:#?} for pretty-print) instead
   = note: this error originates in the macro `$crate::format_args_nl` which comes from the expansion of the macro `println` (in Nightly builds, run with -Z macro-backtrace for more info)
```

Since the user named their field `pointer`, it conflicts with the `pointer` field on `Pin`, which is public but unstable since Rust 1.60.0 with #93176. On versions from 1.33.0 to 1.59.0, where the field on `Pin` is private, this program compiles and prints `42` as expected.

To avoid this confusing behavior, this PR renames `pointer` to `__pointer`, so that it's less likely to conflict with a `pointer` field on the underlying type, as accessed through the `Deref` impl. This is technically a breaking change for anyone who names their field `__pointer` on the inner type; if this is undesirable, it could be renamed to something more longwinded. It's also a nightly breaking change for any external users of `unsafe_pin_internals`.
2024-01-26 23:15:49 +01:00
Matthias Krüger 7f19365560
Rollup merge of #119342 - sjwang05:issue-112254, r=wesleywiser
Emit suggestion when trying to write exclusive ranges as `..<`

Closes #112254
2024-01-26 23:15:49 +01:00
Matthias Krüger 092ea4ba19
Rollup merge of #113489 - tguichaoua:cow_from_array, r=dtolnay
impl `From<&[T; N]>` for `Cow<[T]>`

Implement `From<&[T; N]>` for `Cow<[T]>` to simplify its usage in the following example.

```rust
fn foo(data: impl Into<Cow<'static, [&'static str]>>) { /* ... */ }

fn main() {
    foo(vec!["hello", "world"]);
    foo(&["hello", "world"]); // Error: the trait `From<&[&str; 2]>` is not implemented for `Cow<'static, [&'static str]>`
    foo(&["hello", "world"] as &[_]); // Explicit convertion into a slice is required
}
```
2024-01-26 23:15:48 +01:00
Matthias Krüger c9ab37bf4f
Rollup merge of #103522 - Dylan-DPC:76118/array-methods-stab, r=dtolnay
stabilise array methods

Closes #76118

Stabilises the remaining array methods

FCP is yet to be carried out for this

There wasn't a clear consensus on the naming, but all the other alternatives had some flaws as discussed in the tracking issue and there was a silence on this issue for a year
2024-01-26 23:15:47 +01:00
bors c073f56a41 Auto merge of #120395 - bjorn3:sync_cg_clif-2024-01-26, r=bjorn3
Subtree sync for rustc_codegen_cranelift

A couple of fixes as well as an update to Cranelift 0.104, which includes a fix for the ABI of `Option<u128>`.

r? `@ghost`

`@rustbot` label +A-codegen +A-cranelift +T-compiler
2024-01-26 22:12:35 +00:00
Thom Chiovoloni 169c72861f
Remove myself from review rotation 2024-01-26 12:31:46 -08:00
Urgau 93ff4a4f48
Fix typo
Co-authored-by: Michael Goulet <michael@errs.io>
2024-01-26 21:01:45 +01:00
Urgau 304361a10c Improve handling of numbers in IntoDiagnosticArg 2024-01-26 20:32:55 +01:00
Michael Goulet 866364cc5d Normalize field types before checking validity 2024-01-26 18:36:15 +00:00
bjorn3 37018026f0 Merge commit '3e50cf65025f96854d6597e80449b0d64ad89589' into sync_cg_clif-2024-01-26 2024-01-26 18:33:45 +00:00
bjorn3 3e50cf6502 Rustup to rustc 1.77.0-nightly (5bd5d214e 2024-01-25) 2024-01-26 18:24:04 +00:00
bjorn3 dff600d1d3 Sync from rust 5bd5d214ef 2024-01-26 18:11:31 +00:00
bjorn3 f78617994a Update rand test
This contains a fix for a recently introduced warning.
2024-01-26 18:08:00 +00:00
León Orell Valerian Liehr f941247bdd
Add fmease to the compiler review rotation 2024-01-26 18:26:36 +01:00
klensy 90254cd55f ScopeTree: remove destruction_scopes as unused
last usages removed by https://github.com/rust-lang/rust/pull/116170
2024-01-26 19:45:00 +03:00
Deadbeef e17f91dd8b Classify closure arguments in refutable pattern in argument error 2024-01-26 23:54:08 +08:00
bors e7bbe8ce93 Auto merge of #120375 - matthiaskrgr:rollup-ueakvms, r=matthiaskrgr
Rollup of 9 pull requests

Successful merges:

 - #117420 (Make `#![allow_internal_unstable(..)]` work with `stmt_expr_attributes`)
 - #117678 (Stabilize `slice_group_by`)
 - #119917 (Remove special-case handling of `vec.split_off(0)`)
 - #120117 (Update `std::io::Error::downcast` return type)
 - #120329 (RFC 3349 precursors)
 - #120339 (privacy: Refactor top-level visiting in `NamePrivacyVisitor`)
 - #120345 (Clippy subtree update)
 - #120360 (Don't fire `OPAQUE_HIDDEN_INFERRED_BOUND` on sized return of AFIT)
 - #120372 (Fix outdated comment on Box)

r? `@ghost`
`@rustbot` modify labels: rollup
2024-01-26 14:58:10 +00:00
lcnr 7b6ac8bf21 remove unnecessary test 2024-01-26 15:55:23 +01:00
lcnr e87b8c7f34 move alias-relate tests 2024-01-26 15:55:23 +01:00
lcnr a39a2f73d6 next-solver: normalize in `LoweredTy::from_raw` 2024-01-26 15:54:57 +01:00
bjorn3 604c8a7cf8 Accept [u8; N] bitmasks in simd_select_bitmask
Fixes rust-lang/rustc_codegen_cranelift#1446
2024-01-26 14:19:11 +00:00
Matthias Krüger d1c3ddee2e
Rollup merge of #120372 - bjorn3:fix_outdated_comment, r=Nilstrieb
Fix outdated comment on Box

Caught by `@vi` in https://github.com/rust-lang/rust/pull/113960#discussion_r1454278520
2024-01-26 14:43:33 +01:00
Matthias Krüger b4b483574f
Rollup merge of #120360 - compiler-errors:afit-sized-lol, r=lcnr
Don't fire `OPAQUE_HIDDEN_INFERRED_BOUND` on sized return of AFIT

Conceptually, we should probably not fire `OPAQUE_HIDDEN_INFERRED_BOUND` for methods like:

```
trait Foo { async fn bar() -> Self; }
```

Even though we technically cannot prove that `Self: Sized`, which is one of the item bounds of the `Output` type in the `-> impl Future<Output = Sized>` from the async desugaring.

This is somewhat justifiable along the same lines as how we allow regular methods to return `-> Self` even though `Self` isn't sized.

Fixes #113538

(side-note: some days i wonder if we should just remove the `OPAQUE_HIDDEN_INFERRED_BOUND` lint... it does make me sad that we have non-well-formed types in signatures, though.)
2024-01-26 14:43:32 +01:00
Matthias Krüger 37b9022cef
Rollup merge of #120345 - flip1995:clippy-subtree-update, r=Manishearth
Clippy subtree update

r? `@Manishearth`

Closes https://github.com/rust-lang/rust-clippy/issues/12148
2024-01-26 14:43:32 +01:00
Matthias Krüger c48c77e160
Rollup merge of #120339 - petrochenkov:nameprivisit, r=michaelwoerister
privacy: Refactor top-level visiting in `NamePrivacyVisitor`

Full hierarchical visiting (`nested_filter::All`) is not necessary, visiting all item-likes in isolation is enough.
Tracking current item is not necessary, passing any `HirId` with the same parent module to `adjust_ident_and_get_scope` is enough.

Follow up to https://github.com/rust-lang/rust/pull/120284.
2024-01-26 14:43:31 +01:00
Matthias Krüger 5f1f6176a5
Rollup merge of #120329 - nnethercote:3349-precursors, r=fee1-dead
RFC 3349 precursors

Some cleanups I found while working on RFC 3349 that are worth landing separately.

r? `@fee1-dead`
2024-01-26 14:43:31 +01:00
Matthias Krüger b09f2328d6
Rollup merge of #120117 - NobodyXu:99262/update-api-and-doc, r=m-ou-se
Update `std::io::Error::downcast` return type

and update its doc according to decision made by rust libs-api team in https://github.com/rust-lang/rust/issues/99262#issuecomment-1894246216
2024-01-26 14:43:30 +01:00
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
HTGAzureX1212. 2241d16189
fix 2024-01-26 20:34:13 +08:00
HTGAzureX1212. 8f89e57e9f
remove redundant call to Error::last_os_error 2024-01-26 20:27:20 +08:00
bjorn3 1f994c7695 Fix outdated comment on Box 2024-01-26 12:15:46 +00:00
HTGAzureX1212. 3269513eb0
fix issue 120040 2024-01-26 20:15:30 +08: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
bors fae15df5c6 Auto merge of #3280 - rust-lang:rustup-2024-01-26, r=RalfJung
Automatic Rustup
2024-01-26 06:59:26 +00:00
Ralf Jung 2318b0825c alidate the operand passed to is_val_statically_known 2024-01-26 07:56:36 +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