Commit Graph

246645 Commits

Author SHA1 Message Date
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
klensy
f6fa03bfae compiletest: fix regex rebuilds 2024-02-17 12:40:26 +03:00
klensy
12f9de7d0e tidy: wrap regexes with lazy_static
yes, once_cell better, but ...

this reduces from

==31349== Total:     1,365,199,543 bytes in 4,774,213 blocks
==31349== At t-gmax: 10,975,708 bytes in 66,093 blocks
==31349== At t-end:  2,880,947 bytes in 12,332 blocks
==31349== Reads:     5,210,008,956 bytes
==31349== Writes:    1,280,920,127 bytes

to

==47796== Total:     821,467,407 bytes in 3,955,595 blocks
==47796== At t-gmax: 10,976,209 bytes in 66,100 blocks
==47796== At t-end:  2,944,016 bytes in 12,490 blocks
==47796== Reads:     4,788,959,023 bytes
==47796== Writes:    975,493,639 bytes

miropt-test-tools: remove regex usage

this removes regex usage and slightly refactors ext stripping in one case
2024-02-17 12:29:05 +03:00
Ralf Jung
340f8aac7e const_mut_refs: allow mutable refs to statics 2024-02-17 10:19:17 +01:00
hi-rustin
6f1383cf5b Remove unnecessary unit binding
Signed-off-by: hi-rustin <rustin.liu@gmail.com>
2024-02-17 16:20:09 +08: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
León Orell Valerian Liehr
fde4556785
Properly check constrainedness of gen params in the presence of weak alias types 2024-02-17 08:39:01 +01:00
León Orell Valerian Liehr
8677d64c72
Support weak alias types as self type of inherent impls 2024-02-17 08:38:59 +01:00
León Orell Valerian Liehr
38a2a65f0b
Remove astconv::ConvertedBinding 2024-02-17 08:20:05 +01:00
León Orell Valerian Liehr
f62a695572
Update comments and variable names 2024-02-17 08:19:23 +01: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
Shoyu Vanilla
f5d43a052b Fix missing trait impls for type in rustc docs 2024-02-17 14:27:05 +09: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
lcnr
54b3c8759a yeet GeneralizerDelegate 2024-02-17 02:56:08 +01:00
lcnr
5c540044d6 use instantiate_ty_var in nll
we already use `instantiate_const_var`. This does lose some debugging
info for nll because we stop populating the `reg_var_to_origin` table with
`RegionCtxt::Existential(None)`, I don't think that matters however.
Supporting this adds additional complexity to one of the most involved
parts of the type system, so I really don't think it's worth it.
2024-02-17 02:32:19 +01:00
lcnr
88a559fa9f move ty var instantiation into the generalize module 2024-02-17 01:42:36 +01: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
Mads Marquart
d80198595c Fix comment 2024-02-17 01:17:43 +01:00
Mads Marquart
dae22a598b Fix cfg(target_abi = "sim") on i386-apple-ios
i386-apple-ios is also a simulator target
2024-02-17 01:15:08 +01:00
Josh Stone
c36ae932f9 Clarify the flatten specialization comment 2024-02-16 16:08:01 -08: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
lcnr
f65e743748 add fixme 2024-02-17 00:26:57 +01:00
lcnr
42e7338eae rename needs_wf and clarify comment 2024-02-17 00:25:49 +01:00
Nicholas Nethercote
e72e7e9ae3 Merge CompilerError::CompilationFailed and CompilerError::ICE.
`CompilerError` has `CompilationFailed` and `ICE` variants, which seems
reasonable at first. But the way it identifies them is flawed:
- If compilation errors out, i.e. `RunCompiler::run` returns an `Err`,
  it uses `CompilationFailed`, which is reasonable.
- If compilation panics with `FatalError`, it catches the panic and uses
  `ICE`. This is sometimes right, because ICEs do cause `FatalError`
  panics, but sometimes wrong, because certain compiler errors also
  cause `FatalError` panics. (The compiler/rustdoc/clippy/whatever just
  catches the `FatalError` with `catch_with_exit_code` in `main`.)

In other words, certain non-ICE compilation failures get miscategorized
as ICEs. It's not possible to reliably distinguish the two cases, so
this commit merges them. It also renames the combined variant as just
`Failed`, to better match the existing `Interrupted` and `Skipped`
variants.

Here is an example of a non-ICE failure that causes a `FatalError`
panic, from `tests/ui/recursion_limit/issue-105700.rs`:
```
 #![recursion_limit="4"]
 #![invalid_attribute]
 #![invalid_attribute]
 #![invalid_attribute]
 #![invalid_attribute]
 #![invalid_attribute]
 //~^ERROR recursion limit reached while expanding

 fn main() {{}}
```
2024-02-17 09:40:44 +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
Josh Stone
974bc455ee Specialize flattening iterators with only one inner item
For iterators like `Once` and `option::IntoIter` that only ever have a
single item at most, the front and back iterator states in `FlatMap` and
`Flatten` are a waste, as they're always consumed already. We can use
specialization for these types to simplify the iterator methods.

It's a somewhat common pattern to use `flatten()` for options and
results, even recommended by [multiple][1] [clippy][2] [lints][3]. The
implementation is more efficient with `filter_map`, as mentioned in
[clippy#9377], but this new specialization should close some of that
gap for existing code that flattens.

[1]: https://rust-lang.github.io/rust-clippy/master/#filter_map_identity
[2]: https://rust-lang.github.io/rust-clippy/master/#option_filter_map
[3]: https://rust-lang.github.io/rust-clippy/master/#result_filter_map
[clippy#9377]: https://github.com/rust-lang/rust-clippy/issues/9377
2024-02-16 13:49:29 -08: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
León Orell Valerian Liehr
5fbb1b2f4d
rustdoc: fix and refactor HTML rendering a bit 2024-02-16 21:29:16 +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
bors
ac998a74b3 Auto merge of #16579 - DropDemBits:structured-snippet-fix-with-escaped-bits-and-cr, r=Veykril
fix: Fix snippets being placed leftwards of where they should be

Snippet bits were being escaped before placing snippets, shifting snippets leftwards. Snippets were also being shifted leftwards on files with CRLF line endings since they were placed done after the Unix -> DOS line ending conversion.

Hoping this fixes all of the little bugs related to snippet rendering 😅
2024-02-16 18:45:43 +00:00
Tshepang Mbambo
3a917cdfcb make "invalid fragment specifier" translatable 2024-02-16 20:15:07 +02: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