Commit graph

246326 commits

Author SHA1 Message Date
Matthias Krüger a387b71b0c
Rollup merge of #121209 - nnethercote:infallible-join_codegen, r=bjorn3
Make `CodegenBackend::join_codegen` infallible.

Because they all are, in practice.

r? ```@bjorn3```
2024-02-17 18:47:42 +01:00
Matthias Krüger df3712ce21
Rollup merge of #121193 - compiler-errors:coherence-fulfillment, r=lcnr
Use fulfillment in next trait solver coherence

Use fulfillment in the new trait solver's `impl_intersection_has_impossible_obligation` routine. This means that inference that falls out of processing other obligations can influence whether we can determine if an obligation is impossible to satisfy. See the committed test.

This should be completely sound, since evaluation and fulfillment both respect intercrate mode equally.

We run the risk of breaking coherence later if we were to change the rules of fulfillment and/or inference during coherence, but this is a problem which affects evaluation, as nested obligations from a trait goal are processed together and can influence each other in the same way.

r? lcnr
cc #114862

Also changed obligationctxt -> fulfillmentctxt because it feels kind of redundant to use an ocx here. I don't really care enough and can change it back if it really matters much.
2024-02-17 18:47:42 +01:00
Matthias Krüger cb371797d6
Rollup merge of #121149 - SebastianJL:patch-1, r=Mark-Simulacrum
Fix typo in VecDeque::handle_capacity_increase() doc comment.

Strategies B and C both show a full buffer before the capacity increase, while strategy A had one empty element left. Filled the last element in.
2024-02-17 18:47:41 +01:00
Matthias Krüger 60cc6b93f6
Rollup merge of #121091 - onur-ozkan:bypass-stage0-download-in-tests, r=albertlarsan68
use build.rustc config and skip-stage0-validation flag

This change helps us to bypass downloading the beta compiler in bootstrap tests.

more context: https://rust-lang.zulipchat.com/#narrow/stream/326414-t-infra.2Fbootstrap/topic/tests.20causing.20downloads.20of.20native.20rustc.20for.20other.20platforms/near/421467975
2024-02-17 18:47:41 +01:00
Matthias Krüger 45d5773704
Rollup merge of #121085 - davidtwco:always-eager-diagnostics, r=nnethercote
errors: only eagerly translate subdiagnostics

Subdiagnostics don't need to be lazily translated, they can always be eagerly translated. Eager translation is slightly more complex as we need to have a `DiagCtxt` available to perform the translation, which involves slightly more threading of that context.

This slight increase in complexity should enable later simplifications - like passing `DiagCtxt` into `AddToDiagnostic` and moving Fluent messages into the diagnostic structs rather than having them in separate files (working on that was what led to this change).

r? ```@nnethercote```
2024-02-17 18:47:40 +01:00
Matthias Krüger 59972868e6
Rollup merge of #120952 - saethlin:vec-into-iter, r=the8472
Don't use mem::zeroed in vec::IntoIter

`mem::zeroed` is not a trivial function. Maybe it was once, but now it involves multiple locals, copies, and an intrinsic that gets monomorphized into a call to `panic_nounwind` for iterators of types like `Vec<&T>`. Of course all that complexity is trivially optimized out, but generating a bunch of IR where we don't need to just so we can optimize it away later is silly.
2024-02-17 18:47:40 +01:00
bors eeeb021954 Auto merge of #121232 - RalfJung:miri, r=RalfJung
Miri subtree update

r? `@ghost`
2024-02-17 13:41:14 +00:00
Ralf Jung fd5a84b529 update lockfile 2024-02-17 13:02:04 +01:00
bors ba824a2e25 Auto merge of #121227 - Nadrieril:rollup-n6qky3z, r=Nadrieril
Rollup of 8 pull requests

Successful merges:

 - #119032 (Use a hardcoded constant instead of calling OpenProcessToken.)
 - #120932 (const_mut_refs: allow mutable pointers to statics)
 - #121059 (Add and use a simple extension trait derive macro in the compiler)
 - #121135 (coverage: Discard spans that fill the entire function body)
 - #121187 (Add examples to document the return type of quickselect functions)
 - #121191 (Add myself to review rotation (and a rustbot ping))
 - #121192 (Give some intrinsics fallback bodies)
 - #121197 (Ensure `./configure` works when `configure.py` path contains spaces)

