Commit Graph

549 Commits

Author SHA1 Message Date
Matthias Krüger 48caf81484 Rollup merge of #138084 - nnethercote:workspace-lints, r=jieyouxu
Use workspace lints for crates in `compiler/`

This is nicer and hopefully less error prone than specifying lints via bootstrap.

r? ``@jieyouxu``
2025-03-09 10:34:50 +01:00
Nicholas Nethercote 8a3e03392e Remove #![warn(unreachable_pub)] from all compiler/ crates.
(Except for `rustc_codegen_cranelift`.)

It's no longer necessary now that `unreachable_pub` is in the workspace
lints.
2025-03-08 08:41:43 +11:00
Matthias Krüger acc7de6c77 Rollup merge of #138111 - estebank:use-dfv, r=nnethercote
Use `default_field_values` for `rustc_errors::Context`, `rustc_session::config::NextSolverConfig` and `rustc_session::config::ErrorOutputType`

Wanted to see  where `#![feature(default_field_values)]` could be used in the codebase. These three seemed like no-brainers. There are a bunch of more places where we could remove manual `Default` impls, but they `derive` other traits that rely on `syn`, which [doesn't yet support `default_field_values`](https://github.com/dtolnay/syn/issues/1774).
2025-03-07 10:12:48 +01:00
Michael Goulet ca9f615525 Rollup merge of #137303 - compiler-errors:maybe-forgor, r=cjgillot
Remove `MaybeForgetReturn` suggestion

#115196 implemented a suggestion to add a missing `return` when there is an ambiguity error, when that ambiguity error could be constrained by the return type of the function.

I initially reviewed it and thought it could be useful; however, looking back at that code now, I feel like it's a bit too much of a hack to be worth keeping around in typeck, especially given how rare it's expected to fire in practice. This is especially true because it depends on `StashKey::MaybeForgetReturn`, which is only stashed when we have *Sized* obligation ambiguity errors. Let's remove it for now.

I'd like to note that it's basically impossible to get this suggestion to apply in its current state except for what I'd consider somewhat artificial examples, involving no generic trait bounds. For example, it's not triggered for:

```rust
struct W<T>(T);

fn bar<T: Default>() -> W<T> { todo!() }

fn foo() -> W<i32> {
    if true {
        bar();
    }
    W(0)
}
```

Nor is it triggered for:

```
fn foo() -> i32 {
    if true {
        Default::default();
    }
    0
}
```

It's basically only triggered iff there's only one ambiguity error on the type, which is `Sized`.

Generally, suggesting something that affects control flow is a pretty dramatic suggestion; therefore, both the accuracy and precision of this diagnostic should be pretty high.

One other, somewhat unrelated observation is that this might be using stashed diagnostics incorrectly (or at least unnecessarily). Stashed diagnostics are used when error detection is fragmented over several major stages of the compiler, like a parse or resolver error which later can be recovered in typeck. However, this one is a bit different since it is fully handled within typeck -- perhaps that suggests that if this were to be reimplemented, it wouldn't need to be so complicated of an implementation.
2025-03-06 12:22:10 -05:00
Esteban Küber 2a4204bf6c Use default field values in markdown::parse::Context 2025-03-03 20:04:20 +00:00
bendn c39f33baae stabilize extract_if 2025-02-23 21:11:12 +07:00
Michael Goulet 9323ba54d3 Remove MaybeForgetReturn suggestion 2025-02-22 00:04:26 +00:00
Michael Goulet 160905b625 Trim suggestion part before generating highlights 2025-02-21 00:54:01 +00:00
Michael Goulet 0a7ab1d6df More sophisticated span trimming 2025-02-21 00:41:17 +00:00
Ben Kimock 4cf21866e8 Move hashes from rustc_data_structure to rustc_hashes so they can be shared with rust-analyzer 2025-02-16 16:18:30 -05:00
Michael Goulet 6d71251cf9 Trim suggestion parts to the subset that is purely additive 2025-02-14 00:44:10 -08:00
Michael Goulet f6406dfd4e Consider add-prefix replacements too 2025-02-14 00:27:17 -08:00
Michael Goulet b480a9214a Use underline suggestions for purely 'additive' replacements 2025-02-14 00:27:13 -08:00
bjorn3 8a0adec05b Avoid manually producing FatalError in a couple of places 2025-02-06 17:29:15 +00:00
Matthias Krüger f1bdf3ba4a Rollup merge of #136445 - bjorn3:diag_ctxt_cleanup, r=oli-obk
Couple of cleanups to DiagCtxt and EarlyDiagCtxt
2025-02-02 23:06:57 +01:00
bjorn3 6a566ee092 Replace ParseSess::set_dcx with DiagCtxt::set_emitter
Replacing the error emitter doesn't accidentally clear the error count.
2025-02-02 16:09:39 +00:00
bjorn3 6556147d15 Use fallback fluent bundle from inner emitter in SilentEmitter 2025-02-02 16:06:43 +00:00
bjorn3 aa2b870bb5 Slightly simplify DiagCtxt::make_silent 2025-02-02 16:06:43 +00:00
Esteban Küber 8e9422f94e Make comma separated lists of anything easier to make for errors
Provide a new function `listify`, meant to be used in cases similar to `pluralize!`. When you have a slice of arbitrary elements that need to be presented to the user, `listify` allows you to turn that into a list of comma separated strings.

This reduces a lot of redundant logic that happens often in diagnostics.
2025-01-31 20:36:44 +00:00
Yotam Ofek 1951d86a35 Manual cleanup of some is_{or_none|some_and} usages 2025-01-19 20:50:43 +00:00
Yotam Ofek 264fa0fc54 Run clippy --fix for unnecessary_map_or lint 2025-01-19 19:15:00 +00:00
Michael Goulet 85c9ce6d79 Remove a bunch of diagnostic stashing that doesn't do anything 2025-01-11 19:22:06 +00:00
The 8472 fe521506a6 update uses of extract_if in the compiler 2024-12-16 22:06:52 +01:00
Matthias Krüger 2ced8b31c7 Rollup merge of #134187 - nnethercote:rm-PErr, r=jieyouxu
Remove `PErr`.

It's just a synonym for `Diag` that adds no value and is only used in a few places.

r? ``@spastorino``
2024-12-12 08:07:05 +01:00
Matthias Krüger 1d784225f1 Rollup merge of #134154 - dev-ardi:field-expr-generics, r=compiler-errors
suppress field expr with generics error message if it's a method

Don't emit "field expressions may not have generic arguments" if it's a method call without `()`

r? estebank
Fixes #67680

Is this the best way to go? It's by far the simplest I could come up with.
2024-12-12 08:07:02 +01:00
Nicholas Nethercote 40c964510c Remove PErr.
It's just a synonym for `Diag` that adds no value and is only used in a
few places.
2024-12-12 11:31:55 +11:00
Orion Gonzalez 014363e89e Don't emit "field expressions may not have generic arguments" if it's a method call without () 2024-12-11 16:23:04 +01:00
Orion Gonzalez 55806e5655 document check_expr_field 2024-12-11 13:48:50 +01:00
bjorn3 618d4c3eeb Handle unwinding out of the closure argument of run_compiler with pending delayed bugs 2024-12-06 18:42:31 +00:00
bjorn3 030545d8c3 Store a single copy of the error registry in DiagCtxt
And pass this to the individual emitters when necessary.
2024-12-06 18:42:31 +00:00
Rémy Rakic c6659251c9 clarify must_produce_diag ICE for debugging 2024-11-12 11:21:43 +00:00
Matthias Krüger df61a0b1b2 Rollup merge of #131344 - nnethercote:ref-Lrc, r=compiler-errors
Avoid `&Lrc<T>` in various places

Seeing `&Lrc<T>` is a bit suspicious, and `&T` or `Lrc<T>` is often better.

r? `@oli-obk`
2024-10-07 12:23:54 +02:00
Nicholas Nethercote 731469fee5 Convert Option<&Lrc<T>> return types to Option<&T>.
It's simpler and more concise.
2024-10-07 13:56:29 +11:00
Nicholas Nethercote 25d1ef1993 Remove InferCtxt::err_count_on_creation.
It's no longer used meaningfully.

This also means `DiagCtxtHandle::err_count_excluding_lint_errs` can be
removed.
2024-10-07 09:50:50 +11:00
Michael Goulet c682aa162b Reformat using the new identifier sorting from rustfmt 2024-09-22 19:11:29 -04:00
Lieselotte db09345ef6 Add suggestions for expressions in patterns 2024-09-18 20:38:43 +02:00
Veera 741005792e Implement a Method to Seal DiagInner's Suggestions 2024-09-12 21:27:44 -04:00
Camille GILLOT 6dfc4033be Do not ICE on expect(warnings). 2024-09-07 01:34:59 +00:00
Camille GILLOT 94f8347bae Check AttrId for expectations. 2024-09-06 20:51:06 +00:00
Matthias Krüger cfb12716e9 Rollup merge of #129875 - Sajjon:sajjon_fix_typos_batch_1, r=compiler-errors,jieyouxu
chore: Fix typos in 'compiler' (batch 1)

Batch 1/3: Fixes typos in `compiler`

(See [issue](https://github.com/rust-lang/rust/issues/129874) tracking all PRs with typos fixes)
2024-09-02 22:35:20 +02:00
Alexander Cyon ac69544a17 chore: Fix typos in 'compiler' (batch 1) 2024-09-02 07:42:38 +02:00
Camille GILLOT 5f1f45b095 Remove attr_id from stable lint ids. 2024-08-31 14:01:07 +00:00
Camille GILLOT 4928b22fa8 Use AttrId key for unstable<->stable expectation map. 2024-08-31 13:58:01 +00:00
Nicholas Nethercote 5fd503ab44 Add warn(unreachable_pub) to rustc_errors. 2024-08-27 12:03:37 +10:00
Jaic1 8557b56ec7 Add | to make the html doc of Level rendered correctly 2024-08-14 13:38:03 +08:00
Guillaume Gomez 7c6dca9050 Rollup merge of #128978 - compiler-errors:assert-matches, r=jieyouxu
Use `assert_matches` around the compiler more

It's a useful assertion, especially since it actually prints out the LHS.
2024-08-12 17:09:19 +02:00
Michael Goulet c361c924a0 Use assert_matches around the compiler 2024-08-11 12:25:39 -04:00
León Orell Valerian Liehr c4c518d2d4 Use more slice patterns inside the compiler 2024-08-07 13:37:52 +02:00
Esteban Küber 8ce8c42e0b Do not underline suggestions for code that is already there
When a suggestion part is for already present code, do not highlight it. If after that there are no highlights left, do not show the suggestion at all.

Fix clippy lint suggestion incorrectly treated as `span_help`.
2024-08-01 18:53:42 +00:00
Nicholas Nethercote 84ac80f192 Reformat use declarations.
The previous commit updated `rustfmt.toml` appropriately. This commit is
the outcome of running `x fmt --all` with the new formatting options.
2024-07-29 08:26:52 +10:00