about summary refs log tree commit diff
path: root/compiler/rustc_borrowck/src/diagnostics
AgeCommit message (Collapse)AuthorLines
2024-03-15Rollup merge of #122513 - petrochenkov:somehir4, r=fmeaseGuillaume Gomez-10/+4
hir: Remove `opt_local_def_id_to_hir_id` and `opt_hir_node_by_def_id` Also replace a few `hir_node()` calls with `hir_node_by_def_id()`. Follow up to https://github.com/rust-lang/rust/pull/120943.
2024-03-15Rollup merge of #122468 - beepster4096:borrowck_prefixes_cleanup, r=NadrierilGuillaume Gomez-20/+7
Cleanup `MirBorrowckCtxt::prefixes` Some of the uses of this method aren't necessary anymore and `PrefixSet::Supporting` is not used anywhere. With `PrefixSet::Supporting` removed, this could technically be moved to an extension trait on `PlaceRef`. However, it would have to be moved back to `MirBorrowckCtxt` when the `Derefer` MIR pass is moved before borrowck so I didn't.
2024-03-14hir: Remove `opt_local_def_id_to_hir_id` and `opt_hir_node_by_def_id`Vadim Petrochenkov-10/+4
Also replace a few `hir_node()` calls with `hir_node_by_def_id()`
2024-03-14Rename `hir::StmtKind::Local` into `hir::StmtKind::Let`Guillaume Gomez-3/+3
2024-03-13Account for UnOps in borrowck messageEsteban Küber-2/+9
2024-03-13Detect calls to `.clone()` on `T: !Clone` types on borrowck errorsEsteban Küber-7/+106
When encountering a lifetime error on a type that *holds* a type that doesn't implement `Clone`, explore the item's body for potential calls to `.clone()` that are only cloning the reference `&T` instead of `T` because `T: !Clone`. If we find this, suggest `T: Clone`. ``` error[E0502]: cannot borrow `*list` as mutable because it is also borrowed as immutable --> $DIR/clone-on-ref.rs:7:5 | LL | for v in list.iter() { | ---- immutable borrow occurs here LL | cloned_items.push(v.clone()) | ------- this call doesn't do anything, the result is still `&T` because `T` doesn't implement `Clone` LL | } LL | list.push(T::default()); | ^^^^^^^^^^^^^^^^^^^^^^^ mutable borrow occurs here LL | LL | drop(cloned_items); | ------------ immutable borrow later used here | help: consider further restricting this bound | LL | fn foo<T: Default + Clone>(list: &mut Vec<T>) { | +++++++ ``` ``` error[E0505]: cannot move out of `x` because it is borrowed --> $DIR/clone-on-ref.rs:23:10 | LL | fn qux(x: A) { | - binding `x` declared here LL | let a = &x; | -- borrow of `x` occurs here LL | let b = a.clone(); | ------- this call doesn't do anything, the result is still `&A` because `A` doesn't implement `Clone` LL | drop(x); | ^ move out of `x` occurs here LL | LL | println!("{b:?}"); | ----- borrow later used here | help: consider annotating `A` with `#[derive(Clone)]` | LL + #[derive(Clone)] LL | struct A; | ```
2024-03-13cleanup prefixes iteratorbeepster4096-20/+7
2024-03-11Rename `IntoDiagnosticArg` as `IntoDiagArg`.Nicholas Nethercote-3/+3
Also rename `into_diagnostic_arg` as `into_diag_arg`, and `NotIntoDiagnosticArg` as `NotInotDiagArg`.
2024-03-09Drive-by fix string fmtEsteban Küber-6/+6
2024-03-08Rollup merge of #121563 - Jarcho:use_cf, r=petrochenkovMatthias Krüger-47/+29
Use `ControlFlow` in visitors. Follow up to #121256 This does have a few small behaviour changes in some diagnostic output where the visitor will now find the first match rather than the last match. The change in `find_anon_types.rs` has the only affected test. I don't see this being an issue as the last occurrence isn't any better of a choice than the first.
2024-03-06Add missing `#[rustc_lint_diagnostics]` attributes.Nicholas Nethercote-3/+11
Prior to the previous commit, `#[rust_lint_diagnostics]` attributes could only be used on methods with an `impl Into<{D,Subd}iagMessage>` parameter. But there are many other nearby diagnostic methods (e.g. `Diag::span`) that don't take such a parameter and should have the attribute. This commit adds the missing attribute to these `Diag` methods. This requires adding some missing `#[allow(rustc::diagnostic_outside_of_impl)]` markers at call sites to these methods.
2024-03-06Rewrite the `untranslatable_diagnostic` lint.Nicholas Nethercote-0/+5
Currently it only checks calls to functions marked with `#[rustc_lint_diagnostics]`. This commit changes it to check calls to any function with an `impl Into<{D,Subd}iagMessage>` parameter. This greatly improves its coverage and doesn't rely on people remembering to add `#[rustc_lint_diagnostics]`. The commit also adds `#[allow(rustc::untranslatable_diagnostic)`] attributes to places that need it that are caught by the improved lint. These places that might be easy to convert to translatable diagnostics. Finally, it also: - Expands and corrects some comments. - Does some minor formatting improvements. - Adds missing `DecorateLint` cases to `tests/ui-fulldeps/internal-lints/diagnostics.rs`.
2024-03-05Use `ControlFlow` in HIR visitorsJason Newcomb-47/+29
2024-03-01Rollup merge of #120646 - clubby789:uninit-destructuring-sugg, ↵Matthias Krüger-1/+6
r=michaelwoerister Fix incorrect suggestion for uninitialized binding in pattern Fixes #120634
2024-02-28Rename `DiagnosticArg{,Map,Name,Value}` as `DiagArg{,Map,Name,Value}`.Nicholas Nethercote-1/+1
2024-02-28Rename `DiagnosticBuilder` as `Diag`.Nicholas Nethercote-115/+77
Much better! Note that this involves renaming (and updating the value of) `DIAGNOSTIC_BUILDER` in clippy.
2024-02-27Avoid a `span_delayed_bug` in `compute_regions`.Nicholas Nethercote-7/+11
By storing error guarantees in `RegionErrors`.
2024-02-23compiler: clippy::complexity fixesMatthias Krüger-5/+4
2024-02-21Convert `bug`s back to `delayed_bug`s.Nicholas Nethercote-2/+2
This commit undoes some of the previous commit's mechanical changes, based on human judgment.
2024-02-21Convert `delayed_bug`s to `bug`s.Nicholas Nethercote-1/+1
I have a suspicion that quite a few delayed bug paths are impossible to reach, so I did an experiment. I converted every `delayed_bug` to a `bug`, ran the full test suite, then converted back every `bug` that was hit. A surprising number were never hit. The next commit will convert some more back, based on human judgment.
2024-02-20Reduce capabilities of `Diagnostic`.Nicholas Nethercote-0/+15
Currently many diagnostic modifier methods are available on both `Diagnostic` and `DiagnosticBuilder`. This commit removes most of them from `Diagnostic`. To minimize the diff size, it keeps them within `diagnostic.rs` but changes the surrounding `impl Diagnostic` block to `impl DiagnosticBuilder`. (I intend to move things around later, to give a more sensible code layout.) `Diagnostic` keeps a few methods that it still needs, like `sub`, `arg`, and `replace_args`. The `forward!` macro, which defined two additional methods per call (e.g. `note` and `with_note`), is replaced by the `with_fn!` macro, which defines one additional method per call (e.g. `with_note`). It's now also only used when necessary -- not all modifier methods currently need a `with_*` form. (New ones can be easily added as necessary.) All this also requires changing `trait AddToDiagnostic` so its methods take `DiagnosticBuilder` instead of `Diagnostic`, which leads to many mechanical changes. `SubdiagnosticMessageOp` gains a type parameter `G`. There are three subdiagnostics -- `DelayedAtWithoutNewline`, `DelayedAtWithNewline`, and `InvalidFlushedDelayedDiagnosticLevel` -- that are created within the diagnostics machinery and appended to external diagnostics. These are handled at the `Diagnostic` level, which means it's now hard to construct them via `derive(Diagnostic)`, so instead we construct them by hand. This has no effect on what they look like when printed. There are lots of new `allow` markers for `untranslatable_diagnostics` and `diagnostics_outside_of_impl`. This is because `#[rustc_lint_diagnostics]` annotations were present on the `Diagnostic` modifier methods, but missing from the `DiagnosticBuilder` modifier methods. They're now present.
2024-02-19Prefer `DiagnosticBuilder` over `Diagnostic` in diagnostic modifiers.Nicholas Nethercote-47/+64
There are lots of functions that modify a diagnostic. This can be via a `&mut Diagnostic` or a `&mut DiagnosticBuilder`, because the latter type wraps the former and impls `DerefMut`. This commit converts all the `&mut Diagnostic` occurrences to `&mut DiagnosticBuilder`. This is a step towards greatly simplifying `Diagnostic`. Some of the relevant function are made generic, because they deal with both errors and warnings. No function bodies are changed, because all the modifier methods are available on both `Diagnostic` and `DiagnosticBuilder`.
2024-02-17Rollup merge of #121085 - davidtwco:always-eager-diagnostics, r=nnethercoteMatthias Krüger-143/+207
errors: only eagerly translate subdiagnostics Subdiagnostics don't need to be lazily translated, they can always be eagerly translated. Eager translation is slightly more complex as we need to have a `DiagCtxt` available to perform the translation, which involves slightly more threading of that context. This slight increase in complexity should enable later simplifications - like passing `DiagCtxt` into `AddToDiagnostic` and moving Fluent messages into the diagnostic structs rather than having them in separate files (working on that was what led to this change). r? ```@nnethercote```
2024-02-15errors: only eagerly translate subdiagnosticsDavid Wood-143/+207
Subdiagnostics don't need to be lazily translated, they can always be eagerly translated. Eager translation is slightly more complex as we need to have a `DiagCtxt` available to perform the translation, which involves slightly more threading of that context. This slight increase in complexity should enable later simplifications - like passing `DiagCtxt` into `AddToDiagnostic` and moving Fluent messages into the diagnostic structs rather than having them in separate files (working on that was what led to this change). Signed-off-by: David Wood <david@davidtw.co>
2024-02-13Avoid an ICE in diagnosticsOli Scherer-1/+1
2024-02-12Rollup merge of #120958 - ShoyuVanilla:remove-subst, r=oli-obkMatthias Krüger-1/+1
Dejargonize `subst` In favor of #110793, replace almost every occurence of `subst` and `substitution` from rustc codes, but they still remains in subtrees under `src/tools/` like clippy and test codes (I'd like to replace them after this)
2024-02-12Rollup merge of #120950 - compiler-errors:miri-async-closurs, r=RalfJung,oli-obkMatthias Krüger-8/+7
Fix async closures in CTFE First commit renames `is_coroutine_or_closure` into `is_closure_like`, because `is_coroutine_or_closure_or_coroutine_closure` seems confusing and long. Second commit fixes some forgotten cases where we want to handle `TyKind::CoroutineClosure` the same as closures and coroutines. The test exercises the change to `ValidityVisitor::aggregate_field_path_elem` which is the source of #120946, but not the change to `UsedParamsNeedSubstVisitor`, though I feel like it's not that big of a deal. Let me know if you'd like for me to look into constructing a test for the latter, though I have no idea what it'd look like (we can't assert against `TooGeneric` anywhere?). Fixes #120946 r? oli-obk cc ``@RalfJung``
2024-02-12Rollup merge of #120917 - chenyukang:yukang-dead-parameters, r=compiler-errorsMatthias Krüger-1/+0
Remove a bunch of dead parameters in functions Found this kind of issue when working on https://github.com/rust-lang/rust/pull/119650 I wrote a trivial toy lint and manual review to find these.
2024-02-12Dejargnonize substShoyu Vanilla-1/+1
2024-02-12remove a bunch of dead parameters in fnyukang-1/+0
2024-02-11is_closure_likeMichael Goulet-8/+7
2024-02-10hir: Remove `hir::Map::{opt_parent_id,parent_id,get_parent,find_parent}`Vadim Petrochenkov-8/+9
2024-02-09Rollup merge of #120704 - amandasystems:silly-region-name-rewrite, ↵Matthias Krüger-27/+31
r=compiler-errors A drive-by rewrite of `give_region_a_name()` This drive-by rewrite makes the cache-updating nature of the method clearer, using the Entry API into the hash table for region names to capture the update-insert nature of the method. May be marginally more efficient since it only runtime-borrows and indexes the map once, but in this context the performance impact is almost certainly completely negligible. Note that this commit should preserve all externally visible behaviour. Notably, it preserves the debug logging: 1. printing even in the case of a `None` for the new computed name, and 2. only printing on new values, begin silent on reused values
2024-02-09Rollup merge of #120693 - nnethercote:invert-diagnostic-lints, r=davidtwcoMatthias Krüger-14/+18
Invert diagnostic lints. That is, change `diagnostic_outside_of_impl` and `untranslatable_diagnostic` from `allow` to `deny`, because more than half of the compiler has been converted to use translated diagnostics. This commit removes more `deny` attributes than it adds `allow` attributes, which proves that this change is warranted. r? ````@davidtwco````
2024-02-08Make `RegionName` `Copy` by (transitively) interning the few string variantsAmanda Stjerna-13/+13
2024-02-07hir: Remove `fn opt_hir_id` and `fn opt_span`Vadim Petrochenkov-72/+65
2024-02-07hir: Make sure all `HirId`s have corresponding HIR `Node`sVadim Petrochenkov-1/+2
2024-02-06Fix incorrect suggestion for uninitialize binding in destructuring patternclubby789-1/+6
2024-02-06A drive-by rewrite of give_region_a_name()Amanda Stjerna-17/+21
This rewrite makes the cache-updating nature of the function slightly clearer, using the Entry API into the hash table for region names to capture the update-insert nature of the method. May be marginally more efficient since it only runtime-borrows the map once, but in this context the performance impact is almost certainly completely negligible.
2024-02-06Teach typeck/borrowck/solvers how to deal with async closuresMichael Goulet-10/+11
2024-02-06Add CoroutineClosure to TyKind, AggregateKind, UpvarArgsMichael Goulet-1/+1
2024-02-06Make async closures directly lower to ClosureKind::CoroutineClosureMichael Goulet-13/+29
2024-02-06Invert diagnostic lints.Nicholas Nethercote-14/+18
That is, change `diagnostic_outside_of_impl` and `untranslatable_diagnostic` from `allow` to `deny`, because more than half of the compiler has be converted to use translated diagnostics. This commit removes more `deny` attributes than it adds `allow` attributes, which proves that this change is warranted.
2024-02-03Rollup merge of #120592 - trevyn:cleanup-to-string, r=NilstriebMatthias Krüger-2/+2
Remove unnecessary `.to_string()`/`.as_str()`s
2024-02-03Rollup merge of #120573 - nnethercote:rm-BorrowckErrors-tainted_by_errors, ↵Matthias Krüger-13/+13
r=oli-obk Remove `BorrowckErrors::tainted_by_errors` This PR removes one of the `tainted_by_errors` occurrences, replacing it with direct use of `ErrorGuaranteed`. r? `@oli-obk`
2024-02-02Remove unnecessary `.to_string()`/`.as_str()`strevyn-2/+2
2024-02-03Improve a local variable name.Nicholas Nethercote-2/+2
2024-02-02Remove `BorrowckErrors::tainted_by_errors`.Nicholas Nethercote-12/+12
`BorrowckErrors` stores a mix of error and non-error diags in `buffered`. As a result, it downgrades `DiagnosticBuilder`s to `Diagnostic`s, losing the emission guarantees, and so has to use a `tainted_by_errors` field to record whether an error has occurred. This commit splits `buffered` into `buffered_errors` and `buffered_non_errors`, keeping them as `DiagnosticBuilder`s and preserving the emission guarantees. This also requires fixing a bunch of incorrect lifetimes on `DiagnosticBuilder` use points.
2024-02-02Rename `buffer_non_error_diag` as `buffer_non_error`.Nicholas Nethercote-1/+1
To match `buffer_error`.
2024-01-30Remove the lifetime from `DiagnosticArgValue`.Nicholas Nethercote-1/+1
Because it's almost always static. This makes `impl IntoDiagnosticArg for DiagnosticArgValue` trivial, which is nice. There are a few diagnostics constructed in `compiler/rustc_mir_build/src/check_unsafety.rs` and `compiler/rustc_mir_transform/src/errors.rs` that now need symbols converted to `String` with `to_string` instead of `&str` with `as_str`, but that' no big deal, and worth it for the simplifications elsewhere.