r? `@ghost`
`@rustbot` modify labels: rollup
2024-02-17 11:44:02 +00:00
Guillaume Boisseau e266a12307
Rollup merge of #121197 - beetrees:configure-quotes, r=Nilstrieb
Ensure `./configure` works when `configure.py` path contains spaces

Add quotes around paths that may contains spaces in `configure` to avoid the shell splitting the path into multiple arguments.
2024-02-17 11:23:09 +01:00
Guillaume Boisseau 936b666c4a
Rollup merge of #121192 - oli-obk:intrinsics2.0, r=WaffleLapkin
Give some intrinsics fallback bodies

cc #93145
2024-02-17 11:23:08 +01:00
Guillaume Boisseau ac619c05da
Rollup merge of #121191 - Nadrieril:ping, r=compiler-errors
Add myself to review rotation (and a rustbot ping)

I've still got a ~month of unemployment ( 🤞 ), so I'll put some of that time into reviewing.

Unrelatedly, I've now poked enough at match lowering that I want to follow what happens to it, so I added a rustbot ping.
2024-02-17 11:23:08 +01:00
Guillaume Boisseau f3d9abc590
Rollup merge of #121187 - Takashiidobe:takashi/examples-for-quickselect, r=Nilstrieb
Add examples to document the return type of quickselect functions

Currently, `select_nth_unstable`, `select_nth_unstable_by`, and `select_nth_unstable_by_key`'s examples do not show how to use the return values of the functions in an example, so this PR adds that in.

Note: I didn't know what to call the parameters, so I settled on lesser, median, greater because the example is used for median finding so I retained that naming for the pivot, but lesser and greater are poor names for the example that sorts in descending order, because lesser and greater are then flipped.

I think it's common to say "lo" and "hi" for low and high respectively, but that's also not great when the comparator flips the elements. Otherwise, "left" and "right" are also commonly used but I think that's poor naming because some languages read right to left so those names are also unintuitive.

Lesser and greater are also not that great but I found a test that used `less`, `equal`, `greater` so I took that: dfa88b328f/library/core/tests/slice.rs (L1962)
2024-02-17 11:23:07 +01:00
Guillaume Boisseau c7701ba803
Rollup merge of #121135 - Zalathar:no-whole-body-span, r=wesleywiser
coverage: Discard spans that fill the entire function body

While debugging some other coverage changes, I discovered a frustrating inconsistency that occurs in functions containing closures, if they end with an implicit `()` return instead of an explicit trailing-expression.

This turns out to have been caused by the corresponding node in MIR having a span that covers the entire function body. When preparing coverage spans, any span that fills the whole body tends to cause more harm than good, so this PR detects and discards those spans.

