about summary refs log tree commit diff
path: root/compiler/rustc_borrowck/src/diagnostics/mod.rs
AgeCommit message (Collapse)AuthorLines
2025-09-26ProjectionElem::Subtype -> CastKind::Subtypebeepster4096-4/+3
2025-08-14add commentlcnr-0/+3
2025-08-13rework `add_placeholder_from_predicate_note`lcnr-9/+49
2025-08-13avoid duplicate error stringlcnr-1/+1
2025-08-08borrowck: defer opaque type errorslcnr-1/+1
2025-08-03Rename `Printer` variables.Nicholas Nethercote-8/+8
Currently they are mostly named `cx`, which is a terrible name for a type that impls `Printer`/`PrettyPrinter`, and is easy to confuse with other types like `TyCtxt`. This commit changes them to `p`. A couple of existing `p` variables had to be renamed to make way.
2025-07-28Rename trait_of_item -> trait_of_assocCameron Steffen-1/+1
2025-07-28use let chains in ast, borrowck, codegen, const_evalKivooeo-34/+30
2025-06-25Rollup merge of #142724 - xizheyin:avoid_overwrite_args, r=oli-obkJana Dönszelmann-1/+7
Add runtime check to avoid overwrite arg in `Diag` ## Origin PR description At first, I set up a `debug_assert` check for the arg method to make sure that `args` in `Diag` aren't easily overwritten, and I added the `remove_arg()` method, so that if you do need to overwrite an arg, then you can explicitly call `remove_arg()` to remove it first, then call `arg()` to overwrite it. For the code before the rust-lang/rust#142015 change, it won't compile because it will report an error ``` arg `instance`already exists. ``` This PR also modifies all diagnostics that fail the check to pass the check. There are two cases of check failure: 1. ~~Between *the parent diagnostic and the subdiagnostic*, or *between the subdiagnostics* have the same field between them. In this case, I renamed the conflicting fields.~~ 2. ~~For subdiagnostics stored in `Vec`, the rendering may iteratively write the same arg over and over again. In this case, I changed the auto-generation with `derive(SubDiagnostic)` to manually implementing `SubDiagnostic` and manually rendered it with `eagerly_translate()`, similar to https://github.com/rust-lang/rust/issues/142031#issuecomment-2984812090, and after rendering it I manually deleted useless arg with the newly added `remove_arg` method.~~ ## Final Decision After trying and discussing, we made a final decision. For `#[derive(Subdiagnostic)]`, This PR made two changes: 1. After the subdiagnostic is rendered, remove all args of this subdiagnostic, which allows for usage like `Vec<Subdiag>`. 2. Store `diag.args` before setting arguments, so that you can restore the contents of the main diagnostic after deleting the arguments after subdiagnostic is rendered, to avoid deleting the main diagnostic's arg when they have the same name args.
2025-06-25Add runtime check to avoid overwrite arg easily in diag and store and ↵xizheyin-1/+7
restore snapshot when set subdiag arg Signed-off-by: xizheyin <xizheyin@smail.nju.edu.cn>
2025-06-22Init local_names lazily for borrowck diagnosticsKornel-4/+39
2025-05-02Test that names of variables in external macros are not shown on a borrow errorJana Dönszelmann-0/+8
2025-04-10Rollup merge of #139510 - nnethercote:name-to-ident, r=fee1-deadMatthias Krüger-1/+1
Rename some `name` variables as `ident`. It bugs me when variables of type `Ident` are called `name`. It leads to silly things like `name.name`. `Ident` variables should be called `ident`, and `name` should be used for variables of type `Symbol`. This commit improves things by by doing `s/name/ident/` on a bunch of `Ident` variables. Not all of them, but a decent chunk. r? `@fee1-dead`
2025-04-10Rename some `name` variables as `ident`.Nicholas Nethercote-1/+1
It bugs me when variables of type `Ident` are called `name`. It leads to silly things like `name.name`. `Ident` variables should be called `ident`, and `name` should be used for variables of type `Symbol`. This commit improves things by by doing `s/name/ident/` on a bunch of `Ident` variables. Not all of them, but a decent chunk.
2025-04-08Rollup merge of #139509 - xizheyin:issue-139359, r=lcnrMatthias Krüger-2/+2
clean: remove Deref<Target=RegionKind> impl for Region and use `.kind()` Closes #139359 r? `@lcnr`
2025-04-08clean code: remove Deref<Target=RegionKind> impl for Region and use `.kind()`xizheyin-2/+2
Signed-off-by: xizheyin <xizheyin@smail.nju.edu.cn>
2025-04-07rm `RegionInferenceContext::var_infos`lcnr-6/+3
we already track this info in the `definitions` field
2025-03-19Use `Option<Ident>` for lowered param names.Nicholas Nethercote-1/+1
Parameter patterns are lowered to an `Ident` by `lower_fn_params_to_names`, which is used when lowering bare function types, trait methods, and foreign functions. Currently, there are two exceptional cases where the lowered param can become an empty `Ident`. - If the incoming pattern is an empty `Ident`. This occurs if the parameter is anonymous, e.g. in a bare function type. - If the incoming pattern is neither an ident nor an underscore. Any such parameter will have triggered a compile error (hence the `span_delayed_bug`), but lowering still occurs. This commit replaces these empty `Ident` results with `None`, which eliminates a number of `kw::Empty` uses, and makes it impossible to fail to check for these exceptional cases. Note: the `FIXME` comment in `is_unwrap_or_empty_symbol` is removed. It actually should have been removed in #138482, the precursor to this PR. That PR changed the lowering of wild patterns to `_` symbols instead of empty symbols, which made the mentioned underscore check load-bearing.
2025-03-12Move methods from `Map` to `TyCtxt`, part 4.Nicholas Nethercote-2/+2
Continuing the work from #137350. Removes the unused methods: `expect_variant`, `expect_field`, `expect_foreign_item`. Every method gains a `hir_` prefix.
2025-02-22Fix binding mode problemsMichael Goulet-1/+1
2025-02-19Remove `rustc_middle::mir::tcx` module.Nicholas Nethercote-2/+1
This is a really weird module. For example, what does `tcx` in `rustc_middle::mir::tcx::PlaceTy` mean? The answer is "not much". The top-level module comment says: > Methods for the various MIR types. These are intended for use after > building is complete. Awfully broad for a module that has a handful of impl blocks for some MIR types, none of which really relates to `TyCtxt`. `git blame` indicates the comment is ancient, from 2015, and made sense then. This module is now vestigial. This commit removes it and moves all the code within into `rustc_middle::mir::statement`. Some specifics: - `Place`, `PlaceRef`, `Rvalue`, `Operand`, `BorrowKind`: they all have `impl` blocks in both the `tcx` and `statement` modules. The commit merges the former into the latter. - `BinOp`, `UnOp`: they only have `impl` blocks in `tcx`. The commit moves these into `statement`. - `PlaceTy`, `RvalueInitializationState`: they are defined in `tcx`. This commit moves them into `statement` *and* makes them available in `mir::*`, like many other MIR types.
2025-02-17Move some `Map` methods onto `TyCtxt`.Nicholas Nethercote-1/+1
The end goal is to eliminate `Map` altogether. I added a `hir_` prefix to all of them, that seemed simplest. The exceptions are `module_items` which became `hir_module_free_items` because there was already a `hir_module_items`, and `items` which became `hir_free_items` for consistency with `hir_module_free_items`.
2025-02-10Rename rustc_middle::Ty::is_unsafe_ptr to is_raw_ptrBastian Kersting-1/+1
The wording unsafe pointer is less common and not mentioned in a lot of places, instead this is usually called a "raw pointer". For the sake of uniformity, we rename this method. This came up during the review of https://github.com/rust-lang/rust/pull/134424.
2025-02-08Rustfmtbjorn3-4/+4
2025-02-02Rollup merge of #136368 - estebank:listify, r=fee1-deadMatthias Krüger-11/+9
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-02-01Rollup merge of #130514 - compiler-errors:unsafe-binders, r=oli-obkMatthias Krüger-3/+4
Implement MIR lowering for unsafe binders This is the final bit of the unsafe binders puzzle. It implements MIR, CTFE, and codegen for unsafe binders, and enforces that (for now) they are `Copy`. Later on, I'll introduce a new trait that relaxes this requirement to being "is `Copy` or `ManuallyDrop<T>`" which more closely models how we treat union fields. Namely, wrapping unsafe binders is now `Rvalue::WrapUnsafeBinder`, which acts much like an `Rvalue::Aggregate`. Unwrapping unsafe binders are implemented as a MIR projection `ProjectionElem::UnwrapUnsafeBinder`, which acts much like `ProjectionElem::Field`. Tracking: - https://github.com/rust-lang/rust/issues/130516
2025-01-31Make comma separated lists of anything easier to make for errorsEsteban Küber-11/+9
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-31Implement MIR, CTFE, and codegen for unsafe bindersMichael Goulet-3/+4
2025-01-31Move `find_self_call`.Nicholas Nethercote-7/+4
It's a function that does stuff with MIR and yet it weirdly has its own module in `rustc_middle::util`. This commit moves it into `rustc_middle::mir`, a more sensible home.
2025-01-13Assert that Instance::try_resolve is only used on body-like thingsMichael Goulet-3/+3
2025-01-08Try to explain borrow for tail expr temporary drop order change in 2024Michael Goulet-5/+6
2025-01-06point out unblamed constraints from `Copy`/`Sized` bounds in region errorsdianne-0/+22
2025-01-06cleanup: remove `ExtraConstraintInfo`dianne-4/+32
`ExtraConstraintInfo` was used only for a single subdiagnostic, so this moves the logic for that to its own function and eliminates the indirection. In order to do so cleanly, this also changes the arguments to `BorrowExplanation::add_explanation_to_diagnostic`, which happens to simplify its call sites.
2025-01-06Remove CallKind::Deref hack from UseSpansMichael Goulet-9/+0
It's not really necessary
2024-12-30rename `diags` fieldRémy Rakic-12/+12
2024-12-30clean up `BorrowckDiags`Rémy Rakic-17/+6
- rename it to what it does, buffer diagnostics - remove single-use functions - use derives
2024-12-30merge `diags` module into `diagnostics`Rémy Rakic-2/+136
it's a more natural place for diagnostics-related structures and functions
2024-12-18Re-export more `rustc_span::symbol` things from `rustc_span`.Nicholas Nethercote-2/+1
`rustc_span::symbol` defines some things that are re-exported from `rustc_span`, such as `Symbol` and `sym`. But it doesn't re-export some closely related things such as `Ident` and `kw`. So you can do `use rustc_span::{Symbol, sym}` but you have to do `use rustc_span::symbol::{Ident, kw}`, which is inconsistent for no good reason. This commit re-exports `Ident`, `kw`, and `MacroRulesNormalizedIdent`, and changes many `rustc_span::symbol::` qualifiers in `compiler/` to `rustc_span::`. This is a 200+ net line of code reduction, mostly because many files with two `use rustc_span` items can be reduced to one.
2024-11-25Refactor `where` predicates, and reserve for attributes supportFrank King-2/+2
2024-11-19Put `param_env` into `infcx`.Nicholas Nethercote-4/+4
Because they get passed around together a lot.
2024-11-18use `TypingEnv` when no `infcx` is availablelcnr-1/+1
the behavior of the type system not only depends on the current assumptions, but also the currentnphase of the compiler. This is mostly necessary as we need to decide whether and how to reveal opaque types. We track this via the `TypingMode`.
2024-11-04Tidy up comments and some formatting.Nicholas Nethercote-1/+1
Mostly by wrapping overly long comment lines, plus a few other things.
2024-11-02compiler: Replace rustc_target with _abi in _borrowckJubilee Young-1/+1
2024-10-31Try to point out when edition 2024 lifetime capture rules cause borrowck issuesMichael Goulet-0/+1
2024-09-22Reformat using the new identifier sorting from rustfmtMichael Goulet-8/+8
2024-09-09Remove unnecessary lifetimes in dataflow structs.Nicholas Nethercote-2/+2
There are four related dataflow structs: `MaybeInitializedPlaces`, `MaybeUninitializedPlaces`, and `EverInitializedPlaces`, `DefinitelyInitializedPlaces`. They all have a `&Body` and a `&MoveData<'tcx>` field. The first three use different lifetimes for the two fields, but the last one uses the same lifetime for both. This commit changes the first three to use the same lifetime, removing the need for one of the lifetimes. Other structs that also lose a lifetime as a result of this are `LivenessContext`, `LivenessResults`, `InitializationData`. It then does similar things in various other structs.
2024-09-06Make `Ty::boxed_ty` return an `Option`Pavel Grigorenko-2/+2
2024-08-30Remove `#[macro_use] extern crate tracing` from `rustc_borrowck`.Nicholas Nethercote-0/+1
2024-08-16Add `warn(unreachable_pub)` to `rustc_borrowck`.Nicholas Nethercote-2/+2
2024-07-29Reformat `use` declarations.Nicholas Nethercote-12/+11
The previous commit updated `rustfmt.toml` appropriately. This commit is the outcome of running `x fmt --all` with the new formatting options.