Commit Graph

258747 Commits

Author SHA1 Message Date
Matthias Krüger 2724aeaaeb
Rollup merge of #126618 - mu001999-contrib:dead/enhance, r=pnkfelix
Mark assoc tys live only if the corresponding trait is live

r? ````@pnkfelix````
2024-06-25 18:02:58 +02:00
bors c290e9de32 Auto merge of #126326 - eggyal:ununsafe-StableOrd, r=michaelwoerister
Un-unsafe the `StableOrd` trait

Whilst incorrect implementations of this trait can cause miscompilation, they cannot cause memory unsafety in rustc.

[Discussed on Zulip](https://rust-lang.zulipchat.com/#narrow/stream/182449-t-compiler.2Fhelp/topic/Policy.20of.20.60unsafe.60.20within.20the.20compiler).

cc [MCP 533](https://github.com/rust-lang/compiler-team/issues/533), #105175, `@michaelwoerister`

r? `@Nilstrieb`
2024-06-25 15:51:35 +00:00
xFrednet d9e32a69a7
RFC 2373: Update tests for rustdoc for `lint_reasons` 2024-06-25 17:50:55 +02:00
xFrednet e3a2c9887c
RFC 2383: Update documentation 2024-06-25 17:50:55 +02:00
xFrednet ee0623b78d
RFC 2383: Stabilize `lint_reasons` in Miri 2024-06-25 17:50:54 +02:00
xFrednet 48310525bd
RFC 2383: Stabilize `lint_reasons` in Clippy 🖇️ 2024-06-25 17:50:48 +02:00
mu001999 6997b6876d Detect unused structs which derived Default 2024-06-25 23:29:44 +08:00
xFrednet 8b14e23dce
RFC 2383: Stabilize `lint_reasons` 🎉 2024-06-25 17:22:22 +02:00
Bryanskiy d30d85fd9e Delegation: ast lowering refactor 2024-06-25 16:44:51 +03:00
ash aa46a3368e `PathBuf::as_mut_vec` removed and verified for UEFI and Windows platforms #126333 2024-06-25 07:36:34 -06:00
ash 7e187e8e4b remove references to `PathBuf::as_mut_vec` in `PathBuf::_set_extension` 2024-06-25 07:36:34 -06:00
ash b08cd69684 inner truncate methods for UEFI platforms 2024-06-25 07:36:34 -06:00
ash 2155c6c477 #126333 remove `PathBuf::as_mut_vec` reference at top of `PathBuf::_push` 2024-06-25 07:36:34 -06:00
Ralf Jung d9a3423288 miri: make sure we can find link_section statics even for the local crate 2024-06-25 14:00:35 +02:00
bors d929a42a66 Auto merge of #125741 - petrochenkov:atvisord, r=davidtwco
ast: Standardize visiting order for attributes and node IDs

This should only affect `macro_rules` scopes and order of diagnostics.

Also add a deprecation lint for `macro_rules` called outside of their scope, like in https://github.com/rust-lang/rust/issues/124535.
2024-06-25 11:48:14 +00:00
cyrgani c7b579a7cb
Add missing slash in const_eval_select doc comment 2024-06-25 13:37:22 +02:00
Urgau 604caa09ed De-duplicate all consecutive native libs regardless of their options 2024-06-25 13:18:19 +02:00
bors c2d2bb38c9 Auto merge of #126834 - bjorn3:interface_refactor, r=michaelwoerister
Various refactorings to rustc_interface

This should make it easier to move the driver interface away from queries in the future. Many custom drivers call queries like `queries.global_ctxt()` before they are supposed to be called, breaking some things like certain `--print` and `-Zunpretty` options, `-Zparse-only` and emitting the dep info at the wrong point in time. They are also not actually necessary at all. Passing around the query output manually would avoid recomputation too and would be just as easy. Removing driver queries would also reduce the amount of global mutable state of the compiler. I'm not removing driver queries in this PR to avoid breaking the aforementioned custom drivers.
2024-06-25 09:35:53 +00:00
Zalathar c2f1072e01 Tweak `FlatPat::new` to avoid a temporarily-invalid state
It was somewhat confusing that the old constructor would create a `FlatPat` in
a (possibly) non-simplified state, and then simplify its contents in-place.

So instead we now create its fields as local variables, perform simplification,
and then create the struct afterwards.

This doesn't affect correctness, but is less confusing.
2024-06-25 17:46:35 +10:00
bors bda221a0eb Auto merge of #125740 - RalfJung:transmute-size-check, r=oli-obk
transmute size check: properly account for alignment

Fixes another place where ZST alignment was ignored when checking whether something is a newtype. I wonder how many more of these there are...

Fixes https://github.com/rust-lang/rust/issues/101084
2024-06-25 07:21:17 +00:00
Trevor Gross e181297c8c Add tests for `f16` and `f128`
This suite tests all library functions that are now available for the
types. Tests are only run on certain platforms where `f16` and `f128`
are known to work (have symbols available and don't crash LLVM).
2024-06-25 01:32:36 -04:00
Trevor Gross 6e2d934a88 Add more `f16` and `f128` library functions and constants
This adds everything that was directly or transitively blocked on const
arithmetic for these types, which was recently merged.

Since const arithmetic is recent, most of these need to be gated by
`bootstrap`.

Anything that relies on intrinsics that are still missing is excluded.
2024-06-25 01:32:36 -04:00
Trevor Gross 0eee0557d0 Add doctests to existing `f16` and `f128` functions
The symbols that these tests rely on are not available on all platforms
and some ABIs are buggy, tests that rely on external functions are
configured to only run on x86 (`f128`) or aarch64 (`f16`).
2024-06-25 01:32:36 -04:00
Trevor Gross 99ed3d3e99 Add build.rs config for reliable `f16` and `f128`
There are some complexities about what platforms we can test f16 and
f128 on.  Put this in build.rs so we have an easy way to configure tests
with a single attribute, and keep it up to date.
2024-06-25 01:32:36 -04:00
bors 164e1297e1 Auto merge of #125610 - oli-obk:define_opaque_types14, r=compiler-errors
Allow constraining opaque types during various unsizing casts

allows unsizing of tuples, arrays and Adts to constraint opaque types in their generic parameters to concrete types on either side of the unsizing cast.

Also allows constraining opaque types during trait object casts that only differ in auto traits or lifetimes.

cc #116652
2024-06-25 05:09:30 +00:00
Jubilee Young 050595a826 core: VaArgSafe is an unsafe trait
`T: VaArgSafe` is relied on for soundness. Safe impls promise nothing.
Therefore this must be an unsafe trait. Slightly pedantic, as
only core can impl this, but we could choose to unseal the trait.
That would allow soundly (but unsafely) implementing this for e.g.
a `#[repr(C)] struct` that should be passable by varargs.
2024-06-24 20:40:33 -07:00
bors fc555cd832 Auto merge of #126852 - scottmcm:more-checked-math-tweaks, r=Amanieu
Also get `add nuw` from `uN::checked_add`

When I was doing this for `checked_{sub,shl,shr}`, it was mentioned https://github.com/rust-lang/rust/pull/124114#issuecomment-2066173305 that it'd be worth trying for `checked_add` too.

It makes a particularly-big difference for `x.checked_add(C)`, as doing this means that LLVM removes the intrinsic and does it as a normal `x <= MAX - C` instead.

cc `@DianQK` who had commented about `checked_add` related to https://github.com/rust-lang/hashbrown/issues/509 before

cc https://github.com/llvm/llvm-project/issues/80637 for how LLVM is unlikely to do this itself
2024-06-25 02:50:37 +00:00
Zalathar 8016940ef4 Tweak a confusing comment in `create_match_candidates` 2024-06-25 12:16:49 +10:00
surechen 2a6a42329f Change E0369 diagnostic give note information for foreign items.
Make it easy for developers to understand why the binop cannot be applied.

fixes #125631
2024-06-25 10:00:30 +08:00
bors 5b270e1198 Auto merge of #126813 - compiler-errors:SliceLike, r=lcnr
Add `SliceLike` to `rustc_type_ir`, use it in the generic solver code (+ some other changes)

First, we split out `TraitRef::new_from_args` which takes *just* `ty::GenericArgsRef` from `TraitRef::new` which takes `impl IntoIterator<Item: Into<GenericArg>>`. I will explain in a minute why.

Second, we introduce `SliceLike`, which allows us to be generic over `List<T>` and `[T]`. This trait has an `as_slice()` and `into_iter()` method, and some other convenience functions. However, importantly, since types like `I::GenericArgs` now implement `SliceLike` rather than `IntoIter<Item = I::GenericArg>`, we can't use `TraitRef::new` on this directly. That's where `new_from_args` comes in.

Finally, we adjust all the code to use these slice operators. Some things get simpler, some things get a bit more annoying since we need to use `as_slice()` in a few places. 🤷

r? lcnr
2024-06-25 00:33:49 +00:00
bors 6b0f4b5ec3 Auto merge of #126914 - compiler-errors:rollup-zx0hchm, r=compiler-errors
Rollup of 11 pull requests

Successful merges:

 - #124460 (Show notice about  "never used" of Debug for enum)
 - #124712 (Deprecate no-op codegen option `-Cinline-threshold=...`)
 - #125082 (Remove `MaybeUninit::uninit_array()` and replace it with inline const blocks.)
 - #125575 (SmartPointer derive-macro)
 - #126413 (compiletest: make the crash test error message abit more informative)
 - #126673 (Ensure we don't accidentally succeed when we want to report an error)
 - #126682 (coverage: Overhaul validation of the `#[coverage(..)]` attribute)
 - #126899 (Suggest inline const blocks for array initialization)
 - #126904 (Small fixme in core now that NonZero is generic)
 - #126909 (add `@kobzol` to bootstrap team for triagebot)
 - #126911 (Split the lifetimes of `MirBorrowckCtxt`)

r? `@ghost`
`@rustbot` modify labels: rollup
2024-06-24 21:33:02 +00:00
SparkyPotato 26677eb06e don't suggest awaiting type expr patterns 2024-06-24 16:20:22 -05:00
Ana Hobden 553a69030e
Specify target specific linker for riscv64gc-gnu job 2024-06-24 12:58:40 -07:00
Michael Goulet 16bd6e25e1
Rollup merge of #126911 - oli-obk:do_not_count_errors, r=compiler-errors
Split the lifetimes of `MirBorrowckCtxt`

These lifetimes are sometimes too general and will link things together that are independent. These are a blocker for actually finishing tracking more state (e.g. error tainting) in the diagnostic context handle, and I'd rather land it in its own PR instead of together with functional changes.

Also changes a bunch of named lifetimes to `'_` where they were irrelevant

follow-up to https://github.com/rust-lang/rust/pull/126623
2024-06-24 15:51:06 -04:00
Michael Goulet 59c258f51f
Rollup merge of #126909 - onur-ozkan:add-kobzol, r=matthiaskrgr
add @kobzol to bootstrap team for triagebot

Welcome ``@Kobzol`` !
2024-06-24 15:51:05 -04:00
Michael Goulet 85eb835a14
Rollup merge of #126904 - GrigorenkoPV:nonzero-fixme, r=joboet
Small fixme in core now that NonZero is generic

I doubt I have the rights to, but
`@bors` rollup=always
2024-06-24 15:51:05 -04:00
Michael Goulet a7721a0373
Rollup merge of #126899 - GrigorenkoPV:suggest-const-block, r=davidtwco
Suggest inline const blocks for array initialization

#126894
2024-06-24 15:51:04 -04:00
Michael Goulet 9ce2a070b3
Rollup merge of #126682 - Zalathar:coverage-attr, r=lcnr
coverage: Overhaul validation of the `#[coverage(..)]` attribute

This PR makes sweeping changes to how the (currently-unstable) coverage attribute is validated:
- Multiple coverage attributes on the same item/expression are now treated as an error.
- The attribute must always be `#[coverage(off)]` or `#[coverage(on)]`, and the error messages for this are more consistent.
  -  A trailing comma is still allowed after off/on, since that's part of the normal attribute syntax.
- Some places that silently ignored a coverage attribute now produce an error instead.
  - These cases were all clearly bugs.
- Some places that ignored a coverage attribute (with a warning) now produce an error instead.
  - These were originally added as lints, but I don't think it makes much sense to knowingly allow new attributes to be used in meaningless places.
  - Some of these errors might soon disappear, if it's easy to extend recursive coverage attributes to things like modules and impl blocks.

---

One of the goals of this PR is to lay a more solid foundation for making the coverage attribute recursive, so that it applies to all nested functions/closures instead of just the one it is directly attached to.

Fixes #126658.

This PR incorporates #126659, which adds more tests for validation of the coverage attribute.

`@rustbot` label +A-code-coverage
2024-06-24 15:51:03 -04:00
Michael Goulet 49bdf460a2
Rollup merge of #126673 - oli-obk:dont_rely_on_err_reporting, r=compiler-errors
Ensure we don't accidentally succeed when we want to report an error

This also changes the `DefiningOpaqueTypes::No` to `Yes` without adding tests, as it is solely run on the error path to improve diagnostics. I was unable to provide a test that changes diagnostics, as all the tests I came up with ended up successfully constraining the opaque type and thus succeeding the coercion.

r? ```@compiler-errors```

cc https://github.com/rust-lang/rust/issues/116652
2024-06-24 15:51:02 -04:00
Michael Goulet 46e43984d1
Rollup merge of #126413 - matthiaskrgr:crshmsg, r=oli-obk
compiletest: make the crash test error message abit more informative

r?  ```@oli-obk```
2024-06-24 15:51:02 -04:00
Michael Goulet ed460d2eaa
Rollup merge of #125575 - dingxiangfei2009:derive-smart-ptr, r=davidtwco
SmartPointer derive-macro

<!--
If this PR is related to an unstable feature or an otherwise tracked effort,
please link to the relevant tracking issue here. If you don't know of a related
tracking issue or there are none, feel free to ignore this.

This PR will get automatically assigned to a reviewer. In case you would like
a specific user to review your work, you can assign it to them by using

    r​? <reviewer name>
-->

Possibly replacing #123472 for continued upkeep of the proposal rust-lang/rfcs#3621 and implementation of the tracking issue #123430.

cc `@Darksonn` `@wedsonaf`
2024-06-24 15:51:01 -04:00
Michael Goulet c77dc28f87
Rollup merge of #125082 - kpreid:const-uninit, r=dtolnay
Remove `MaybeUninit::uninit_array()` and replace it with inline const blocks.

\[This PR originally contained the changes in #125995 too. See edit history for the original PR description.]

The documentation of `MaybeUninit::uninit_array()` says:

> Note: in a future Rust version this method may become unnecessary when Rust allows [inline const expressions](https://github.com/rust-lang/rust/issues/76001). The example below could then use `let mut buf = [const { MaybeUninit::<u8>::uninit() }; 32];`.

The PR adding it also said: <https://github.com/rust-lang/rust/pull/65580#issuecomment-544200681>

> if it’s stabilized soon enough maybe it’s not worth having a standard library method that will be replaceable with `let buffer = [MaybeUninit::<T>::uninit(); $N];`

That time has come to pass — inline const expressions are stable — so `MaybeUninit::uninit_array()` is now unnecessary. The only remaining question is whether it is an important enough *convenience* to keep it around.

I believe it is net good to remove this function, on the principle that it is better to compose two orthogonal features (`MaybeUninit` and array construction) than to have a specific function for the specific combination, now that that is possible.
2024-06-24 15:51:01 -04:00
Michael Goulet faa28be2f1
Rollup merge of #124712 - Enselic:deprecate-inline-threshold, r=pnkfelix
Deprecate no-op codegen option `-Cinline-threshold=...`

This deprecates `-Cinline-threshold` since using it has no effect. This has been the case since the new LLVM pass manager started being used, more than 2 years ago.

Recommend using `-Cllvm-args=--inline-threshold=...` instead.

Closes #89742 which is E-help-wanted.
2024-06-24 15:51:00 -04:00
Michael Goulet 00e5f5886a
Rollup merge of #124460 - long-long-float:show-notice-about-enum-with-debug, r=pnkfelix
Show notice about  "never used" of Debug for enum

Close #123068

If an ADT implements `Debug` trait and it is not used, the compiler says a note that indicates intentionally ignored during dead code analysis as [this note](2207179a59/tests/ui/lint/dead-code/unused-variant.stderr (L9)).
However this node is not shown for variants that have fields in enum. This PR fixes to show the note.
2024-06-24 15:51:00 -04:00
bors d8d5732456 Auto merge of #126784 - scottmcm:smaller-terminator, r=compiler-errors
Save 2 pointers in `TerminatorKind` (96 → 80 bytes)

These things don't need to be `Vec`s; boxed slices are enough.

The frequent one here is call arguments, but MIR building knows the number of arguments from the THIR, so the collect is always getting the allocation right in the first place, and thus this shouldn't ever add the shrink-in-place overhead.
2024-06-24 19:22:01 +00:00
Kevin Reid 13fca73f49 Replace `MaybeUninit::uninit_array()` with array repeat expression.
This is possible now that inline const blocks are stable; the idea was
even mentioned as an alternative when `uninit_array()` was added:
<https://github.com/rust-lang/rust/pull/65580#issuecomment-544200681>

> if it’s stabilized soon enough maybe it’s not worth having a
> standard library method that will be replaceable with
> `let buffer = [MaybeUninit::<T>::uninit(); $N];`

Const array repetition and inline const blocks are now stable (in the
next release), so that circumstance has come to pass, and we no longer
have reason to want `uninit_array()` other than convenience. Therefore,
let’s evaluate the inconvenience by not using `uninit_array()` in
the standard library, before potentially deleting it entirely.
2024-06-24 10:23:50 -07:00
Michael Goulet 6521c3971d Deny use<> for RPITITs 2024-06-24 12:03:09 -04:00
bors 5a3e2a4e92 Auto merge of #126523 - joboet:the_great_big_tls_refactor, r=Mark-Simulacrum
std: refactor the TLS implementation

As discovered by Mara in #110897, our TLS implementation is a total mess. In the past months, I have simplified the actual macros and their expansions, but the majority of the complexity comes from the platform-specific support code needed to create keys and register destructors. In keeping with #117276, I have therefore moved all of the `thread_local_key`/`thread_local_dtor` modules to the `thread_local` module in `sys` and merged them into a new structure, so that future porters of `std` can simply mix-and-match the existing code instead of having to copy the same (bad) implementation everywhere. The new structure should become obvious when looking at `sys/thread_local/mod.rs`.

Unfortunately, the documentation changes associated with the refactoring have made this PR rather large. That said, this contains no functional changes except for two small ones:
* the key-based destructor fallback now, by virtue of sharing the implementation used by macOS and others, stores its list in a `#[thread_local]` static instead of in the key, eliminating one indirection layer and drastically simplifying its code.
* I've switched over ZKVM (tier 3) to use the same implementation as WebAssembly, as the implementation was just a way worse version of that

Please let me know if I can make this easier to review! I know these large PRs aren't optimal, but I couldn't think of any good intermediate steps.

`@rustbot` label +A-thread-locals
2024-06-24 15:55:28 +00:00
Michael Goulet d521e2148e Also migrate FnInputTys 2024-06-24 11:53:34 -04:00
Michael Goulet 24e41f1d13 Replace Deref bounds on Interner in favor of a SliceLike trait 2024-06-24 11:53:34 -04:00