summary refs log tree commit diff
path: root/compiler/rustc_borrowck/src
AgeCommit message (Collapse)AuthorLines
2022-01-03Rollup merge of #90102 - nbdd0121:box3, r=jonas-schievinkMatthias Krüger-4/+0
Remove `NullOp::Box` Follow up of #89030 and MCP rust-lang/compiler-team#460. ~1 month later nothing seems to be broken, apart from a small regression that #89332 (1aac85bb716c09304b313d69d30d74fe7e8e1a8e) shows could be regained by remvoing the diverging path, so it shall be safe to continue and remove `NullOp::Box` completely. r? `@jonas-schievink` `@rustbot` label T-compiler
2021-12-30Use SparseIntervalMatrix instead of SparseBitMatrixMark Rousskov-17/+20
Region inference contains several bitsets which are filled with large intervals representing liveness. These can cause excessive memory usage, and are relatively slow when growing to large sizes compared to the IntervalSet.
2021-12-29Refactor variance diagnostics to work with more typesAaron Hill-7/+37
Instead of special-casing mutable pointers/references, we now support general generic types (currently, we handle `ty::Ref`, `ty::RawPtr`, and `ty::Adt`) When a `ty::Adt` is involved, we show an additional note explaining which of the type's generic parameters is invariant (e.g. the `T` in `Cell<T>`). Currently, we don't explain *why* a particular generic parameter ends up becoming invariant. In the general case, this could require printing a long 'backtrace' of types, so doing this would be more suitable for a follow-up PR. We still only handle the case where our variance switches to `ty::Invariant`.
2021-12-22Store a `DefId` instead of an `AdtDef` in `AggregateKind::Adt`Aaron Hill-3/+4
The `AggregateKind` enum ends up in the final mir `Body`. Currently, any changes to `AdtDef` (regardless of how significant they are) will legitimately cause the overall result of `optimized_mir` to change, invalidating any codegen re-use involving that mir. This will get worse once we start hashing the `Span` inside `FieldDef` (which is itself contained in `AdtDef`). To try to reduce these kinds of invalidations, this commit changes `AggregateKind::Adt` to store just the `DefId`, instead of the full `AdtDef`. This allows the result of `optimized_mir` to be unchanged if the `AdtDef` changes in a way that doesn't actually affect any of the MIR we build.
2021-12-19Auto merge of #91957 - nnethercote:rm-SymbolStr, r=oli-obkbors-3/+3
Remove `SymbolStr` This was originally proposed in https://github.com/rust-lang/rust/pull/74554#discussion_r466203544. As well as removing the icky `SymbolStr` type, it allows the removal of a lot of `&` and `*` occurrences. Best reviewed one commit at a time. r? `@oli-obk`
2021-12-18get_mut_span_in_struct_field uses span.betweenLucas Kent-8/+6
2021-12-17Improve suggestion to change struct field to &mutLucas Kent-26/+13
2021-12-15Remove in_band_lifetimes from borrowckDániel Buga-33/+32
2021-12-15Remove unnecessary sigils around `Symbol::as_str()` calls.Nicholas Nethercote-3/+3
2021-12-14Stabilize iter::zip.PFPoitras-1/+0
2021-12-12Revert "Auto merge of #91491 - spastorino:revert-91354, r=oli-obk"Deadbeef-1/+1
This reverts commit ff2439b7b9bafcfdff86b7847128014699df8442, reversing changes made to 2a9e0831d6603d87220cedd1b1293e2eb82ef55c.
2021-12-11Auto merge of #91799 - matthiaskrgr:rollup-b38xx6i, r=matthiaskrgrbors-2/+115
Rollup of 6 pull requests Successful merges: - #83174 (Suggest using a temporary variable to fix borrowck errors) - #89734 (Point at capture points for non-`'static` reference crossing a `yield` point) - #90270 (Make `Borrow` and `BorrowMut` impls `const`) - #90741 (Const `Option::cloned`) - #91548 (Add spin_loop hint for RISC-V architecture) - #91721 (Minor improvements to `future::join!`'s implementation) Failed merges: r? `@ghost` `@rustbot` modify labels: rollup
2021-12-11Rollup merge of #89734 - estebank:issue-72312, r=nikomatsakisMatthias Krüger-0/+1
Point at capture points for non-`'static` reference crossing a `yield` point ``` error[E0759]: `self` has an anonymous lifetime `'_` but it needs to satisfy a `'static` lifetime requirement --> $DIR/issue-72312.rs:10:24 | LL | pub async fn start(&self) { | ^^^^^ this data with an anonymous lifetime `'_`... ... LL | require_static(async move { | -------------- ...is required to live as long as `'static` here... LL | &self; | ----- ...and is captured here | note: `'static` lifetime requirement introduced by this trait bound --> $DIR/issue-72312.rs:2:22 | LL | fn require_static<T: 'static>(val: T) -> T { | ^^^^^^^ error: aborting due to previous error For more information about this error, try `rustc --explain E0759`. ``` Fix #72312.
2021-12-10Suggest using a temporary variable to fix borrowck errorsNoah Lev-2/+114
In Rust, nesting method calls with both require `&mut` access to `self` produces a borrow-check error: error[E0499]: cannot borrow `*self` as mutable more than once at a time --> src/lib.rs:7:14 | 7 | self.foo(self.bar()); | ---------^^^^^^^^^^- | | | | | | | second mutable borrow occurs here | | first borrow later used by call | first mutable borrow occurs here That's because Rust has a left-to-right evaluation order, and the method receiver is passed first. Thus, the argument to the method cannot then mutate `self`. There's an easy solution to this error: just extract a local variable for the inner argument: let tmp = self.bar(); self.foo(tmp); However, the error doesn't give any suggestion of how to solve the problem. As a result, new users may assume that it's impossible to express their code correctly and get stuck. This commit adds a (non-structured) suggestion to extract a local variable for the inner argument to solve the error. The suggestion uses heuristics that eliminate most false positives, though there are a few false negatives (cases where the suggestion should be emitted but is not). Those other cases can be implemented in a future change.
2021-12-10Point at capture points for non-`'static` reference crossing a `yield` pointEsteban Kuber-0/+1
``` error[E0759]: `self` has an anonymous lifetime `'_` but it needs to satisfy a `'static` lifetime requirement --> $DIR/issue-72312.rs:10:24 | LL | pub async fn start(&self) { | ^^^^^ this data with an anonymous lifetime `'_`... ... LL | require_static(async move { | -------------- ...is required to live as long as `'static` here... LL | &self; | ----- ...and is captured here | note: `'static` lifetime requirement introduced by this trait bound --> $DIR/issue-72312.rs:2:22 | LL | fn require_static<T: 'static>(val: T) -> T { | ^^^^^^^ error: aborting due to previous error For more information about this error, try `rustc --explain E0759`. ``` Fix #72312.
2021-12-07Store impl_trait_fn inside OpaqueTyOrigin.Camille GILLOT-1/+1
2021-12-04Auto merge of #88439 - cynecx:unwind_asm, r=Amanieubors-6/+13
Unwinding support for inline assembly r? `@Amanieu`
2021-12-04Rollup merge of #91488 - compiler-errors:issue-91477, r=estebankMatthias Krüger-3/+23
Fix ICE when `yield`ing in function returning `impl Trait` Change an assert to a `delay_span_bug` and remove an unwrap, that should fix it. Fixes #91477
2021-12-03Add initial AST and MIR support for unwinding from inline assemblyAmanieu d'Antras-6/+13
2021-12-03Revert "Auto merge of #91354 - fee1-dead:const_env, r=spastorino"Santiago Pastorino-1/+1
This reverts commit 18bb8c61a975fff6424cda831ace5b0404277145, reversing changes made to d9baa361902b172be716f96619b909f340802dea.
2021-12-02Fix ICE when yielding in fn returning impl TraitMichael Goulet-3/+23
2021-12-02Rollup merge of #91321 - matthewjasper:constaint-placeholders, r=jackh726Matthias Krüger-1/+14
Handle placeholder regions in NLL type outlive constraints Closes #76168
2021-12-02Auto merge of #91455 - matthiaskrgr:rollup-gix2hy6, r=matthiaskrgrbors-28/+40
Rollup of 4 iffy pull requests Successful merges: - #89234 (Disallow non-c-like but "fieldless" ADTs from being casted to integer if they use arbitrary enum discriminant) - #91045 (Issue 90702 fix: Stop treating some crate loading failures as fatal errors) - #91394 (Bump stage0 compiler) - #91411 (Enable svh tests on msvc) Failed merges: r? `@ghost` `@rustbot` modify labels: rollup
2021-12-02Rollup merge of #91394 - Mark-Simulacrum:bump-stage0, r=pietroalbiniMatthias Krüger-28/+40
Bump stage0 compiler r? `@pietroalbini` (or anyone else)
2021-12-02Auto merge of #91354 - fee1-dead:const_env, r=spastorinobors-1/+1
Cleanup: Eliminate ConstnessAnd This is almost a behaviour-free change and purely a refactoring. "almost" because we appear to be using the wrong ParamEnv somewhere already, and this is now exposed by failing a test using the unstable `~const` feature. We most definitely need to review all `without_const` and at some point should probably get rid of many of them by using `TraitPredicate` instead of `TraitRef`. This is a continuation of https://github.com/rust-lang/rust/pull/90274. r? `@oli-obk` cc `@spastorino` `@ecstatic-morse`
2021-12-01Auto merge of #90446 - cjgillot:late-elided, r=jackh726bors-1/+1
Lint elided lifetimes in path during lifetime resolution. The lifetime elision lint is known to be brittle and can be redundant with later lifetime resolution errors. This PR aims to remove the redundancy by performing the lint after lifetime resolution. This PR proposes to carry the information that an elision should be linted against by using a special `LifetimeName`. I am not certain this is the best solution, but it is certainly the easiest. Fixes https://github.com/rust-lang/rust/issues/60199 Fixes https://github.com/rust-lang/rust/issues/55768 Fixes https://github.com/rust-lang/rust/issues/63110 Fixes https://github.com/rust-lang/rust/issues/71957
2021-12-01Rollup merge of #90985 - camsteffen:diag-name-usage, r=jackh726Matthias Krüger-20/+15
Use `get_diagnostic_name` more
2021-11-30Rollup merge of #91294 - cjgillot:process-elem, r=jackh726Matthias Krüger-17/+1
Visit type in process_projection_elem. Instead of reimplementing it for each visitor.
2021-11-30Merge Implicit and ImplicitMissing.Camille GILLOT-3/+1
2021-11-30Lint elided lifetimes in path during lifetime resolution.Camille GILLOT-1/+3
2021-11-30re-format with new rustfmtMark Rousskov-27/+40
2021-11-30Apply cfg-bootstrap switchMark Rousskov-1/+0
2021-11-30Rollup merge of #91243 - jackh726:issue-91068, r=nikomatsakisYuki Okushi-4/+2
Don't treat unnormalized function arguments as well-formed Partial revert of #88312 r? ``@pnkfelix`` cc ``@nikomatsakis``
2021-11-29Completely remove ConstnessAndOli Scherer-1/+1
2021-11-27Visit type in process_projection_elem.Camille GILLOT-17/+1
2021-11-26Handle placeholder regions in NLL type outlive constraintsMatthew Jasper-1/+14
2021-11-25Don't treat unnormalized function arguments as well-formedjackh726-4/+2
2021-11-25Fix issue 91206Michael Goulet-10/+14
2021-11-24Auto merge of #90491 - Mark-Simulacrum:push-pred-faster, r=matthewjasperbors-28/+40
Optimize live point computation This refactors the live-point computation to lower per-MIR-instruction costs by operating on a largely per-block level. This doesn't fundamentally change the number of operations necessary, but it greatly improves the practical performance by aggregating bit manipulation into ranges rather than single-bit; this scales much better with larger blocks. On the benchmark provided in #90445, with 100,000 array elements, walltime for a check build is improved from 143 seconds to 15. I consider the tiny losses here acceptable given the many small wins on real world benchmarks and large wins on stress tests. The new code scales much better, but on some subset of inputs the slightly higher constant overheads decrease performance somewhat. Overall though, this is expected to be a big win for pathological cases (as illustrated by the test case motivating this work) and largely not material for non-pathological cases. I consider the new code somewhat easier to follow, too.
2021-11-21Simplify for loop desugarCameron Steffen-19/+30
2021-11-16Use get_diagnostic_name moreCameron Steffen-20/+15
2021-11-16Rollup merge of #90801 - b-naber:missing_normalization_equate_inputs_output, ↵Yuki Okushi-24/+41
r=jackh726 Normalize both arguments of `equate_normalized_input_or_output` Fixes https://github.com/rust-lang/rust/issues/90638 Fixes https://github.com/rust-lang/rust/issues/90612 Temporary fix for a more complex underlying problem stemming from an inability to normalize closure substs during typecheck. r? ````@jackh726````
2021-11-15Stabilize format_args_captureJosh Triplett-1/+1
Works as expected, and there are widespread reports of success with it, as well as interest in it.
2021-11-11normalize argument b in equate_normalized_inputs_outputb-naber-24/+41
2021-11-09Rollup merge of #89561 - nbdd0121:const_typeck, r=nikomatsakisMatthias Krüger-46/+150
Type inference for inline consts Fixes #78132 Fixes #78174 Fixes #81857 Fixes #89964 Perform type checking/inference of inline consts in the same context as the outer def, similar to what is currently done to closure. Doing so would require `closure_base_def_id` of the inline const to return the outer def, and since `closure_base_def_id` can be called on non-local crate (and thus have no HIR available), a new `DefKind` is created for inline consts. The type of the generated anon const can capture lifetime of outer def, so we couldn't just use the typeck result as the type of the inline const's def. Closure has a similar issue, and it uses extra type params `CK, CS, U` to capture closure kind, input/output signature and upvars. I use a similar approach for inline consts, letting it have an extra type param `R`, and then `typeof(InlineConst<[paremt generics], R>)` would just be `R`. In borrowck region requirements are also propagated to the outer MIR body just like it's currently done for closure. With this PR, inline consts in expression position are quitely usable now; however the usage in pattern position is still incomplete -- since those does not remain in the MIR borrowck couldn't verify the lifetime there. I have left an ignored test as a FIXME. Some disucssions can be found on [this Zulip thread](https://rust-lang.zulipchat.com/#narrow/stream/260443-project-const-generics/topic/inline.20consts.20typeck). cc `````@spastorino````` `````@lcnr````` r? `````@nikomatsakis````` `````@rustbot````` label A-inference F-inline_const T-compiler
2021-11-08Make select_* methods return Vec for TraitEngineDeadbeef-1/+1
2021-11-07more clippy fixesMatthias Krüger-1/+1
2021-11-07Rename functions reflect that inline const is also "typeck_child"Gary Guo-37/+27
2021-11-07Ensure closure requirements are proven for inline constGary Guo-5/+79
2021-11-07Implement type inference for inline constsGary Guo-13/+53
In most cases it is handled in the same way as closures.