about summary refs log tree commit diff
path: root/compiler/rustc_borrowck/src
AgeCommit message (Collapse)AuthorLines
2023-07-21Double check that hidden types match the expected hidden typeOli Scherer-2/+2
2023-07-17Rename arg_iter to iter_instantiatedMichael Goulet-1/+1
2023-07-14Rollup merge of #113599 - chenyukang:yukang-fix-use-maybe_body_owned_by, ↵Matthias Krüger-77/+61
r=cjgillot Use maybe_body_owned_by for multiple suggestions This is a continued work from https://github.com/rust-lang/rust/pull/113567 We have several other suggestions not working for closure, this PR use `maybe_body_owned_by` to fix them and add test cases for them.
2023-07-14refactor(rustc_middle): Substs -> GenericArgMahdi Dibaiee-246/+237
2023-07-14fix the issue of shorthand in suggest_cloningyukang-3/+15
2023-07-14use maybe_body_owned_by for closureyukang-74/+46
2023-07-12Re-format let-else per rustfmt updateMark Rousskov-78/+107
2023-07-12Auto merge of #112945 - compiler-errors:tighten-span-of-adjustment-error, ↵bors-4/+4
r=oli-obk (re-)tighten sourceinfo span of adjustments in MIR Diagnostics rely on the spans of MIR statements being (approximately) correct in order to give suggestions relative to that span (i.e. `shrink_to_hi` and `shrink_to_lo`). I discovered that we're *intentionally* lowering THIR exprs with their parent expr's span if they come from adjustments that are due to a parent expression. While I understand why that may be desirable to demonstrate the relationship of an adjustment and the expression that requires it, it leads to 1. very verbose borrowck output 2. incorrect spans for suggestions Some diagnostics get around that by giving suggestions relative to other spans we've collected during MIR lowering, such as the span of the method's identifier (e.g. `name` in `.name()`), but this doesn't work too well when things come from desugaring. I assume it also has lead to numerous tweaks and complications to diagnostics code down the road, which this PR doesn't necessarily aim to fix but may open the gates to fixing later... The last three commits are simplifications due to the fact that we can assume that the move span actually points to what is being moved (and a test). This regressed in #89110, which was debated somewhat in #90286. cc `@Aaron1011` who originally made this change. r? diagnostics Fixes #113547 Fixes #111016
2023-07-11Auto merge of #113316 - DrMeepster:underefer_perf, r=oli-obkbors-2/+2
Rewrite `UnDerefer`, again This PR is intended to improve the perf regression introduced by #112882. `UnDerefer` has been separated out again for borrowck reasons. It was a bit overzealous to remove it in the previous PR. r? `@oli-obk`
2023-07-10Fix another strange suggestion spanMichael Goulet-2/+2
2023-07-10Don't use method span on clone suggestionMichael Goulet-2/+2
2023-07-07Rename `adjustment::PointerCast` and variants using it to `PointerCoercion`Nilstrieb-9/+13
It makes it sound like the `ExprKind` and `Rvalue` are supposed to represent all pointer related casts, when in reality their just used to share a some enum variants. Make it clear there these are only coercion to make it clear why only some pointer related "casts" are in the enum.
2023-07-05Move `TyCtxt::mk_x` to `Ty::new_x` where applicableBoxy-16/+17
2023-07-04bring back un_derefer and rewrite it againDrMeepster-2/+2
2023-07-03Auto merge of #112882 - DrMeepster:new_un_derefer, r=oli-obkbors-1/+1
Rewrite `UnDerefer` Currently, `UnDerefer` is used by drop elaboration to undo the effects of the `Derefer` pass. However, it just recreates the original places with derefs in the middle of the projection. Because `ProjectionElem::Deref` is intended to be removed completely in the future, this will not work forever. This PR introduces a `deref_chain` method that returns the places behind `DerefTemp` locals in a place and rewrites the move path code to use this. In the process, `UnDerefer` was merged into `MovePathLookup`. Now that move paths use the same places as in the MIR, the other uses of `UnDerefer` no longer require it. See #98145 cc `@ouz-a` r? `@oli-obk`
2023-07-01Rollup merge of #113174 - chenyukang:yukang-fix-102972-loop-next, ↵Matthias Krüger-2/+80
r=compiler-errors Better messages for next on a iterator inside for loops Fixes #102972
2023-06-30add typecheck for iteratoryukang-20/+17
2023-06-30Better messages for next in a iterator inside for loopsyukang-2/+83
2023-06-30Rollup merge of #111403 - y21:suggest-slice-swap, r=compiler-errorsMatthias Krüger-3/+4
suggest `slice::swap` for `mem::swap(&mut x[0], &mut x[1])` borrowck error Recently saw someone ask why this code (example slightly modified): ```rs fn main() { let mut foo = [1, 2]; std::mem::swap(&mut foo[0], &mut foo[1]); } ``` triggers this error and how to fix it: ``` error[E0499]: cannot borrow `foo[_]` as mutable more than once at a time --> src/main.rs:4:33 | 4 | std::mem::swap(&mut foo[0], &mut foo[1]); | -------------- ----------- ^^^^^^^^^^^ second mutable borrow occurs here | | | | | first mutable borrow occurs here | first borrow later used by call | = help: consider using `.split_at_mut(position)` or similar method to obtain two mutable non-overlapping sub-slices ``` The current help message is nice and goes in the right direction, but I think we can do better for this specific instance and suggest `slice::swap`, which makes this compile
2023-06-29Merge `un_derefer` into `MovePathLookup`DrMeepster-1/+1
2023-06-29add `slice::swap` suggestiony21-3/+4
2023-06-28don't suggest `move` for borrows that aren't closuresLukas Markeffsky-13/+14
2023-06-28Rollup merge of #112236 - cjgillot:interval-kill, r=davidtwcoDylan DPC-51/+43
Simplify computation of killed borrows Follow-up to https://github.com/rust-lang/rust/pull/111759 Processing the first block manually once makes the pre-order walk simpler.
2023-06-27Extract the local != local case in borrow_conflicts_with_place.Camille GILLOT-76/+67
2023-06-27Only consider places with the same local in each_borrow_involving_path.Camille GILLOT-14/+20
2023-06-27Auto merge of #112938 - compiler-errors:clause-3, r=oli-obkbors-7/+7
Migrate `TyCtxt::predicates_of` and `ParamEnv::caller_bounds` to `Clause` The last big change in the series. I will follow-up with additional filed issues once this PR lands: - [ ] Investigate making `TypeFoldable<TyCtxt<'tcx>> for ty::Clause<'tcx>` implementation less weird: https://github.com/rust-lang/rust/blob/2efe09170530fa18e42ff05b8d9dd23f00b5c430/compiler/rustc_middle/src/ty/structural_impls.rs#L672 - [ ] Clean up the elaborator since it should only be emitting child clauses, not predicates - [ ] Rename identifiers like `pred` and `predicates` to `clause` if they're actually clauses around the codebase - [ ] Validate that all of the `ToPredicate` impls are acutally still needed, or prune them if they're not r? `@ghost` until the other branch lands
2023-06-27Auto merge of #112693 - ericmarkmartin:use-more-placeref, r=spastorinobors-36/+12
Use PlaceRef abstractions more often Associated issue: https://github.com/rust-lang/rust/issues/80647 r? `@spastorino`
2023-06-26Migrate predicates_of and caller_bounds to ClauseMichael Goulet-7/+7
2023-06-25use PlaceRef abstractions more consistentlyEric Mark Martin-36/+12
2023-06-24Rollup merge of #112703 - aliemjay:next-solver-root-var, r=compiler-errorsGuillaume Gomez-3/+2
[-Ztrait-solver=next, mir-typeck] instantiate hidden types in the root universe Fixes an ICE in the test `member-constraints-in-root-universe`. Main motivation is to make #112691 pass under the new solver. r? ``@compiler-errors``
2023-06-24instantiate hidden types in root universeAli MJ Al-Nasrawy-3/+2
2023-06-23Rollup merge of #112870 - compiler-errors:clause-2, r=oli-obkMatthias Krüger-1/+1
Migrate `item_bounds` to `ty::Clause` Should be simpler than the next PR that's coming up. Last three commits are the relevant ones. r? ``@oli-obk`` or ``@lcnr``
2023-06-23Rollup merge of #112933 - TaKO8Ki:avoid-&format-in-error-message-code, r=oli-obkMatthias Krüger-1/+1
Avoid `&format` in error message code follow-up of #111633
2023-06-22Migrate item_bounds to ty::ClauseMichael Goulet-1/+1
2023-06-23avoid `&format` in error message codeTakayuki Maeda-1/+1
2023-06-21Rollup merge of #112772 - compiler-errors:clauses-1, r=lcnrNilstrieb-17/+21
Add a fully fledged `Clause` type, rename old `Clause` to `ClauseKind` Does two basic things before I put up a more delicate set of PRs (along the lines of #112714, but hopefully much cleaner) that migrate existing usages of `ty::Predicate` to `ty::Clause` (`predicates_of`/`item_bounds`/`ParamEnv::caller_bounds`). 1. Rename `Clause` to `ClauseKind`, so it's parallel with `PredicateKind`. 2. Add a new `Clause` type which is parallel to `Predicate`. * This type exposes `Clause::kind(self) -> Binder<'tcx, ClauseKind<'tcx>>` which is parallel to `Predicate::kind` 😸 The new `Clause` type essentially acts as a newtype wrapper around `Predicate` that asserts that it is specifically a `PredicateKind::Clause`. Turns out from experimentation[^1] that this is not negative performance-wise, which is wonderful, since this a much simpler design than something that requires encoding the discriminant into the alignment bits of a predicate kind, or something else like that... r? ``@lcnr`` or ``@oli-obk`` [^1]: https://github.com/rust-lang/rust/pull/112714#issuecomment-1595653910
2023-06-20address most easy commentsZiru Niu-12/+15
2023-06-20merge `BorrowKind::Unique` into `BorrowKind::Mut`Ziru Niu-54/+55
2023-06-19Rollup merge of #112781 - compiler-errors:new-solver-tait-overlaps-hidden, ↵Michael Goulet-1/+2
r=lcnr Don't consider TAIT normalizable to hidden ty if it would result in impossible item bounds See test for example where we shouldn't consider it possible to alias-relate a TAIT and hidden type. r? `@lcnr`
2023-06-19Rollup merge of #112232 - fee1-dead-contrib:match-eq-const-msg, r=b-naberMichael Goulet-16/+25
Better error for non const `PartialEq` call generated by `match` Resolves #90237
2023-06-19s/Clause/ClauseKindMichael Goulet-17/+21
2023-06-19Don't consider TAIT normalizable to hidden ty if it would result in ↵Michael Goulet-1/+2
impossible item bounds
2023-06-18Better error for non const `PartialEq` call generated by `match`Deadbeef-16/+25
2023-06-17Move WF goal to clauseMichael Goulet-5/+8
2023-06-15Rollup merge of #112654 - aliemjay:closure-output-normalize, r=compiler-errorsGuillaume Gomez-15/+1
normalize closure output in equate_inputs_and_outputs Fixes #112604
2023-06-15normalize closure output before relationAli MJ Al-Nasrawy-15/+1
2023-06-09split opaque type handling in new solverlcnr-7/+21
be more explicit in where we only add new hidden types and where we also have to deal with item bounds.
2023-06-09extract opaque type wf check into separate fnlcnr-65/+74
2023-06-09recompute opaque type originlcnr-18/+11
2023-06-08Auto merge of #108293 - Jarcho:mut_analyses, r=eholkbors-12/+15
Take MIR dataflow analyses by mutable reference The main motivation here is any analysis requiring dynamically sized scratch memory to work. One concrete example would be pointer target tracking, where tracking the results of a dereference can result in multiple possible targets. This leads to processing multi-level dereferences requiring the ability to handle a changing number of potential targets per step. A (simplified) function for this would be `fn apply_deref(potential_targets: &mut Vec<Target>)` which would use the scratch space contained in the analysis to send arguments and receive the results. The alternative to this would be to wrap everything in a `RefCell`, which is what `MaybeRequiresStorage` currently does. This comes with a small perf cost and loses the compiler's guarantee that we don't try to take multiple borrows at the same time. For the implementation: * `AnalysisResults` is an unfortunate requirement to avoid an unconstrained type parameter error. * `CloneAnalysis` could just be `Clone` instead, but that would result in more work than is required to have multiple cursors over the same result set. * `ResultsVisitor` now takes the results type on in each function as there's no other way to have access to the analysis without cloning it. This could use an associated type rather than a type parameter, but the current approach makes it easier to not care about the type when it's not necessary. * `MaybeRequiresStorage` now no longer uses a `RefCell`, but the graphviz formatter now does. It could be removed, but that would require even more changes and doesn't really seem necessary.