about summary refs log tree commit diff
path: root/compiler/rustc_borrowck
AgeCommit message (Collapse)AuthorLines
2023-11-26rustc: `hir().local_def_id_to_hir_id()` -> `tcx.local_def_id_to_hir_id()` ↵Vadim Petrochenkov-9/+9
cleanup
2023-11-26Auto merge of #117880 - lqd:liveness-values, r=cjgillotbors-62/+67
Refactor borrowck liveness values This PR starts cleaning up `rustc_borrowck`, in particular around liveness values: - refactors simple names that make no sense anymore: either referring to older structures using region elements, or to bitset containers and values. - improves comments and fixes others - removes unused return values and unneeded generic arguments r? `@matthewjasper`
2023-11-26Clean dead codesr0cky-60/+0
2023-11-25Rollup merge of #118158 - nnethercote:reduce-fluent-boilerplate, ↵Michael Goulet-3/+2
r=compiler-errors Reduce fluent boilerplate Best reviewed one commit at a time. r? `@davidtwco`
2023-11-26Use `rustc_fluent_macro::fluent_messages!` directly.Nicholas Nethercote-2/+1
Currently we always do this: ``` use rustc_fluent_macro::fluent_messages; ... fluent_messages! { "./example.ftl" } ``` But there is no need, we can just do this everywhere: ``` rustc_fluent_macro::fluent_messages! { "./example.ftl" } ``` which is shorter.
2023-11-26Avoid need for `{D,Subd}iagnosticMessage` imports.Nicholas Nethercote-1/+1
The `fluent_messages!` macro produces uses of `crate::{D,Subd}iagnosticMessage`, which means that every crate using the macro must have this import: ``` use rustc_errors::{DiagnosticMessage, SubdiagnosticMessage}; ``` This commit changes the macro to instead use `rustc_errors::{D,Subd}iagnosticMessage`, which avoids the need for the imports.
2023-11-25Remove HirId from QPath::LangItemMichael Goulet-8/+4
2023-11-25Auto merge of #118203 - nnethercote:rustc_mir_dataflow, r=cjgillotbors-18/+18
Minor `rustc_mir_dataflow` cleanups r? `@cjgillot`
2023-11-24Remove unused `EverInitializedPlaces::tcx` field.Nicholas Nethercote-1/+1
2023-11-23Use `'mir` lifetime name more.Nicholas Nethercote-17/+17
Some types have a `body: &'mir Body<'tcx>` and some have `body: &'a Body<'tcx>`. The former is more readable, so this commit converts some fo the latter to the former.
2023-11-22Replace `no_ord_impl` with `orderable`.Nicholas Nethercote-0/+4
Similar to the previous commit, this replaces `newtype_index`'s opt-out `no_ord_impl` attribute with the opt-in `orderable` attribute.
2023-11-22Replace `custom_encodable` with `encodable`.Nicholas Nethercote-1/+0
By default, `newtype_index!` types get a default `Encodable`/`Decodable` impl. You can opt out of this with `custom_encodable`. Opting out is the opposite to how Rust normally works with autogenerated (derived) impls. This commit inverts the behaviour, replacing `custom_encodable` with `encodable` which opts into the default `Encodable`/`Decodable` impl. Only 23 of the 59 `newtype_index!` occurrences need `encodable`. Even better, there were eight crates with a dependency on `rustc_serialize` just from unused default `Encodable`/`Decodable` impls. This commit removes that dependency from those eight crates.
2023-11-22Auto merge of #117928 - nnethercote:rustc_ast_pretty, r=fee1-deadbors-1/+1
`rustc_ast_pretty` cleanups Some improvements I found while looking at this code. r? `@fee1-dead`
2023-11-22Update itertools to 0.11.Nicholas Nethercote-1/+1
Because the API for `with_position` improved in 0.11 and I want to use it.
2023-11-21Fix `clippy::needless_borrow` in the compilerNilstrieb-76/+72
`x clippy compiler -Aclippy::all -Wclippy::needless_borrow --fix`. Then I had to remove a few unnecessary parens and muts that were exposed now.
2023-11-21Rollup merge of #118035 - ouz-a:november_ice2, r=compiler-errorsNilstrieb-2/+9
Fix early param lifetimes in generic_const_exprs In cases like below, we never actually be able to capture region name for two reasons, first `'static` becomes anonymous lifetime and second we never capture region if it doesn't have a name so this results in ICE. ``` struct DataWrapper<'static> { data: &'a [u8; Self::SIZE], } impl DataWrapper<'a> { ``` Fixes https://github.com/rust-lang/rust/issues/118021
2023-11-20Fix early param lifetimes in generic_const_exprsouz-a-2/+9
2023-11-20Rollup merge of #117835 - Nilstrieb:note-object-lifetime-defaults, ↵Matthias Krüger-10/+76
r=compiler-errors Note about object lifetime defaults in does not live long enough error This is a aspect of Rust that frequently trips up people who are not aware of it yet. This diagnostic attempts to explain what's happening and why the lifetime constraint, that was never mentioned in the source, arose. The implementation feels a bit questionable, I'm not sure whether there are better ways to do this. There probably are. fixes #117835 r? types
2023-11-17Auto merge of #117944 - lcnr:region-refactor-uwu, r=BoxyUwUbors-8/+9
some additional region refactorings the commits are selfcontained ✨ r? `@BoxyUwU`
2023-11-17Auto merge of #112422 - aliemjay:implied-bounds-placeholders, r=lcnrbors-1/+4
ignore implied bounds with placeholders given the following code: ```rust trait Trait { type Ty<'a> where Self: 'a; } impl<T> Trait for T { type Ty<'a> = () where Self: 'a; } struct Foo<T: Trait>(T) where for<'x> T::Ty<'x>: Sized; ``` when computing the implied bounds from `Foo<X>` we incorrectly get the bound `X: !x` from the normalization of ` for<'x> <X as Trait>::Ty::<'x>: Sized`. This is a a known bug! we shouldn't use the constraints that arise from normalization as implied bounds. See #109628. Ignore these bounds for now. This should prevent later ICEs. Fixes #112250 Fixes #107409
2023-11-17rename bound region instantiationlcnr-8/+9
- `erase_late_bound_regions` -> `instantiate_bound_regions_with_erased` - `replace_late_bound_regions_X` -> `instantiate_bound_regions_X`
2023-11-16Auto merge of #116097 - jackh726:higher-ranked-lifetime-error-backup, ↵bors-13/+54
r=compiler-errors Try to use approximate placeholder regions when outputting an AscribeUserType error in borrowck Fixes #114866 Hi from GOSIM :)
2023-11-16ignore implied bounds with placeholdersAli MJ Al-Nasrawy-1/+4
2023-11-15Re-format code with new rustfmtMark Rousskov-1/+2
2023-11-15Bump cfg(bootstrap)sMark Rousskov-2/+2
2023-11-14finish `RegionKind` renamelcnr-32/+35
- `ReFree` -> `ReLateParam` - `ReEarlyBound` -> `ReEarlyParam`
2023-11-14rename debugging support functionsRémy Rakic-11/+14
2023-11-14`LivenessValues` does not need to be generic over regionsRémy Rakic-18/+18
2023-11-14introduce `is_live_anywhere` instead of peeking into pointsRémy Rakic-6/+12
and refactor misnamed `get_elements`
2023-11-13fix docRémy Rakic-5/+3
2023-11-13regions do not contain liveness elementsRémy Rakic-8/+8
2023-11-13refer to points and not "elements", and remove unused return valueRémy Rakic-6/+5
2023-11-13add locations instead of "element"s, and remove unused return valueRémy Rakic-10/+9
2023-11-13iterate over regions and not "rows" in liveness valuesRémy Rakic-3/+3
2023-11-13stop referring to a region as a "row" in liveness valuesRémy Rakic-17/+17
2023-11-13continue renaminglcnr-7/+7
- `RegionVariableOrigin::~~Late~~BoundRegion` - `~~Late~~BoundRegionConversionTime`
2023-11-13rename `ReLateBound` to `ReBound`lcnr-4/+4
other changes: - `Region::new_late_bound` -> `Region::new_bound` - `Region::is_late_bound` -> `Region::is_bound`
2023-11-13remove unnecessary `_` in variable namelcnr-2/+2
2023-11-13add fixme to `RegionCtxt`lcnr-0/+3
2023-11-12Note about object lifetime defaults in does not live long enough errorNilstrieb-10/+76
This is a aspect of Rust that frequently trips up people who are not aware of it yet. This diagnostic attempts to explain what's happening and why the lifetime constraint, that was never mentioned in the source, arose.
2023-11-09Auto merge of #117712 - lcnr:expand-coroutine, r=jackh726bors-31/+30
generator layout: ignore fake borrows fixes #117059 We emit fake shallow borrows in case the scrutinee place uses a `Deref` and there is a match guard. This is necessary to prevent the match guard from mutating the scrutinee: https://github.com/rust-lang/rust/blob/fab1054e1742790c22ccc92a625736d658363677/compiler/rustc_mir_build/src/build/matches/mod.rs#L1250-L1265 These fake borrows end up impacting the generator witness computation in `mir_generator_witnesses`, which causes the issue in #117059. This PR now completely ignores fake borrows during this computation. This is sound as thse are always removed after analysis and the actual computation of the generator layout happens afterwards. Only the second commit impacts behavior, and could be backported by itself. r? types
2023-11-08rename `BorrowKind::Shallow` to `Fake`lcnr-31/+30
also adds some comments
2023-11-08Auto merge of #117560 - lqd:issue-117146, r=matthewjasperbors-13/+14
Compute polonius loan scopes over the region graph In issue #117146 a loan flows into an SCC containing a placeholder, and whose representative is an existential region. Since we currently compute loan scopes by looking at SCCs and their representatives only, polonius would compute kill points for this loan here whereas NLLs would not of course. There are a few ways to fix this: - don't try to be efficient by doing the computation over SCCs, and simply look for free regions and placeholders in the successors of the issuing region. - change how the SCC representatives are picked, biasing towards placeholders over existential regions. They *shouldn't* matter much, but some downstream code may subtly depend on the current scheme (though no tests fail if we do such a change). This is for unrelated reasons also the way #116891 changes the representative computation. So that PR would also fix issue #117146. - try to remove placeholders from the main path, and contain them to a pre-pass + a post-pass kind of polonius leak check. If possible, it would fix this issue by turning an outlives constraints to a placeholder into a constraint to 'static. This should also fix the issue, as the representative would be the free region in the SCC. We want to prototype this change to see if it's possible to try to simplify the borrowck main path from having to deal with placeholders and higher-ranked subtyping 🤞. I'd like to take advantage of fuzzing and a crater run sooner rather than later, so that we grow more confidence that the 2 models are indeed equivalent empirically. Therefore this PR implements option 1 to fix the issue now. We can take care of efficiency later after validation, and once we implement option 3 (which could also impact option 2 and that associated PR, maybe the lack of placeholders could remove the need to change the representative computation) to traverse SCCs and their representative again. (Or we maybe will have some kind of naive position-dependent outlives propagation by then and this code would have been changed) Fixes #117146. r? `@matthewjasper`
2023-11-07Auto merge of #117511 - gurry:117406-err-packed-structs, r=compiler-errorsbors-1/+19
Emit explanatory note for move errors in packed struct derives Derive expansions for packed structs with non-`Copy` fields cause move errors because they prefer copying over borrowing since borrowing the fields of a packed struct can result in unaligned access. This underlying cause of the errors, however, is not apparent to the user. This PR adds a diagnostic note to make it clear to the user (the new note is on the second last line): ``` tests/ui/derives/deriving-with-repr-packed-move-errors.rs:13:16 | 12 | #[derive(Debug, PartialEq, Eq, PartialOrd, Ord, Hash, Clone, Default)] | ----- in this derive macro expansion 13 | struct StructA(String); | ^^^^^^ move occurs because `self.0` has type `String`, which does not implement the `Copy` trait | = note: `#[derive(Debug)]` triggers a move because taking references to the fields of a packed struct is undefined behaviour = note: this error originates in the derive macro `Debug` (in Nightly builds, run with -Z macro-backtrace for more info) ``` Fixes #117406 Partially addresses #110777
2023-11-04traverse region graph instead of SCCs to compute polonius loan scopesRémy Rakic-13/+14
By using SCC for better performance, we also have to take into account SCCs whose representative is an existential region but also contains a placeholder. By only checking the representative, we may miss that the loan escapes the function. This can be fixed by picking a better representative, or removing placeholders from the main path. This is the simplest fix: forgo efficiency and traverse the region graph instead of the SCCs.
2023-11-03Emit explanatory note for move errors in packed struct derivesGurinder Singh-1/+19
Derive expansions for packed structs cause move errors because they prefer copying over borrowing since borrowing the fields of a packed struct can result in unaligned access and therefore undefined behaviour. This underlying cause of the errors, however, is not apparent to the user. We add a diagnostic note here to remedy that.
2023-11-02Minimize `pub` usage in `source_map.rs`.Nicholas Nethercote-3/+2
Most notably, this commit changes the `pub use crate::*;` in that file to `use crate::*;`. This requires a lot of `use` items in other crates to be adjusted, because everything defined within `rustc_span::*` was also available via `rustc_span::source_map::*`, which is bizarre. The commit also removes `SourceMap::span_to_relative_line_string`, which is unused.
2023-10-31prepopulate opaque ty storage before using it :>lcnr-6/+8
2023-10-30Rollup merge of #117357 - tmiasko:terminate, r=wesleywiserGuillaume Gomez-1/+1
Rename a few remaining references to abort terminator Follow up to e3f2edc75bf2becb57d7d770bba20606da1c4224
2023-10-30Clean up `rustc_*/Cargo.toml`.Nicholas Nethercote-6/+6
- Sort dependencies and features sections. - Add `tidy` markers to the sorted sections so they stay sorted. - Remove empty `[lib`] sections. - Remove "See more keys..." comments. Excluded files: - rustc_codegen_{cranelift,gcc}, because they're external. - rustc_lexer, because it has external use. - stable_mir, because it has external use.