Commit Graph

37385 Commits

Author SHA1 Message Date
Michael Goulet 1160eecba5 supertrait_def_ids was already implemented in middle 2024-06-27 12:29:34 -04:00
Michael Goulet c9870cfa4b supertrait_def_ids 2024-06-27 12:11:09 -04:00
Michael Goulet 81c2c57519 Make queries more explicit 2024-06-27 12:03:57 -04:00
bors 036b38ced3 Auto merge of #126993 - petrochenkov:atvisord3, r=BoxyUwU
ast: Standardize visiting order

Order: ID, attributes, inner nodes in source order if possible, tokens, span.

Also always use exhaustive matching in visiting infra, and visit some discovered missing nodes.

Unlike https://github.com/rust-lang/rust/pull/125741 this shouldn't affect anything serious like `macro_rules` scopes.
2024-06-27 12:25:46 +00:00
Trevor Gross 648cb16920 Enable const casting for `f16` and `f128` 2024-06-27 04:36:29 -05:00
bors 127fa2261b Auto merge of #127014 - jhpratt:rollup-45ic8f5, r=jhpratt
Rollup of 6 pull requests

Successful merges:

 - #126571 (Less `maybe_whole_expr`, take 2)
 - #126721 (coverage: Make `#[coverage(..)]` apply recursively to nested functions)
 - #126928 (Some `Nonterminal` removal precursors)
 - #126929 (Remove `__rust_force_expr`.)
 - #126980 (set self.is_known_utf8 to false in extend_from_slice)
 - #126983 (Remove `f16` and `f128` ICE paths from smir)

r? `@ghost`
`@rustbot` modify labels: rollup
2024-06-27 07:54:44 +00:00
Jacob Pratt 73016dc8a4
Rollup merge of #126983 - tgross35:f16-f128-smir, r=celinval
Remove `f16` and `f128` ICE paths from smir

Just chasing down some possible ICE paths. ```@compiler-errors``` mentioned in https://github.com/rust-lang/rust/pull/121728#discussion_r1506133496 that it is okay not to support these in smir, but this change seems pretty trivial?

r? ```@celinval``` since you reviewed https://github.com/rust-lang/rust/pull/114607#pullrequestreview-1771673591
2024-06-27 02:06:20 -04:00
Jacob Pratt b1f43974c4
Rollup merge of #126928 - nnethercote:124141-pre, r=oli-obk
Some `Nonterminal` removal precursors

Small things to prepare for #124141, more or less.

r? ```@oli-obk```
2024-06-27 02:06:19 -04:00
Jacob Pratt 70b69a2384
Rollup merge of #126721 - Zalathar:nested-cov-attr, r=oli-obk
coverage: Make `#[coverage(..)]` apply recursively to nested functions

This PR makes the (currently-unstable) `#[coverage(off)]` and `#[coverage(on)]` attributes apply recursively to all nested functions/closures, instead of just the function they are directly attached to.

Those attributes can now also be applied to modules and to impl/impl-trait blocks, where they have no direct effect, but will be inherited by all enclosed functions/closures/methods that don't override the inherited value.

---

Fixes #126625.
2024-06-27 02:06:18 -04:00
Jacob Pratt 5ec93b8e36
Rollup merge of #126571 - nnethercote:less-maybe_whole-expr-2, r=petrochenkov
Less `maybe_whole_expr`, take 2

I first tried this in #107550. I now think it's worth doing again, as a precursor to #124141.

r? ```@petrochenkov```
2024-06-27 02:06:18 -04:00
Urgau 0c0dfb88ee Switch back `non_local_definitions` lint to allow-by-default
as request T-lang is requesting some major changes in the lint inner
workings in #126768#issuecomment-2192634762
2024-06-27 08:05:07 +02:00
bors 536235f07e Auto merge of #126907 - glaubitz:sparc-fixes, r=nagisa
Fixes for 32-bit SPARC on Linux

This PR fixes a number of issues which previously prevented `rustc` from being built
successfully for 32-bit SPARC using the `sparc-unknown-linux-gnu` triplet.

In particular, it adds linking against `libatomic` where necessary, uses portable `AtomicU64`
for `rustc_data_structures` and rewrites the spec for `sparc_unknown_linux_gnu` to use
`TargetOptions` and replaces the previously used `-mv8plus` with the more portable
`-mcpu=v9 -m32`.

