about summary refs log tree commit diff
path: root/compiler/rustc_borrowck/src
AgeCommit message (Collapse)AuthorLines
2025-02-03Contracts core intrinsics.Felix S. Klock II-0/+1
These are hooks to: 1. control whether contract checks are run 2. allow 3rd party tools to intercept and reintepret the results of running contracts.
2025-02-03Rollup merge of #136299 - lqd:polonius-next-episode-9, r=jackh726Matthias Krüger-82/+153
Ignore NLL boring locals in polonius diagnostics Another easy one ``@jackh726`` (the diff is inflated by blessed test expectations don't worry :) NLLs don't compute liveness for boring locals, and therefore cannot find them in causes explaining borrows. In polonius, we don't have this liveness optimization (we may be able to do something partially similar in the future, e.g. for function parameters and the like), so we do encounter these in diagnostics even though we don't want to. This PR: - restructures the polonius context into per-phase data, in spirit as you requested in an earlier review - stores the locals NLLs would consider boring into the errors/diagnostics data - ignores these if a boring local is found when trying to explain borrows This PR fixes around 80 cases of diagnostics differences between `-Zpolonius=next` and NLLs. I've also added explicit revisions to a few polonius tests (both for the in-tree implementation as well as the datalog implementation -- even if we'll eventually remove them). I didn't do this for all the "dead" expectations that were removed from #136112 for that same reason, it's fine. I'll soon/eventually add explicit revisions where they're needed: there's only a handful of tests left to fix. r? ``@jackh726``
2025-02-02Rollup merge of #136402 - notriddle:notriddle/let-expr-detector, ↵Matthias Krüger-18/+92
r=compiler-errors diagnostics: fix borrowck suggestions for if/while let conditionals This code detects the case where one of the borrows is inside the let init expr while the other end is not. If that happens, we don't want to suggest adding a semicolon, because it won't work. Fixes #133941
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-02Rollup merge of #136328 - estebank:long-ty-path, r=jieyouxu,lqdMatthias Krüger-35/+4
Rework "long type names" printing logic Make it so more type-system types can be printed in a shortened version (like `Predicate`s). Centralize printing the information about the "full type name path". Make the "long type path" for the file where long types are written part of `Diag`, so that it becomes easier to keep track of it, and ensure it will always will be printed out last in the diagnostic by making its addition to the output implicit. Tweak the shortening of types in "expected/found" labels. Remove dead file `note.rs`.
2025-02-01diagnostics: fix borrowck suggestions for if/while let conditionalsMichael Howell-18/+92
This code detects the case where one of the borrows is inside the let init expr while the other end is not. If that happens, we don't want to suggest adding a semicolon, because it won't work.
2025-02-01Rollup merge of #130514 - compiler-errors:unsafe-binders, r=oli-obkMatthias Krüger-10/+78
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-31Rework "long type names" printing logicEsteban Küber-35/+4
Make it so more type-system types can be printed in a shortened version (like `Predicate`s). Centralize printing the information about the "full type name path". Make the "long type path" for the file where long types are written part of `Diag`, so that it becomes easier to keep track of it, and ensure it will always will be printed out last in the diagnostic by making its addition to the output implicit. Tweak the shortening of types in "expected/found" labels. Remove dead file `note.rs`.
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-10/+78
2025-01-31Rollup merge of #136336 - nnethercote:overhaul-rustc_middle-util, r=jieyouxuMatthias Krüger-8/+5
Overhaul `rustc_middle::util` It's an odd module with some odd stuff in it. r? `@Noratrieb`
2025-01-31record boring locals in polonius contextRémy Rakic-29/+69
this is used in diagnostics to focus on relevant live locals to match NLL diagnostics
2025-01-31create context for errors and diagnostics for last borrowck phaseRémy Rakic-17/+28
2025-01-31split polonius context into per-phase dataRémy Rakic-50/+70
- describe how that data flows during borrowck - prepares for recording some liveness data for diagnostics, not just for the main analysis
2025-01-31Rollup merge of #136278 - lqd:polonius-debugger-episode-3, r=matthewjasperJacob Pratt-9/+101
add constraint graph to polonius MIR dump Another easy one while I work on diagnostics. This PR adds a mermaid visualization of the polonius constraint graph to the polonius MIR dump. Adding kills is left to a future PR (until they're encoded in edges directly or I set up recording debugging info in and out of the analysis), because right now they're only computed during traversal. [Here's](https://gistpreview.github.io/?096b0131e8258f9a3125c55c7ac369bc) how that looks. r? `@matthewjasper` but as always feel free to reroll.
2025-01-31Move `find_self_call`.Nicholas Nethercote-8/+5
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-30Auto merge of #136038 - compiler-errors:outlives, r=lcnrbors-9/+7
Simplify and consolidate the way we handle construct `OutlivesEnvironment` for lexical region resolution This is best reviewed commit-by-commit. I tried to consolidate the API for lexical region resolution *first*, then change the API when it was finally behind a single surface. r? lcnr or reassign
2025-01-30add constraint graph to polonius MIR dumpRémy Rakic-9/+101
2025-01-29Rollup merge of #136212 - estebank:span-tweak, r=petrochenkovMatthias Krüger-15/+10
Tweak `&mut self` suggestion span ``` error[E0596]: cannot borrow `*self.s` as mutable, as it is behind a `&` reference --> $DIR/issue-38147-1.rs:17:9 | LL | self.s.push('x'); | ^^^^^^ `self` is a `&` reference, so the data it refers to cannot be borrowed as mutable | help: consider changing this to be a mutable reference | LL | fn f(&mut self) { | +++ ``` Note the suggestion to add `mut` instead of replacing the entire `&self` with `&mut self`.
2025-01-29Rollup merge of #136104 - lqd:polonius-debugger-episode-2, r=matthewjasperLeón Orell Valerian Liehr-5/+136
Add mermaid graphs of NLL regions and SCCs to polonius MIR dump This PR expands the polonius MIR dump again with a couple of mermaid charts ported from the graphviz version: - the NLL region graph - and the NLL SCCs I still have done zero visual design on this until now, but [here's](https://gistpreview.github.io/?fbbf900fed2ad21108c7ca0353456398) how it looks (i.e. still bad) just to give an idea of the result. r? `````@matthewjasper````` (feel free to reassign) or anyone
2025-01-28Auto merge of #136203 - matthiaskrgr:rollup-1k0f44l, r=matthiaskrgrbors-1/+1
Rollup of 9 pull requests Successful merges: - #135869 (Make docs for AtomicUsize::from_mut platform-independent) - #135892 (-Znext-solver: "normalize" signature before checking it mentions self in `deduce_closure_signature`) - #136055 (Implement MIR const trait stability checks) - #136066 (Pass spans to `perform_locally_in_new_solver`) - #136071 ([Clippy] Add vec_reserve & vecdeque_reserve diagnostic items) - #136124 (Arbitrary self types v2: explain test.) - #136149 (Flip the `rustc-rayon`/`indexmap` dependency order) - #136173 (Update comments and sort target_arch in c_char_definition) - #136178 (Update username in build helper example) r? `@ghost` `@rustbot` modify labels: rollup
2025-01-28Tweak `&mut self` suggestion spanEsteban Küber-15/+10
``` error[E0596]: cannot borrow `*self.s` as mutable, as it is behind a `&` reference --> $DIR/issue-38147-1.rs:17:9 | LL | self.s.push('x'); | ^^^^^^ `self` is a `&` reference, so the data it refers to cannot be borrowed as mutable | help: consider changing this to be a mutable reference | LL | fn f(&mut self) { | +++ ``` Note the suggestion to add `mut` instead of replacing the entire `&self` with `&mut self`.
2025-01-28Move outlives env computation into methodsMichael Goulet-9/+7
2025-01-28Consolidate OutlivesEnv construction with resolve_regionsMichael Goulet-1/+1
2025-01-28Rollup merge of #136066 - compiler-errors:local-spans, r=lcnrMatthias Krüger-1/+1
Pass spans to `perform_locally_in_new_solver` Nothing changes yet, but we may be able to use these spans in the future once we start dealing w the response region constraints better. r? lcnr
2025-01-28Represent the raw pointer for a array length check as a new kind of fake borrowMichael Goulet-15/+17
2025-01-27Type level consts can show up in MIR type checkerMichael Goulet-2/+2
2025-01-26tidy up html structureRémy Rakic-4/+4
- invert pre/code which was an invalid combination, that works fine in practice - remove unneeded code wrapper for graphs
2025-01-26add NLL SCCs to polonius MIR dumpRémy Rakic-0/+49
2025-01-26add NLL region graph to the polonius MIR dumpRémy Rakic-1/+83
2025-01-25Rollup merge of #136031 - lqd:polonius-debugger-episode-1, r=compiler-errorsJacob Pratt-11/+170
Expand polonius MIR dump This PR starts expanding the polonius MIR: - switches to an HTML file, to show graphs in the same document as the MIR dump, share them more easily since it's a single file that can be hosted as a gist, and also to allow for interactivity in the near future. - adds the regular NLL MIR + polonius constraints - embeds a mermaid version of the CFG, similar to the graphviz one, but that needs a smaller js than `dot`'s emscripten js from graphvizonline [Here's an example](https://gistpreview.github.io/?0c18f2a59b5e24ac0f96447aa34ffe00) of how it looks. --- In future PRs: mermaid graphs of the NLL region graph, of the NLL SCCs, of the polonius localized outlives constraints, and the interactive polonius MIR dump. r? ```@matthewjasper```
2025-01-25Pass spans to perform_locally_in_new_solverMichael Goulet-1/+1
2025-01-25add CFG to polonius MIR dumpRémy Rakic-2/+71
2025-01-25switch polonius MIR dump to HTMLRémy Rakic-9/+67
escape the regular raw MIR into its own section
2025-01-25use more explicit MIR dumping processRémy Rakic-4/+36
2025-01-25Rollup merge of #136018 - estebank:long-moved-type, r=jieyouxuMatthias Krüger-6/+41
Use short ty string for move errors ``` error[E0382]: use of moved value: `x` --> bay.rs:14:14 | 12 | fn foo(x: D) { | - move occurs because `x` has type `(((..., ..., ..., ...), ..., ..., ...), ..., ..., ...)`, which does not implement the `Copy` trait 13 | let _a = x; | - value moved here 14 | let _b = x; //~ ERROR use of moved value | ^ value used here after move | = note: the full type name has been written to 'bay.long-type-14349227078439097973.txt' = note: consider using `--verbose` to print the full type name to the console help: consider cloning the value if the performance cost is acceptable | 13 | let _a = x.clone(); | ++++++++ ``` Address 4th case in #135919.
2025-01-24Use short ty string for move errorsEsteban Küber-6/+41
``` error[E0382]: use of moved value: `x` --> bay.rs:14:14 | 12 | fn foo(x: D) { | - move occurs because `x` has type `(((..., ..., ..., ...), ..., ..., ...), ..., ..., ...)`, which does not implement the `Copy` trait 13 | let _a = x; | - value moved here 14 | let _b = x; //~ ERROR use of moved value | ^ value used here after move | = note: the full type name has been written to 'bay.long-type-14349227078439097973.txt' = note: consider using `--verbose` to print the full type name to the console help: consider cloning the value if the performance cost is acceptable | 13 | let _a = x.clone(); | ++++++++ ```
2025-01-23`visit_x_unambig`Boxy-1/+1
2025-01-23Split hir `TyKind` and `ConstArgKind` in two and update `hir::Visitor`Boxy-4/+4
2025-01-23Make `hir::TyKind::TraitObject` use tagged ptrBoxy-1/+1
2025-01-22Rename `structurally_normalize` to `structurally_normalize_ty`Boxy-2/+2
2025-01-21Move supertrait_def_ids into the elaborate module like all other fnsMichael Goulet-3/+4
2025-01-19Run `clippy --fix` for `unnecessary_map_or` lintYotam Ofek-3/+3
2025-01-19Auto merge of #135709 - lqd:bring-back-len, r=compiler-errorsbors-5/+19
Temporarily bring back `Rvalue::Len` r? `@compiler-errors` as requested in https://github.com/rust-lang/rust/issues/135671#issuecomment-2599580364 > However, in the mean time, I'd rather we not crunch trying to find and more importantly validate the soundness of a solution 🤔 Agreed. To fix the IMO P-critical #135671 for which we somehow didn't have test coverage, this PR temporarily reverts: - https://github.com/rust-lang/rust/pull/133734 - its bugfix https://github.com/rust-lang/rust/pull/134371 - https://github.com/rust-lang/rust/pull/134330 cc `@scottmcm` I added the few samples from that issue as a test, but we can add more in the future, in particular it seems `@steffahn` [will work on that](https://github.com/rust-lang/rust/issues/135671#issuecomment-2599714354). Fixes #135671. And if we want to land this, it should also be nominated for beta backport.
2025-01-18Do not ICE on default_field_value const with lifetimesEsteban Küber-1/+5
Fix #135649.
2025-01-18Revert "Auto merge of #134330 - scottmcm:no-more-rvalue-len, r=matthewjasper"Rémy Rakic-5/+19
This reverts commit e108481f74ff123ad98a63bd107a18d13035b275, reversing changes made to 303e8bd768526a5812bb1776e798e829ddb7d3ca.
2025-01-18Auto merge of #135682 - matthiaskrgr:rollup-cl7zlt1, r=matthiaskrgrbors-40/+66
Rollup of 7 pull requests Successful merges: - #133700 (const-eval: detect more pointers as definitely not-null) - #135290 (Encode constraints that hold at all points as logical edges in location-sensitive polonius) - #135478 (Run clippy for rustc_codegen_gcc on CI) - #135583 (Move `std::pipe::*` into `std::io`) - #135612 (Include x scripts in tarballs) - #135624 (ci: mirror buildkit image to ghcr) - #135661 (Stabilize `float_next_up_down`) r? `@ghost` `@rustbot` modify labels: rollup
2025-01-18Rollup merge of #134455 - lcnr:move-errors-in-promoteds, r=compiler-errorsMatthias Krüger-9/+9
cleanup promoteds move check r? types
2025-01-17encode `Locations::All` typeck constraints as logical edgesRémy Rakic-25/+49
Instead of materializing `Locations::All` constraints as physical edges at all the points in the CFG, we record them as logical edges and only materialize them during traversal as successors for a given node. This fixes the slowness/hang in the `saturating-float-casts.rs` test.
2025-01-17make `LocalizedConstraintGraph` a struct and not an aliasRémy Rakic-21/+23
this prepares the code structure for adding logical edges to the graph next