Commit graph

14852 commits

Author SHA1 Message Date
bjorn3
401dd840ff Remove all threading through of ErrorGuaranteed from the driver
It was inconsistently done (sometimes even within a single function) and
most of the rest of the compiler uses fatal errors instead, which need
to be caught using catch_with_exit_code anyway. Using fatal errors
instead of ErrorGuaranteed everywhere in the driver simplifies things a
bit.
2024-12-06 18:42:31 +00:00
bors
8dc83770f7 Auto merge of #133089 - eholk:stabilize-noop-waker, r=dtolnay
Stabilize noop_waker

Tracking Issue: #98286

This is a handy feature that's been used widely in tests and example async code and it'd be nice to make it available to users.

cc `@rust-lang/wg-async`
2024-12-06 18:34:16 +00:00
Oli Scherer
060cecba1a Hide errors whose suggestions would contain error constants or types 2024-12-06 10:50:20 +00:00
Oli Scherer
cb72b9bb37 Silence follow-up errors from lit_to_const 2024-12-06 10:50:20 +00:00
Matthias Krüger
820ddaf67a
Rollup merge of #130777 - azhogin:azhogin/reg-struct-return, r=workingjubilee
rust_for_linux: -Zreg-struct-return commandline flag for X86 (#116973)

Command line flag `-Zreg-struct-return` for X86 (32-bit) for rust-for-linux.
This flag enables the same behavior as the `abi_return_struct_as_int` target spec key.

- Tracking issue: https://github.com/rust-lang/rust/issues/116973
2024-12-06 09:27:38 +01:00
bors
acf48426b6 Auto merge of #133559 - compiler-errors:structurally-resolve-adjust-for-branch, r=lcnr
Structurally resolve in `adjust_for_branches`

r? lcnr
2024-12-06 04:55:35 +00:00
Jack Wrenn
a122dde217 do not implement unsafe auto traits for types with unsafe fields
If a type has unsafe fields, its safety invariants are not simply
the conjunction of its field types' safety invariants. Consequently,
it's invalid to reason about the safety properties of these types
in a purely structural manner — i.e., the manner in which `auto`
traits are implemented.

Makes progress towards #132922.
2024-12-05 23:52:21 +00:00
Guillaume Gomez
beb9b240f1
Rollup merge of #133921 - TimNN:nuw-infer, r=nikic
Adapt codegen tests for NUW inference

These were broken by 462cb3cd6c

Let me know if you think we should have a FIXME / tracking issue to update the tests after the LLVM 20 upgrade to make these required.

`@rustbot` label: +llvm-main

r? `@nikic`
2024-12-05 23:47:12 +01:00
Guillaume Gomez
e82ee9626e
Rollup merge of #133910 - TimNN:llvm-target-cpus, r=jieyouxu
Normalize target-cpus.rs stdout test for LLVM changes

LLVM has recently added support for the `lime1` CPU in 35cce408ee, so the `target-cpus.rs` test currently produces different output depending on the LLVM version.

This CL adds a normalization directive, to remove the new CPU from the output list.

Alternatives fixes I can think of:

* Add two revisions of the test (one per LLVM version)
* Ignore the test on one of the LLVM versions
  * I dislike this, because it's possible that the test won't get updated for the next LLVM version.

I don't think the exact list of target CPUs is relevant for this test, so it shouldn't be too bad if the normalization sticks around longer than necessary.

`@rustbot` label: +llvm-main
2024-12-05 23:47:12 +01:00
Guillaume Gomez
5a9c9ef541
Rollup merge of #133821 - Kobzol:replace-black-with-ruff, r=onur-ozkan
Replace black with ruff in `tidy`

`ruff` can both lint and format Python code (in fact, it should be a mostly drop-in replacement for `black` in terms of formatting), so it's not needed to use `black` anymore. This PR removes `black` and replaces it with `ruff`, to get rid of one Python dependency, and also to make Python formatting faster (although that's a small thing).

If we decide to merge this, we'll need to "reformat the world" - `ruff` is not perfectly compatible with `black`, and it also looks like `black` was actually ignoring some files before. I tried it locally (`./x test tidy --extra-checks=py:fmt --bless`) and it also reformatted some code in subtrees (e.g. `clippy` or `rustc_codegen_gcc`) - I'm not sure how to handle that.
2024-12-05 23:47:11 +01:00
Guillaume Gomez
e941e73368
Rollup merge of #133607 - WaffleLapkin:tail-call-checks, r=compiler-errors
implement checks for tail calls

