about summary refs log tree commit diff
path: root/compiler/rustc_borrowck/src
AgeCommit message (Collapse)AuthorLines
2023-06-07Rollup merge of #112122 - compiler-errors:next-coherence, r=lcnrDylan DPC-2/+2
Add `-Ztrait-solver=next-coherence` Flag that conditionally uses the trait solver *only* during coherence, for more testing and/or eventual partial-migration onto the trait solver (in the medium- to long-term). * This still uses the selection context in some of the coherence methods I think, so it's not "complete". Putting this up for review and/or for further work in-tree. * I probably need to spend a bit more time making sure that we don't sneakily create any other infcx's during coherence that also need the new solver enabled. r? `@lcnr`
2023-06-06Auto merge of #112361 - matthiaskrgr:rollup-39zxrw1, r=matthiaskrgrbors-9/+3
Rollup of 8 pull requests Successful merges: - #111250 (Add Terminator conversion from MIR to SMIR, part #2) - #112310 (Add new Tier-3 targets: `loongarch64-unknown-none*`) - #112334 (Add myself to highfive rotation) - #112340 (remove `TyCtxt::has_error_field` helper method) - #112343 (Prevent emitting `missing_docs` for `pub extern crate`) - #112350 (Avoid duplicate type sanitization of local decls in borrowck) - #112356 (Fix comment for `get_region_var_origins`) - #112358 (Remove default visitor impl in region constraint generation) r? `@ghost` `@rustbot` modify labels: rollup
2023-06-06Rollup merge of #112358 - Nilstrieb:fancy-more-borrowck-cleanups, ↵Matthias Krüger-6/+2
r=compiler-errors Remove default visitor impl in region constraint generation I wanted to group it together with other possibly minor borrowck cleanups but that's all I have right now so I rather put it up than forget about it before doing something else. r? `@compiler-errors`
2023-06-06Remove default visitor impl in region constraint generationNilstrieb-6/+2
2023-06-06Avoid duplicate type sanitization of local declsNilstrieb-3/+1
The type of the local decl is already sanitized in `visit_local_decl`.
2023-06-06New trait solver is a property of inference contextMichael Goulet-2/+2
2023-06-06Rollup merge of #112019 - jieyouxu:issue-111554, r=compiler-errorsMatthias Krüger-6/+22
Don't suggest changing `&self` and `&mut self` in function signature to be mutable when taking `&mut self` in closure Current suggestion for when taking a mutable reference to `self` in a closure (as an upvar) will produce a machine-applicable suggestion to change the `self` in the function signature to `mut self`, but does not account for the specialness of implicit self in that it can already have `&` and `&mut` (see #111554). This causes the function signature to become `test(&mut mut self)` which does not seem desirable. ``` error[E0596]: cannot borrow `self` as mutable, as it is not declared as mutable --> src/sound_player.rs:870:11 | 869 | pub fn test(&mut self) { | ---- help: consider changing this to be mutable: `mut self` 870 | || test2(&mut self); | ^^^^^^^^^ cannot borrow as mutable ``` This PR suppresses the "changing this to be mutable" suggestion if the implicit self is either `ImplicitSelfKind::ImmRef` or `ImplicitSelfKind::MutRef`. Fixes #111554.
2023-06-02Simplify pre-order algorithm.Camille GILLOT-51/+43
2023-06-01Rollup merge of #111980 - compiler-errors:unmapped-substs, r=lcnrDylan DPC-9/+13
Preserve substs in opaques recorded in typeck results This means that we now prepopulate MIR with opaques with the right substs. The first commit is a hack that I think we discussed, having to do with `DefiningAnchor::Bubble` basically being equivalent to `DefiningAnchor::Error` in the new solver, so having to use `DefiningAnchor::Bind` instead, lol. r? `@lcnr`
2023-05-31Auto merge of #112070 - lcnr:disjoint-closure-capture-ub, r=oli-obkbors-3/+2
change `BorrowKind::Unique` to be a mutating `PlaceContext` fixes #112056 I believe that `BorrowKind::Unique` is a footgun in general, so I added a FIXME and opened https://github.com/rust-lang/rust/issues/112072. This is a bit too involved for this PR though.
2023-05-29Rename `tcx.mk_re_*` => `Region::new_*`Maybe Waffle-31/+34
2023-05-29unique borrows are mutating useslcnr-3/+2
2023-05-29Don't suggest changing {ImmRef,MutRef} implicit self to be mutable许杰友 Jieyou Xu (Joe)-6/+22
2023-05-27Rollup merge of #111983 - compiler-errors:type-op-locally, r=lcnrGuillaume Gomez-1/+1
Perform MIR type ops locally in new solver The new solver already does caching, and it's generally more correct to be using the infcx of the MIR typeck (which has the defining anchor set correctly and has already initialized all the opaques from HIR typeck). This is based on #111918 so look at the final 3 commits. This actually causes some tests to go from passing to failing, and failing to passing. Here's the full diff: https://www.diffchecker.com/hB4bh1A9/ Putting this up for exposure mostly. r? `@lcnr`
2023-05-27Rollup merge of #111952 - cjgillot:drop-replace, r=WaffleLapkinGuillaume Gomez-39/+21
Remove DesugaringKind::Replace. A simple boolean flag is enough.
2023-05-27Uplift complex type ops back into typeck so we can call them locallyMichael Goulet-1/+1
2023-05-26Wait until type_of to remap HIR opaques back to their defn paramsMichael Goulet-7/+1
2023-05-26Use DefiningAnchor::Bind in infer_opaque_definition_from_instantiationMichael Goulet-2/+12
2023-05-25Remove DesugaringKind::Replace.Camille GILLOT-39/+21
2023-05-25Fallible<_> -> Result<_, NoSolution>Michael Goulet-7/+8
2023-05-25Use ErrorGuaranteed more in MIR type opsMichael Goulet-86/+65
2023-05-25Add InferCtxt::register_hidden_type_in_new_solverMichael Goulet-1/+0
2023-05-25Pre-populate MIR with opaques, prefer subst-relate candidateMichael Goulet-0/+62
2023-05-25Move DefiningAnchorMichael Goulet-3/+6
2023-05-25Auto merge of #111925 - Manishearth:rollup-z6z6l2v, r=Manishearthbors-110/+188
Rollup of 5 pull requests Successful merges: - #111741 (Use `ObligationCtxt` in custom type ops) - #111840 (Expose more information in `get_body_with_borrowck_facts`) - #111876 (Roll compiler_builtins to 0.1.92) - #111912 (Use `Option::is_some_and` and `Result::is_ok_and` in the compiler ) - #111915 (libtest: Improve error when missing `-Zunstable-options`) r? `@ghost` `@rustbot` modify labels: rollup
2023-05-24Rollup merge of #111912 - WaffleLapkin:is_some_and_in_the_compiler, ↵Manish Goregaokar-14/+9
r=petrochenkov Use `Option::is_some_and` and `Result::is_ok_and` in the compiler `.is_some_and(..)`/`.is_ok_and(..)` replace `.map_or(false, ..)` and `.map(..).unwrap_or(false)`, making the code more readable. This PR is a sibling of https://github.com/rust-lang/rust/pull/111873#issuecomment-1561316515
2023-05-24Rollup merge of #111840 - voidc:borrowck-consumers, r=oli-obkManish Goregaokar-63/+140
Expose more information in `get_body_with_borrowck_facts` Verification tools for Rust such as, for example, Creusot or Prusti would benefit from having access to more information computed by the borrow checker. As a first step in that direction, #86977 added the `get_body_with_borrowck_facts` API, allowing compiler consumers to obtain a `mir::Body` with accompanying borrow checker information. At RustVerify 2023, multiple people working on verification tools expressed their need for a more comprehensive API. While eventually borrow information could be part of Stable MIR, in the meantime, this PR proposes a more limited approach, extending the existing `get_body_with_borrowck_facts` API. In summary, we propose the following changes: - Permit obtaining the borrow-checked body without necessarily running Polonius - Return the `BorrowSet` and the `RegionInferenceContext` in `BodyWithBorrowckFacts` - Provide a way to compute the `borrows_out_of_scope_at_location` map - Make some helper methods public This is similar to #108328 but smaller in scope. `@smoelius` Do you think these changes would also be sufficient for your needs? r? `@oli-obk` cc `@JonasAlaif`
2023-05-24Rollup merge of #111741 - compiler-errors:custom-type-op, r=lcnrManish Goregaokar-33/+39
Use `ObligationCtxt` in custom type ops We already make one when evaluating the `CustomTypeOp`, so it's simpler to just pass it to the user. Removes a redundant `ObligationCtxt::new_in_snapshot` usage and simplifies some other code. This makes several refactorings related to opaque types in the new solver simpler, but those are not included in this PR.
2023-05-24Rollup merge of #111863 - compiler-errors:check-more-mir, r=b-naberMatthias Krüger-27/+9
Don't skip mir typeck if body has errors Comment says: ``` // if verifier failed, don't do further checks to avoid ICEs ``` But there are no ICEs to be found. The comment is quite old, so perhaps something fixed it... maybe because the MIR typechecker is delaying span bugs rather than panicking via eager bugs? IDK I'm generally inclined to fix the ICEs themselves that were to arise from this, rather than just totally skipping large parts of the compiler that have impacts on downstream logic (namely, our opaque type results are affected). Anyways, this happens on the error path, so it shouldn't really matter. Fixes this hack: https://github.com/rust-lang/rust/pull/111853/files#r1201501540
2023-05-24Rollup merge of #111759 - cjgillot:interval-kill, r=b-naberMatthias Krüger-50/+77
Leverage the interval property to precompute borrow kill points.
2023-05-24Don't skip mir typeck if body has errorsMichael Goulet-27/+9
2023-05-24Auto merge of #111673 - cjgillot:dominator-preprocess, r=cjgillot,tmiaskobors-8/+3
Preprocess and cache dominator tree Preprocessing dominators has a very strong effect for https://github.com/rust-lang/rust/pull/111344. That pass checks that assignments dominate their uses repeatedly. Using the unprocessed dominator tree caused a quadratic runtime (number of bbs x depth of the dominator tree). This PR also caches the dominator tree and the pre-processed dominators in the MIR cfg cache. Rebase of https://github.com/rust-lang/rust/pull/107157 cc `@tmiasko`
2023-05-24Use ObligationCtxt in custom type opsMichael Goulet-33/+39
2023-05-24Use `is_some_and`/`is_ok_and` in less obvious spotsMaybe Waffle-10/+5
2023-05-24Use `Option::is_some_and` and `Result::is_ok_and` in the compilerMaybe Waffle-4/+4
2023-05-23Add RegionInferenceContext::outlives_constraintsDominik Stolz-1/+7
2023-05-23Move BodyWithBorrowckFacts to consumersDominik Stolz-31/+34
2023-05-23Make place helpers accessibleDominik Stolz-0/+2
2023-05-23Return promoteds in BodyWithBorrowckFactsDominik Stolz-0/+3
2023-05-23Allow consumers to retrieve borrowck outputJonáš Fiala-48/+111
2023-05-22Check opaques for mismatch during writebackMichael Goulet-0/+2
2023-05-19Leverage the interval property to precompute borrow kill points.Camille GILLOT-50/+77
2023-05-18Take MIR dataflow analyses by mutable reference.Jason Newcomb-12/+15
2023-05-17Compute dominators on demand for borrowck.Camille GILLOT-8/+8
2023-05-17Cache dominators.Camille GILLOT-12/+7
2023-05-16Avoid `&format("...")` calls in error message code.Nicholas Nethercote-4/+4
Error message all end up passing into a function as an `impl Into<{D,Subd}iagnosticMessage>`. If an error message is creatd as `&format("...")` that means we allocate a string (in the `format!` call), then take a reference, and then clone (allocating again) the reference to produce the `{D,Subd}iagnosticMessage`, which is silly. This commit removes the leading `&` from a lot of these cases. This means the original `String` is moved into the `{D,Subd}iagnosticMessage`, avoiding the double allocations. This requires changing some function argument types from `&str` to `String` (when all arguments are `String`) or `impl Into<{D,Subd}iagnosticMessage>` (when some arguments are `String` and some are `&str`).
2023-05-15Move expansion of query macros in rustc_middle to rustc_middle::queryJohn Kåre Alsaker-1/+1
2023-05-13Rollup merge of #110454 - oli-obk:limited_impl_trait_in_assoc_type, ↵Dylan DPC-2/+2
r=compiler-errors Require impl Trait in associated types to appear in method signatures This implements the limited version of TAIT that was proposed in https://github.com/rust-lang/rust/issues/107645#issuecomment-1477899536 Similar to `impl Trait` in return types, `impl Trait` in associated types may only be used within the impl block which it is a part of. To make everything simpler and forward compatible to getting desugared to a plain type alias impl trait in the future, we're requiring that any associated functions or constants that want to register hidden types must be using the associated type in their signature (type of the constant or argument/return type of the associated method. Where bounds mentioning the associated type are ignored). We have preexisting tests checking that this works transitively across multiple associated types in situations like ```rust impl Foo for Bar { type A = impl Trait; type B = impl Iterator<Item = Self::A>; fn foo() -> Self::B { ...... } } ```
2023-05-12Auto merge of #111396 - vlad20012:reduce-Borrows-dataflow-bitset-size, ↵bors-1/+1
r=cjgillot Reduce BitSet size used in `Borrows` dataflow analysis It looks like it is not needed to multiply the number of borrows by 2. Bits greater than `self.borrow_set.len()` are never set in this bitset. This should decrease the memory usage by an epsilon.
2023-05-12Require `impl Trait` in associated types to appear in method signaturesOli Scherer-2/+2