about summary refs log tree commit diff
path: root/compiler/rustc_borrowck
AgeCommit message (Collapse)AuthorLines
2021-10-11Rollup merge of #89675 - oli-obk:type_checker, r=davidtwcoMatthias Krüger-81/+53
Re-use TypeChecker instead of passing around some of its fields In the future (for lazy TAIT) we will need more of its fields, but even ignoring that, this change seems reasonable on its own to me.
2021-10-08Rollup merge of #89649 - matthiaskrgr:clippycompl, r=jyn514Guillaume Gomez-3/+2
clippy::complexity fixes
2021-10-08clippy::complexity fixesMatthias Krüger-3/+2
2021-10-08Directly call relate_types function instead of having a method wrapperOli Scherer-37/+26
2021-10-08Re-use TypeChecker instead of passing around some of its fieldsOli Scherer-48/+31
2021-10-07Rollup merge of #89615 - willcrichton:fix-get-body-with-borrowck-facts, ↵Guillaume Gomez-1/+1
r=oli-obk Add InferCtxt::with_opaque_type_inference to get_body_with_borrowck_facts `mir_borrowck` uses `with_opaque_type_inference` before calling `do_mir_borrowck`: https://github.com/rust-lang/rust/blob/0eabf25b90396dead0b2a1aaa275af18a1ae6008/compiler/rustc_borrowck/src/lib.rs#L132 However `get_body_with_borrowck_facts` does not. Therefore I get an ICE eg when calling this function on the bodies of an async function as described here: https://rust-lang.zulipchat.com/#narrow/stream/182449-t-compiler.2Fhelp/topic/.E2.9C.94.20ICE.20when.20using.20get_body_with_borrowck_facts.20with.20async This change fixes that bug. r? `@nikomatsakis`
2021-10-06Add InferCtxt::with_opaque_type_inference to get_body_with_borrowck_factsWill Crichton-1/+1
2021-10-05Note specific regions involved in 'borrowed data escapes' errorAaron Hill-0/+21
Fixes #67007 Currently, a 'borrowed data escapes' error does not mention the specific lifetime involved (except indirectly through a suggestion about adding a lifetime bound). We now explain the specific lifetime relationship that failed to hold, which improves otherwise vague error messages.
2021-10-04Rollup merge of #89504 - Aaron1011:rpit-nll-static, r=nikomatsakisManish Goregaokar-3/+1
Don't suggest replacing region with 'static in NLL Fixes #73159 This is similar to #69350 - if the user didn't initially write out a 'static lifetime, adding 'static in response to a lifetime error is usually the wrong thing to do.
2021-10-04Rollup merge of #89508 - jhpratt:stabilize-const_panic, r=joshtriplettJubilee-1/+1
Stabilize `const_panic` Closes #51999 FCP completed in #89006 ```@rustbot``` label +A-const-eval +A-const-fn +T-lang cc ```@oli-obk``` for review (not `r?`'ing as not on lang team)
2021-10-04Stabilize `const_panic`Jacob Pratt-1/+1
2021-10-03Rollup merge of #88481 - bjorn3:remove_feature_gates, r=cjgillotManish Goregaokar-2/+2
Remove some feature gates The first commit removes various feature gates that are unused. The second commit replaces some `Fn` implementations with `Iterator` implementations, which is much cleaner IMO. The third commit replaces an unboxed_closures feature gate with min_specialization. For some reason the unboxed_closures feature gate suppresses the min_specialization feature gate from triggering on an `TrustedStep` impl. The last comment just turns a regular comment into a doc comment as drive by cleanup. I can move it to a separate PR if preferred.
2021-10-03Don't suggest replacing region with 'static in NLLAaron Hill-3/+1
Fixes #73159 This is similar to #69350 - if the user didn't initially write out a 'static lifetime, adding 'static in response to a lifetime error is usually the wrong thing to do.
2021-10-03Replace Fn impls with RPIT impls in rustc_indexbjorn3-2/+2
This is cleaner and removes an unstable feature usage
2021-10-02Make diangostic item names consistentCameron Steffen-4/+4
2021-10-01Fix clippy lintsGuillaume Gomez-12/+12
2021-09-30Rollup merge of #89327 - oli-obk:nll_diag_infer_vars, r=wesleywiserManish Goregaokar-1/+16
Pick one possible lifetime in case there are multiple choices In case a lifetime variable is created, but doesn't have an obvious lifetime in the list of named lifetimes that it should be inferred to, just pick the first one for the diagnostic. This happens e.g. in ```rust fn foo<'a, 'b>(a: Struct<'a>, b: Struct<'b>) -> impl Trait<'a, 'b> { if bar() { a } else { b } } ``` where we get a lifetime variable that combines the lifetimes of `a` and `b` creating a lifetime that is the intersection of both. Right now the type system cannot express this and thus we get an error, but that error also can't express this. I can also create an entirely new diagnostic that mentions all involved lifetimes, so it would actually mention `'a` and `'b` instead of just `'b`.
2021-09-30Auto merge of #87998 - nneonneo:master, r=oli-obkbors-28/+80
Avoid spurious "previous iteration of loop" errors Only follow backwards edges during `get_moved_indexes` if the move path is definitely initialized at loop entry. Otherwise, the error occurred prior to the loop, so we ignore the backwards edges to avoid generating misleading "value moved here, in previous iteration of loop" errors. This patch also slightly improves the analysis of inits, including `NonPanicPathOnly` initializations (which are ignored by `drop_flag_effects::for_location_inits`). This is required for the definite initialization analysis, but may also help find certain skipped reinits in rare cases. Patch passes all non-ignored src/test/ui testcases. Fixes #72649.
2021-09-28Pick one possible lifetime in case there are multiple choicesOli Scherer-1/+16
2021-09-28More tracing instrumentationOli Scherer-98/+78
2021-09-27Remove `DefId` from `ConstraintCategory::Predicate`Aaron Hill-8/+16
This shirnks the size of `ConstraintCategory`, hopefully fixing a performance regression.
2021-09-27Improve cause information for NLL higher-ranked errorsAaron Hill-74/+137
This PR has several interconnected pieces: 1. In some of the NLL region error code, we now pass around an `ObligationCause`, instead of just a plain `Span`. This gets forwarded into `fulfill_cx.register_predicate_obligation` during error reporting. 2. The general InferCtxt error reporting code is extended to handle `ObligationCauseCode::BindingObligation` 3. A new enum variant `ConstraintCategory::Predicate` is added. We try to avoid using this as the 'best blame constraint' - instead, we use it to enhance the `ObligationCause` of the `BlameConstraint` that we do end up choosing. As a result, several NLL error messages now contain the same "the lifetime requirement is introduced here" message as non-NLL errors. Having an `ObligationCause` available will likely prove useful for future improvements to NLL error messages.
2021-09-25Auto merge of #89030 - nbdd0121:box2, r=jonas-schievinkbors-9/+6
Introduce `Rvalue::ShallowInitBox` Polished version of #88700. Implements MCP rust-lang/compiler-team#460, and should allow #43596 to go forward. In short, creating an empty box is split from a nullary-op `NullOp::Box` into two steps, first a call to `exchange_malloc`, then a `Rvalue::ShallowInitBox` which transmutes `*mut u8` to a shallow-initialized `Box<T>`. This allows the `exchange_malloc` call to unwind. Details can be found in the MCP. `NullOp::Box` is not yet removed, purely to make reverting easier in case anything goes wrong as the result of this PR. If revert is needed a reversion of "Use Rvalue::ShallowInitBox for box expression" commit followed by a test bless should be sufficient. Experiments in #88700 showed a very slight compile-time perf regression due to (supposedly) slightly more time spent in LLVM. We could omit unwind edge generation (in non-`oom=panic` case) in box expression MIR construction to restore perf; but I don't think it's necessary since runtime perf isn't affected and perf difference is rather small.
2021-09-25Introduce `Rvalue::ShallowInitBox`Gary Guo-9/+6
2021-09-24Rollup merge of #89001 - jackh726:binder-cleanup, r=nikomatsakisJubilee-5/+9
Be explicit about using Binder::dummy This is somewhat of a late followup to the binder refactor PR. It removes `ToPredicate` and `ToPolyTraitImpls` that hide the use of `Binder::dummy`. While this does make code a bit more verbose, it allows us be more careful about where we create binders. Another alternative here might be to add a new trait `ToBinder` or something with a `dummy()` fn. Which could still allow grepping but allows doing something like `trait_ref.dummy()` (but I also wonder if longer-term, it would be better to be even more explicit with a `bind_with_vars(ty::List::empty())` *but* that's not clear yet. r? ``@nikomatsakis``
2021-09-23Check that TAIT generics are fully generic in mir typeck instead of ↵Oli Scherer-11/+116
wf-check, as wf-check can by definition only check TAIT in return position and not account for TAITs defined in the body of the function
2021-09-20Migrate to 2021Mark Rousskov-1/+1
2021-09-20Auto merge of #88708 - Aaron1011:aggregate-usage, r=oli-obkbors-0/+14
Add `ConstraintCategory::Usage` for handling aggregate construction In some cases, we emit borrowcheck diagnostics pointing at a particular field expression in a struct expression (e.g. `MyStruct { field: my_expr }`). However, this behavior currently relies on us choosing the `ConstraintCategory::Boring` with the 'correct' span. When adding additional variants to `ConstraintCategory`, (or changing existing usages away from `ConstraintCategory::Boring`), the current behavior can easily get broken, since a non-boring constraint will get chosen over a boring one. To make the diagnostic output less fragile, this commit adds a `ConstraintCategory::Usage` variant. We use this variant for the temporary assignments created for each field of an aggregate we are constructing. Using this new variant, we can emit a message mentioning "this usage", emphasizing the fact that the error message is related to the specific use site (in the struct expression). This is preparation for additional work on improving NLL error messages (see #57374)
2021-09-18Auto merge of #88980 - tmiasko:instrument-debug, r=oli-obkbors-1/+1
Use explicit log level in tracing instrument macro Specify a log level in tracing instrument macro explicitly. Additionally reduce the used log level from a default info level to a debug level (all of those appear to be developer oriented logs, so there should be no need to include them in release builds).
2021-09-17Rollup merge of #87460 - FabianWolff:issue-87456, r=Aaron1011Guillaume Gomez-4/+8
Point to closure when emitting 'cannot move out' for captured variable Attempts to fix #87456. The error message now points to the capturing closure, but I was not able to explain _why_ the closure implements `Fn` or `FnMut` (`TypeckResults::closure_kind_origins` did not contain anything for the closure in question). cc `@Aaron1011`
2021-09-16Auto merge of #88719 - estebank:point-at-arg-for-obligation, r=nagisabors-1/+0
Point at argument instead of call for their obligations When an obligation is introduced by a specific `fn` argument, point at the argument instead of the `fn` call if the obligation fails to be fulfilled. Move the information about pointing at the call argument expression in an unmet obligation span from the `FulfillmentError` to a new `ObligationCauseCode`. When giving an error about an obligation introduced by a function call that an argument doesn't fulfill, and that argument is a block, add a span_label pointing at the innermost tail expression. Current output: ``` error[E0425]: cannot find value `x` in this scope --> f10.rs:4:14 | 4 | Some(x * 2) | ^ not found in this scope error[E0277]: expected a `FnOnce<({integer},)>` closure, found `Option<_>` --> f10.rs:2:31 | 2 | let p = Some(45).and_then({ | ______________________--------_^ | | | | | required by a bound introduced by this call 3 | | |x| println!("doubling {}", x); 4 | | Some(x * 2) | | ----------- 5 | | }); | |_____^ expected an `FnOnce<({integer},)>` closure, found `Option<_>` | = help: the trait `FnOnce<({integer},)>` is not implemented for `Option<_>` ``` Previous output: ``` error[E0425]: cannot find value `x` in this scope --> f10.rs:4:14 | 4 | Some(x * 2) | ^ not found in this scope error[E0277]: expected a `FnOnce<({integer},)>` closure, found `Option<_>` --> f10.rs:2:22 | 2 | let p = Some(45).and_then({ | ^^^^^^^^ expected an `FnOnce<({integer},)>` closure, found `Option<_>` | = help: the trait `FnOnce<({integer},)>` is not implemented for `Option<_>` ``` Partially address #27300. Will require rebasing on top of #88546.
2021-09-16Add `ConstraintCategory::Usage` for handling aggregate constructionAaron Hill-0/+14
In some cases, we emit borrowcheck diagnostics pointing at a particular field expression in a struct expression (e.g. `MyStruct { field: my_expr }`). However, this behavior currently relies on us choosing the `ConstraintCategory::Boring` with the 'correct' span. When adding additional variants to `ConstraintCategory`, (or changing existing usages away from `ConstraintCategory::Boring`), the current behavior can easily get broken, since a non-boring constraint will get chosen over a boring one. To make the diagnostic output less fragile, this commit adds a `ConstraintCategory::Usage` variant. We use this variant for the temporary assignments created for each field of an aggregate we are constructing. Using this new variant, we can emit a message mentioning "this usage", emphasizing the fact that the error message is related to the specific use site (in the struct expression). This is preparation for additional work on improving NLL error messages (see #57374)
2021-09-16Refactor `FulfillmentError` to track less dataEsteban Kuber-1/+0
Move the information about pointing at the call argument expression in an unmet obligation span from the `FulfillmentError` to a new `ObligationCauseCode`.
2021-09-15Remove ToPredicate impls that use Binder::dummyjackh726-5/+9
2021-09-15Allow call to get_body_with_borrowck_facts without -Z poloniusWill Crichton-10/+10
2021-09-15Use explicit log level in tracing instrument macroTomasz Miąsko-1/+1
Specify a log level in tracing instrument macro explicitly. Additionally reduce the used log level from a default info level to a debug level (all of those appear to be developer oriented logs, so there should be no need to include them in release builds).
2021-09-15Point to closure when emitting 'cannot move out' for captured variableFabian Wolff-4/+8
2021-09-12Auto merge of #88811 - jackh726:issue-88446, r=nikomatsakisbors-15/+24
Use a HashMap for UniverseInfo in mir borrowck Fixes #88446 r? `@nikomatsakis`
2021-09-12Auto merge of #88771 - jackh726:wf_tys_set, r=nikomatsakisbors-3/+4
Use FxHashSet instead of Vec for well formed tys Trying to recover perf from #88312 r? `@ghost`
2021-09-11don't clone types that are Copy (clippy::clone_on_copy)Matthias Krüger-4/+4
2021-09-09Use FxHashMapjackh726-17/+21
2021-09-09In relate_tys, when creating new universes, insert missing universes as otherjackh726-3/+8
2021-09-09Fix two uses of `span_note` when the source is not availableFabian Wolff-2/+17
2021-09-09Only add_implied_bounds for norm_ty if differentjackh726-3/+4
2021-09-09Fix issue #72649: avoid spurious "previous iteration of loop" errors.Robert Xiao-28/+80
Only follow backwards edges during get_moved_indexes if the move path is definitely initialized at loop entry. Otherwise, the error occurred prior to the loop, so we ignore the backwards edges to avoid generating misleading "value moved here, in previous iteration of loop" errors. This patch also slightly improves the analysis of inits, including NonPanicPathOnly initializations (which are ignored by drop_flag_effects::for_location_inits). This is required for the definite initialization analysis, but may also help find certain skipped reinits in rare cases. Patch passes all non-ignored src/test/ui testcases.
2021-09-08Rebase fallout.Camille GILLOT-1/+1
2021-09-07Rename rustc_mir to rustc_const_eval.Camille GILLOT-10/+11
2021-09-07Move the dataflow framework to its own crate.Camille GILLOT-40/+39
2021-09-07Move rustc_mir::borrow_check to new crate rustc_borrowck.Camille GILLOT-0/+24009