about summary refs log tree commit diff
path: root/compiler/rustc_borrowck/src
AgeCommit message (Collapse)AuthorLines
2025-01-06Improve span when temporary receiver is dropped in edition 2024Michael Goulet-0/+34
2025-01-04turn hir::ItemKind::Fn into a named-field variantRalf Jung-2/+6
2025-01-01remove borrowck duplicate of `std::ops::ControlFlow`Rémy Rakic-19/+16
2025-01-01remove `allow_two_phase_borrow`Rémy Rakic-14/+6
it's been simplified over the years, but now it's no longer useful. - document its replacement in `BorrowKind` - use that everywhere instead
2025-01-01remove empty `util` moduleRémy Rakic-39/+0
2025-01-01move `find_assignments` to its only use siteRémy Rakic-2/+34
this is to remove the entire `util` module
2025-01-01localize typeck constraintsRémy Rakic-6/+199
it's still partially a skeleton, but works well enough for almost all tests to pass
2025-01-01move typeck constraints conversion to its own moduleRémy Rakic-39/+44
2025-01-01Rollup merge of #134945 - compiler-errors:map-mutate-nits, r=estebankStuart Cook-7/+10
Some small nits to the borrowck suggestions for mutating a map through index 1. Suggesting users to either use `.insert` or `.get_mut` (which do totally different things) can be a bit of a footgun, so let's make that a bit more nuanced. 2. I find the suggestion of `.get_mut(|val| { *val = whatever; })` to be a bit awkward. I changed this to be an if-let instead. 3. Fix a bug which was suppressing the structured suggestion for some mutations via the index operator on `HashMap`/`BTreeMap`. r? estebank or reassign
2024-12-31Rollup merge of #133486 - dianne:fix-move-error-suggestion, r=estebankTrevor Gross-39/+118
borrowck diagnostics: make `add_move_error_suggestions` use the HIR rather than `SourceMap` This PR aims to fix #132806 by rewriting `add_move_error_suggestions`[^1]. Previously, it manually scanned the source text to find a leading `&`, which isn't always going to produce a correct result (see: that issue). Admittedly, the HIR visitor in this PR introduces a lot of boilerplate, but hopefully the logic at its core isn't too complicated (I go over it in the comments). I also tried a simpler version that didn't use a HIR visitor and suggested adding `ref` always, but the `&ref x` suggestions really didn't look good. As a bonus for the added complexity though, it's now able to produce nice `&`-removing suggestions in more cases. I tried to do this such that it avoids edition-dependent checks and its suggestions can be applied together with those from the match ergonomics 2024 migration lint. I haven't added tests for that since the details of match ergonomics 2024 are still being sorted out, but I can try if desired once that's finalized. [^1]: In brief, it fires on patterns where users try to bind by-value in such a way that moves out of a reference to a non-Copy type (including slice references with non-copy elements). The suggestions are to change the binding's mode to be by-reference, either by removing[^2] an enclosing `&`/`&mut` or adding `ref` to the binding. [^2]: Incidentally, I find the terminology of "consider removing the borrow" a bit confusing for a suggestion to remove a `&` pattern in order to make bindings borrow rather than move. I'm not sure what a good, concise way to explain that would be though, and that should go in a separate PR anyway.
2024-12-31Fix span for IndexMut method call on HashMap/BTreeMapMichael Goulet-2/+2
2024-12-31Use if-let in structured suggestion instead of Option::mapMichael Goulet-6/+9
2024-12-31Explain how to mutate a HashMap/BTreeMap with more nuanceMichael Goulet-1/+1
2024-12-30rename `diags` fieldRémy Rakic-19/+26
2024-12-30clean up `BorrowckDiags`Rémy Rakic-23/+13
- rename it to what it does, buffer diagnostics - remove single-use functions - use derives
2024-12-30merge `diags` module into `diagnostics`Rémy Rakic-149/+142
it's a more natural place for diagnostics-related structures and functions
2024-12-30move `facts` module to polonius legacy moduleRémy Rakic-22/+17
this is specific to the old datalog implementation and wasn't noticed in the previous module move
2024-12-30simplify `add_extra_drop_facts`Rémy Rakic-25/+20
this is mostly to remove imports of the polonius legacy module also what is going on in this function, what the...
2024-12-30move `location` module to polonius legacy moduleRémy Rakic-11/+11
this is specific to the old datalog implementation and wasn't noticed in the previous module move
2024-12-30fix a couple nitsRémy Rakic-6/+5
- remove unneeded type ascription - fix variable name - fix typo in comment - fix `var_origins` var and function name: these are `VarInfos`
2024-12-29address review commentsRémy Rakic-7/+24
- add a FIXME when looking for the region variance of unexpected regions - drive-by: fix a doc comment link - drive-by: simplify the variance match using exported variants instead
2024-12-29liveness constraints: draw the rest of the owlRémy Rakic-71/+180
2024-12-29finish filling polonius contextRémy Rakic-8/+40
transpose liveness matrix and record live regions at the end of MIR typeck
2024-12-29record variance of regular live regionsRémy Rakic-3/+21
2024-12-29record variance of use/drop live regionsRémy Rakic-6/+12
records the variance of: - use live types - drop live generic args
2024-12-29add variance recordingRémy Rakic-0/+126
Following the Generalizer's structure, relating e.g. a type with itself will allow tracking the variance wrt the contained regions.
2024-12-29introduce polonius contextRémy Rakic-47/+104
This context struct will hold data to help creating localized constraints: - the live regions, with the shape matching a CFG walk, indexed per point - the variance of these live regions, represented as the direction we'll add the appropriate We also add this structure to the mir typeck to record liveness data, and make it responsible for localized constraint creation.
2024-12-29Auto merge of #134627 - estebank:issue-133252, r=jackh726bors-2/+8
Avoid ICE in borrowck Provide a fallback in `best_blame_constraint` when `find_constraint_paths_between_regions` doesn't have a result. This code is due a rework to avoid the letf-over `unwrap()`, but avoids the ICE caused by the repro. Fix #133252.
2024-12-27Rollup merge of #134827 - compiler-errors:borrowck-nits, r=lqdDavid Tolnay-0/+6
Some random region tweaks Remove a redundant function and add an assertion that I think is useful
2024-12-27Make sure there are no registered constraints from creating universal region ↵Michael Goulet-0/+6
vids
2024-12-27Fix typoschloefeal-1/+1
Signed-off-by: chloefeal <188809157+chloefeal@users.noreply.github.com>
2024-12-24Auto merge of #134625 - compiler-errors:unsafe-binders-ty, r=oli-obkbors-0/+2
Begin to implement type system layer of unsafe binders Mostly TODOs, but there's a lot of match arms that are basically just noops so I wanted to split these out before I put up the MIR lowering/projection part of this logic. r? oli-obk Tracking: - https://github.com/rust-lang/rust/issues/130516
2024-12-23Auto merge of #134465 - lcnr:type-verifier, r=compiler-errorsbors-317/+84
cleanup `TypeVerifier` We should merge it with the `TypeChecker` as we no longer bail in cases where it encounters an error since #111863. It's quite inconsistent whether a check lives in the verifier or the `TypeChecker`, so this feels like a quite impactful cleanup. I expect that for this we may want to change the `TypeChecker` to also be a MIR visitor :thinking: this is non-trivial so I didn't fully do it in this PR. Best reviewed commit by commit. r? `@compiler-errors` feel free to reassign however
2024-12-22Begin to implement type system layer of unsafe bindersMichael Goulet-0/+2
2024-12-22Delete `Rvalue::Len`Scott McMurray-19/+5
Everything's moved to `PtrMetadata` instead.
2024-12-21Auto merge of #134268 - lqd:polonius-next, r=jackh726bors-34/+408
Foundations of location-sensitive polonius I'd like to land the prototype I'm describing in the [polonius project goal](https://github.com/rust-lang/rust-project-goals/issues/118). It still is incomplete and naive and terrible but it's working "well enough" to consider landing. I'd also like to make review easier by not opening a huge PR, but have a couple small-ish ones (the +/- line change summary of this PR looks big, but >80% is moving datalog to a single place). This PR starts laying the foundation for that work: - it refactors and collects 99% of the old datalog fact gen, which was spread around everywhere, into a single dedicated module. It's still present at 3 small places (one of which we should revert anyways) that are kinda deep within localized components and are not as easily extractable into the rest of fact gen, so it's fine for now. - starts introducing the localized constraints, the building blocks of the naive way of implementing the location-sensitive analysis in-tree, which is roughly sketched out in https://smallcultfollowing.com/babysteps/blog/2023/09/22/polonius-part-1/ and https://smallcultfollowing.com/babysteps/blog/2023/09/29/polonius-part-2/ but with a different vibe than per-point environments described in these posts, just `r1@p: r2@q` constraints. - sets up the skeleton of generating these localized constraints: converting NLL typeck constraints, and creating liveness constraints - introduces the polonius dual to NLL MIR to help development and debugging. It doesn't do much currently but is a way to see these localized constraints: it's an NLL MIR dump + a dumb listing of the constraints, that can be dumped with `-Zdump-mir=polonius -Zpolonius=next`. Its current state is not intended to be a long-term thing, just for testing purposes -- I will replace its contents in the future with a different approach (an HTML+js file where we can more easily explore/filter/trace these constraints and loan reachability, have mermaid graphs of the usual graphviz dumps, etc). I've started documenting the approach in this PR, I'll add more in the future. It's quite simple, and should be very clear when more constraints are introduced anyways. r? `@matthewjasper` Best reviewed per commit so that the datalog move is less bothersome to read, but if you'd prefer we separate that into a different PR, I can do that (and michael has offered to review these more mechanical changes if it'd help).
2024-12-21Avoid ICE in borrowckEsteban Küber-2/+8
Provide a fallback in `best_blame_constraint` when `find_constraint_paths_between_regions` doesn't have a result. This code is due a rework to avoid the letf-over `unwrap()`, but avoids the ICE caused by the repro. Fix #133252.
2024-12-21Auto merge of #134501 - lcnr:member-constraints-yeet, r=oli-obkbors-96/+381
handle member constraints directly in the mir type checker cleaner, faster, easier to change going forward :> fixes #109654 r? `@oli-obk` `@compiler-errors`
2024-12-20Rollup merge of #134574 - lcnr:opaque-ty-hack-yeet, r=compiler-errorsMatthias Krüger-6/+7
next-solver: disable unnecessary hack the new solver never constrains inference variables to normalizeable aliases, so this is no longer necessary.
2024-12-20next-solver: rm opaque type hacklcnr-6/+7
2024-12-20add commentslcnr-3/+6
2024-12-20remove non-borrowck member constraintslcnr-33/+14
2024-12-20more directly handle member constraintslcnr-71/+375
2024-12-20cleanup promoteds move checklcnr-9/+9
2024-12-19Auto merge of #134499 - jieyouxu:rollup-zmaveur, r=jieyouxubors-29/+33
Rollup of 7 pull requests Successful merges: - #133702 (Variants::Single: do not use invalid VariantIdx for uninhabited enums) - #134427 (ci: remove duplicate task definition) - #134432 (Fix intra doc links not generated inside footnote definitions) - #134437 (reduce compiler `Assemble` complexity) - #134474 (Forbid overwriting types in typeck) - #134477 (move lint_unused_mut into sub-fn) - #134491 (Some destructor/drop related tweaks) r? `@ghost` `@rustbot` modify labels: rollup
2024-12-19Rollup merge of #134477 - lcnr:move-lint-into-subfn, r=lqd许杰友 Jieyou Xu (Joe)-29/+33
move lint_unused_mut into sub-fn also, stop `mem::take`-ing stuff we only use by reference :shrug:
2024-12-19Auto merge of #133961 - lcnr:borrowck-cleanup, r=jackh726bors-16/+18
cleanup region handling: add `LateParamRegionKind` The second commit is to enable a split between `BoundRegionKind` and `LateParamRegionKind`, by avoiding `BoundRegionKind` where it isn't necessary. The third comment then adds `LateParamRegionKind` to avoid having the same late-param region for separate bound regions. This fixes #124021. r? `@compiler-errors`
2024-12-18Auto merge of #133328 - nnethercote:simplify-SwitchInt-handling, r=tmiaskobors-11/+1
Simplify `SwitchInt` handling Dataflow handling of `SwitchInt` is currently complicated. This PR simplifies it. r? `@cjgillot`
2024-12-18move lint_unused_mut into subfnlcnr-29/+33
2024-12-18fix crasheslcnr-1/+1