about summary refs log tree commit diff
path: root/compiler/rustc_borrowck/src/diagnostics
AgeCommit message (Collapse)AuthorLines
2024-07-31Rollup merge of #128244 - compiler-errors:move-clone-sugg, r=estebankMatthias Krüger-80/+28
Peel off explicit (or implicit) deref before suggesting clone on move error in borrowck, remove some hacks Also remove a heck of a lot of weird hacks in `suggest_cloning` that I don't think we should have around. I know this regresses tests, but I don't believe most of these suggestions were accurate, b/c: 1. They either produced type errors (e.g. turning `&x` into `x.clone()`) 2. They don't fix the issue 3. They fix the issue ostensibly, but introduce logic errors (e.g. cloning a `&mut Option<T>` to then `Option::take` out...) Most of the suggestions are still wrong, but they're not particularly *less* wrong IMO. Stacked on top of #128241, which is an "obviously worth landing" subset of this PR. r? estebank
2024-07-29Reformat `use` declarations.Nicholas Nethercote-90/+69
The previous commit updated `rustfmt.toml` appropriately. This commit is the outcome of running `x fmt --all` with the new formatting options.
2024-07-27Rollup merge of #128241 - compiler-errors:clone-sugg, r=jieyouxuTrevor Gross-31/+0
Remove logic to suggest clone of function output I can't exactly tell, but I believe that this suggestion is operating off of a heuristic that the lifetime of a function's input is correlated with the lifetime of a function's output in such a way that cloning would fix an error. I don't think that actually manages to hit the bar of "actually provides useful suggestions" most of the time. Specifically, I've hit false-positives due to this suggestion *twice* when fixing ICEs in the compiler, so I don't think it's worthwhile having this logic around. Neither of the two affected UI tests are actually fixed by the suggestion.
2024-07-26Peel off explicit (or implicit) deref before suggesting clone on move error ↵Michael Goulet-80/+28
in borrowck
2024-07-26Remove logic to suggest clone of function outputMichael Goulet-31/+0
2024-07-26Suppress useless clone suggestionMichael Goulet-0/+5
2024-07-24Don't ICE if HIR and middle types disagree in borrowck error reportingMichael Goulet-8/+26
2024-07-21Move all error reporting into rustc_trait_selectionMichael Goulet-9/+12
2024-07-21Move some stuff to TypeErrCtxtMichael Goulet-4/+10
2024-07-19fixes panic errorsurechen-4/+9
fixes #127915
2024-07-17If the moved value is a mut reference, it is used in a generic function and ↵surechen-29/+73
it's type is a generic param, it can be reborrowed to avoid moving. for example: ```rust struct Y(u32); // x's type is '& mut Y' and it is used in `fn generic<T>(x: T) {}`. fn generic<T>(x: T) {} ``` fixes #127285
2024-07-16Rollup merge of #127501 - compiler-errors:invert-infer-error-mod-struture, ↵Trevor Gross-3/+3
r=lcnr Invert infer `error_reporting` mod struture Parallel change to #127493, which moves `rustc_infer::infer::error_reporting` to `rustc_infer::error_reporting::infer`. After this, we should just be able to merge this into `rustc_trait_selection::error_reporting::infer`, and pull down `TypeErrCtxt` into that crate. 👍 r? lcnr
2024-07-15Move rustc_infer::infer::error_reporting to rustc_infer::error_reporting::inferMichael Goulet-3/+3
2024-07-16Suggest a borrow when using dbgyukang-2/+63
2024-07-16Remove invalid help diagnostics for const pointeryukang-12/+21
2024-07-11Rollup merge of #124599 - estebank:issue-41708, r=wesleywiserMatthias Krüger-19/+70
Suggest borrowing on fn argument that is `impl AsRef` When encountering a move conflict, on an expression that is `!Copy` passed as an argument to an `fn` that is `impl AsRef`, suggest borrowing the expression. ``` error[E0382]: use of moved value: `bar` --> f204.rs:14:15 | 12 | let bar = Bar; | --- move occurs because `bar` has type `Bar`, which does not implement the `Copy` trait 13 | foo(bar); | --- value moved here 14 | let baa = bar; | ^^^ value used here after move | help: borrow the value to avoid moving it | 13 | foo(&bar); | + ``` Fix #41708
2024-07-09Auto merge of #127500 - compiler-errors:consolidate-region-errors, r=lcnrbors-7/+5
Consolidate region error reporting in `rustc_infer` More work on https://github.com/rust-lang/rust/issues/127492. Separate but important step, since I'm gonna likely pull everything else here into another module. I don't think I'm confident whether `nice_region_error` should be a submodule of the new `rustc_infer::infer::error_reporting::region` module, so I left it alone for now. r? lcnr
2024-07-08Consolidate region error reporting in rustc_inferMichael Goulet-7/+5
2024-07-08Move trait selection error reporting to its own top-level moduleMichael Goulet-6/+6
2024-07-05Use `ControlFlow` results for visitors that are only looking for a single valueOli Scherer-38/+23
2024-07-04More accurate mutability suggestionEsteban Küber-11/+14
2024-07-04Fix `&mut` removal suggestionEsteban Küber-2/+2
2024-07-04Better span for "make binding mutable" suggestionEsteban Küber-14/+11
2024-07-03Auto merge of #125507 - compiler-errors:type-length-limit, r=lcnrbors-2/+2
Re-implement a type-size based limit r? lcnr This PR reintroduces the type length limit added in #37789, which was accidentally made practically useless by the caching changes to `Ty::walk` in #72412, which caused the `walk` function to no longer walk over identical elements. Hitting this length limit is not fatal unless we are in codegen -- so it shouldn't affect passes like the mir inliner which creates potentially very large types (which we observed, for example, when the new trait solver compiles `itertools` in `--release` mode). This also increases the type length limit from `1048576 == 2 ** 20` to `2 ** 24`, which covers all of the code that can be reached with craterbot-check. Individual crates can increase the length limit further if desired. Perf regression is mild and I think we should accept it -- reinstating this limit is important for the new trait solver and to make sure we don't accidentally hit more type-size related regressions in the future. Fixes #125460
2024-07-03Auto merge of #123720 - amandasystems:dyn-enable-refactor, r=nikomatsakisbors-1/+2
Rewrite handling of universe-leaking placeholder regions into outlives constraints This commit prepares for Polonius by moving handling of leak check/universe errors out of the inference step by rewriting any universe error into an outlives-static constraint. This variant is a work in progress but seems to pass most tests. Note that a few debug assertions no longer hold; a few extra eyes on those changes are appreciated!
2024-07-02Instance::resolve -> Instance::try_resolve, and other nitsMichael Goulet-2/+2
2024-07-01Handle universe leaks by rewriting the constraint graphAmanda Stjerna-1/+2
This version is a squash-rebased version of a series of exiermental commits, since large parts of them were broken out into PR #125069. It explicitly handles universe violations in higher-kinded outlives constraints by adding extra outlives static constraints.
2024-07-01Auto merge of #126996 - oli-obk:do_not_count_errors, r=nnethercotebors-51/+72
Automatically taint InferCtxt when errors are emitted r? `@nnethercote` Basically `InferCtxt::dcx` now returns a `DiagCtxt` that refers back to the `Cell<Option<ErrorGuaranteed>>` of the `InferCtxt` and thus when invoking `Diag::emit`, and the diagnostic is an error, we taint the `InferCtxt` directly. That change on its own has no effect at all, because `InferCtxt` already tracks whether errors have been emitted by recording the global error count when it gets opened, and checking at the end whether the count changed. So I removed that error count check, which had a bit of fallout that I immediately fixed by invoking `InferCtxt::dcx` instead of `TyCtxt::dcx` in a bunch of places. The remaining new errors are because an error was reported in another query, and never bubbled up. I think they are minor enough for this to be ok, and sometimes it actually improves diagnostics, by not silencing useful diagnostics anymore. fixes #126485 (cc `@olafes)` There are more improvements we can do (like tainting in hir ty lowering), but I would rather do that in follow up PRs, because it requires some refactorings.
2024-06-29fix: prefer `(*p).clone` to `p.clone` if the `p` is a raw pointerLin Yihai-9/+44
2024-06-27Rename `'cx` to `'infcx`Oli Scherer-40/+40
2024-06-26Automatically taint InferCtxt when errors are emittedOli Scherer-1/+1
2024-06-26Restrict diagnostic context lifetime of InferCtxt to itself instead of TyCtxtOli Scherer-24/+45
2024-06-26Restrict diagnostic context lifetime of mir borrowck to InferCtxt instead of ↵Oli Scherer-26/+26
TyCtxt
2024-06-25Rollup merge of #126884 - estebank:issue-125634, r=NadrierilMatthias Krüger-2/+4
Do not ICE when suggesting dereferencing closure arg Account for `for` lifetimes when constructing closure to see if dereferencing the return value would be valid. Fix #125634, fix #124563.
2024-06-24Separate the mir body lifetime from the other lifetimesOli Scherer-20/+24
2024-06-24Separate the lifetimes of the `BorrowckInferCtxt` from the other borrowed itemsOli Scherer-20/+20
2024-06-24Do not ICE when suggesting dereferencing closure argEsteban Küber-2/+4
Account for `for` lifetimes when constructing closure to see if dereferencing the return value would be valid. Fix #125634, fix #124563.
2024-06-24Auto merge of #126023 - amandasystems:you-dropped-this-again, r=nikomatsakisbors-6/+5
Remove confusing `use_polonius` flag and do less cloning The `use_polonius` flag is both redundant and confusing since every function it's propagated to also checks if `all_facts` is `Some`, the true test of whether to generate Polonius facts for Polonius or for external consumers. This PR makes that path clearer by simply doing away with the argument and handling the logic in precisely two places: where facts are populated (check for `Some`), and where `all_facts` are initialised. It also delays some statements until after that check to avoid the miniscule performance penalty of executing them when Polonius is disabled. This also addresses `@lqd's` concern in #125652 by reducing the size of what is cloned out of Polonius facts to just the facts being added, as opposed to the entire vector of potential inputs, and added descriptive comments. *Reviewer note*: the comments in `add_extra_drop_facts` should be inspected by a reviewer, in particular the one on [L#259](https://github.com/rust-lang/rust/compare/master...amandasystems:you-dropped-this-again?expand=1#diff-aa727290e6670264df2face84f012897878e11a70e9c8b156543cfcd9619bac3R259) in this PR, which should be trivial for someone with the right background knowledge to address. I also included some lints I found on the way there that I couldn't help myself from addressing.
2024-06-18Remove redundant argument from `subdiagnostic` methodOli Scherer-263/+167
2024-06-18Use a dedicated type instead of a reference for the diagnostic contextOli Scherer-5/+5
This paves the way for tracking more state (e.g. error tainting) in the diagnostic context handle
2024-06-18Use a more precise lifetimeOli Scherer-4/+4
2024-06-17Rollup merge of #126567 - compiler-errors:instance-kind, r=oli-obk,lcnrMatthias Krüger-2/+2
Rename `InstanceDef` -> `InstanceKind` Renames `InstanceDef` to `InstanceKind`. The `Def` here is confusing, and makes it hard to distinguish `Instance` and `InstanceDef`. `InstanceKind` makes this more obvious, since it's really just describing what *kind* of instance we have. Not sure if this is large enough to warrant a types team MCP -- it's only 53 files. I don't personally think it does, but happy to write one if anyone disagrees. cc ``@rust-lang/types`` r? types
2024-06-17Rollup merge of #126570 - nnethercote:fix-126385, r=lcnrGuillaume Gomez-3/+1
Convert a `span_bug` to a `span_delayed_bug`. PR #121208 converted this from a `span_delayed_bug` to a `span_bug` because nothing in the test suite caused execution to hit this path. But now fuzzing has found a test case that does hit it. So this commit converts it back to `span_delayed_bug` and adds the relevant test. Fixes #126385. r? `@lcnr`
2024-06-17Rollup merge of #126226 - gurry:125325-improve-closure-arg-sugg, r=oli-obkGuillaume Gomez-44/+69
Make suggestion to change `Fn` to `FnMut` work with methods as well Fixes #125325 The issue occurred because the code that emitted the suggestion to change `Fn` to `FnMut` worked only for function calls and not method calls. This PR makes it work with methods as well.
2024-06-17Convert a `span_bug` to a `span_delayed_bug`.Nicholas Nethercote-3/+1
PR #121208 converted this from a `span_delayed_bug` to a `span_bug` because nothing in the test suite caused execution to hit this path. But now fuzzing has found a test case that does hit it. So this commit converts it back to `span_delayed_bug` and adds the relevant test. Fixes #126385.
2024-06-16Rename InstanceDef -> InstanceKindMichael Goulet-2/+2
2024-06-15Rollup merge of #126508 - beepster4096:minor_borrowck_cherrypick, ↵Guillaume Gomez-3/+3
r=compiler-errors Make uninitialized_error_reported a set of locals Another artifact of how places used to be able to be based on statics and not just locals. This set is exclusively filled with PlaceRefs that are just locals, so it should just contain locals directly.
2024-06-14make uninitialized_error_reported a set of localsbeepster4096-3/+3
2024-06-14Use is_lang_item more aggressivelyMichael Goulet-15/+13
2024-06-14Rollup merge of #126320 - oli-obk:pat_ice, r=lcnrMatthias Krüger-5/+5
Avoid ICES after reporting errors on erroneous patterns fixes #109812 fixes #125914 fixes #124004