To make `rustc` build successfully, support for 32-bit SPARC needs to be added to the `object`
crate as well as the `nix` crate which I will be sending out later as well.

r? nagisa
2024-06-27 05:44:47 +00:00
bors 7033f9b14a Auto merge of #123918 - DianQK:clang-format, r=Kobzol
Use `clang-format` in `tidy` to check the C++ code style under `llvm-wrapper`

Fixes #123510.

Based on the discussion at https://rust-lang.zulipchat.com/#narrow/stream/233931-t-compiler.2Fmajor-changes/topic/Enable.20.60clang-format.60.20for.20.60rustc.60.20compiler-team.23756/near/443562800, we can use clang-format from pip to achieve the code formatting.

r? `@Kobzol`
2024-06-27 01:18:56 +00:00
bors 4bc39f028d Auto merge of #120924 - xFrednet:rfc-2383-stabilization-party, r=Urgau,blyxyas
Let's `#[expect]` some lints: Stabilize `lint_reasons` (RFC 2383)

Let's give this another try! The [previous stabilization attempt](https://github.com/rust-lang/rust/pull/99063) was stalled by some unresolved questions. These have been discussed in a [lang team](https://github.com/rust-lang/lang-team/issues/191) meeting. The last open question, regarding the semantics of the `#[expect]` attribute was decided on in https://github.com/rust-lang/rust/issues/115980

I've just updated the [stabilization report](https://github.com/rust-lang/rust/issues/54503#issuecomment-1179563964) with the discussed questions and decisions. Luckily, the decision is inline with the current implementation.

This hopefully covers everything. Let's hope that the CI will be green like the spring.

fixes #115980
fixes #54503

---

r? `@wesleywiser`

Tacking Issue: https://github.com/rust-lang/rust/issues/54503
Stabilization Report: https://github.com/rust-lang/rust/issues/54503#issuecomment-1179563964
Documentation Update: https://github.com/rust-lang/reference/pull/1237

<!--
For Clippy:

changelog: [`allow_attributes`]: Is now available on stable, since the `lint_reasons` feature was stabilized
changelog: [`allow_attributes_without_reason`]: Is now available on stable, since the `lint_reasons` feature was stabilized
-->

---

Roses are red,
Violets are blue,
Let's expect lints,
With reason clues
2024-06-26 16:38:30 +00:00
Urgau 7666534381
Clarify comment on changing to warn future breakage items
https://github.com/rust-lang/rust/pull/120924/files#r1653512240
2024-06-26 17:00:46 +02:00
Vadim Petrochenkov ba3f6812c1 ast: Standardize visiting order
Id, attributes, inner nodes in source order if possible, tokens, span.

Also always use exhaustive matching in visiting infra, and visit some missing nodes.
2024-06-26 17:41:24 +03:00
bors d7c59370ce Auto merge of #126844 - scottmcm:more-ptr-cast-gvn, r=saethlin
Remove more `PtrToPtr` casts in GVN

This addresses two things I noticed in MIR:

1. `NonNull::<T>::eq` does `(a as *mut T) == (b as *mut T)`, but it could just compare the `*const T`s, so this removes `PtrToPtr` casts that are on both sides of a pointer comparison, so long as they're not fat-to-thin casts.

2. `NonNull::<T>::addr` does `transmute::<_, usize>(p as *const ())`, but so long as `T: Thin` that cast doesn't do anything, and thus we can directly transmute the `*const T` instead.

r? mir-opt
2024-06-26 14:22:31 +00:00
DianQK e17c16d55b
Format C++ files in `llvm-wrapper` 2024-06-26 20:18:49 +08:00
Trevor Gross 518b74ec5d Remove `f16` and `f128` ICE paths from smir 2024-06-26 02:56:48 -04:00
Matthias Krüger b2720867f1
Rollup merge of #126973 - chenyukang:yukang-fix-126756-unsafe-suggestion-error, r=spastorino
Fix bad replacement for unsafe extern block suggestion

Fixes #126756

r? ``@spastorino``

link #123743
2024-06-26 07:50:21 +02:00
Matthias Krüger 8c6c6a7591
Rollup merge of #126968 - lqd:issue-126670, r=compiler-errors
Don't ICE during RPITIT refinement checking for resolution errors after normalization

