Commit Graph

37385 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
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
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
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
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
Nicholas Nethercote 379b761462 Inline and remove `maybe_whole_expr!`.
And remove the `NtPath` and `NtBlock` cases in
`parse_literal_maybe_minus`, because they are unnecessary.
2024-06-25 14:57:56 +10:00
Nicholas Nethercote 2e4d547d4a Extra panic cases.
Just some extra sanity checking, making explicit some values not
possible in code working with token trees -- we shouldn't be seeing
explicit delimiter tokens, because they should be represented as
`TokenTree::Delimited`.
2024-06-25 14:29:25 +10: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
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 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 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
John Paul Adrian Glaubitz e57bbb3779 rustc_target: Build sparc_unknown_linux_gnu with -mcpu=v9 and -m32
The previously -mv8plus parameter is supported by GCC only, so let's
use something that the SPARC backend in LLVM supports as well.
2024-06-24 17:58:21 +02:00
John Paul Adrian Glaubitz a194f42d21 rustc_target: Rewrite sparc_unknown_linux_gnu spec to use TargetOptions 2024-06-24 17:57:59 +02: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
Michael Goulet f26cc349d9 Split out IntoIterator and non-Iterator constructors for AliasTy/AliasTerm/TraitRef/projection 2024-06-24 11:28:21 -04:00
John Paul Adrian Glaubitz dc8ac3ec91 rustc_llvm: Link against libatomic on 32-bit SPARC
While at it, order the list of architectures alphabetically.
2024-06-24 16:53:09 +02:00
John Paul Adrian Glaubitz 572ae3b227 rustc_data_structures: Use portable AtomicU64 on 32-bit SPARC
While at it, order the list of architectures alphabetically.
2024-06-24 16:52:19 +02:00
Oli Scherer 8fc6b3de19 Separate the mir body lifetime from the other lifetimes 2024-06-24 14:28:14 +00:00
Oli Scherer 1c4d0ced58 Separate the lifetimes of the `BorrowckInferCtxt` from the other borrowed items 2024-06-24 14:28:13 +00:00
Vadim Petrochenkov c4c7859e40 resolve: Implement a lint for out-of-scope use of `macro_rules` 2024-06-24 17:12:08 +03:00
Vadim Petrochenkov 0195758c1a ast: Standardize visiting order for attributes and node IDs 2024-06-24 16:08:51 +03:00
Matthias Krüger a80ee9159b
Rollup merge of #126882 - estebank:multiline-order, r=WaffleLapkin
Special case when a code line only has multiline span starts

Minimize multline span overlap when there are multiple of them starting on the same line:

```
3 |       X0 Y0 Z0
  |  _____^  -  -
  | | _______|  |
  | || _________|
4 | |||   X1 Y1 Z1
5 | |||   X2 Y2 Z2
  | |||____^__-__- `Z` label
  | ||_____|__|
  | |______|  `Y` is a good letter too
  |        `X` is a good letter
```
2024-06-24 15:06:23 +02:00
Matthias Krüger 9d24ecc37b
Rollup merge of #125241 - Veykril:tool-rust-analyzer, r=davidtwco
Add `rust_analyzer` as a predefined tool

Given all the other rust-lang tools have it, I'd expect r-a to have it too. (we have a few ideas for using this https://github.com/rust-lang/rust-analyzer/issues/11556).
2024-06-24 15:06:21 +02:00
Pavel Grigorenko ba5ec1fc5c Suggest inline const blocks for array initialization 2024-06-24 15:30:24 +03:00
Zalathar b7c057c9b2 coverage: Always error on `#[coverage(..)]` in unexpected places
This upgrades some warnings to errors, and also catches cases where the
attribute was silently ignored.
2024-06-24 20:15:03 +10:00
Zalathar a000fa8b54 coverage: Tighten validation of `#[coverage(off)]` and `#[coverage(on)]` 2024-06-24 20:15:01 +10:00
Zalathar b5dfeba0e1 coverage: Forbid multiple `#[coverage(..)]` attributes
It might make sense to allow this in the future, if we add values that aren't
mutually exclusive, but for now having multiple coverage attributes on one item
is useless.
2024-06-24 20:10:35 +10:00
Matthias Krüger 3108dfaced
Rollup merge of #126849 - workingjubilee:correctly-classify-arm-low-dregs, r=Amanieu
Fix 32-bit Arm reg classes by hierarchically sorting them

