summary refs log tree commit diff
path: root/compiler/rustc_borrowck/src
AgeCommit message (Collapse)AuthorLines
2025-02-14further simplify a matchdianne-12/+11
2025-02-13remove `fr_is_local` and `outlived_fr_is_local` fields from ↵dianne-31/+14
`ErrorConstraintInfo` `fr_is_local` was fully unused, and `outlived_fr_is_local` was used once
2025-02-13Rollup merge of #136559 - ↵Jacob Pratt-2/+5
compiler-errors:resolve-regions-for-type-test-failure, r=BoxyUwU Resolve named regions when reporting type test failures in NLL Just a improvement tweak to an error message that I broke out of a bigger PR that I had to close lol
2025-02-13Improved named region errorsMichael Goulet-2/+5
2025-02-12Auto merge of #135994 - 1c3t3a:rename-unsafe-ptr, r=oli-obkbors-1/+1
Rename rustc_middle::Ty::is_unsafe_ptr to is_raw_ptr 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. r? `@Noratrieb`
2025-02-11Deeply normalize signature in new solverMichael Goulet-6/+72
2025-02-11Deeply normalize in impl headerMichael Goulet-1/+1
2025-02-11Deeply normalize args for implied boundsMichael Goulet-1/+1
2025-02-11Make DeeplyNormalize a real type opMichael Goulet-34/+8
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-78/+91
2025-02-06Add opt_alias_variances and use it in outlives codeMichael Goulet-5/+7
2025-02-05Rollup merge of #128045 - pnkfelix:rustc-contracts, r=oli-obkLeón Orell Valerian Liehr-0/+1
#[contracts::requires(...)] + #[contracts::ensures(...)] cc https://github.com/rust-lang/rust/issues/128044 Updated contract support: attribute syntax for preconditions and postconditions, implemented via a series of desugarings that culminates in: 1. a compile-time flag (`-Z contract-checks`) that, similar to `-Z ub-checks`, attempts to ensure that the decision of enabling/disabling contract checks is delayed until the end user program is compiled, 2. invocations of lang-items that handle invoking the precondition, building a checker for the post-condition, and invoking that post-condition checker at the return sites for the function, and 3. intrinsics for the actual evaluation of pre- and post-condition predicates that third-party verification tools can intercept and reinterpret for their own purposes (e.g. creating shims of behavior that abstract away the function body and replace it solely with the pre- and post-conditions). Known issues: * My original intent, as described in the MCP (https://github.com/rust-lang/compiler-team/issues/759) was to have a rustc-prefixed attribute namespace (like rustc_contracts::requires). But I could not get things working when I tried to do rewriting via a rustc-prefixed builtin attribute-macro. So for now it is called `contracts::requires`. * Our attribute macro machinery does not provide direct support for attribute arguments that are parsed like rust expressions. I spent some time trying to add that (e.g. something that would parse the attribute arguments as an AST while treating the remainder of the items as a token-tree), but its too big a lift for me to undertake. So instead I hacked in something approximating that goal, by semi-trivially desugaring the token-tree attribute contents into internal AST constucts. This may be too fragile for the long-term. * (In particular, it *definitely* breaks when you try to add a contract to a function like this: `fn foo1(x: i32) -> S<{ 23 }> { ... }`, because its token-tree based search for where to inject the internal AST constructs cannot immediately see that the `{ 23 }` is within a generics list. I think we can live for this for the short-term, i.e. land the work, and continue working on it while in parallel adding a new attribute variant that takes a token-tree attribute alongside an AST annotation, which would completely resolve the issue here.) * the *intent* of `-Z contract-checks` is that it behaves like `-Z ub-checks`, in that we do not prematurely commit to including or excluding the contract evaluation in upstream crates (most notably, `core` and `std`). But the current test suite does not actually *check* that this is the case. Ideally the test suite would be extended with a multi-crate test that explores the matrix of enabling/disabling contracts on both the upstream lib and final ("leaf") bin crates.
2025-02-04fix NLL TLS end of function spansRémy Rakic-1/+13
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.