#126670 shows a case where resolution errors after normalization can happen during RPITIT refinement checking. Our tests didn't reach this path before, and we explicitly ICEd until we had a test. We can now delay a bug since we're sure it is reachable and have the test from the isue.

The comment I added likely still needs more expert wordsmithing.

r? ``@compiler-errors`` who's making me work during vacation (j/k).
Fixes #126670
2024-06-26 07:50:20 +02:00
Matthias Krüger 8b3bbee26b
Rollup merge of #126954 - petrochenkov:globamb, r=compiler-errors
resolve: Tweak some naming around import ambiguities
2024-06-26 07:50:19 +02:00
Matthias Krüger 5c4ede88c6
Rollup merge of #126938 - RalfJung:link_section, r=compiler-errors
miri: make sure we can find link_section statics even for the local crate

Miri needs some way to iterate all the exported functions and "used" statics of all crates. For dependency crates, this already works fine since we can overwrite the query resonsible for computing `exported_symbols`, but it turns out for local binary crates this does not work: for binaries, `reachable_set` skips a lot of its logic and only checks `contains_extern_indicator()` and `RUSTC_STD_INTERNAL_SYMBOL`. Other flags like `CodegenFnAttrFlags::USED` are entirely ignored.

This PR proposes to use the same check, `has_custom_linkage`, in binaries that we already use to drive the main workqueue of the reachability recursive traversal. I have no idea why binaries used a slightly different check that ignores `USED` -- was that deliberate or does it just not matter most of the time?
2024-06-26 07:50:19 +02:00
Matthias Krüger 95332b8918
Rollup merge of #126925 - surechen:fix_125631, r=compiler-errors
Change E0369 to give note informations for foreign items.

Change E0369 to give note informations for foreign items.
Make it easy for developers to understand why the binop cannot be applied.

fixes #125631
2024-06-26 07:50:18 +02:00
Matthias Krüger dc22ffc725
Rollup merge of #126812 - compiler-errors:tcx-cx, r=lcnr
Rename `tcx` to `cx` in new solver generic code

self-explanatory, should be last major churn-y rename

r? lcnr
2024-06-26 07:50:17 +02:00
Matthias Krüger dd6b04663e
Rollup merge of #126724 - nnethercote:fix-parse_ty_bare_fn-span, r=compiler-errors
Fix a span in `parse_ty_bare_fn`.

It currently goes one token too far.

Example: line 259 of `tests/ui/abi/compatibility.rs`:
```
test_abi_compatible!(fn_fn, fn(), fn(i32) -> i32);
```
This commit changes the span for the second element from `fn(),` to `fn()`, i.e. removes the extraneous comma.

This doesn't affect any tests. I found it while debugging some other code. Not a big deal but an easy fix so I figure it worth doing.

r? ``@spastorino``
2024-06-26 07:50:16 +02:00
yukang 0addda6578 Fix bad replacement for unsafe extern block suggestion 2024-06-26 08:50:50 +08:00
Zalathar 7f37f8af5f coverage: Allow `#[coverage(..)]` on `impl` and `mod`
These attributes apply to all enclosed functions/methods/closures, unless
explicitly overridden by another coverage attribute.
2024-06-26 10:08:05 +10:00
Zalathar 3262611cc5 coverage: Apply `#[coverage(..)]` recursively to nested functions 2024-06-26 10:08:05 +10:00
Zalathar 457fda1701 coverage: Detach `#[coverage(..)]` from codegen attribute handling 2024-06-26 10:08:05 +10:00
bors 31f8b70d2e Auto merge of #126951 - matthiaskrgr:rollup-xg0o4mc, r=matthiaskrgr
Rollup of 7 pull requests

Successful merges:

 - #126618 (Mark assoc tys live only if the corresponding trait is live)
 - #126746 (Deny `use<>` for RPITITs)
 - #126868 (not use offset when there is not ends with brace)
 - #126884 (Do not ICE when suggesting dereferencing closure arg)
 - #126893 (Eliminate the distinction between PREC_POSTFIX and PREC_PAREN precedence level)
 - #126915 (Don't suggest awaiting in closure patterns)
 - #126943 (De-duplicate all consecutive native libs regardless of their options)

