about summary refs log tree commit diff
path: root/compiler/rustc_borrowck
AgeCommit message (Collapse)AuthorLines
2024-07-16Suggest a borrow when using dbgyukang-2/+63
2024-07-16Remove invalid help diagnostics for const pointeryukang-12/+21
2024-07-14Stop using the gen keyword in the compilerMichael Goulet-1/+1
2024-07-12Rollup merge of #127625 - SkiFire13:revert-comment-deletion, r=workingjubileeMatthias Krüger-0/+2
Revert accidental comment deletion This reverts an accidental comment deletion made in #113128 See also https://github.com/rust-lang/rust/pull/113128#discussion_r1674614882
2024-07-11Revert accidental comment deletionGiacomo Stevanato-0/+2
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-8/+8
2024-07-08Rollup merge of #120248 - WaffleLapkin:bonk-ptr-object-casts, ↵Matthias Krüger-1/+66
r=compiler-errors,oli-obk,lnicola Make casts of pointers to trait objects stricter This is an attempt to `fix` https://github.com/rust-lang/rust/issues/120222 and https://github.com/rust-lang/rust/issues/120217. This is done by adding restrictions on casting pointers to trait objects. Before this PR the rules were as follows: > When casting `*const X<dyn A>` -> `*const Y<dyn B>`, principal traits in `A` and `B` must refer to the same trait definition (or no trait). With this PR the rules are changed to > When casting `*const X<dyn Src>` -> `*const Y<dyn Dst>` > - if `Dst` has a principal trait `DstP`, > - `Src` must have a principal trait `SrcP` > - `dyn SrcP` and `dyn DstP` must be the same type (modulo the trait object lifetime, `dyn T+'a` -> `dyn T+'b` is allowed) > - Auto traits in `Dst` must be a subset of auto traits in `Src` > - Not adhering to this is currently a FCW (warn-by-default + `FutureReleaseErrorReportInDeps`), instead of an error > - if `Src` has a principal trait `Dst` must as well > - this restriction will be removed in a follow up PR This ensures that 1. Principal trait's generic arguments match (no `*const dyn Tr<A>` -> `*const dyn Tr<B>` casts, which are a problem for [#120222](https://github.com/rust-lang/rust/issues/120222)) 2. Principal trait's lifetime arguments match (no `*const dyn Tr<'a>` -> `*const dyn Tr<'b>` casts, which are a problem for [#120217](https://github.com/rust-lang/rust/issues/120217)) 3. No auto traits can be _added_ (this is a problem for arbitrary self types, see [this comment](https://github.com/rust-lang/rust/pull/120248#discussion_r1463835350)) Some notes: - We only care about the metadata/last field, so you can still cast `*const dyn T` to `*const WithHeader<dyn T>`, etc - The lifetime of the trait object itself (`dyn A + 'lt`) is not checked, so you can still cast `*mut FnOnce() + '_` to `*mut FnOnce() + 'static`, etc - This feels fishy, but I couldn't come up with a reason it must be checked The diagnostics are currently not great, to say the least, but as far as I can tell this correctly fixes the issues. cc `@oli-obk` `@compiler-errors` `@lcnr`
2024-07-08Auto merge of #113128 - WaffleLapkin:become_trully_unuwuable, r=oli-obk,RalfJungbors-5/+30
Support tail calls in mir via `TerminatorKind::TailCall` This is one of the interesting bits in tail call implementation — MIR support. This adds a new `TerminatorKind` which represents a tail call: ```rust TailCall { func: Operand<'tcx>, args: Vec<Operand<'tcx>>, fn_span: Span, }, ``` *Structurally* this is very similar to a normal `Call` but is missing a few fields: - `destination` — tail calls don't write to destination, instead they pass caller's destination to the callee (such that eventual `return` will write to the caller of the function that used tail call) - `target` — similarly to `destination` tail calls pass the caller's return address to the callee, so there is nothing to do - `unwind` — I _think_ this is applicable too, although it's a bit confusing - `call_source` — `become` forbids operators and is not created as a lowering of something else; tail calls always come from HIR (at least for now) It might be helpful to read the interpreter implementation to understand what `TailCall` means exactly, although I've tried documenting it too. ----- There are a few `FIXME`-questions still left, ideally we'd be able to answer them during review ':) ----- r? `@oli-obk` cc `@scottmcm` `@DrMeepster` `@JakobDegen`
2024-07-07Support tail calls in mir via `TerminatorKind::TailCall`Maybe Waffle-5/+30
2024-07-06Uplift PredicateEmittingRelation firstMichael Goulet-4/+5
2024-07-05Equate types instead of using `Unsize`Maybe Lapkin-37/+28
2024-07-05Use `ControlFlow` results for visitors that are only looking for a single valueOli Scherer-38/+23
2024-07-04Auto merge of #127326 - matthiaskrgr:rollup-kz7vd3w, r=matthiaskrgrbors-27/+27
Rollup of 9 pull requests Successful merges: - #123043 (Disable dead variant removal for `#[repr(C)]` enums.) - #126405 (Migrate some rustc_builtin_macros to SessionDiagnostic) - #127037 (Remove some duplicated tests) - #127283 (Reject SmartPointer constructions not serving the purpose) - #127301 (Tweak some structured suggestions to be more verbose and accurate) - #127307 (Allow to have different types for arguments of `Rustc::remap_path_prefix`) - #127309 (jsondocck: add `$FILE` built-in variable) - #127314 (Trivial update on tidy bless note) - #127319 (Remove a use of `StructuredDiag`, which is incompatible with automatic error tainting and error translations) r? `@ghost` `@rustbot` modify labels: rollup
2024-07-04Properly normalize types in bck when checking pointer castsMaybe Lapkin-2/+5
2024-07-04Remove unhelpful comments and add helpful onesMaybe Lapkin-0/+4
2024-07-04Align the changes to the lang decisionMaybe Lapkin-8/+29
2024-07-04Add more checks for pointers with vtable metaMaybe Waffle-1/+47
The rules for casting `*mut X<dyn A>` -> `*mut Y<dyn B>` are as follows: - If `B` has a principal - `A` must have exactly the same principal (including generics) - Auto traits of `B` must be a subset of autotraits in `A` Note that `X<_>` and `Y<_>` can be identity, or arbitrary structs with last field being the dyn type. The lifetime of the trait object itself (`dyn ... + 'a`) is not checked. This prevents a few soundness issues with `#![feature(arbitrary_self_types)]` and trait upcasting. Namely, these checks make sure that vtable is always valid for the pointee.
2024-07-04Auto merge of #127170 - bjorn3:no_specialize_index_borrowck, r=michaelwoeristerbors-3/+26
Stop using specialization in rustc_index and rustc_borrowck For rustc_borrowck the version with specialization isn't much more readable anyway IMO. For rustc_index it probably doesn't affect perf in any noticeable way anyway.
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-73/+137
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-01Add description for why this PR was madeAmanda Stjerna-3/+25
2024-07-01Code review: rename the method `min_universe()`Amanda Stjerna-7/+9
2024-07-01Handle universe leaks by rewriting the constraint graphAmanda Stjerna-68/+108
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-160/+186
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-30Remove usage of specialization from rustc_borrowckbjorn3-3/+26
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-90/+90
2024-06-26Automatically taint InferCtxt when errors are emittedOli Scherer-5/+10
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-75/+75
TyCtxt
2024-06-26Split lifetimes on mir borrowck dataflowOli Scherer-50/+50
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-61/+70
2024-06-24Separate the lifetimes of the `BorrowckInferCtxt` from the other borrowed itemsOli Scherer-39/+41
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-51/+57
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-21Rename a bunch of thingsMichael Goulet-1/+1
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-7/+7
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.