We were rejecting legal `asm!` because we were asking for the "greatest" feature that includes a register class, instead of the "least" feature that includes a register class. This was only revealed on certain 32-bit Arm targets because not all have the same register limitations.

This is a somewhat hacky solution, but other solutions would require potentially rearchitecting how the internals of parsing or rejecting register classes work for all targets.

Fixes #126797

r​? ``@Amanieu``
2024-06-24 06:27:16 +02:00
Matthias Krüger ad0531ae0d
Rollup merge of #126455 - surechen:fix_126222, r=estebank
For [E0308]: mismatched types, when expr is in an arm's body, not add semicolon ';' at the end of it.

For [E0308]: mismatched types, when expr is in an arm's body, and it is the end expr without a semicolon of the block, not add semicolon ';' at the end of it.

fixes #126222

<!--
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>
-->
2024-06-24 06:27:13 +02:00
Matthias Krüger 9a591ea1ce
Rollup merge of #126177 - carbotaniuman:unsafe_attr_errors, r=jieyouxu
Add hard error and migration lint for unsafe attrs

More implementation work for https://github.com/rust-lang/rust/issues/123757

This adds the migration lint for unsafe attributes, as well as making it a hard error in Rust 2024.
2024-06-24 06:27:12 +02:00
Esteban Küber a2298a6f19 Do not ICE when suggesting dereferencing closure arg
Account for `for` lifetimes when constructing closure to see if dereferencing the return value would be valid.

Fix #125634, fix #124563.
2024-06-24 03:39:54 +00:00
David Tolnay 273447cec7
Rename the 2 unambiguous precedence levels to PREC_UNAMBIGUOUS 2024-06-23 18:31:47 -07:00
David Tolnay 8cfd4b180b
Unify the precedence level for PREC_POSTFIX and PREC_PAREN 2024-06-23 18:29:51 -07:00
bors d49994b060 Auto merge of #126023 - amandasystems:you-dropped-this-again, r=nikomatsakis
Remove confusing `use_polonius` flag and do less cloning

The `use_polonius` flag is both redundant and confusing since every function it's propagated to also checks if `all_facts` is `Some`, the true test of whether to generate Polonius facts for Polonius or for external consumers. This PR makes that path clearer by simply doing away with the argument and handling the logic in precisely two places: where facts are populated (check for `Some`), and where `all_facts` are initialised. It also delays some statements until after that check to avoid the miniscule performance penalty of executing them when Polonius is disabled.

This also addresses `@lqd's` concern in #125652 by reducing the size of what is cloned out of Polonius facts to just the facts being added, as opposed to the entire vector of potential inputs, and added descriptive comments.