r? `@ghost`
`@rustbot` modify labels: rollup
2024-06-25 23:29:58 +00:00
Nicholas Nethercote cf0251d92c Fix a span in `parse_ty_bare_fn`.
It currently goes one token too far.

Example: line 259 of `tests/ui/abi/compatibility.rs`:
```
test_abi_compatible!(fn_fn, fn(), fn(i32) -> i32);
```
This commit changes the span for the second element from `fn(),` to
`fn()`, i.e. removes the extraneous comma.
2024-06-26 08:23:57 +10:00
Michael Goulet 275d922dab Rename tcx to cx 2024-06-25 17:36:52 -04:00
Rémy Rakic 6402909f42 delay bug in RPITIT refinement checking with resolution errors 2024-06-25 21:05:54 +00:00
xFrednet 1d667a0937
Prevent ICE from expected future breakage 2024-06-25 22:32:46 +02:00
Matthias Krüger 4ebd69c063
Rollup merge of #126947 - Bryanskiy:delegation-lowering-refactoring, r=petrochenkov
Delegation: ast lowering refactor

refactoring changes for https://github.com/rust-lang/rust/pull/126699

r? ```@petrochenkov```
2024-06-25 21:33:45 +02:00
Matthias Krüger 7e1489cf63
Rollup merge of #126932 - Zalathar:flat-pat, r=Nadrieril
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.

---

I've also included some semi-related comments that I made while trying to navigate this code.
2024-06-25 21:33:44 +02:00
Matthias Krüger 6077c0ed9d
Rollup merge of #126926 - Zalathar:candidate-per-arm, r=Nadrieril
Tweak a confusing comment in `create_match_candidates`

This comment was accurate at the time it was written, but various later changes reshuffled things in ways that caused the existing comment to become confusing.

I've therefore tried to clarify that *these* candidates are 1:1 with match arms, while also warning that that isn't the case in general.
2024-06-25 21:33:43 +02:00
Matthias Krüger 58bbade921
Rollup merge of #126302 - mu001999-contrib:ignore/default, r=michaelwoerister
Detect unused structs which derived Default

<!--
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>
-->

