Commit Graph

12862 Commits

Author SHA1 Message Date
Matthias Krüger 5c3370d684
Rollup merge of #129837 - aDotInTheVoid:test-better-json, r=jieyouxu
Actually parse stdout json, instead of using hacky contains logic.

Fixes up the test added in #128963, to actually parse the stdout to JSON, instead of just checking that it contains `{"`.

CC ``@GuillaumeGomez``

r? ``@jieyouxu``
2024-09-02 04:19:30 +02:00
Matthias Krüger e0039171ff
Rollup merge of #129678 - compiler-errors:type-ir-inherent, r=fmease
Deny imports of `rustc_type_ir::inherent` outside of type ir + new trait solver

We shouldn't encourage using `rustc_type_ir::inherent` outside of the new solver[^1], though this can happen by accident due to rust-analyzer, for example. See https://github.com/rust-lang/rust/pull/127537#discussion_r1733813842 for an example in practice.

r? fmease

[^1]: Unless we go the fully radical approach of always using these inherent methods everywhere in favor of inherent methods, which would be a major overhaul of the compiler, IMO. I don't really want to consider that possibility right now, tho.
2024-09-02 04:19:28 +02:00
Matthias Krüger c90991db17
Rollup merge of #127474 - tesuji:foldable-inline-derefs, r=t-rustdoc
doc: Make block of inline Deref methods foldable