*Reviewer note*: the comments in `add_extra_drop_facts` should be inspected by a reviewer, in particular the one on [L#259](https://github.com/rust-lang/rust/compare/master...amandasystems:you-dropped-this-again?expand=1#diff-aa727290e6670264df2face84f012897878e11a70e9c8b156543cfcd9619bac3R259) in this PR, which should be trivial for someone with the right background knowledge to address.

I also included some lints I found on the way there that I couldn't help myself from addressing.
2024-06-24 00:24:51 +00:00
carbotaniuman a23917cfd0 Add hard error and migration lint for unsafe attrs 2024-06-23 19:02:14 -05:00
Nicholas Nethercote aa30dd444b Fix a typo in a comment. 2024-06-24 09:44:19 +10:00
Esteban Küber 284437d434 Special case when a code line only has multiline span starts
```
3 |       X0 Y0 Z0
  |  _____^  -  -
  | | _______|  |
  | || _________|
4 | |||   X1 Y1 Z1
5 | |||   X2 Y2 Z2
  | |||____^__-__- `Z` label
  | ||_____|__|
  | |______|  `Y` is a good letter too
  |        `X` is a good letter
```
2024-06-23 22:00:52 +00:00
Matthias Krüger 0149bc47d8
Rollup merge of #126851 - nnethercote:NtExprKind-NtPatKind, r=compiler-errors
Rework pattern and expression nonterminal kinds.

Some tweaks to `NonterminalKind` that will assist with #124141. Details in the individual commits.

r? compiler-errors
cc ```@eholk```
2024-06-23 22:39:01 +02:00
Matthias Krüger 2c0311dbbe
Rollup merge of #126837 - petrochenkov:delegfix, r=compiler-errors
delegation: Do not crash on qpaths without a trait

Fixes https://github.com/rust-lang/rust/issues/126742
2024-06-23 22:39:01 +02:00
Matthias Krüger a9959bd1ab
Rollup merge of #126833 - RalfJung:extern-type-field-ice, r=compiler-errors
don't ICE when encountering an extern type field during validation

"extern type" is a pain that keeps on giving...

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

r? ```@oli-obk```
2024-06-23 22:39:00 +02:00
Matthias Krüger 0a7adafe4f
Rollup merge of #126830 - RalfJung:unsized-fn-params, r=compiler-errors
make unsized_fn_params an internal feature

As suggested [here](https://github.com/rust-lang/rust/pull/123894#issuecomment-2054043053).
r? `@compiler-errors`

Fixes https://github.com/rust-lang/rust/issues/123887 (kind of -- ICEs on internal features are considered acceptable so this issue is not-a-bug once this PR lands)
2024-06-23 22:39:00 +02:00
Xiangfei Ding f1be59fa72
SmartPointer derive-macro
Co-authored-by: Wedson Almeida Filho <walmeida@microsoft.com>
2024-06-24 03:03:34 +08:00
bohan 594fa01aba not use offset when there is not ends with brace 2024-06-23 23:44:22 +08:00
bors aabbf84b45 Auto merge of #123088 - tgross35:f16-f128-pattern-analysis, r=Nadrieril
Replace `f16` and `f128` pattern matching stubs with real implementations

This section of code depends on `rustc_apfloat` rather than our internal types, so this is one potential ICE that we should be able to melt now.

r? `@Nadrieril`
2024-06-23 14:14:48 +00:00
bors c3d7fb3985 Auto merge of #124733 - workingjubilee:cant-beleaf-we-dont-have-this, r=saethlin
Support `-Cforce-frame-pointers=non-leaf`

Why don't we already support this...?

Suggested impl for https://github.com/rust-lang/compiler-team/issues/744
2024-06-23 11:12:11 +00:00
Trevor Gross 6fb6c19c96 Replace `f16` and `f128` pattern matching stubs with real implementations
This section of code depends on `rustc_apfloat` rather than our internal
types, so this is one potential ICE that we should be able to melt now.

This also fixes some missing range and match handling in `rustc_middle`.
2024-06-23 04:28:42 -05:00
Jubilee Young 761ba5bb07 compiler: parse the empty frame-pointer 2024-06-23 02:22:55 -07:00
Scott McMurray dd545e148c Make MIR inlining costs in build-std independent of config.toml 2024-06-23 01:48:41 -07:00
Jubilee Young 598e265d43 compiler: Accept -Cforce-frame-pointers=always
Also lands behind -Zunstable-options, for now.
Take the opportunity to do some mild cleanup.
2024-06-23 00:36:34 -07:00
Jubilee Young 7d160ae61a compiler: Support nightly -Cforce-frame-pointers=non-leaf
Requires -Zunstable-options as this is a -C flag already.
2024-06-23 00:36:34 -07:00
Jubilee Young 79416c4118 cg_clif: Define build opts from FramePointer 2024-06-23 00:36:33 -07:00
Jubilee Young b3a1975cdc compiler(nfc): -Cforce-frame-pointers is a FramePointer 2024-06-23 00:36:33 -07:00
Jubilee Young 7c0b5cf99f compiler: Add FramePointer::ratchet 2024-06-23 00:36:33 -07:00
Jubilee Young 43a6b018a2 compiler: Mention C-unwind in C-variadic error 2024-06-22 23:30:31 -07:00
Nicholas Nethercote e2aa38e6ab Rework pattern and expression nonterminal kinds.
Merge `PatParam`/`PatWithOr`, and `Expr`/`Expr2021`, for a few reasons.

- It's conceptually nice, because the two pattern kinds and the two
  expression kinds are very similar.

- With expressions in particular, there are several places where both
  expression kinds get the same treatment.

- It removes one unreachable match arm.

- Most importantly, for #124141 I will need to introduce a new type
  `MetaVarKind` that is very similar to `NonterminalKind`, but records a
  couple of extra fields for expression metavars. It's nicer to have a
  single `MetaVarKind::Expr` expression variant to hold those extra
  fields instead of duplicating them across two variants
  `MetaVarKind::{Expr,Expr2021}`. And then it makes sense for patterns
  to be treated the same way, and for `NonterminalKind` to also be
  treated the same way.

I also clarified the comments, because I have long found them a little
hard to understand.
2024-06-23 15:57:24 +10:00
Jubilee Young 0d8f734172 compiler: Fix arm32 asm issues by hierarchically sorting reg classes 2024-06-22 21:39:58 -07:00
Scott McMurray 9088cd95a3 GVN away PtrToPtr-then-Transmute when possible 2024-06-22 20:34:09 -07:00
Scott McMurray dd1e19e7c2 GVN away PtrToPtr before comparisons
Notably this happens in `NonNull::eq` :/
2024-06-22 20:27:08 -07:00
Scott McMurray a76e1d9b09 Add a `pointee_metadata_ty_or_projection` helper 2024-06-22 20:27:08 -07:00
surechen e8b5ba1111 For [E0308]: mismatched types, when expr is in an arm's body, not add semicolon ';' at the end of it.
fixes #126222
2024-06-23 10:19:02 +08:00
Jubilee Young 26dccadb47 Allow "C-unwind" fn to have C variadics 2024-06-22 15:14:14 -07:00
Nicholas Nethercote 70fa67c0b2 Tweak some ugly formatting. 2024-06-23 08:13:41 +10:00
Nicholas Nethercote 470b0e9c3c Import `NonterminalKind` in `compiler/rustc_expand/src/mbe/quoted.rs`.
So we can omit the `token::` qualifier, which gives more space to some
cramped code.
2024-06-23 08:11:54 +10:00
Matthias Krüger dc9a08f535
Rollup merge of #126552 - fee1-dead-contrib:rmfx, r=compiler-errors
Remove use of const traits (and `feature(effects)`) from stdlib

The current uses are already unsound because they are using non-const impls in const contexts. We can reintroduce them by reverting the commit in this PR, after #120639 lands.

Also, make `effects` an incomplete feature.

cc `@rust-lang/project-const-traits`
r? `@compiler-errors`
2024-06-22 19:33:56 +02:00
bjorn3 8d1f5b30ef Avoid a couple of unnecessary EarlyDiagCtxt uses 2024-06-22 17:06:47 +00:00
bjorn3 e3ffbbd226 Ensure run_compiler always aborts on errors
Before if the closure passed to run_compiler emitted an error without
calling abort_if_errors and no diagnostics have been stashed,
run_compiler would return normally as if no error had occured.
2024-06-22 17:06:47 +00:00
bjorn3 7332e79d5f Inline write_dep_info query 2024-06-22 17:06:47 +00:00
Nadrieril beb1d35d7d Change comment to reflect switch to THIR unsafeck 2024-06-22 19:06:40 +02:00
Nadrieril ff49c3769b Reuse `lower_let_expr` for `let .. else` lowering 2024-06-22 19:05:50 +02:00
Nadrieril 7b150a161e Don't use fake wildcards when we can get the failure block directly
This commit too was obtained by repeatedly inlining and simplifying.
2024-06-22 19:05:48 +02:00
Vadim Petrochenkov 0a265957dd delegation: Do not crash on qpaths without a trait 2024-06-22 19:57:19 +03:00
bjorn3 391bdb3c12 Clarify visibility of several rustc_interface passes 2024-06-22 15:44:36 +00:00
bjorn3 d8c9dd4172 Move has_errors_or_delayed_bugs check into start_codegen 2024-06-22 15:44:36 +00:00
bjorn3 e2aadc296d Call check_for_rustc_errors_attr from start_codegen 2024-06-22 15:44:36 +00:00
bjorn3 c8380cbe6a Move almost all code from Queries::global_ctxt into passes::create_global_ctxt 2024-06-22 15:44:33 +00:00
Ralf Jung 763e3131cc don't ICE when encountering an extern type field during validation 2024-06-22 17:39:01 +02:00
Deadbeef 81da6a6d40 Make `effects` an incomplete feature 2024-06-22 14:11:11 +00:00
Ralf Jung 093799693a make unsized_fn_params an internal feature 2024-06-22 15:34:50 +02:00
Guillaume Gomez 399c5cabdd
Rollup merge of #126723 - estebank:dot-dot-dot, r=Nadrieril
Fix `...` in multline code-skips in suggestions

When we have long code skips, we write `...` in the line number gutter.

For suggestions, we were "centering" the `...` with the line, but that was inconsistent with what we do in every other case *and* off-center.
2024-06-22 12:57:19 +02:00
Guillaume Gomez 3ed2cd74b5
Rollup merge of #126686 - fmease:dump-preds-n-item-bounds, r=compiler-errors
Add `#[rustc_dump_{predicates,item_bounds}]`

Conflicts with #126668.

As discussed
r? compiler-errors CC ``@fee1-dead``
2024-06-22 12:57:19 +02:00
Guillaume Gomez 07e8b3ac01
Rollup merge of #126555 - beetrees:f16-inline-asm-arm, r=Amanieu
Add `f16` inline ASM support for 32-bit ARM

Adds `f16` inline ASM support for 32-bit ARM. SIMD vector types are taken from [here](https://developer.arm.com/architectures/instruction-sets/intrinsics/#f:`@navigationhierarchiesreturnbasetype=[float]&f:@navigationhierarchieselementbitsize=[16]&f:@navigationhierarchiesarchitectures=[A32]).`

Relevant issue: #125398
Tracking issue: #116909

`@rustbot` label +F-f16_and_f128
2024-06-22 12:57:18 +02:00
Alan Egerton 0e73e7095a
Ensure careful consideration is given by impls
Added an associated `const THIS_IMPLEMENTATION_HAS_BEEN_TRIPLE_CHECKED`
to the `StableOrd` trait to ensure that implementors carefully consider
whether the trait's contract is upheld, as incorrect implementations can
cause miscompilations.
2024-06-22 07:17:02 +01:00
León Orell Valerian Liehr 38bd7a0fcb
Add `#[rustc_dump_{predicates,item_bounds}]` 2024-06-22 06:34:09 +02:00
Jubilee 1916b3d57f
Rollup merge of #126811 - compiler-errors:tidy-ftl, r=estebank
Add a tidy rule to check that fluent messages and attrs don't end in `.`

This adds a new dependency on `fluent-parse` to `tidy` -- we already rely on it in rustc so I feel like it's not that big of a deal.

This PR also adjusts many error messages that currently end in `.`; not all of them since I added an `ALLOWLIST`, excluded `rustc_codegen_*` ftl files, and `.teach_note` attributes.

r? ``@estebank`` ``@oli-obk``
2024-06-21 21:02:29 -07:00
Jubilee 539090e5cd
Rollup merge of #126809 - estebank:wording-tweak, r=oli-obk
Remove stray `.` from error message
2024-06-21 21:02:28 -07:00
Jubilee 9498d5cf2f
Rollup merge of #126787 - Strophox:get-bytes, r=RalfJung
Add direct accessors for memory addresses in `Machine` (for Miri)

The purpose of this PR is to enable direct (immutable) access to memory addresses in `Machine`, which will be needed for further extension of Miri.

This is done by adding (/completing missings pairs of) accessor functions, with the relevant signatures as follows:
```rust
/* rust/compiler/rustc_middle/src/mir/interpret/allocation.rs */

pub trait AllocBytes {
  // ..

  fn as_ptr(&self) -> *const u8;
/*fn as_mut_ptr(&mut self) -> *mut u8; -- Already in the compiler*/
}

impl<Prov: Provenance, Extra, Bytes: AllocBytes> Allocation<Prov, Extra, Bytes> {
  // ..

  pub fn get_bytes_unchecked_raw(&self) -> *const u8;
/*pub fn get_bytes_unchecked_raw_mut(&mut self) -> *mut u8; -- Already in the compiler*/
}
```
```rust
/* rust/compiler/rustc_const_eval/src/interpret/memory.rs */

impl<'tcx, M: Machine<'tcx>> InterpCx<'tcx, M> {
  // ..

  pub fn get_alloc_bytes_unchecked_raw(&self, id: AllocId) -> InterpResult<'tcx, *const u8>;
  pub fn get_alloc_bytes_unchecked_raw_mut(&mut self, id: AllocId) -> InterpResult<'tcx, *mut u8>;
}
```

r? ``@RalfJung``
2024-06-21 21:02:27 -07:00
Jubilee 1f9793f1aa
Rollup merge of #126722 - adwinwhite:ptr_fn_abi, r=celinval
Add method to get `FnAbi` of function pointer

Provide a StableMIR API to query `FnAbi` of a function pointer.

Fixes [rust-lang/project-stable-mir#63](https://github.com/rust-lang/project-stable-mir/issues/63)
2024-06-21 21:02:27 -07:00
Jubilee e7956cd994
Rollup merge of #126530 - beetrees:f16-inline-asm-riscv, r=Amanieu
Add `f16` inline ASM support for RISC-V

This PR adds `f16` inline ASM support for RISC-V. A `FIXME` is left for `f128` support as LLVM does not support the required `Q` (Quad-Precision Floating-Point) extension yet.

Relevant issue: #125398
Tracking issue: #116909

`@rustbot` label +F-f16_and_f128
2024-06-21 21:02:26 -07:00
Scott McMurray b28efb11af 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-21 18:02:05 -07:00
bors fcae62649e Auto merge of #126758 - spastorino:avoid-safe-outside-unsafe-blocks, r=compiler-errors
Do not allow safe/unsafe on static and fn items

Fixes #126749

r? `@compiler-errors`

Tracking:

- https://github.com/rust-lang/rust/issues/123743
2024-06-22 00:40:12 +00:00
Michael Goulet ffd72b1700 Fix remaining cases 2024-06-21 19:00:18 -04:00
Esteban Küber 5d5892e966 Remove stray `.` from error message 2024-06-21 21:13:10 +00:00
bjorn3 84f45bb093 Fix doc comment 2024-06-21 19:30:26 +00:00
bjorn3 887f57ff0b Remove type_i1 and type_struct from cg_ssa
They are not representable by Cranelift
2024-06-21 19:30:26 +00:00
bjorn3 aacdce38f7 Remove check_overflow method from MiscMethods
It can be retrieved from the Session too.
2024-06-21 19:30:26 +00:00
bjorn3 22b32432ca Move all intrinsic handling code in codegen_call_terminators together 2024-06-21 19:30:24 +00:00
bjorn3 e32eb4c9e9 Dedup some intrinsic handling code for caller_location 2024-06-21 19:26:07 +00:00
bjorn3 98e8601ac3 Remove const_bitcast from ConstMethods 2024-06-21 19:26:07 +00:00
bjorn3 7f445329ec Remove PrintBackendInfo trait
It is only implemented for a single type. Directly passing this type is
simpler and avoids overhead from indirect calls.
2024-06-21 19:26:06 +00:00
bjorn3 e9ea578147 Move vcall_visibility_metadata optimization hint out of a debuginfo generation method 2024-06-21 19:26:06 +00:00
bors c1b336cb6b Auto merge of #126650 - compiler-errors:renames, r=lcnr
Rename a bunch of things in the new solver and `rustc_type_ir`

* Renames `interner()` to `cx()` in the solver and `TypeFolder`.
* Renames `Infcx` generic param to `D`
* Moves `infcx.rs` to `delegate.rs`

r? lcnr
2024-06-21 18:14:50 +00:00
beetrees 771e44ebd3
Add `f16` inline ASM support for RISC-V 2024-06-21 18:48:20 +01:00
beetrees 753fb070bb
Add `f16` inline ASM support for 32-bit ARM 2024-06-21 18:26:42 +01:00
Michael Goulet db638ab968 Rename a bunch of things 2024-06-21 12:32:05 -04:00
bors 5ced3dad57 Auto merge of #125853 - tesuji:promote-fail-fast, r=cjgillot
promote_consts: some clean-up after experimenting

This is some clean-up after experimenting in #125916,
Prefer to review commit-by-commit.
2024-06-21 16:00:14 +00:00
Lzu Tao 7002a3f37f interpret: use trace to reduce noice 2024-06-21 13:51:33 +00:00
Lzu Tao 62a287528a Reuse allocation for Vec<Candidate> 2024-06-21 13:51:33 +00:00
bors 25c9f2ca06 Auto merge of #123165 - oli-obk:no_ord_def_id3, r=cjgillot
Stop sorting `Span`s' `SyntaxContext`, as that is incompatible with incremental

work towards https://github.com/rust-lang/rust/issues/90317

Luckily no one actually needed these to be sorted, so it didn't even affect diagnostics. I'm guessing they'd have been sorted by creation time anyway, so it wouldn't really have mattered.

r? `@cjgillot`
2024-06-21 13:47:43 +00:00
Santiago Pastorino 22831ed117
Do not allow safe usafe on static and fn items 2024-06-21 09:12:13 -03:00
Strophox b512bf6f77 add as_ptr to trait AllocBytes, fix 2 impls; add pub fn get_bytes_unchecked_raw in allocation.rs; add pub fn get_alloc_bytes_unchecked_raw[_mut] in memory.rs 2024-06-21 12:50:24 +02:00
Lukas Wirth 339015920d Add `rust_analyzer` as a predefined tool 2024-06-21 12:10:18 +02:00
Deadbeef 02aaea1803 update intrinsic const param counting 2024-06-21 09:23:54 +00:00
bors d40f30e1df Auto merge of #126781 - matthiaskrgr:rollup-5u4pens, r=matthiaskrgr
Rollup of 8 pull requests

Successful merges:

 - #126125 (Improve conflict marker recovery)
 - #126481 (Add `powerpc-unknown-openbsd` maintenance status)
 - #126613 (Print the tested value in int_log tests)
 - #126617 (Expand `avx512_target_feature` to include VEX variants)
 - #126700 (Make edition dependent `:expr` macro fragment act like the edition-dependent `:pat` fragment does)
 - #126707 (Pass target to inaccessible-temp-dir rmake test)
 - #126767 (`StaticForeignItem` and `StaticItem` are the same)
 - #126774 (Fix another assertion failure for some Expect diagnostics.)

r? `@ghost`
`@rustbot` modify labels: rollup
2024-06-21 09:22:09 +00:00
bors e32ea4822b Auto merge of #126541 - scottmcm:more-ptr-metadata-gvn, r=cjgillot
More ptr metadata gvn

There's basically 3 parts to this PR.

1. Allow references as arguments to `UnOp::PtrMetadata`

This is a MIR semantics addition, so
r? mir

Rather than just raw pointers, also allow references to be passed to `PtrMetadata`.  That means the length of a slice can be just `PtrMetadata(_1)` instead of also needing a ref-to-pointer statement (`_2 = &raw *_1` + `PtrMetadata(_2)`).

AFAIK there should be no provenance or tagging implications of looking at the *metadata* of a pointer, and the code in the backends actually already supported it (other than a debug assert, given that they don't care about ptr vs reference, really), so we might as well allow it.

2. Simplify the argument to `PtrMetadata` in GVN

Because the specific kind of pointer-like thing isn't that important, GVN can simplify all those details away.  Things like `*const`-to-`*mut` casts and `&mut`-to-`&` reborrows are irrelevant, and skipping them lets it see more interesting things.

cc `@cjgillot`

Notably, unsizing casts for arrays.  GVN supported that for `Len`, and now it sees it for `PtrMetadata` as well, allowing `PtrMetadata(pointer)` to become a constant if that pointer came from an array-to-slice unsizing, even through a bunch of other possible steps.

3. Replace `NormalizeArrayLen` with GVN

The `NormalizeArrayLen` pass hasn't been running even in optimized builds for well over a year, and it turns out that GVN -- which *is* on in optimized builds -- can do everything it was trying to do.

So the code for the pass is deleted, but the tests are kept, just changed to the different pass.

As part of this, `LowerSliceLen` was changed to emit `PtrMetadata(_1)` instead of `Len(*_1)`, a small step on the road to eventually eliminating `Rvalue::Len`.
2024-06-21 07:12:50 +00:00
Matthias Krüger d86736c9be
Rollup merge of #126774 - nnethercote:fix-126751, r=oli-obk
Fix another assertion failure for some Expect diagnostics.

Very similar to #126719. So much so that I added a new case to the test from that PR rather than creating a new one.

r? `@oli-obk`
2024-06-21 09:12:38 +02:00
Matthias Krüger f577d808b7
Rollup merge of #126767 - compiler-errors:static-foreign-item, r=spastorino
`StaticForeignItem` and `StaticItem` are the same

The struct `StaticItem` and `StaticForeignItem` are the same, so remove `StaticForeignItem`. Having them be separate is unique to `static` items -- unlike `ForeignItemKind::{Fn,TyAlias}`, which use the normal AST item.

r? ``@spastorino`` or ``@oli-obk``
2024-06-21 09:12:37 +02:00
Matthias Krüger 3bd84f18bc
Rollup merge of #126700 - compiler-errors:fragment, r=fmease
Make edition dependent `:expr` macro fragment act like the edition-dependent `:pat` fragment does

Parse the `:expr` fragment as `:expr_2021` in editions <=2021, and as `:expr` in edition 2024. This is similar to how we parse `:pat` as `:pat_param` in edition <=2018 and `:pat_with_or` in >=2021, and means we can get rid of a span dependency from `nonterminal_may_begin_with`.

Specifically, this fixes a theoretical regression since the `expr_2021` macro fragment previously would allow `const {}` if the *caller* is edition 2024. This is inconsistent with the way that the `pat` macro fragment was upgraded, and also leads to surprising behavior when a macro *caller* crate upgrades to edtion 2024, since they may have parsing changes that they never asked for (with no way of opting out of it).

This PR also allows using `expr_2021` in all editions. Why was this was disallowed in the first place? It's purely additive, and also it's still feature gated?

r? ```@fmease``` ```@eholk``` cc ```@vincenzopalazzo```
cc #123865

Tracking:

- https://github.com/rust-lang/rust/issues/123742
2024-06-21 09:12:36 +02:00
Matthias Krüger 2b7f6e274e
Rollup merge of #126617 - sayantn:veorq, r=workingjubilee
Expand `avx512_target_feature` to include VEX variants

Added 5 new target features for x86:

 - `AVX-IFMA`
 - `AVX-NE-CONVERT`
 - `AVX-VNNI`
 - `AVX-VNNI_INT8`
 - `AVX-VNNI_INT16`

Both LLVM and GCC already have support for these.

See also the [stdarch PR](https://github.com/rust-lang/stdarch/pull/1586)
2024-06-21 09:12:35 +02:00
Matthias Krüger 73cc4eca56
Rollup merge of #126125 - dev-ardi:conflict-markers, r=estebank
Improve conflict marker recovery

<!--
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>
-->
closes #113826
r? ```@estebank``` since you reviewed #115413
cc: ```@rben01``` since you opened up the issue in the first place
2024-06-21 09:12:34 +02:00
Adwin White 225796a2df Add method to get `FnAbi` of function pointer 2024-06-21 14:50:56 +08:00
Scott McMurray 55d13379ac [GVN] Add tests for generic pointees with PtrMetadata 2024-06-20 22:16:59 -07:00
Scott McMurray b611b6bbb8 Replace `NormalizeArrayLen` with `GVN`
GVN is actually on in release, and covers all the same things (or more), with `LowerSliceLen` changed to produce `PtrMetadata`.
2024-06-20 22:16:59 -07:00
Scott McMurray 4a7b6c0e6c More GVN for PtrMetadata
`PtrMetadata` doesn't care about `*const`/`*mut`/`&`/`&mut`, so GVN away those casts in its argument.

This includes updating MIR to allow calling PtrMetadata on references too, not just raw pointers.  That means that `[T]::len` can be just `_0 = PtrMetadata(_1)`, for example.

# Conflicts:
#	tests/mir-opt/pre-codegen/slice_index.slice_get_unchecked_mut_range.PreCodegen.after.panic-abort.mir
#	tests/mir-opt/pre-codegen/slice_index.slice_get_unchecked_mut_range.PreCodegen.after.panic-unwind.mir
2024-06-20 22:16:59 -07:00
Scott McMurray 31d8696ac9 Add a try_as_constant+try_as_local helper
No behaviour changes.
2024-06-20 21:40:29 -07:00
Nicholas Nethercote d6efcbb760 Fix another assertion failure for some Expect diagnostics.
Very similar to #126719. So much so that I added a new case to the test
from that PR rather than creating a new one.
2024-06-21 14:29:25 +10:00
bors 4e6de37349 Auto merge of #126757 - compiler-errors:safe, r=spastorino
Properly gate `safe` keyword in pre-expansion

This PR gates `safe` keyword in pre-expansion contexts. Should mitigate the fallout of https://github.com/rust-lang/rust/issues/126755, which is that `safe` is now usable on beta lol.

r? `@spastorino` or `@oli-obk`

cc #124482 tracking #123743
2024-06-21 04:22:02 +00:00
bors 7a08f84627 Auto merge of #126578 - scottmcm:inlining-bonuses-too, r=davidtwco
Account for things that optimize out in inlining costs

This updates the MIR inlining `CostChecker` to have both bonuses and penalties, rather than just penalties.

That lets us add bonuses for some things where we want to encourage inlining without risking wrapping into a gigantic cost.  For example, `switchInt(const …)` we give an inlining bonus because codegen will actually eliminate the branch (and associated dead blocks) once it's monomorphized, so measuring both sides of the branch gives an unrealistically-high cost to it.  Similarly, an `unreachable` terminator gets a small bonus, because whatever branch leads there doesn't actually exist post-codegen.
2024-06-21 02:06:27 +00:00
Michael Goulet 3e59f0c3c5 StaticForeignItem and StaticItem are the same 2024-06-20 19:51:09 -04:00
bors a9c8887c7d Auto merge of #126544 - petrochenkov:upparent, r=cjgillot
rustc_span: Optimize span parent get/set methods

Like https://github.com/rust-lang/rust/pull/125017, but for span parents.

r? `@cjgillot`
2024-06-20 23:35:42 +00:00
León Orell Valerian Liehr bc12972bcd
Slightly refactor the dumping of HIR analysis data 2024-06-20 20:31:32 +02:00