Commit graph

37240 commits

Author SHA1 Message Date
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
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
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
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
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
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 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
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
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
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
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
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