about summary refs log tree commit diff
path: root/compiler/rustc_borrowck
AgeCommit message (Collapse)AuthorLines
2024-12-13rustc_borrowck: Convert suggest_ampmut() 4-tuple to struct for readabilityMartin Nordholts-13/+46
2024-12-13rustc_borrowck: Stop suggesting the invalid syntax `&mut raw const`Martin Nordholts-0/+5
A legitimate suggestion would be to change from &raw const val to &raw mut val But until we have figured out how to make that happen we should at least stop suggesting invalid syntax.
2024-12-13rustc_borrowck: Make suggest_ampmut() return type match its useMartin Nordholts-9/+8
So that it becomes easy for a later commit to return `None`.
2024-12-12Make BorrowSet/BorrowData fields accessible via public gettersWill Crichton-10/+56
2024-12-11Make some types and methods related to Polonius + Miri public.Will Crichton-14/+14
2024-12-10Rename some `Analysis` and `ResultsVisitor` methods.Nicholas Nethercote-23/+23
The words "before" and "after" have an obvious temporal meaning, e.g. `seek_before_primary_effect`, `visit_statement_{before,after}_primary_effect`. But "before" is also used to name the effect that occurs before the primary effect of a statement/terminator; this is `Effect::Before`. This leads to the confusing possibility of talking about things happening "before/after the before event". This commit removes this awkward overloading of "before" by renaming `Effect::Before` as `Effect::Early`. It also renames some of the `Analysis` and `ResultsVisitor` methods to be more consistent. Here are the before and after names: - `Effect::{Before,Primary}` -> `Effect::{Early,Primary}` - `apply_before_statement_effect` -> `apply_early_statement_effect` - `apply_statement_effect` -> `apply_primary_statement_effect` - `visit_statement_before_primary_effect` -> `visit_after_early_statement_effect` - `visit_statement_after_primary_effect` -> `visit_after_primary_statement_effect` (And s/statement/terminator/ for all the terminator events.)
2024-12-10Rename `EntrySets` as `EntryStates`.Nicholas Nethercote-6/+6
"Set" doesn't make much sense here, we refer to domain values as "state" everywhere else. (This name confused me for a while.)
2024-12-10Call all `Domain` values `state`.Nicholas Nethercote-15/+15
Currently they are called (most common) `state`, or `trans`, or (rare) `on_entry`. I think `trans` is short for "transfer function", which perhaps made more sense when `GenKillAnalysis` existed. Using `state` everywhere now is more consistent.
2024-12-10Remove lifetimes from `BorrowckDomain`.Nicholas Nethercote-34/+30
They are only present because it's currently defined in terms of the domains of `Borrows` and `MaybeUninitializedPlaces` and `EverInitializedPlaces` via associated types. This commit introduces typedefs for those domains, avoiding the lifetimes.
2024-12-09Introduce `default_field_values` featureEsteban Küber-2/+6
Initial implementation of `#[feature(default_field_values]`, proposed in https://github.com/rust-lang/rfcs/pull/3681. Support default fields in enum struct variant Allow default values in an enum struct variant definition: ```rust pub enum Bar { Foo { bar: S = S, baz: i32 = 42 + 3, } } ``` Allow using `..` without a base on an enum struct variant ```rust Bar::Foo { .. } ``` `#[derive(Default)]` doesn't account for these as it is still gating `#[default]` only being allowed on unit variants. Support `#[derive(Default)]` on enum struct variants with all defaulted fields ```rust pub enum Bar { #[default] Foo { bar: S = S, baz: i32 = 42 + 3, } } ``` Check for missing fields in typeck instead of mir_build. Expand test with `const` param case (needs `generic_const_exprs` enabled). Properly instantiate MIR const The following works: ```rust struct S<A> { a: Vec<A> = Vec::new(), } S::<i32> { .. } ``` Add lint for default fields that will always fail const-eval We *allow* this to happen for API writers that might want to rely on users' getting a compile error when using the default field, different to the error that they would get when the field isn't default. We could change this to *always* error instead of being a lint, if we wanted. This will *not* catch errors for partially evaluated consts, like when the expression relies on a const parameter. Suggestions when encountering `Foo { .. }` without `#[feature(default_field_values)]`: - Suggest adding a base expression if there are missing fields. - Suggest enabling the feature if all the missing fields have optional values. - Suggest removing `..` if there are no missing fields.
2024-12-09Auto merge of #133891 - nnethercote:MixedBitSet, r=Mark-Simulacrumbors-2/+2
Introduce `MixedBitSet` `ChunkedBitSet` is good at avoiding excessive memory usage for programs with very large functgions where dataflow bitsets have very large domain sizes. But it's overly heavyweight for small bitsets, because any non-empty `ChunkedBitSet` takes up at least 256 bytes. This PR introduces `MixedBitSet`, which is a simple bitset that uses `BitSet` for small/medium bitsets and `ChunkedBitSet` for large bitsets. It's a speed and memory usage win. r? `@Mark-Simulacrum`
2024-12-07Mention type parameter in more cases and don't suggest ~const bound already ↵Esteban Küber-3/+4
there
2024-12-05Change `ChunkedBitSet<MovePathIndex>`s to `MixedBitSet`.Nicholas Nethercote-2/+2
It's a performance win because `MixedBitSet` is faster and uses less memory than `ChunkedBitSet`. Also reflow some overlong comment lines in `lint_tail_expr_drop_order.rs`.
2024-12-04add assertlcnr-0/+7
2024-12-04remove unnecessary `eval_verify_bound`lcnr-18/+1
2024-12-04Rollup merge of #133798 - lcnr:nested-bodies-opaques, r=compiler-errorsMatthias Krüger-43/+8
stop replacing bivariant args with `'static` when computing closure requirements It is unnecessary, these get constrained when checking that the opaque type is well-formed. It also results in the opaque type no longer being well formed. If you've got `fn foo<'a>() -> impl Sized + 'a` the opaque is `type Opaque<'a, 'aDummy> where 'a: 'aDummy, 'aDummy: 'a` where `'aDummy` is bivariant. If we call `foo::<'b>()` inside of a closure and its return type ends up in a type test, we start out with the WF `Opaque<'b, 'b>`, and then replace the bivariant `'b` with `'static`. `Opaque<'b, 'static>` is no longer well-formed. Given how these type tests are used, I don't think this caused any practical issues. r? types
2024-12-03Rollup merge of #133545 - clubby789:symbol-intern-lit, r=jieyouxuMatthias Krüger-6/+4
Lint against Symbol::intern on a string literal Disabled in tests where this doesn't make much sense
2024-12-03small code cleanuplcnr-10/+7
2024-12-03closure requirements: don't replace bivariant opaque argslcnr-30/+0
It is unnecessary, these get constrained when checking that the opaque type is well-formed. It also results in the opaque type no longer being well formed. If you've got `fn foo<'a>() -> impl Sized + 'a` the opaque is `type Opaque<'a, 'aDummy> where 'a: 'aDummy, 'aDummy: 'a` where `'aDummy` is bivariant. If we call `foo::<'b>()` inside of a closure and its return type ends up in a type test, we start out with the WF `Opaque<'b, 'b>`, and then replace the bivariant `'b` with `'static`. `Opaque<'b, 'static>` is no longer well-formed. Given how these type tests are used, I don't think this caused any practical issues.
2024-12-03update instrumentationlcnr-3/+1
2024-11-28Replace `Symbol::intern` calls with preinterned symbolsclubby789-6/+4
2024-11-28uplift fold_regions to rustc_type_irlcnr-13/+19
2024-11-27Structurally resolve before applying projection in borrowckMichael Goulet-2/+40
2024-11-25`add_move_error_suggestions`: use a HIR visitor rather than `SourceMap`dianne-39/+118
2024-11-25Refactor `where` predicates, and reserve for attributes supportFrank King-11/+7
2024-11-20reduce false positives of tail-expr-drop-order from consumed valuesDing Xiang Fei-0/+5
take 2 open up coroutines tweak the wordings the lint works up until 2021 We were missing one case, for ADTs, which was causing `Result` to yield incorrect results. only include field spans with significant types deduplicate and eliminate field spans switch to emit spans to impl Drops Co-authored-by: Niko Matsakis <nikomat@amazon.com> collect drops instead of taking liveness diff apply some suggestions and add explantory notes small fix on the cache let the query recurse through coroutine new suggestion format with extracted variable name fine-tune the drop span and messages bugfix on runtime borrows tweak message wording filter out ecosystem types earlier apply suggestions clippy check lint level at session level further restrict applicability of the lint translate bid into nop for stable mir detect cycle in type structure
2024-11-19move `fn is_item_raw` to `TypingEnv`lcnr-1/+2
2024-11-19Pass `flow_inits` by value.Nicholas Nethercote-11/+7
It's simpler that way, and we don't need the explicit `drop`.
2024-11-19Put `param_env` into `infcx`.Nicholas Nethercote-81/+72
Because they get passed around together a lot.
2024-11-19Pass `constraints` to `RegionInferenceContext::new`.Nicholas Nethercote-37/+25
Instead of destructuring it in advance and passing all the components individually. It's less code that way.
2024-11-19Don't refcount `PlaceholderIndices`.Nicholas Nethercote-5/+3
It's not necessary.
2024-11-19Inline and remove `TypeVerifier::new`.Nicholas Nethercote-8/+1
It has a single call site.
2024-11-19Compute `upvars` lazily.Nicholas Nethercote-7/+3
It can be computed from `tcx` on demand, instead of computing it eagerly and passing it around.
2024-11-19Clean up `UniversalRegions`.Nicholas Nethercote-60/+46
There is an `Rc<UniversalRegions>` within `UniversalRegionRelations`, and yet the two types get passed around in tandem a lot. This commit makes `UniversalRegionRelations` own `UniversalRegions`, removing the `Rc` (which wasn't truly needed) and the tandem-passing. This requires adding a `universal_relations` method to `UniversalRegionRelations`, and renaming a couple of existing methods producing iterators to avoid a name clash.
2024-11-19Make `TypeChecker::region_bound_pairs` owned.Nicholas Nethercote-4/+4
No reason not to be, and it's simpler that way.
2024-11-19Make `TypeChecker::known_type_outlives_obligations` owned.Nicholas Nethercote-9/+7
This avoids the need to arena allocate it. `ConstraintConversion` needs some simple lifetime adjustments to allow this.
2024-11-19Don't pass `universal_regions` unnecessarily.Nicholas Nethercote-6/+5
`TypeChecker` already has it in a field.
2024-11-18reviewlcnr-1/+3
2024-11-18use `TypingEnv` when no `infcx` is availablelcnr-8/+19
the behavior of the type system not only depends on the current assumptions, but also the currentnphase of the compiler. This is mostly necessary as we need to decide whether and how to reveal opaque types. We track this via the `TypingMode`.
2024-11-17Rollup merge of #133130 - dianne:fix-133118, r=compiler-errorsJacob Pratt-16/+10
`suggest_borrow_generic_arg`: instantiate clauses properly This simplifies and fixes the way `suggest_borrow_generic_arg` instantiates callees' predicates when testing them to see if a moved argument can instead be borrowed. Previously, it would ICE if the moved argument's type included a region variable, since it was getting passed to a call of `EarlyBinder::instantiate`. This makes the instantiation much more straightforward, which also fixes the ICE. Fixes #133118 This also modifies `tests/ui/moves/moved-value-on-as-ref-arg.rs` to have more useful bounds on the tests for suggestions to borrow `Borrow` and `BorrowMut` arguments. With its old tautological `T: BorrowMut<T>` bound, this fix would make it suggest a shared borrow for that argument.
2024-11-17`suggest_borrow_generic_arg`: instantiate clauses properlydianne-16/+10
Fixes issue 133118. This also modifies `tests/ui/moves/moved-value-on-as-ref-arg.rs` to have more useful bounds on the tests for suggestions to borrow `Borrow` and `BorrowMut` arguments. With its old tautological `T: BorrowMut<T>` bound, this fix would make it suggest a shared borrow for that argument.
2024-11-16Rollup merge of #132134 - nnethercote:rm-ResultsVisitable, r=cjgillotMatthias Krüger-80/+173
Remove `ResultsVisitable` `ResultsVisitable` has annoyed me for a while. This PR removes it. Details in the individual commits. r? `@cjgillot.`
2024-11-13Suggest borrowing arguments in generic positions when trait bounds are satisfieddianne-159/+157
This subsumes the suggestions to borrow arguments with `AsRef`/`Borrow` bounds and those to borrow arguments with `Fn` and `FnMut` bounds. It works for other traits implemented on references as well, such as `std::io::Read`, `std::io::Write`, and `core::fmt::Write`. Incidentally, by making the logic for suggesting borrowing closures general, this removes some spurious suggestions to mutably borrow `FnMut` closures in assignments, as well as an unhelpful suggestion to add a `Clone` constraint to an `impl Fn` argument.
2024-11-13Use a common subdiagnostic format for generic borrowsdianne-5/+10
This is setup for unifing the logic for suggestions to borrow arguments in generic positions. As of this commit, it's still special cases for `AsRef`/`Borrow`-like traits and `Fn`-like traits.
2024-11-13Provide borrow-instead-of-move suggestions for calls of fn-like items from ↵dianne-39/+40
other crates This also downgrades its applicability to MaybeIncorrect. Its suggestion can result in ill-typed code when the type parameter it suggests providing a different generic argument for appears elsewhere in the callee's signature or predicates.
2024-11-09Dont suggest use<APIT>Michael Goulet-26/+45
2024-11-08Get rid of check_opaque_type_well_formedMichael Goulet-89/+1
2024-11-05Auto merge of #132580 - compiler-errors:globs, r=Noratriebbors-23/+20
Remove unnecessary pub enum glob-imports from `rustc_middle::ty` We used to have an idiom in the compiler where we'd prefix or suffix all the variants of an enum, for example `BoundRegionKind`, with something like `Br`, and then *glob-import* that enum variant directly. `@noratrieb` brought this up, and I think that it's easier to read when we just use the normal style `EnumName::Variant`. This PR is a bit large, but it's just naming. The only somewhat opinionated change that this PR does is rename `BorrowKind::Imm` to `BorrowKind::Immutable` and same for the other variants. I think these enums are used sparingly enough that the extra length is fine. r? `@noratrieb` or reassign
2024-11-04Rollup merge of #131153 - VulnBandit:copy_impl_vuln, r=compiler-errorsJubilee-0/+17
Improve duplicate derive Copy/Clone diagnostics Improve duplicate derive Copy/Clone diagnostics. Closes #131083
2024-11-05Remove `ResultsVisitable`.Nicholas Nethercote-10/+6
Now that `Results` is the only impl of `ResultsVisitable`, the trait can be removed. This simplifies things by removining unnecessary layers of indirection and abstraction. - `ResultsVisitor` is simpler. - Its type parameter changes from `R` (an analysis result) to the simpler `A` (an analysis). - It no longer needs the `Domain` associated type, because it can use `A::Domain`. - Occurrences of `R` become `Results<'tcx, A>`, because there is now only one kind of analysis results. - `save_as_intervals` also changes type parameter from `R` to `A`. - The `results.reconstruct_*` method calls are replaced with `results.analysis.apply_*` method calls, which are equivalent. - `Direction::visit_results_in_block` is simpler, with a single generic param (`A`) instead of two (`D` and `R`/`F`, with a bound connecting them). Likewise for `visit_results`. - The `ResultsVisitor` impls for `MirBorrowCtxt` and `StorageConflictVisitor` are now specific about the type of the analysis results they work with. They both used to have a type param `R` but they weren't genuinely generic. In both cases there was only a single results type that made sense to instantiate them with.