about summary refs log tree commit diff
path: root/src/librustc_mir/borrow_check/diagnostics
AgeCommit message (Collapse)AuthorLines
2020-08-30mv compiler to compiler/mark-6967/+0
2020-08-26Point to a move-related span when pointing to closure upvarsAaron Hill-3/+22
Fixes #75904 When emitting move/borrow errors, we may point into a closure to indicate why an upvar is used in the closure. However, we use the 'upvar span', which is just an arbitrary usage of the upvar. If the upvar is used in multiple places (e.g. a borrow and a move), we may end up pointing to the borrow. If the overall error is a move error, this can be confusing. This PR tracks the span that caused an upvar to become captured by-value instead of by-ref (assuming that it's not a `move` closure). We use this span instead of the 'upvar' span when we need to point to an upvar usage during borrow checking.
2020-08-25Auto merge of #75302 - Aaron1011:feature/partial-move-diag, r=estebankbors-25/+68
Be consistent when describing a move as a 'partial' in diagnostics When an error occurs due to a partial move, we would use the world "partial" in some parts of the error message, but not in others. This commit ensures that we use the word 'partial' in either all or none of the diagnostic messages. Additionally, we no longer describe a move out of a `Box` via `*` as a 'partial move'. This was a pre-existing issue, but became more noticable when the word 'partial' is used in more places.
2020-08-22Use smaller def span for functionsAaron Hill-1/+1
Currently, the def span of a funtion encompasses the entire function signature and body. However, this is usually unnecessarily verbose - when we are pointing at an entire function in a diagnostic, we almost always want to point at the signature. The actual contents of the body tends to be irrelevant to the diagnostic we are emitting, and just takes up additional screen space. This commit changes the `def_span` of all function items (freestanding functions, `impl`-block methods, and `trait`-block methods) to be the span of the signature. For example, the function ```rust pub fn foo<T>(val: T) -> T { val } ``` now has a `def_span` corresponding to `pub fn foo<T>(val: T) -> T` (everything before the opening curly brace). Trait methods without a body have a `def_span` which includes the trailing semicolon. For example: ```rust trait Foo { fn bar(); }``` the function definition `Foo::bar` has a `def_span` of `fn bar();` This makes our diagnostic output much shorter, and emphasizes information that is relevant to whatever diagnostic we are reporting. We continue to use the full span (including the body) in a few of places: * MIR building uses the full span when building source scopes. * 'Outlives suggestions' use the full span to sort the diagnostics being emitted. * The `#[rustc_on_unimplemented(enclosing_scope="in this scope")]` attribute points the entire scope body. * The 'unconditional recursion' lint uses the full span to show additional context for the recursive call. All of these cases work only with local items, so we don't need to add anything extra to crate metadata.
2020-08-15replaced log with tracingGurpreet Singh-1/+1
2020-08-13merge `as_local_hir_id` with `local_def_id_to_hir_id`Bastian Kauschke-12/+12
2020-08-08Be consistent when describing a move as a 'partial' in diagnosticsAaron Hill-25/+68
When an error occurs due to a partial move, we would use the world "partial" in some parts of the error message, but not in others. This commit ensures that we use the word 'partial' in either all or none of the diagnostic messages. Additionally, we no longer describe a move out of a `Box` via `*` as a 'partial move'. This was a pre-existing issue, but became more noticable when the word 'partial' is used in more places.
2020-08-08fix clippy::needless_return: remove unneeded return statementsMatthias Krüger-1/+1
2020-07-27introduce PredicateAtomBastian Kauschke-2/+2
2020-07-27this might be unqualified, but at least it's now quantifiedBastian Kauschke-1/+1
2020-07-27split ignore_qualifiersBastian Kauschke-1/+1
2020-07-27`PredicateKint` -> `PredicateKind`, the beginning of the endBastian Kauschke-4/+4
2020-07-23rename arguments to highlight_if_we_can_match_hir_tySNCPlay42-7/+6
2020-07-23move highlight_if_we_can_match_hir_ty callSNCPlay42-6/+5
out of highlight_if_we_can_match_hir_ty_from_argument, which is then renamed
2020-07-22decouple highlight_if_we_cannot_match_hir_tySNCPlay42-10/+10
2020-07-22clean up give_name_if_anonymous_region_appears_in_argumentsSNCPlay42-18/+9
2020-07-22rename functionsSNCPlay42-7/+7
2020-07-22change returns to RegionNameHighlightSNCPlay42-38/+29
2020-07-22extract RegionNameHighlightSNCPlay42-23/+40
2020-07-22add RegionName::spanSNCPlay42-13/+19
2020-07-17Rename TypeckTables to TypeckResults.Valentin Lazureanu-10/+5
2020-07-15Add and use more static symbols.Nicholas Nethercote-6/+4
Note that the output of `unpretty-debug.stdout` has changed. In that test the hash values are normalized from a symbol numbers to small numbers like "0#0" and "0#1". The increase in the number of static symbols must have caused the original numbers to contain more digits, resulting in different pretty-printing prior to normalization.
2020-07-01Rollup merge of #73806 - Aaron1011:feature/approx-universal-upper, r=estebankManish Goregaokar-1/+3
Use an 'approximate' universal upper bound when reporting region errors Fixes #67765 When reporting errors during MIR region inference, we sometimes use `universal_upper_bound` to obtain a named universal region that we can display to the user. However, this is not always possible - in a case like `fn foo<'a, 'b>() { .. }`, the only upper bound for a region containing `'a` and `'b` is `'static`. When displaying diagnostics, it's usually better to display *some* named region (even if there are multiple involved) rather than fall back to a generic error involving `'static`. This commit adds a new `approx_universal_upper_bound` method, which uses the lowest-numbered universal region if the only alternative is to return `'static`.
2020-06-30change `skip_binder` to use T by valueBastian Kauschke-2/+2
2020-06-27Rollup merge of #73796 - lcnr:LocalDefId, r=matthewjasperManish Goregaokar-3/+3
replace more `DefId`s with `LocalDefId` part of https://github.com/rust-lang/rust/issues/70853
2020-06-27Use an 'approximate' universal upper bound when reporting region errorsAaron Hill-1/+3
Fixes #67765 When reporting errors during MIR region inference, we sometimes use `universal_upper_bound` to obtain a named universal region that we can display to the user. However, this is not always possible - in a case like `fn foo<'a, 'b>() { .. }`, the only upper bound for a region containing `'a` and `'b` is `'static`. When displaying diagnostics, it's usually better to display *some* named region (even if there are multiple involved) rather than fall back to a generic error involving `'static`. This commit adds a new `approx_universal_upper_bound` method, which uses the lowest-numbered universal region if the only alternative is to return `'static`.
2020-06-27more LocalDefId cleanupBastian Kauschke-4/+4
2020-06-27more LocalDefId in ty::contextBastian Kauschke-1/+1
2020-06-26Explain move errors that occur due to method calls involving `self`Aaron Hill-30/+207
This is a re-attempt of #72389 (which was reverted in #73594) Instead of using `ExpnKind::Desugaring` to represent operators, this PR checks the lang item directly.
2020-06-24Provide suggestions for some moved value errorsEsteban Küber-10/+51
When encountering an used moved value where the previous move happened in a `match` or `if let` pattern, suggest using `ref`. Fix #63988. When encountering a `&mut` value that is used in multiple iterations of a loop, suggest reborrowing it with `&mut *`. Fix #62112.
2020-06-23Rollup merge of #73600 - Aaron1011:fix/move-in-macro, r=ecstatic-morseDylan DPC-1/+1
Fix spurious 'value moved here in previous iteration of loop' messages Fixes #46099 Previously, we would check the 'move' and 'use' spans to see if we should emit this message. However, this can give false positives when macros are involved, since two distinct expressions may end up with the same span. Instead, we check the actual MIR `Location`, which eliminates false positives.
2020-06-22Revert "Rollup merge of #72389 - Aaron1011:feature/move-fn-self-msg, ↵Aaron Hill-198/+30
r=nikomatsakis" This reverts commit 372cb9b69c76a042d0b9d4b48ff6084f64c84a2c, reversing changes made to 5c61a8dc34c3e2fc6d7f02cb288c350f0233f944.
2020-06-21Fix spurious 'value moved here in previous iteration of loop' messagesAaron Hill-1/+1
Fixes #46099 Previously, we would check the 'move' and 'use' spans to see if we should emit this message. However, this can give false positives when macros are involved, since two distinct expressions may end up with the same span. Instead, we check the actual MIR `Location`, which eliminates false positives.
2020-06-15Rollup merge of #72598 - Aaron1011:feature/fnmut-capture-span, r=nikomatsakisRalf Jung-19/+44
Display information about captured variable in `FnMut` error Fixes #69446 When we encounter a region error involving an `FnMut` closure, we display a specialized error message. However, we currently do not tell the user which upvar was captured. This makes it difficult to determine the cause of the error, especially when the closure is large. This commit records marks constraints involving closure upvars with `ConstraintCategory::ClosureUpvar`. When we decide to 'blame' a `ConstraintCategory::Return`, we additionall store the captured upvar if we found a `ConstraintCategory::ClosureUpvar` in the path. When generating an error message, we point to relevant spans if we have closure upvar information available. We further customize the message if an `async` closure is being returned, to make it clear that the captured variable is being returned indirectly.
2020-06-11Run fmtAaron Hill-4/+2
2020-06-11Use `fn_span` to point to the actual method callAaron Hill-3/+3
2020-06-11Explain move errors that occur due to method calls involving `self`Aaron Hill-30/+200
2020-06-11Rollup merge of #72380 - lcnr:const_context, r=estebankDylan DPC-1/+1
Fix `is_const_context`, update `check_for_cast` A better version of #71477 Adds `fn enclosing_body_owner` and uses it in `is_const_context`. `is_const_context` now uses the same mechanism as `mir_const_qualif` as it was previously incorrect. Renames `is_const_context` to `is_inside_const_context`. I also updated `check_for_cast` in the second commit, so r? @estebank (I removed one lvl of indentation, so it might be easier to review by hiding whitespace changes)
2020-05-29Rollup merge of #72103 - lcnr:borrowck-localdefid, r=jonas-schievinkRalf Jung-55/+49
borrowck `DefId` -> `LocalDefId` Replaces some `DefId`s which must always be local with `LocalDefId` in `librustc_mir/borrowck`. cc @marmeladema
2020-05-25Display information about captured variable in `FnMut` errorAaron Hill-19/+44
Fixes #69446 When we encounter a region error involving an `FnMut` closure, we display a specialized error message. However, we currently do not tell the user which upvar was captured. This makes it difficult to determine the cause of the error, especially when the closure is large. This commit records marks constraints involving closure upvars with `ConstraintCategory::ClosureUpvar`. When we decide to 'blame' a `ConstraintCategory::Return`, we additionall store the captured upvar if we found a `ConstraintCategory::ClosureUpvar` in the path. When generating an error message, we point to relevant spans if we have closure upvar information available. We further customize the message if an `async` closure is being returned, to make it clear that the captured variable is being returned indirectly.
2020-05-25Rollup merge of #72544 - sexxi-goose:upvars_mentioned, r=matthewjasperRalf Jung-4/+9
librustc_middle: Rename upvars query to upvars_mentioned As part of supporting RFC 2229, we will be capturing all the Places that were mentioned in the closure. This commit modifies the name of the upvars query to upvars_mentioned. r? @nikomatsakis @blitzerr @matthewjasper
2020-05-24librustc_middle: Rename upvars query to upvars_mentionedAman Arora-4/+9
As part of supporting RFC 2229, we will be capturing all the Places that were mentioned in the closure. This commit modifies the name of the upvars query to upvars_mentioned. Co-authored-by: Aman Arora <me@aman-arora.com> Co-authored-by: Chris Pardy <chrispardy36@gmail.com>
2020-05-22Remove dead ScopeTree codeMatthew Jasper-4/+0
2020-05-22Remove ReScopeMatthew Jasper-1/+0
2020-05-20introduce newtype'd `Predicate<'tcx>`Bastian Kauschke-1/+1
2020-05-20rename `Predicate` to `PredicateKind`, introduce aliasBastian Kauschke-1/+1
2020-05-20fix is_const_contextBastian Kauschke-1/+1
2020-05-11borrowck `DefId` -> `LocalDefId`Bastian Kauschke-55/+49
2020-05-09Rollup merge of #71942 - nnethercote:shrink-LocalDecl, r=matthewjasperDylan DPC-20/+19
Shrink `LocalDecl` `LocalDecl` contributes 4-8% of peak heap memory usage on a range of benchmarks. This PR reduces its size from 128 bytes to 56 bytes on 64-bit, and does some clean-ups as well. r? @matthewjasper
2020-05-08Rollup merge of #71993 - ecstatic-morse:cleanup-old-liveness, r=jonas-schievinkDylan DPC-2/+2
Remove old `util/liveness.rs` module The liveness dataflow analysis now lives in the `dataflow` module, so this one is no longer necessary. I've copied the relevant bits of the module docs for `util::liveness` to `MaybeLiveLocals`. The example in the docs is now a `mir-dataflow` test: https://github.com/rust-lang/rust/blob/a08c47310c7d49cbdc5d7afb38408ba519967ecd/src/test/ui/mir-dataflow/liveness-ptr.rs#L6-L26 The borrow-checker used the same notion of "defs" and "uses", so I've moved it into a submodule. I would have moved it to `util/def_use.rs`, since it seems generally useful, but there's already a slightly [different version](https://github.com/rust-lang/rust/blob/master/src/librustc_mir/util/def_use.rs) of the same abstraction needed for copy propagation.