(This isn't the first time whole-body spans have caused problems; we also eliminated some of them in #118525.)
2024-02-17 11:23:04 +01:00
Guillaume Boisseau 5ff9022306
Rollup merge of #121059 - compiler-errors:extension, r=davidtwco,Nilstrieb
Add and use a simple extension trait derive macro in the compiler

Adds `#[extension]` to `rustc_macros` for implementing an extension trait. This expands an impl (with an optional visibility) into two parallel trait + impl definitions.

before:
```rust
pub trait Extension {
  fn a();
}
impl Extension for () {
  fn a() {}
}
```

to:
```rust
#[extension]
pub impl Extension for () {
  fn a() {}
}
```

Opted to just implement it by hand because I couldn't figure if there was a "canonical" choice of extension trait macro in the ecosystem. It's really lightweight anyways, and can always be changed.

I'm interested in adding this because I'd like to later split up the large `TypeErrCtxtExt` traits into several different files. This should make it one step easier.
2024-02-17 11:23:04 +01:00
Guillaume Boisseau f70f13a1d3
Rollup merge of #120932 - RalfJung:mut-ptr-to-static, r=oli-obk
const_mut_refs: allow mutable pointers to statics

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

Writing this PR became a bit messy, see [Zulip](https://rust-lang.zulipchat.com/#narrow/stream/146212-t-compiler.2Fconst-eval/topic/Statics.20pointing.20to.20interior.20mutable.20statics) for some of my journey.^^ Turns out there was a long-standing bug in our qualif logic that led to us incorrectly classifying certain places as "no interior mut" when they actually had interior mut. Due to that the `const_refs_to_cell` feature gate was required far less often than it otherwise would, e.g. in [this code](https://play.rust-lang.org/?version=nightly&mode=debug&edition=2021&gist=9e0c042c451b3d11d64dd6263679a164). Fixing this however would be a massive breaking change all over libcore and likely the wider ecosystem. So I also changed the const-checking logic to just not require the feature gate for the affected cases. While doing so I discovered a bunch of logic that is not explained and that I could not explain. However I think stabilizing some const-eval feature will make most of that logic inconsequential so I just added some FIXMEs and left it at that.

r? `@oli-obk`
2024-02-17 11:23:03 +01:00
Guillaume Boisseau 5f21609463
Rollup merge of #119032 - smmalis37:patch-1, r=ChrisDenton
Use a hardcoded constant instead of calling OpenProcessToken.

Now that Win 7 support is dropped, we can resurrect #90144.

GetCurrentProcessToken is defined in processthreadsapi.h as:

FORCEINLINE
HANDLE
GetCurrentProcessToken (
    VOID
    )
{
    return (HANDLE)(LONG_PTR) -4;
}

Since it's very unlikely that this constant will ever change, let's just use it instead of making calls to get the same information.
2024-02-17 11:23:03 +01:00
Ralf Jung 340f8aac7e const_mut_refs: allow mutable refs to statics 2024-02-17 10:19:17 +01:00
bors dfdbe30004 Auto merge of #119432 - gurry:117949-make-lint-run-on-promoteds, r=oli-obk
Make `ConstPropLint` lint run on promoteds

Fixes #117949 wherein the lint didn't fire for the following promoteds:

- SHL or SHR operators in a non-optimized build
- any arithmetic operator in an optimized build

What I have done here is simply enabled `ConstPropLint` to run on promoted bodies by removing the relevant `if` check.

After this change _all_ promoted arithmetic operators will lint _in both non-optimized and optimized builds_. On the flip side programs containing the above mentioned overflowing promoteds that were accepted earlier will now be rejected. Hope that is okay from a backward compatibility standpoint.

I have added tests covering all overflowing promoted & non-promoted ops for both compile-time and runtime operations and for optimized as well as non-optimized builds.

I had to amend some existing tests to make them pass and had to delete a couple that were set to pass despite overflows.

This PR increases the number of duplicate diagnostics emitted (because the same operator might get linted in both the promoted MIR and the main MIR). I hope that is an acceptable trade-off given that we now lint overflows much more comprehensively than earlier.
2024-02-17 07:46:36 +00:00
bors bbfce9196f Auto merge of #3303 - rust-lang:rustup-2024-02-17, r=saethlin
Automatic Rustup
2024-02-17 05:44:08 +00:00
The Miri Conjob Bot d523cab910 Merge from rustc 2024-02-17 05:17:43 +00:00
Gurinder Singh 5010ca001c Enable ConstPropLint for promoteds
This fixes the issue wherein the lint didn't fire for promoteds
in the case of SHL/SHR operators in non-optimized builds
and all arithmetic operators in optimized builds
2024-02-17 10:44:46 +05:30
The Miri Conjob Bot 63240d758b Preparing for merge from rustc 2024-02-17 05:10:27 +00:00
bors 4316d0c625 Auto merge of #120563 - reitermarkus:generic-nonzero-get, r=dtolnay
Make `NonZero::get` generic.

Tracking issue: https://github.com/rust-lang/rust/issues/120257

Depends on https://github.com/rust-lang/rust/pull/120521.

r? `@dtolnay`
2024-02-17 02:30:53 +00:00
bors 405b22f1a3 Auto merge of #120741 - a1phyr:safe_buffer_advance, r=m-ou-se
Make `io::BorrowedCursor::advance` safe

This also keeps the old `advance` method under `advance_unchecked` name.

This makes pattern like `std::io::default_read_buf` safe to write.
2024-02-17 00:23:15 +00:00
Steven 3b63edeb99 Remove cfg_attr 2024-02-16 23:55:58 +00:00
Michael Goulet 228441dbd6 Use fulfillment in next trait solver coherence 2024-02-16 23:53:09 +00:00
Steven 40719384e1 Use a hardcoded constant instead of calling OpenProcessToken.
Now that Win 7 support is dropped, we can resurrect #90144.

GetCurrentProcessToken is defined in processthreadsapi.h as:

FORCEINLINE
HANDLE
GetCurrentProcessToken (
    VOID
    )
{
    return (HANDLE)(LONG_PTR) -4;
}

Since it's very unlikely that this constant will ever change, let's just use it instead of making calls to get the same information.
2024-02-16 23:52:33 +00:00
Nicholas Nethercote ede99234c4 Make CodegenBackend::join_codegen infallible.
Because they all are, in practice.
2024-02-17 10:51:35 +11:00
Oli Scherer dd40a80102 Give the (un)likely intrinsics fallback bodies 2024-02-16 22:26:01 +00:00
Oli Scherer 6a671bdbf1 Give the assume intrinsic a fallback body 2024-02-16 22:24:50 +00:00
bors bccb9bbb41 Auto merge of #120881 - jieyouxu:migrate-ui-test-directives, r=oli-obk
Migrate ui tests from legacy compiletest-style directives `//` to `ui_test`-style directives `//@`

## Preface

There's an on-going effort to rewrite parts of or the entirety of compiletest
(<https://github.com/rust-lang/compiler-team/issues/536>). A step towards this involve migrating
ui tests to use the [`ui_test`](https://github.com/oli-obk/ui_test) framework, which involves
changing compiletest directives in `// <directive-name>` style to `ui_test` `//@ <directive-name>`
style (https://github.com/rust-lang/compiler-team/issues/512).

This PR aims to implement the directive-style change from `//` to `//`@`` for ui tests only and
make compiletest only accept `//`@`` directives in the "ui" test suite (only).

## Key Changes

1. All ui test `//` directives are replaced by `//`@`` directives.
2. Only accept `//`@`` directives for "ui" test suite.
3. Errors if a comment could be interpreted as a legacy-style `//` directive.

## Diff Generation

The diff is generated by:

- Collecting directives from ui tests via hacking on compiletest.
- Using a migration tool to replace `//` directives in ui tests with `//`@`.`

### Reproduction Steps

0. Delete the temporary directory `$RUSTC_REPO_PATH/build/x86_64-apple-darwin/test/ui/__directive_lines` and the temporary file `$RUSTC_REPO_PATH/build/x86_64-apple-darwin/test/ui/__directive_lines.txt` (if you ran the collection script before).
1. Use the <https://github.com/jieyouxu/rust/tree/collect-test-directives> collect-test-directives
   script, which outputs temporary files recording headers occuring in each ui test.
   - You need to checkout this branch: `git checkout collect-test-directives`.
   - You might need to rebase on lastest master and ensure there are no conflicts.
   - You likely need to run `./x test tests/ui --stage 1 --force-rerun` to generate the temporary
     files consistently.
2. Checkout the `migrate-ui-test-directives` branch.
4. Run the migration tool <https://github.com/jieyouxu/compiletest-ui_test-header-migration>.
    - You will need to first generate a `migration_config.toml` via `cargo run -- generate-config` under `$CWD`.
    - Then, update `manual_directives = ["// should-fail"]` in `migration_config.toml`. This is required because the collection script doesn't deal with some special meta ui tests and there are no other `// should-fail` occurrences.
5. Check that the migration at least does not cause UI test failures if you change compiletest to
   accept `//`@`` directives for ui tests only.
   - `RUSTC_TEST_FAIL_FAST=1 ./x test tests/ui --stage 1 --bless`
6. Confirm that there is no difference after running the migration tool when you are on the
   `migrate-ui-test-directives` branch.

## Next Steps

- [x] ~~Need to implement some kind of warning or tidy script to help contributors catch old-style
  `// <directive-name>` directives, while only accepting `ui_test`-style `//@ <directive-name>`
  directives.~~ An error is emitted if a comment that could be interpreted as legacy-style test directive is encountered.
- [ ] Need to properly document this change in e.g. rustc-dev-guide (https://github.com/rust-lang/rustc-dev-guide/pull/1885).
    - [x] Add a `README.md` to `tests/ui` describing the directive style change.
2024-02-16 21:00:48 +00:00
bors d2a4ef39ca Auto merge of #3192 - eduardosm:x86-avx-intrinsics, r=RalfJung
Implement x86 AVX intrinsics

~Blocked on <https://github.com/rust-lang/miri/pull/3214>~
2024-02-16 20:53:50 +00:00
Eduardo Sánchez Muñoz 524c16d387 Implement x86 AVX intrinsics 2024-02-16 21:46:45 +01:00
许杰友 Jieyou Xu (Joe) ec2cc761bc
[AUTO-GENERATED] Migrate ui tests from // to //@ directives 2024-02-16 20:02:50 +00:00
许杰友 Jieyou Xu (Joe) e53d6dd35b
Implement infra support for migrating from // to //@ ui test directives 2024-02-16 19:40:23 +00:00
bors 93a65c69ce Auto merge of #120348 - bjorn3:per_target_backend_selection, r=albertlarsan68
Support configuring the set of codegen backends to build per host triple

This allows building the compiler itself with one backend while using another backend at runtime. For example this allows compiling rustc to wasm using LLVM, while using Cranelift at runtime to produce actual code. Cranelift can't compile to wasm, but is perfectly capable of running on wasm. LLVM can compile to wasm, but can't run on wasm. [^1]

[^1]: The prototype of this still requires a couple of other patches.
2024-02-16 19:01:25 +00:00
beetrees d855ca044d
Ensure ./configure works when configure.py path contains spaces 2024-02-16 18:57:22 +00:00
Nadrieril 6c7827c03e Add myself to review rotation 2024-02-16 18:31:13 +01:00
Nadrieril 4b732c990d Let rustbot ping me on changes to match lowering 2024-02-16 18:26:34 +01:00
bors d2e8ecd8bd Auto merge of #121188 - GuillaumeGomez:rollup-bejz7fq, r=GuillaumeGomez
Rollup of 6 pull requests

Successful merges:

 - #119928 (suggest `into_iter()` when `Iterator` method called on `impl IntoIterator`)
 - #121020 (Avoid an ICE in diagnostics)
 - #121111 (For E0038, suggest associated type if available)
 - #121137 (Add clippy into the known `cfg` list)
 - #121179 (allow mutable references in const values when they point to no memory)
 - #121181 (Fix an ICE in the recursion lint)

r? `@ghost`
`@rustbot` modify labels: rollup
2024-02-16 16:40:45 +00:00
Guillaume Gomez f82875e242
Rollup merge of #121181 - oli-obk:normalize_with_conflicting_impls, r=cjgillot
Fix an ICE in the recursion lint

fixes #121170

I looked into it, and there is no good path towards tainting mir_build (where the ICE happens), but using `try_normalize` in a lint seems generally better anyway
2024-02-16 17:08:14 +01:00
Guillaume Gomez 0c92146034
Rollup merge of #121179 - RalfJung:zst-mutable-refs, r=oli-obk
allow mutable references in const values when they point to no memory

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

The second commit is just some drive-by test suite cleanup.

r? `@oli-obk`
2024-02-16 17:08:13 +01:00
Guillaume Gomez f60576b3df
Rollup merge of #121137 - GuillaumeGomez:add-clippy-cfg, r=Urgau,Nilstrieb
Add clippy into the known `cfg` list

In clippy, we are removing the `feature = "cargo-clippy"` cfg to replace it with `clippy` in https://github.com/rust-lang/rust-clippy/pull/12292. But for it to work, we need to declare `clippy` as cfg. It makes it more coherent with other existing tools like rustdoc.

cc `@flip1995`
2024-02-16 17:08:13 +01:00
Guillaume Gomez 670bdbf808
Rollup merge of #121111 - trevyn:associated-type-suggestion, r=davidtwco
For E0038, suggest associated type if available

Closes #116434
2024-02-16 17:08:12 +01:00
Guillaume Gomez e5a743c4c2
Rollup merge of #121020 - oli-obk:diagnostics_ice, r=davidtwco
Avoid an ICE in diagnostics

fixes #121004

just a slice usage in diagnostics code. Sadly we can't yet bubble the `ErrorGuaranteed` from wf check to borrowck for these cases, as that causes cycle errors iirc
2024-02-16 17:08:12 +01:00
Guillaume Gomez f81fd901db
Rollup merge of #119928 - d-sonuga:into-iter-sugg, r=compiler-errors
suggest `into_iter()` when `Iterator` method called on `impl IntoIterator`

Fix for issue #117711.
2024-02-16 17:08:11 +01:00
Ben Kimock 7c2db703b0 Don't use mem::zeroed in vec::IntoIter 2024-02-16 10:44:39 -05:00
Michael Goulet f624d55ea7 Nits 2024-02-16 15:07:37 +00:00
Michael Goulet a9dbf63087 Move trait into attr so it's greppable 2024-02-16 15:07:37 +00:00