about summary refs log tree commit diff
path: root/compiler/rustc_borrowck
AgeCommit message (Collapse)AuthorLines
2023-12-23Give `DiagnosticBuilder` a default type.Nicholas Nethercote-109/+70
`IntoDiagnostic` defaults to `ErrorGuaranteed`, because errors are the most common diagnostic level. It makes sense to do likewise for the closely-related (and much more widely used) `DiagnosticBuilder` type, letting us write `DiagnosticBuilder<'a, ErrorGuaranteed>` as just `DiagnosticBuilder<'a>`. This cuts over 200 lines of code due to many multi-line things becoming single line things.
2023-12-22Auto merge of #118824 - aliemjay:perf-region-cons, r=compiler-errorsbors-7/+12
use Vec for region constraints instead of BTreeMap ~1% perf gain Diagnostic regressions need more investigation. r? `@ghost`
2023-12-19Remove unnecessary param-env from lexical region resolution and fully ↵Michael Goulet-23/+6
structural relations
2023-12-18Rename many `DiagCtxt` arguments.Nicholas Nethercote-2/+2
2023-12-18Rename `Session::span_diagnostic` as `Session::dcx`.Nicholas Nethercote-11/+11
2023-12-18Rename `Handler` as `DiagCtxt`.Nicholas Nethercote-1/+1
2023-12-17fix diagnostic regresssionAli MJ Al-Nasrawy-7/+12
2023-12-15banish hir::GenericBound::LangItemTraitMichael Goulet-20/+10
2023-12-14Rollup merge of #118933 - nnethercote:cleanup-errors-even-more, ↵Jubilee-2/+2
r=compiler-errors Cleanup errors handlers even more A sequel to #118587. r? `@compiler-errors`
2023-12-15Split `Handler::emit_diagnostic` in two.Nicholas Nethercote-2/+2
Currently, `emit_diagnostic` takes `&mut self`. This commit changes it so `emit_diagnostic` takes `self` and the new `emit_diagnostic_without_consuming` function takes `&mut self`. I find the distinction useful. The former case is much more common, and avoids a bunch of `mut` and `&mut` occurrences. We can also restrict the latter with `pub(crate)` which is nice.
2023-12-14consistently use "next solver" instead of "new solver"lcnr-2/+2
2023-12-14update use of feature flagslcnr-2/+2
2023-12-12Move some methods from `tcx.hir()` to `tcx`zetanumbers-47/+48
Renamings: - find -> opt_hir_node - get -> hir_node - find_by_def_id -> opt_hir_node_by_def_id - get_by_def_id -> hir_node_by_def_id Fix rebase changes using removed methods Use `tcx.hir_node_by_def_id()` whenever possible in compiler Fix clippy errors Fix compiler Apply suggestions from code review Co-authored-by: Vadim Petrochenkov <vadim.petrochenkov@gmail.com> Add FIXME for `tcx.hir()` returned type about its removal Simplify with with `tcx.hir_node_by_def_id`
2023-12-11remove some redundant clonesMatthias Krüger-1/+1
2023-12-10remove redundant importssurechen-3/+1
detects redundant imports that can be eliminated. for #117772 : In order to facilitate review and modification, split the checking code and removing redundant imports code into two PR.
2023-12-09Rollup merge of #118638 - nnethercote:rustc_mir_dataflow-more, r=cjgillotGuillaume Gomez-83/+70
More `rustc_mir_dataflow` cleanups r? `@cjgillot`
2023-12-08Implement `async gen` blocksMichael Goulet-4/+30
2023-12-08Tweak `GenKillAnalysis`.Nicholas Nethercote-2/+2
`GenKillAnalysis` has five methods that take a transfer function arg: - `statement_effect` - `before_statement_effect` - `terminator_effect` - `before_terminator_effect` - `call_return_effect` All the transfer function args have type `&mut impl GenKill<Self::Idx>`, except for `terminator_effect`, which takes the simpler `Self::Domain`. But only the first two need to be `impl GenKill`. The other three can all be `Self::Domain`, just like `Analysis`. So this commit changes the last two to take `Self::Domain`, making `GenKillAnalysis` and `Analysis` more similar. (Another idea would be to make all these methods `impl GenKill`. But that doesn't work: `MaybeInitializedPlaces::terminator_effect` requires the arg be `Self::Domain` so that `self_is_unwind_dead(place, state)` can be called on it.)
2023-12-08Remove `BorrowckAnalyses`.Nicholas Nethercote-28/+18
This results in two non-generic types being used: `BorrowckResults` and `BorrowckFlowState`. It's a net reduction in lines of code, and a little easier to read.
2023-12-08Remove `impl_visitable!`.Nicholas Nethercote-65/+62
It is used just once. With it removed, the relevant code is a little boilerplate-y but much easier to read, and is the same length. Overall I think it's an improvement.
2023-12-04Provide more suggestions for cloning immutable bindingsEsteban Küber-1/+101
When encountering multiple mutable borrows, suggest cloning and adding derive annotations as needed. ``` error[E0596]: cannot borrow `sm.x` as mutable, as it is behind a `&` reference --> $DIR/accidentally-cloning-ref-borrow-error.rs:32:9 | LL | foo(&mut sm.x); | ^^^^^^^^^ `sm` is a `&` reference, so the data it refers to cannot be borrowed as mutable | help: `Str` doesn't implement `Clone`, so this call clones the reference `&Str` --> $DIR/accidentally-cloning-ref-borrow-error.rs:31:21 | LL | let mut sm = sr.clone(); | ^^^^^^^ help: consider annotating `Str` with `#[derive(Clone)]` | LL + #[derive(Clone)] LL | struct Str { | help: consider specifying this binding's type | LL | let mut sm: &mut Str = sr.clone(); | ++++++++++ ``` ``` error[E0596]: cannot borrow `*inner` as mutable, as it is behind a `&` reference --> $DIR/issue-91206.rs:14:5 | LL | inner.clear(); | ^^^^^ `inner` is a `&` reference, so the data it refers to cannot be borrowed as mutable | help: you can `clone` the `Vec<usize>` value and consume it, but this might not be your desired behavior --> $DIR/issue-91206.rs:11:17 | LL | let inner = client.get_inner_ref(); | ^^^^^^^^^^^^^^^^^^^^^^ help: consider specifying this binding's type | LL | let inner: &mut Vec<usize> = client.get_inner_ref(); | +++++++++++++++++ ```
2023-12-04Deduplicate some logicEsteban Küber-110/+51
2023-12-04Tweak output on specific caseEsteban Küber-1/+21
2023-12-04Suggest cloning and point out obligation errors on move errorEsteban Küber-48/+124
When encountering a move error, look for implementations of `Clone` for the moved type. If there is one, check if all its obligations are met. If they are, we suggest cloning without caveats. If they aren't, we suggest cloning while mentioning the unmet obligations, potentially suggesting `#[derive(Clone)]` when appropriate. ``` error[E0507]: cannot move out of a shared reference --> $DIR/suggest-clone-when-some-obligation-is-unmet.rs:20:28 | LL | let mut copy: Vec<U> = map.clone().into_values().collect(); | ^^^^^^^^^^^ ------------- value moved due to this method call | | | move occurs because value has type `HashMap<T, U, Hash128_1>`, which does not implement the `Copy` trait | note: `HashMap::<K, V, S>::into_values` takes ownership of the receiver `self`, which moves value --> $SRC_DIR/std/src/collections/hash/map.rs:LL:COL help: you could `clone` the value and consume it, if the `Hash128_1: Clone` trait bound could be satisfied | LL | let mut copy: Vec<U> = <HashMap<T, U, Hash128_1> as Clone>::clone(&map.clone()).into_values().collect(); | ++++++++++++++++++++++++++++++++++++++++++++ + help: consider annotating `Hash128_1` with `#[derive(Clone)]` | LL + #[derive(Clone)] LL | pub struct Hash128_1; | ``` Fix #109429.
2023-12-04Tweak `.clone()` suggestion to work in more casesEsteban Küber-3/+17
When going through auto-deref, the `<T as Clone>` impl sometimes needs to be specified for rustc to actually clone the value and not the reference. ``` error[E0507]: cannot move out of dereference of `S` --> $DIR/needs-clone-through-deref.rs:15:18 | LL | for _ in self.clone().into_iter() {} | ^^^^^^^^^^^^ ----------- value moved due to this method call | | | move occurs because value has type `Vec<usize>`, which does not implement the `Copy` trait | note: `into_iter` takes ownership of the receiver `self`, which moves value --> $SRC_DIR/core/src/iter/traits/collect.rs:LL:COL help: you can `clone` the value and consume it, but this might not be your desired behavior | LL | for _ in <Vec<usize> as Clone>::clone(&self.clone()).into_iter() {} | ++++++++++++++++++++++++++++++ + ``` CC #109429.
2023-12-02Auto merge of #118470 - nnethercote:cleanup-error-handlers, r=compiler-errorsbors-22/+22
Cleanup error handlers Mostly by making function naming more consistent. More to do after this, but this is enough for one PR. r? compiler-errors
2023-12-02Use `Session::diagnostic` in more places.Nicholas Nethercote-5/+5
2023-12-02Rename `HandlerInner::delay_span_bug` as `HandlerInner::span_delayed_bug`.Nicholas Nethercote-15/+15
Because the corresponding `Level` is `DelayedBug` and `span_delayed_bug` follows the pattern used everywhere else: `span_err`, `span_warning`, etc.
2023-12-02Rename `Handler::span_note_diag` as `struct_span_note`.Nicholas Nethercote-2/+2
Because `span_note_diag` doesn't follow the naming structure used for the error reporting functions.
2023-12-01improve NLL/polonius scope equality assertionRémy Rakic-1/+2
2023-12-01move and maintain live loans in `LivenessValues`Rémy Rakic-97/+94
Liveness data is pushed from multiple parts of NLL. Instead of changing the call sites to maintain live loans, move the latter to `LivenessValues` where this liveness data is pushed to, and maintain live loans there. This fixes the differences in polonius scopes on some CFGs where a variable was dead in tracing but as a MIR terminator its regions were marked live from "constraint generation"
2023-12-01rename a couple of trivial variablesRémy Rakic-3/+3
for consistency with how they're named everywhere else
2023-12-01remove useless debug logRémy Rakic-2/+0
2023-12-01Auto merge of #118216 - lqd:constraint-generation-non-non, r=matthewjasperbors-432/+454
Refactor NLL constraint generation and most of polonius fact generation As discussed in #118175, NLL "constraint generation" is only about liveness, but currently also contains legacy polonius fact generation. The latter is quite messy, and this PR cleans this up to prepare for its future removal: - splits polonius fact generation out of NLL constraint generation - merges NLL constraint generation to its more natural place, liveness - extracts all of the polonius fact generation from NLLs apart from MIR typeck (as fact generation is somewhat in a single place there already, but should be cleaned up) into its own explicit module, with a single entry point instead of many. There should be no behavior changes, and tests seem to behave the same as master: without polonius, with legacy polonius, with the in-tree polonius. I've split everything into smaller logical commits for easier review, as it required quite a bit of code to be split and moved around, but it should all be trivial changes. r? `@matthewjasper`
2023-11-28Fix a typo in a `format_args!` noteJosh Stone-1/+1
2023-11-27Address unused tuple struct fields in the compilerJake Goulding-1/+2
2023-11-26Auto merge of #118316 - Mark-Simulacrum:delete-copy-to-upvars, r=cjgillotbors-50/+28
Remove borrowck Upvar duplication This cuts out an extra allocation and copying over from the already cached closure capture information.
2023-11-26Remove Upvar duplicationMark Rousskov-50/+28
This cuts out an extra allocation and copying over from the already cached closure capture information.
2023-11-26Rollup merge of #118311 - bvanjoi:merge_coroutinue_into_closure, r=petrochenkovGuillaume Gomez-2/+11
merge `DefKind::Coroutine` into `Defkind::Closure` Related to #118188 We no longer need to be concerned about the precise type whether it's `DefKind::Closure` or `DefKind::Coroutine`. Furthermore, thanks for the great work done by `@petrochenkov` on investigating https://rust-lang.zulipchat.com/#narrow/stream/182449-t-compiler.2Fhelp/topic/Why.20does.20it.20hang.20when.20querying.20.EF.BB.BF.60opt_def_kind.60.3F r? `@petrochenkov`
2023-11-26Rollup merge of #118302 - mu001999:dead_code/clean, r=cjgillotGuillaume Gomez-60/+0
Clean dead codes Clean dead codes detected by #118257
2023-11-26merge `DefKind::Coroutine` into `DefKind::Closure`bohan-2/+11
2023-11-26move remaining legacy polonius fact generation out of NLL moduleRémy Rakic-40/+46
2023-11-26merge NLL "constraint generation" into livenessRémy Rakic-81/+82
2023-11-26remove polonius fact generation from NLL constraint generationRémy Rakic-202/+21
2023-11-26small polish of loan invalidations fact generationRémy Rakic-22/+12
2023-11-26rename polonius constraint generation to what it actually does: emit loan killsRémy Rakic-28/+20
2023-11-26simplify polonius constraint generationRémy Rakic-107/+83
2023-11-26remove NLL liveness from polonius constraint generationRémy Rakic-81/+7
2023-11-26extract polonius "constraint generation"Rémy Rakic-2/+280
to help review, this duplicates the existing NLL + polonius constraint generation component, before splitting them up to only do what they individually need.
2023-11-26another trivial cleanupRémy Rakic-3/+2
fix a comment and move a variable where it's used