Quoting the [RFC draft](https://github.com/phi-go/rfcs/blob/guaranteed-tco/text/0000-explicit-tail-calls.md):

> The argument to become is a function (or method) call, that exactly matches the function signature and calling convention of the callee. The intent is to ensure a matching ABI. Note that lifetimes may differ as long as they pass borrow checking, see [below](https://github.com/phi-go/rfcs/blob/guaranteed-tco/text/0000-explicit-tail-calls.md#return-type-coercion) for specifics on the return type.

> Tail calling closures and tail calling from closures is not allowed. This is due to the high implementation effort, see below, this restriction can be lifted by a future RFC.

> Invocations of operators were considered as valid targets but were rejected on grounds of being too error-prone. In any case, these can still be called as methods.

> Tail calling [variadic functions](https://doc.rust-lang.org/beta/unstable-book/language-features/c-variadic.html) and tail calling from variadic functions is not allowed. As support for variadic function is stabilized on a per target level, support for tail-calls regarding variadic functions would need to follow a similar approach. To avoid this complexity and to minimize implementation effort for backends, this interaction is currently not allowed but support can be added with a future RFC.

-----

The checks are implemented as a query, similarly to `check_unsafety`.

The code is cherry-picked straight out of #112657 which was written more than a year ago, so I expect we might need to change some things ^^"
2024-12-05 23:47:10 +01:00
Eric Holk
72ce1ab42f
Stabilize noop_waker
Co-authored-by: zachs18 <8355914+zachs18@users.noreply.github.com>
2024-12-05 14:14:17 -08:00
Guillaume Gomez
854ebe7522 Update GUI test after rebase 2024-12-05 22:50:21 +01:00
Guillaume Gomez
90feb9a645 Improve positioning of "..." in collapsed impl block 2024-12-05 22:50:21 +01:00
Guillaume Gomez
abcd094c51 Update GUI tests 2024-12-05 22:50:21 +01:00
Guillaume Gomez
5d26accecd Add GUI test for impl block doc display 2024-12-05 22:50:21 +01:00
Elias Holzmann
31a5657109 Access members of FormattingOptions directly instead of via getters/setters 2024-12-05 21:48:36 +01:00
Elias Holzmann
a282d5d30e Fixed funky_arms (broken mir-opt test due to refactoring fmt::FormattingOptions) 2024-12-05 21:48:35 +01:00
Elias Holzmann
914ab31646 Fixed mir-opt test broken because of std::Formatter changes 2024-12-05 21:48:35 +01:00
Tim Neumann
8f0ea9a7be Adapt codegen tests for NUW inference 2024-12-05 16:08:41 +01:00
Tim Neumann
9aa4be0499 Normalize target-cpus.rs stdout test for LLVM changes 2024-12-05 15:37:56 +01:00
bors
0e98766a54 Auto merge of #133893 - fmease:rollup-11pi6fg, r=fmease
Rollup of 10 pull requests

Successful merges:

 - #118833 (Add lint against function pointer comparisons)
 - #122161 (Fix suggestion when shorthand `self` has erroneous type)
 - #133233 (Add context to "const in pattern" errors)
 - #133761 (Update books)
 - #133843 (Do not emit empty suggestion)
 - #133863 (Rename `core_pattern_type` and `core_pattern_types` lib feature  gates to `pattern_type_macro`)
 - #133872 (No need to create placeholders for GAT args in confirm_object_candidate)
 - #133874 (`fn_sig_for_fn_abi` should return a `ty::FnSig`, no need for a binder)
 - #133890 (Add a new test ui/incoherent-inherent-impls/no-other-unrelated-errors to check E0116 does not cause unrelated errors)
 - #133892 (Revert #133817)

r? `@ghost`
`@rustbot` modify labels: rollup
2024-12-05 07:08:49 +00:00
León Orell Valerian Liehr
37c6b55254
Rollup merge of #133890 - kei519:fix-125814, r=compiler-errors
Add a new test ui/incoherent-inherent-impls/no-other-unrelated-errors to check E0116 does not cause unrelated errors

rustc xxx (we do not know) to 1.82.0 emits unrelated errors when E0116 is present (see #125814).

We do not know what caused and fixed it, but add a test to confirm rustc does not cause the same error in the future.
2024-12-05 07:29:58 +01:00
León Orell Valerian Liehr
44174d9213
Rollup merge of #133863 - oli-obk:push-pystoxvtvssx, r=lqd
Rename `core_pattern_type` and `core_pattern_types` lib feature  gates to `pattern_type_macro`

That's what the gates are actually gating, and the single char difference in naming was not helpful either

fixes #128987
2024-12-05 07:29:56 +01:00
León Orell Valerian Liehr
ab16eeba5c
Rollup merge of #133843 - estebank:empty-semi-sugg, r=jieyouxu
Do not emit empty suggestion

The `println!();` statement's span doesn't include the `;`, and the modified suggestions where trying to get the `;` by getting the differenece between the statement's and the expression's spans, which was an empty suggestion.

Fix #133833, fix #133834.
2024-12-05 07:29:56 +01:00
León Orell Valerian Liehr
626db06409
Rollup merge of #133233 - estebank:const-errors, r=Nadrieril
Add context to "const in pattern" errors

*Each commit addresses specific diagnostics.*

- Add primary span labels
- Point at `const` item, and `const` generic param definition
- Reword messages and notes
- Point at generic param through which an associated `const` is being referenced
- Silence const in pattern with evaluation errors when they come from `const` items that already emit a diagnostic
- On non-structural type in const used as pattern, point at the type that should derive `PartialEq`
2024-12-05 07:29:54 +01:00
León Orell Valerian Liehr
bc13c82e6e
Rollup merge of #122161 - compiler-errors:shorthand-self, r=fmease
Fix suggestion when shorthand `self` has erroneous type

Fixes #122086

r? estebank
2024-12-05 07:29:54 +01:00
León Orell Valerian Liehr
35ea48d588
Rollup merge of #118833 - Urgau:lint_function_pointer_comparisons, r=cjgillot
Add lint against function pointer comparisons

This is kind of a follow-up to https://github.com/rust-lang/rust/pull/117758 where we added a lint against wide pointer comparisons for being ambiguous and unreliable; well function pointer comparisons are also unreliable. We should IMO follow a similar logic and warn people about it.

-----

## `unpredictable_function_pointer_comparisons`

*warn-by-default*

The `unpredictable_function_pointer_comparisons` lint checks comparison of function pointer as the operands.

### Example

```rust
fn foo() {}
let a = foo as fn();

let _ = a == foo;
```

### Explanation

Function pointers comparisons do not produce meaningful result since they are never guaranteed to be unique and could vary between different code generation units. Furthermore different function could have the same address after being merged together.

----

This PR also uplift the very similar `clippy::fn_address_comparisons` lint, which only linted on if one of the operand was an `ty::FnDef` while this PR lints proposes to lint on all `ty::FnPtr` and `ty::FnDef`.

```@rustbot``` labels +I-lang-nominated

~~Edit: Blocked on https://github.com/rust-lang/libs-team/issues/323 being accepted and it's follow-up pr~~
2024-12-05 07:29:53 +01:00
bors
5a0a5e6db9 Auto merge of #133828 - compiler-errors:incr-sad, r=lcnr
Make sure to record deps from cached task in new solver on first run

We weren't actually performing a read of the dep node in `with_cached_task` in the new solver, which meant that all queries that computed a goal for the first time were just not recording the query dependencies that we call in that query.

In the incremental test, the typeck query for `fn poll` isn't being marked red even tho it's invalidated due to its writeback results changing. This happens b/c we normalize `Self::Error` into `Error`, which should call `type_of` which is a red query (since `ty::Adt` contains an `AdtDef`, and that `AdtDef`'s stable hash changes since it's ). However, since we weren't tracking deps in that normalize query, the typeck result was remaining green, and we were trying to decode a def id that no longer exists (the field that got removed).

r? lcnr
2024-12-05 04:16:03 +00:00
kei519
892d5850fb Add a new test ui/incoherent-inherent-impls/no-other-unrelated-errors to check E0116 does not cause unrelated errors
rustc xxx (we do not know) to 1.82.0 emits unrelated errors when E0116
is present (see #125814).

We do not know what caused and fixed it, but add a test to confirm rustc
does not cause the same error in the future.
2024-12-05 13:06:34 +09:00
Michael Goulet
0cf93703a5 Resolve more 2024-12-05 00:56:04 +00:00
Jakub Beránek
536516f949
Reformat Python code with ruff 2024-12-04 23:03:44 +01:00
Esteban Küber
4e6a401b22 review comments: reword messages and simplify logic 2024-12-04 20:49:05 +00:00
Esteban Küber
da58406c73 fix test 2024-12-04 20:29:36 +00:00
Esteban Küber
d136b3108d Add more context to fall-through "const pattern of non-structural type" error
Point at types that need to be marked with `#[derive(PartialEq)]`.

We use a visitor to look at a type that isn't structural, looking for all ADTs that don't derive `PartialEq`. These can either be manual `impl PartialEq`s or no `impl` at all, so we differentiate between those two cases to provide more context to the user. We also only point at types and impls from the local crate, otherwise show only a note.

```
error: constant of non-structural type `&[B]` in a pattern
  --> $DIR/issue-61188-match-slice-forbidden-without-eq.rs:15:9
   |
LL | struct B(i32);
   | -------- must be annotated with `#[derive(PartialEq)]` to be usable in patterns
LL |
LL | const A: &[B] = &[];
   | ------------- constant defined here
...
LL |         A => (),
   |         ^ constant of non-structural type
   |
   = note: see https://doc.rust-lang.org/stable/std/marker/trait.StructuralPartialEq.html for details
```
2024-12-04 20:29:36 +00:00
Esteban Küber
27a1880593 Add context to fall-through "const pattern of non-structural type" error
Unify wording with the regular non-structural type error.
2024-12-04 20:29:36 +00:00
Esteban Küber
335d05aee5 Add additional context for non-sructural type constant used in pattern
- Point at type that should derive `PartialEq` to be structural.
- Point at manual `impl PartialEq`, explaining that it is not sufficient to be structural.

```
error: constant of non-structural type `MyType` in a pattern
  --> $DIR/const-partial_eq-fallback-ice.rs:14:12
   |
LL | struct MyType;
   | ------------- `MyType` must be annotated with `#[derive(PartialEq)]` to be usable in patterns
...
LL | const CONSTANT: &&MyType = &&MyType;
   | ------------------------ constant defined here
...
LL |     if let CONSTANT = &&MyType {
   |            ^^^^^^^^ constant of non-structural type
   |
note: the `PartialEq` trait must be derived, manual `impl`s are not sufficient; see https://doc.rust-lang.org/stable/std/marker/trait.StructuralPartialEq.html for details
  --> $DIR/const-partial_eq-fallback-ice.rs:5:1
   |
LL | impl PartialEq<usize> for MyType {
   | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
```
2024-12-04 20:29:36 +00:00
Esteban Küber
fb2f6a44c0 Reword message for non-structural type constant in pattern 2024-12-04 20:29:36 +00:00
Esteban Küber
a6040bc230 Specify type kind of constant that can't be used in patterns
```
error: trait object `dyn Send` cannot be used in patterns
  --> $DIR/issue-70972-dyn-trait.rs:6:9
   |
LL | const F: &'static dyn Send = &7u32;
   | -------------------------- constant defined here
...
LL |         F => panic!(),
   |         ^ trait object can't be used in patterns
```
2024-12-04 20:29:36 +00:00
Esteban Küber
253eb95d45 Tweak output of some const pattern errors
- Add primary span labels.
- Point at const generic parameter used as pattern.
- Point at statics used as pattern.
- Point at let bindings used in const pattern.
2024-12-04 20:29:36 +00:00
Esteban Küber
87ddc1ea33 Point at generic param through which a const is used in a pattern
```
error[E0158]: constant pattern depends on a generic parameter, which is not allowed
  --> $DIR/associated-const-type-parameter-pattern.rs:20:9
   |
LL | pub trait Foo {
   | -------------
LL |     const X: EFoo;
   |     ------------- constant defined here
...
LL | pub fn test<A: Foo, B: Foo>(arg: EFoo) {
   |             - constant depends on this generic param
LL |     match arg {
LL |         A::X => println!("A::X"),
   |         ^^^^ `const` depends on a generic parameter
```
2024-12-04 20:29:36 +00:00
Esteban Küber
c0f00086f8 Tweak ptr in pattern error
Conform to error style guide.
2024-12-04 20:29:36 +00:00
Esteban Küber
cc492edc9d Tweak unevaluated constant in pattern error
Silence errors that are implied by the errors in the `const` item definition.

Add a primary span label.
2024-12-04 20:29:35 +00:00
Esteban Küber
c6205055e0 On const pattern errors, point at the const item definition
Centralize emitting an error in `const_to_pat` so that all errors from that evaluating a `const` in a pattern can add addditional information. With this, now point at the `const` item's definition:

```
error[E0158]: constant pattern depends on a generic parameter
  --> $DIR/associated-const-type-parameter-pattern.rs:20:9
   |
LL | pub trait Foo {
   | -------------
LL |     const X: EFoo;
   |     ------------- constant defined here
...
LL |         A::X => println!("A::X"),
   |         ^^^^
```
2024-12-04 20:29:35 +00:00
Michael Goulet
05c34cc5ed Fix suggestion when shorthand self has erroneous type 2024-12-04 19:52:53 +00:00
Esteban Küber
1b449e123d Do not emit empty suggestion
The `println!();` statement's span doesn't include the `;`, and the modified suggestions where trying to get the `;` by getting the differenece between the statement's and the expression's spans, which was an empty suggestion.

Fix #133833, fix #133834.
2024-12-04 17:40:39 +00:00
Matthias Krüger
ea4e7192ac
Rollup merge of #133850 - oli-obk:push-xryukktpyooq, r=compiler-errors
Avoid `opaque type not constrained` errors in the presence of other errors

pulled out of https://github.com/rust-lang/rust/pull/128440

These errors carry no new information if the opaque type was actually used in a constraining (but erroneous) way somewhere.
2024-12-04 18:23:43 +01:00
Matthias Krüger
553db5faee
Rollup merge of #133849 - Zalathar:replay, r=oli-obk
coverage: Use a separate counter type and simplification step during counter creation

When instrumenting a function's MIR for coverage, there is a point where we need to decide, for each node in the control-flow graph, whether its execution count will be tracked by a physical counter, or by an expression that combines physical counters from other parts of the graph.

Currently the code for doing that is heavily tied to the final form of the LLVM coverage mapping format, and performs some important simplification steps on-the-fly. These factors make the code extremely difficult to modify without breaking or massively worsening the resulting coverage-instrumentation metadata.

---

This PR aims to improve that situation somewhat by adding an extra intermediate representation between the code that chooses how each node will be counted, and the code that converts those decisions into actual tables of physical counters and trees of counter expressions.

As part of doing that, some of the simplifications that are currently performed during the main counter creation step have been pulled out into a separate step.

In most cases the resulting coverage metadata is equivalent, slightly better, or slightly worse. The biggest outlier is `counters.rs`, where the coverage metadata ends up about 10% larger. This seems to be the result of the new approach having less subexpression sharing (because it relies on flatten-sort-cancel), and therefore being less effective at taking advantage of MIR optimizations to replace counters for unused control-flow with zeroes. I think the modest downside is acceptable in light of the future possibilities opened up by this decoupling.
2024-12-04 18:23:42 +01:00
Matthias Krüger
e6d7ab2c3c
Rollup merge of #133831 - BoxyUwU:ice_on_unfed_type_of, r=compiler-errors
Don't try and handle unfed `type_of` on anon consts

The `type_of` query for anon consts in the type system is actually implemented by feeding the return value during hir ty lowering, not the hir-based logic in `const_arg_anon_type_of`. The HIR based logic is incomplete (doesn't handle all hir nodes) and also generally wrong to call (re-lowers HIR or invokes typeck which can result in query cycles).

r? `@compiler-errors`
2024-12-04 18:23:39 +01:00
Matthias Krüger
4b2d68dc3d
Rollup merge of #133774 - dingxiangfei2009:translatable-coerce-pointee-errors, r=jieyouxu
Make CoercePointee errors translatable

Tracked by #123430

Just in case that a translatable error message would become a blocker to stabilization, this PR switches over to fluent error messages, which also slightly improve the wordings and use more accurate span information.

cc `@Darksonn` `@traviscross`
2024-12-04 18:23:37 +01:00