After:
![image](https://github.com/rust-lang/rust/assets/15225902/3e8ab320-dbf7-436f-9be0-d0ef82664663)
Before:
![image](https://github.com/rust-lang/rust/assets/15225902/f6f7635d-d4c3-437e-a2d9-147726287b05)

Fix  #127470.

Current status:
- [x] Bug when hovering over title "Methods from ...": The anchor sign $ overlaps with `[-]`: https://github.com/rust-lang/rust/pull/127474#issuecomment-2222930038
    => Fixed by https://github.com/rust-lang/rust/pull/127474#issuecomment-2228886292
2024-09-02 04:19:27 +02:00
bors 94885bc699 Auto merge of #129854 - Kobzol:revert-127537, r=lqd
Revert "Auto merge of #127537 - veluca93:struct_tf, r=BoxyUwU"

This reverts https://github.com/rust-lang/rust/pull/127537 (commit acb4e8b625), reversing changes made to 100fde5246.

Opening to see if this can help resolve the recent perf. results [instability](https://rust-lang.zulipchat.com/#narrow/stream/247081-t-compiler.2Fperformance/topic/Weird.20perf.20results).
2024-09-01 19:46:46 +00:00
Michael Goulet 91854453f2 Deny imports of rustc_type_ir::inherent outside of type ir + new trait solver 2024-09-01 12:16:18 -04:00
bors a48861a627 Auto merge of #127313 - cjgillot:single-expect, r=jieyouxu
Rewrite lint_expectations in a single pass.

This PR aims at reducing the perf regression from https://github.com/rust-lang/rust/pull/120924#issuecomment-2202486203 with drive-by simplifications.

Basically, instead of using the lint level builder, which is slow, this PR splits `lint_expectations` logic in 2:
- listing the `LintExpectations` is done in `shallow_lint_levels_on`, on a per-owner basis;
- building the unstable->stable expectation id map is done by iterating on attributes.

r? ghost for perf
2024-09-01 15:50:48 +00:00
Jakub Beránek 47e6b5deed Revert "Auto merge of #127537 - veluca93:struct_tf, r=BoxyUwU"
This reverts commit acb4e8b625, reversing
changes made to 100fde5246.
2024-09-01 16:35:53 +02:00
bors 1a1cc050d8 Auto merge of #127897 - nyurik:add-qnx-70-target, r=saethlin
add `aarch64_unknown_nto_qnx700` target - QNX 7.0 support for aarch64le

This backports the QNX 7.1 aarch64 implementation to 7.0.

* [x] required `-lregex` disabled, see https://github.com/rust-lang/libc/pull/3775 (released in libc 0.2.156)
* [x] uses `libgcc.a` instead of `libgcc_s.so` (7.0 used ancient GCC 5.4 which didn't have gcc_s)
* [x] a fix in `backtrace` crate to support stack traces https://github.com/rust-lang/backtrace-rs/pull/648

This PR bumps libc dependency to 0.2.158

CC: to the folks who did the [initial implementation](https://doc.rust-lang.org/rustc/platform-support/nto-qnx.html): `@flba-eb,` `@gh-tr,` `@jonathanpallant,` `@japaric`

# Compile target

```bash
# Configure qcc build environment
source _path_/_to_/qnx7.0/qnxsdp-env.sh

# Tell rust to use qcc when building QNX 7.0 targets
export build_env='
    CC_aarch64-unknown-nto-qnx700=qcc
    CFLAGS_aarch64-unknown-nto-qnx700=-Vgcc_ntoaarch64le_cxx
    CXX_aarch64-unknown-nto-qnx700=qcc
    AR_aarch64_unknown_nto_qnx700=ntoaarch64-ar'

# Build rust compiler, libs, and the remote test server
env $build_env ./x.py build \
  --target x86_64-unknown-linux-gnu,aarch64-unknown-nto-qnx700 \
  rustc library/core library/alloc library/std src/tools/remote-test-server

rustup toolchain link stage1 build/host/stage1
```

# Compile "hello world"

```bash
source _path_/_to_/qnx7.0/qnxsdp-env.sh

cargo new hello_world
cd hello_world
cargo +stage1 build --release --target aarch64-unknown-nto-qnx700
```

# Configure a remote for testing

Do this from a new shell - we will need to run more commands in the previous one.  I ran into these two issues, and found some workarounds.

* Temporary dir might not work properly
* Default `remote-test-server` has issues binding to an address

```
# ./remote-test-server
starting test server
thread 'main' panicked at src/tools/remote-test-server/src/main.rs:175:29:
called `Result::unwrap()` on an `Err` value: Os { code: 249, kind: AddrNotAvailable, message: "Can't assign requested address" }
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
```

Specifying `--bind` param actually fixes that, and so does setting `TMPDIR` properly.

```bash
# Copy remote-test-server to remote device. You may need to use sftp instead.
# ATTENTION: Note that the path is different from the one in the remote testing documentation for some reason
scp ./build/x86_64-unknown-linux-gnu/stage1-tools-bin/remote-test-server  qnxdevice:/path/

# Run ssh with port forwarding - so that rust tester can connect to the local port instead
ssh -L 12345:127.0.0.1:12345 qnxdevice

# on the device, run
rm -rf tmp && mkdir -p tmp && TMPDIR=$PWD/tmp ./remote-test-server --bind 0.0.0.0:12345
```

# Run test suit

Assume all previous environment variables are still set, or re-init them

```bash
export TEST_DEVICE_ADDR="localhost:12345"

# tidy needs to be skipped due to using un-published libc dependency
export exclude_tests='
    --exclude src/bootstrap
    --exclude src/tools/error_index_generator
    --exclude src/tools/linkchecker
    --exclude src/tools/tidy
    --exclude tests/ui-fulldeps
    --exclude rustc
    --exclude rustdoc
    --exclude tests/run-make-fulldeps'

env $build_env ./x.py test  $exclude_tests --stage 1 --target aarch64-unknown-nto-qnx700
```

try-job: dist-x86_64-msvc
2024-09-01 08:00:25 +00:00
Matthias Krüger f040e689c0
Rollup merge of #129780 - cyrgani:master, r=compiler-errors
add crashtests for several old unfixed ICEs

Adds several new crashtests for some older ICEs that did not yet have any.
Tests were added for #128097, #119095, #117460 and #126443.
2024-09-01 03:58:05 +02:00
Matthias Krüger d24336b8c9
Rollup merge of #129672 - saethlin:enum-debuginfo-tests, r=Mark-Simulacrum
Make option-like-enum.rs UB-free and portable

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

(or, at least the parts of it that aren't https://github.com/rust-lang/rust/issues/128973)
2024-09-01 03:58:05 +02:00
Matthias Krüger 07d5c250be
Rollup merge of #129493 - cjgillot:early-opaque-def, r=petrochenkov
Create opaque definitions in resolver.

Implementing https://github.com/rust-lang/rust/issues/129023#issuecomment-2306079532

That was easier than I expected.

r? `@petrochenkov`
2024-09-01 03:58:04 +02:00
Matthias Krüger 1063c0dd37
Rollup merge of #129207 - GrigorenkoPV:elided-is-named, r=cjgillot
Lint that warns when an elided lifetime ends up being a named lifetime

As suggested in https://github.com/rust-lang/rust/issues/48686#issuecomment-1817334575

Fixes #48686
2024-09-01 03:58:03 +02:00
Alona Enraght-Moony f78979e687 Actually parse stdout json, instead of using hacky contains logic. 2024-08-31 22:08:38 +00:00
bors a7399ba69d Auto merge of #129831 - matthiaskrgr:rollup-befq6zx, r=matthiaskrgr
Rollup of 11 pull requests

Successful merges:

 - #128523 (Add release notes for 1.81.0)
 - #129605 (Add missing `needs-llvm-components` directives for run-make tests that need target-specific codegen)
 - #129650 (Clean up `library/profiler_builtins/build.rs`)
 - #129651 (skip stage 0 target check if `BOOTSTRAP_SKIP_TARGET_SANITY` is set)
 - #129684 (Enable Miri to pass pointers through FFI)
 - #129762 (Update the `wasm-component-ld` binary dependency)
 - #129782 (couple more crash tests)
 - #129816 (tidy: say which feature gate has a stability issue mismatch)
 - #129818 (make the const-unstable-in-stable error more clear)
 - #129824 (Fix code examples buttons not appearing on click on mobile)
 - #129826 (library: Fix typo in `core::mem`)

r? `@ghost`
`@rustbot` modify labels: rollup
2024-08-31 20:59:27 +00:00
Camille GILLOT f68f66538a Create opaque definitions in resolver. 2024-08-31 20:14:43 +00:00
Matthias Krüger b8b2a65035
Rollup merge of #129818 - RalfJung:const-stability, r=compiler-errors
make the const-unstable-in-stable error more clear

The default should be to add `rustc_const_unstable`, not `rustc_allow_const_fn_unstable`.

Also I discovered our check for missing const stability attributes on stable functions -- but strangely that check only kicks in for "reachable" functions. `check_missing_stability` checks for reachability since all reachable functions must have a stability attribute, but I would say if a function has `#[stable]` it should also have const-stability attributes regardless of reachability.
2024-08-31 20:36:27 +02:00
Matthias Krüger 1e0cc8bec3
Rollup merge of #129782 - matthiaskrgr:c, r=jieyouxu
couple more crash tests

r? ```@jieyouxu```
2024-08-31 20:36:26 +02:00
Matthias Krüger d354d4ddd7
Rollup merge of #129605 - jieyouxu:needs-llvm-components, r=Mark-Simulacrum
Add missing `needs-llvm-components` directives for run-make tests that need target-specific codegen

Without suitable `needs-llvm-components` directives, some run-make tests exercising target-specific codegen can fail if the LLVM used is built without the necessary components. Currently, the list is:

```
tests\run-make\print-target-list
tests\run-make\print-to-output
tests\run-make\print-cfg
tests\run-make\target-without-atomic-cas
```

This PR also skips tidy checks for revisions and `needs-llvm-components` for run-make tests since revisions are not supported.

Fixes #129390.
Fixes #127895.

cc ``@petrochenkov`` who noticed this, thanks! Would be great if you could confirm that this fixes the test errors for you locally.
2024-08-31 20:36:23 +02:00
Camille GILLOT 111b0a97b4 Rewrite lint_expectations in a single pass. 2024-08-31 14:00:54 +00:00
Ralf Jung e3b1966137 make the const-unstable-in-stable error more clear 2024-08-31 15:11:48 +02:00
Matthias Krüger ff0c98663e
Rollup merge of #129760 - cuviper:old-timey, r=compiler-errors
Make the "detect-old-time" UI test more representative

The test code did have an inference failure, but that would have failed
on Rust 1.79 and earlier too. Now it is rewritten to be specifically
affected by 1.80's `impl FromIterator<_> for Box<str>`.
2024-08-31 14:46:10 +02:00
Matthias Krüger 6b9ed71c21
Rollup merge of #129757 - saethlin:half-a-recursion, r=compiler-errors
Add a test for trait solver overflow in MIR inliner cycle detection

This test is a combination of the reproducer posted here: https://github.com/rust-lang/rust/issues/128887#issuecomment-2314198229 and the existing test for polymorphic recursion: 784d444733/tests/mir-opt/inline/polymorphic_recursion.rs

r? ```@compiler-errors```
2024-08-31 14:46:10 +02:00
Matthias Krüger 1c51e5b110
Rollup merge of #129711 - lqd:nll-mir-dumps, r=compiler-errors
Expand NLL MIR dumps

This PR is a first step to clean up and expand NLL MIR dumps:
- by restoring the "mir-include-spans" comments which are useful for `-Zdump-mir=nll`
- by adding the list of borrows to NLL MIR dumps, where they are introduced in the CFG and in which region

Comments in MIR dumps were turned off in #112346, but as shown in #114652 they were still useful for us working with NLL MIR dumps. So this PR pulls `-Z mir-include-spans` into its own options struct, so that passes dumping MIR can override them if need be. The rest of the compiler is not affected, only the "nll" pass dumps have these comments enabled again. The CLI still has priority when specifying the flag, so that we can explicitly turn them off in the `mir-opt` tests to keep blessed dumps easier to work with (which was one of the points of #112346).

Then, as part of a couple steps to improve NLL/polonius MIR dumps and `.dot` visualizations, I've also added the list of borrows and where they're introduced. I'm doing all this to help debug some polonius scope issues in my prototype location-sensitive analysis :3. I'll probably add member constraints soon.
2024-08-31 14:46:07 +02:00
Matthias Krüger ea5bb99c0f
Rollup merge of #129659 - RalfJung:const-fn-lang-feat, r=fee1-dead
const fn stability checking: also check declared language features

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

`@oli-obk` I assume it is just an oversight that this didn't use `features().declared()`? Or is there a deep reason that this must only check `declared_lib_features`?
2024-08-31 14:46:06 +02:00
Pavel Grigorenko a9b959a020 elided_named_lifetimes: bless & add tests 2024-08-31 15:35:42 +03:00
Ralf Jung c2984179d9 const fn stability checking: also check declared language features 2024-08-31 12:14:05 +02:00
Matthias Krüger 9f3ce40718
Rollup merge of #129366 - petrochenkov:libsearch, r=jieyouxu
linker: Synchronize native library search in rustc and linker

Also search for static libraries with alternative naming (`libname.a`) on MSVC when producing executables or dynamic libraries, and not just rlibs.

This unblocks https://github.com/rust-lang/rust/pull/123436.

try-job: x86_64-msvc
2024-08-31 10:08:53 +02:00
Matthias Krüger defc245d06
Rollup merge of #129123 - aDotInTheVoid:rustdoc-json-self, r=fmease
rustdoc-json: Add test for `Self` type

Inspired by #128471, the rustdoc-json suite had no tests in place for the `Self` type. This PR adds one.

I've also manually checked locally that this test passes on 29e924841f, confirming that adding `clean::Type::SelfTy` didn't change the JSON output. (potentially adding a self type to json (insead of (ab)using generic) is tracked in #128522)

Updates #81359

r? ````````@fmease````````
2024-08-31 10:08:52 +02:00
Matthias Krüger 1fd0c71818
Rollup merge of #120221 - compiler-errors:statements-are-not-patterns, r=nnethercote
Don't make statement nonterminals match pattern nonterminals

Right now, the heuristic we use to check if a token may begin a pattern nonterminal falls back to `may_be_ident`:
ef71f1047e/compiler/rustc_parse/src/parser/nonterminal.rs (L21-L37)

This has the unfortunate side effect that a `stmt` nonterminal eagerly matches against a `pat` nonterminal, leading to a parse error:
```rust
macro_rules! m {
    ($pat:pat) => {};
    ($stmt:stmt) => {};
}

macro_rules! m2 {
    ($stmt:stmt) => {
        m! { $stmt }
    };
}

m2! { let x = 1 }
```

This PR fixes it by more accurately reflecting the set of nonterminals that may begin a pattern nonterminal.

As a side-effect, I modified `Token::can_begin_pattern` to work correctly and used that in `Parser::nonterminal_may_begin_with`.
2024-08-31 10:08:51 +02:00
cyrgani fff063ee77 add crashtests for several old unfixed ICEs 2024-08-30 12:50:07 +02:00
Matthias Krüger 355d7c9ecd couple more crash tests 2024-08-30 12:38:22 +02:00
Rémy Rakic dff3d3588d add borrows to NLL MIR dumps
explicitly disable `-Zmir-include-spans` in mir-opt tests

This will override the NLL default of true, and keep the blessed dumps
easier to work with.
2024-08-30 07:14:31 +00:00
Yuri Astrakhan f41e0bb41d Squashed `aarch64_unknown_nto_qnx700` support 2024-08-30 01:19:55 -04:00
Josh Stone c339541f73 Make the "detect-old-time" UI test more representative
The test code did have an inference failure, but that would have failed
on Rust 1.79 and earlier too. Now it is rewritten to be specifically
affected by 1.80's `impl FromIterator<_> for Box<str>`.
2024-08-29 13:58:43 -07:00
Ben Kimock c71ede368c Add a test for trait solver overflow in MIR inliner cycle detection 2024-08-29 16:20:08 -04:00
Guillaume Gomez 7dc2caba7b
Rollup merge of #129690 - Oneirical:run-make-tidbits, r=jieyouxu
Add `needs-unwind` compiletest directive to `libtest-thread-limit` and replace some `Path` with `path` in `run-make`

Part of #121876 and the associated [Google Summer of Code project](https://blog.rust-lang.org/2024/05/01/gsoc-2024-selected-projects.html).

This PR does two things:

1. Add this to `libtest-thread-limit` ([Why?](https://github.com/rust-lang/rust/pull/128507#issuecomment-2315158014))
```
//@ needs-unwind
// Reason: this should be ignored in cg_clif (Cranelift) CI and anywhere
// else that uses panic=abort.
```

2. Use `path` instead of `Path` to simplify multiple run-make tests.
2024-08-29 16:21:48 +02:00
Guillaume Gomez a65404aba4
Rollup merge of #129316 - dingxiangfei2009:riscv64-imac-scs, r=nnethercote
riscv64imac: allow shadow call stack sanitizer

cc `@Darksonn` for shadow call stack sanitizer support on RV64IMAC and RV64GC
2024-08-29 16:21:47 +02:00
Guillaume Gomez d5c40d03dc
Rollup merge of #128970 - DianQK:lint-llvm-ir, r=nikic
Add `-Zlint-llvm-ir`

This flag is similar to `-Zverify-llvm-ir` and allows us to lint the generated IR.

r? compiler
2024-08-29 16:21:47 +02:00
Guillaume Gomez 015e9371e0
Rollup merge of #123940 - kornelski:remove-derived-debug, r=Urgau
debug-fmt-detail option

I'd like to propose a new option that makes `#[derive(Debug)]` generate no-op implementations that don't print anything, and makes `{:?}` in format strings a no-op.

There are a couple of motivations for this:

1. A more thorough stripping of debug symbols. Binaries stripped of debug symbols still retain some of them through `Debug` implementations. It's hard to avoid that without compiler's help, because debug formatting can be used in many places, including dependencies, and their loggers, asserts, panics, etc.
   * In my testing it gives about 2% binary size reduction on top of all other binary-minimizing best practices (including `panic_immediate_abort`). There are targets like Web WASM or embedded where users pay attention to binary sizes.
   * Users distributing closed-source binaries may not want to "leak" any symbol names as a matter of principle.
2. Adds ability to test whether code depends on specifics of the `Debug` format implementation in unwise ways (e.g. trying to get data unavailable via public interface, or using it as a serialization format). Because current Rust's debug implementation doesn't change, there's a risk of it becoming a fragile de-facto API that [won't be possible to change in the future](https://www.hyrumslaw.com/). An option that "breaks" it can act as a [grease](https://www.rfc-editor.org/rfc/rfc8701.html).

This implementation is a `-Z fmt-debug=opt` flag that takes:

* `full` — the default, current state.
* `none` — makes derived `Debug` and `{:?}` no-ops. Explicit `impl Debug for T` implementations are left unharmed, but `{:?}` format won't use them, so they may get dead-code eliminated if they aren't invoked directly.
* `shallow` — makes derived `Debug` print only the type's name, without recursing into fields. Fieldless enums print their variant names. `{:?}` works.

The `shallow` option is a compromise between minimizing the `Debug` code, and compatibility. There are popular proc-macro crates that use `Debug::fmt` as a way to convert enum values into their Rust source code.

There's a corresponding `cfg` flag: `#[cfg(fmt_debug = "none")]` that can be used in user code to react to this setting to minimize custom `Debug` implementations or remove unnecessary formatting helper functions.
2024-08-29 16:21:46 +02:00
Oneirical 65cb5deedb Use path instead of Path in some run-make tests 2024-08-29 10:15:17 -04:00
Oneirical da43f95dd3 Add needs-unwind compiletest directive to libtest-thread-limit 2024-08-29 10:13:48 -04:00
Ding Xiang Fei 9c29b33c7e
riscv64imac: allow shadow call stack sanitizer 2024-08-29 21:48:48 +08:00
DianQK 9589eb95d2
Add `-Zlint-llvm-ir` 2024-08-29 18:12:31 +08:00
Jubilee b94887a29c
Rollup merge of #129494 - tshepang:fmt-threads-sendsync, r=Nadrieril
format code in tests/ui/threads-sendsync

was thinking of fixing formatting for 1 test in the directory, but found a bunch of them to also be in need
2024-08-28 19:12:53 -07:00
Jubilee d2418cb888
Rollup merge of #129467 - dingxiangfei2009:smart-pointer-relax-pointee, r=compiler-errors
derive(SmartPointer): assume pointee from the single generic and better error messages

Fix #129465

Actually RFC says that `#[pointee]` can be inferred when there is no ambiguity, or there is only one generic type parameter so to say.

cc ```@Darksonn```

r? ```@compiler-errors```
2024-08-28 19:12:52 -07:00
Jubilee 26f75a65d7
Rollup merge of #129343 - estebank:time-version, r=jieyouxu
Emit specific message for time<=0.3.35

```
error[E0282]: type annotations needed for `Box<_>`
  --> /home/gh-estebank/.cargo/registry/src/index.crates.io-6f17d22bba15001f/time-0.3.34/src/format_description/parse/mod.rs:83:9
   |
83 |     let items = format_items
   |         ^^^^^
...
86 |     Ok(items.into())
   |              ---- type must be known at this point
   |
   = note: this is an inference error on `time` caused by a change in Rust 1.80.0; update `time` to version `>=0.3.36`
```

Partially mitigate the fallout from https://github.com/rust-lang/rust/issues/127343. Although the biggest benefit of this would have been if we had had this in 1.80 before it became stable, the long-tail of that change will be felt for a *long* time, so better late than never.

We can also emit an even more targeted error instead of this inference failure.
2024-08-28 19:12:50 -07:00
Jubilee 4c8c9e092d
Rollup merge of #128192 - mrkajetanp:feature-detect, r=Amanieu
rustc_target: Add various aarch64 features

Add various aarch64 features already supported by LLVM and Linux.
Additionally include some comment fixes to ensure consistency of feature names with the Arm ARM.
Compiler support for features added to stdarch by https://github.com/rust-lang/stdarch/pull/1614.
Tracking issue for unstable aarch64 features is https://github.com/rust-lang/rust/issues/127764.

List of added features:

- FEAT_CSSC
- FEAT_ECV
- FEAT_FAMINMAX
- FEAT_FLAGM2
- FEAT_FP8
- FEAT_FP8DOT2
- FEAT_FP8DOT4
- FEAT_FP8FMA
- FEAT_HBC
- FEAT_LSE128
- FEAT_LSE2
- FEAT_LUT
- FEAT_MOPS
- FEAT_LRCPC3
- FEAT_SVE_B16B16
- FEAT_SVE2p1
- FEAT_WFxT
- FEAT_SME
- FEAT_SME_F16F16
- FEAT_SME_F64F64
- FEAT_SME_F8F16
- FEAT_SME_F8F32
- FEAT_SME_FA64
- FEAT_SME_I16I64
- FEAT_SME_LUTv2
- FEAT_SME2
- FEAT_SME2p1
- FEAT_SSVE_FP8DOT2
- FEAT_SSVE_FP8DOT4
- FEAT_SSVE_FP8FMA

FEAT_FPMR is added in the first commit and then removed in a separate one to highlight it being removed from upstream LLVM 19. The intention is for it to be detectable at runtime through stdarch but not have a corresponding Rust compile-time feature.
2024-08-28 19:12:49 -07:00
bors acb4e8b625 Auto merge of #127537 - veluca93:struct_tf, r=BoxyUwU
Implement a first version of RFC 3525: struct target features

This PR is an attempt at implementing https://github.com/rust-lang/rfcs/pull/3525, behind a feature gate `struct_target_features`.

There's obviously a few tasks that ought to be done before this is merged; in no particular order:
- add proper error messages
- add tests
- create a tracking issue for the RFC
- properly serialize/deserialize the new target_features field in `rmeta` (assuming I even understood that correctly :-))

That said, as I am definitely not a `rustc` expert, I'd like to get some early feedback on the overall approach before fixing those things (and perhaps some pointers for `rmeta`...), hence this early PR :-)

Here's an example piece of code that I have been using for testing - with the new code, the calls to intrinsics get correctly inlined:
```rust
#![feature(struct_target_features)]

use std::arch::x86_64::*;

/*
// fails to compile
#[target_feature(enable = "avx")]
struct Invalid(u32);
*/

#[target_feature(enable = "avx")]
struct Avx {}

#[target_feature(enable = "sse")]
struct Sse();

/*
// fails to compile
extern "C" fn bad_fun(_: Avx) {}
*/

/*
// fails to compile
#[inline(always)]
fn inline_fun(_: Avx) {}
*/

trait Simd {
    fn do_something(&self);
}

impl Simd for Avx {
    fn do_something(&self) {
        unsafe {
            println!("{:?}", _mm256_setzero_ps());
        }
    }
}

impl Simd for Sse {
    fn do_something(&self) {
        unsafe {
            println!("{:?}", _mm_setzero_ps());
        }
    }
}

struct WithAvx {
    #[allow(dead_code)]
    avx: Avx,
}

impl Simd for WithAvx {
    fn do_something(&self) {
        unsafe {
            println!("{:?}", _mm256_setzero_ps());
        }
    }
}

#[inline(never)]
fn dosomething<S: Simd>(simd: &S) {
    simd.do_something();
}

fn main() {
    /*
    // fails to compile
    Avx {};
    */

    if is_x86_feature_detected!("avx") {
        let avx = unsafe { Avx {} };
        dosomething(&avx);
        dosomething(&WithAvx { avx });
    }
    if is_x86_feature_detected!("sse") {
        dosomething(&unsafe { Sse {} })
    }
}
```

Tracking:

- https://github.com/rust-lang/rust/issues/129107
2024-08-28 22:54:55 +00:00
Esteban Küber b013a3ddf0 Emit specific message for `time<0.3.35` inference failure
```
error[E0282]: type annotations needed for `Box<_>`
  --> ~/.cargo/registry/src/index.crates.io-6f17d22bba15001f/time-0.3.34/src/format_description/parse/mod.rs:83:9
   |
83 |     let items = format_items
   |         ^^^^^
...
86 |     Ok(items.into())
   |              ---- type must be known at this point
   |
   = note: this is an inference error on crate `time` caused by a change in Rust 1.80.0; update `time` to version `>=0.3.35`
```

Partially address #127343.
2024-08-28 22:53:02 +00:00
Kornel 88b9edc9db
fmt-debug option
Allows disabling `fmt::Debug` derive and debug formatting.
2024-08-28 23:32:40 +01:00