Fixes #98871
2024-06-25 21:33:41 +02:00
Florian Schmiderer 7c56398e91 Updated code for changes to RFC, added additional error handling, added
tests
2024-06-25 19:00:02 +02:00
Vadim Petrochenkov b6074fffd1 resolve: Tweak some naming around import ambiguities 2024-06-25 19:52:59 +03:00
Matthew Maurer 9b0ae75ecc Support `#[patchable_function_entries]`
See [RFC](https://github.com/maurer/rust-rfcs/blob/patchable-function-entry/text/0000-patchable-function-entry.md) (yet to be numbered)

TODO before submission:
* Needs an RFC
* Improve error reporting for malformed attributes
2024-06-25 18:23:41 +02:00
Matthew Maurer ac7595fdb1 Support for -Z patchable-function-entry
`-Z patchable-function-entry` works like `-fpatchable-function-entry`
on clang/gcc. The arguments are total nop count and function offset.

See MCP rust-lang/compiler-team#704
2024-06-25 18:21:42 +02:00
xFrednet b124b3666e
`sudo CI=green` && Review changes <3 2024-06-25 18:06:22 +02:00
Matthias Krüger 812b8b42a1
Rollup merge of #126943 - Urgau:dedup-all, r=petrochenkov
De-duplicate all consecutive native libs regardless of their options

Address https://github.com/rust-lang/rust/pull/126913#issuecomment-2188184011 by no longer de-duplicating based on the "options" but by only looking at the generated link args, as to avoid consecutive libs that originated from different native-lib with different options (like `raw-dylib` on Windows) but isn't relevant for `--print=native-static-libs`.

r? ``@petrochenkov``
2024-06-25 18:03:02 +02:00
Matthias Krüger dad39e8840
Rollup merge of #126915 - SparkyPotato:fix-126903, r=compiler-errors
Don't suggest awaiting in closure patterns

Fixes #126903.

For
```rust
async fn do_async() {}

fn main() {
    Some(do_async()).map(|()| {});
}
```
the error is now
```rust
error[E0308]: mismatched types
 --> src/main.rs:4:27
  |
4 |     Some(do_async()).map(|()| {});
  |                           ^^
  |                           |
  |                           expected future, found `()`
  |                           expected due to this
  |
  = note: expected opaque type `impl Future<Output = ()>`
               found unit type `()`
```

Ideally, if `main` were to be `async`, it should be
```rs
error[E0308]: mismatched types
 --> src/main.rs:4:27
  |
4 |     Some(do_async()).map(|()| {});
  |                           ^^
  |                           |
  |                           expected future, found `()`
  |                           expected due to this
  |
  = note: expected opaque type `impl Future<Output = ()>`
               found unit type `()`
help: consider `await`ing on the `Future`
  |
4 |     Some(do_async().await).map(|()| {});
  |                    ++++++
```
However, this would mean `FnCtx::check_pat_top` would have to be called with an `origin_expr` in `rustc_hir_typeck::check::check_fn`, and that expr would have to be somehow plumbed through `FnCtxt::check_expr_closure` and closure signature deduction. I'm willing to work on the plumbing but unsure how to start.
2024-06-25 18:03:01 +02:00
Matthias Krüger 709baaef13
Rollup merge of #126893 - dtolnay:prec, r=compiler-errors
Eliminate the distinction between PREC_POSTFIX and PREC_PAREN precedence level

I have been tangling with precedence as part of porting some pretty-printer improvements from syn back to rustc (related to parenthesization of closures, returns, and breaks by the AST pretty-printer).

As far as I have been able to tell, there is no difference between the 2 different precedence levels that rustc identifies as `PREC_POSTFIX` (field access, square bracket index, question mark, method call) and `PREC_PAREN` (loops, if, paths, literals).

There are a bunch of places that look at either `prec < PREC_POSTFIX` or `prec >= PREC_POSTFIX`. But there is nothing that needs to distinguish PREC_POSTFIX and PREC_PAREN from one another.

d49994b060/compiler/rustc_ast/src/util/parser.rs (L236-L237)

d49994b060/compiler/rustc_hir_typeck/src/fn_ctxt/suggestions.rs (L2829)

d49994b060/compiler/rustc_hir_typeck/src/fn_ctxt/suggestions.rs (L1290)

In the interest of eliminating a distinction without a difference, this PR collapses these 2 levels down to 1.

There is exactly 1 case where an expression with PREC_POSTFIX precedence needs to be parenthesized in a location that an expression with PREC_PAREN would not, and that's when the receiver of ExprKind::MethodCall is ExprKind::Field. `x.f()` means a different thing than `(x.f)()`. But this does not justify having separate precedence levels because this special case in the grammar is not governed by precedence. Field access does not have "lower precedence than" method call syntax &mdash; you can tell because if it did, then `x.f[0].f()` wouldn't be able to have its unparenthesized field access in the receiver of a method call. Because this Field/MethodCall special case is not governed by precedence, it already requires special handling and is not affected by eliminating the PREC_POSTFIX precedence level.

d49994b060/compiler/rustc_ast_pretty/src/pprust/state/expr.rs (L217-L221)
2024-06-25 18:03:00 +02:00
Matthias Krüger 175756f683
Rollup merge of #126884 - estebank:issue-125634, r=Nadrieril
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-25 18:03:00 +02:00
Matthias Krüger 52e6f9ce96
Rollup merge of #126868 - bvanjoi:fix-126764, r=davidtwco
not use offset when there is not ends with brace

Fixes #126764
2024-06-25 18:02:59 +02:00
Matthias Krüger 8b72058985
Rollup merge of #126746 - compiler-errors:no-rpitit, r=oli-obk
Deny `use<>` for RPITITs

Precise capturing `use<>` syntax is currently a no-op on RPITITs, since GATs have no variance, so all captured lifetimes are captured invariantly.

We don't currently *need* to support `use<>` on RPITITs, since `use<>` is initially intended for migrating RPIT *overcaptures* from edition 2021->2024, but since RPITITs currently capture all in-scope lifetimes, we'll never need to write `use<>` on an RPITIT.

Eventually, though, it would be desirable to support precise capturing on RPITITs, since RPITITs overcapturing by default can be annoying to some folks. But let's separate that (which will likely require some delicate types team work for adding variances to GATs and adjusting the refinement rules) from the stabilization of the feature for edition 2024.

r? oli-obk cc ``@traviscross``

Tracking:

- https://github.com/rust-lang/rust/issues/123432
2024-06-25 18:02:58 +02:00
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