about summary refs log tree commit diff
path: root/compiler/rustc_borrowck
AgeCommit message (Collapse)AuthorLines
2024-04-11More move error suggestions to cloneEsteban Küber-0/+4
``` error[E0507]: cannot move out of `val`, a captured variable in an `FnMut` closure --> $DIR/issue-87456-point-to-closure.rs:10:28 | LL | let val = String::new(); | --- captured outer variable LL | LL | take_mut(|| { | -- captured by this `FnMut` closure LL | LL | let _foo: String = val; | ^^^ move occurs because `val` has type `String`, which does not implement the `Copy` trait | help: consider borrowing here | LL | let _foo: String = &val; | + help: consider cloning the value if the performance cost is acceptable | LL | let _foo: String = val.clone(); | ++++++++ ```
2024-04-11Suggest `.clone()` in some move errorsEsteban Küber-0/+10
``` error[E0507]: cannot move out of `*x` which is behind a shared reference --> $DIR/borrowck-fn-in-const-a.rs:6:16 | LL | return *x | ^^ move occurs because `*x` has type `String`, which does not implement the `Copy` trait | help: consider cloning the value if the performance cost is acceptable | LL - return *x LL + return x.clone() | ```
2024-04-11Account for unops when suggesting cloningEsteban Küber-19/+24
2024-04-11Suggest `.clone()` when moved while borrowedEsteban Küber-17/+56
2024-04-11Account for `.clone()` when suggesting `<T as Clone>::clone`Esteban Küber-2/+33
2024-04-11Slightly more readable NLL/constraint graph dumpsAmanda Stjerna-6/+38
2024-04-11Rollup merge of #123704 - estebank:diag-changes, r=compiler-errorsMatthias Krüger-26/+70
Tweak value suggestions in `borrowck` and `hir_analysis` Unify the output of `suggest_assign_value` and `ty_kind_suggestion`. Ideally we'd make these a single function, but doing so would likely require modify the crate dependency tree.
2024-04-11Auto merge of #122213 - estebank:issue-50195, r=oli-obk,estebankbors-4/+153
Provide suggestion to dereference closure tail if appropriate When encoutnering a case like ```rust use std::collections::HashMap; fn main() { let vs = vec![0, 0, 1, 1, 3, 4, 5, 6, 3, 3, 3]; let mut counts = HashMap::new(); for num in vs { let count = counts.entry(num).or_insert(0); *count += 1; } let _ = counts.iter().max_by_key(|(_, v)| v); ``` produce the following suggestion ``` error: lifetime may not live long enough --> $DIR/return-value-lifetime-error.rs:13:47 | LL | let _ = counts.iter().max_by_key(|(_, v)| v); | ------- ^ returning this value requires that `'1` must outlive `'2` | | | | | return type of closure is &'2 &i32 | has type `&'1 (&i32, &i32)` | help: dereference the return value | LL | let _ = counts.iter().max_by_key(|(_, v)| **v); | ++ ``` Fix #50195.
2024-04-10Handle more cases of "values to suggest" given a typeEsteban Küber-3/+16
Add handling for `String`, `Box`, `Option` and `Result`.
2024-04-10Handle more cases of value suggestionsEsteban Küber-18/+51
2024-04-10Use trait solver to answer questions instead of manually writing a trait solverOli Scherer-79/+22
2024-04-09Tweak value suggestions in `borrowck` and `hir_analysis`Esteban Küber-10/+8
Unify the output of `suggest_assign_value` and `ty_kind_suggestion`. Ideally we'd make these a single function, but doing so would likely require modify the crate dependency tree.
2024-04-08Auto merge of #122077 - oli-obk:eager_opaque_checks4, r=lcnrbors-8/+23
Pass list of defineable opaque types into canonical queries This eliminates `DefiningAnchor::Bubble` for good and brings the old solver closer to the new one wrt cycles and nested obligations. At that point the difference between `DefiningAnchor::Bind([])` and `DefiningAnchor::Error` was academic. We only used the difference for some sanity checks, which actually had to be worked around in places, so I just removed `DefiningAnchor` entirely and just stored the list of opaques that may be defined. fixes #108498 fixes https://github.com/rust-lang/rust/issues/116877 * [x] run crater - https://github.com/rust-lang/rust/pull/122077#issuecomment-2013293931
2024-04-08Eliminate `DefiningAnchor` now that is just a single-variant enumOli Scherer-8/+5
2024-04-08Eagerly check for accidentally registered region constraints instead of ↵Oli Scherer-0/+6
waiting until borrowck is done
2024-04-08Pass list of defineable opaque types into canonical queriesOli Scherer-0/+12
2024-04-08Actually create ranged int types in the type system.Oli Scherer-0/+2
2024-04-06Account for trait/impl difference when suggesting changing argument from ref ↵Esteban Küber-35/+54
to mut ref Do not ICE when encountering a lifetime error involving an argument with an immutable reference of a method that differs from the trait definition. Fix #123414.
2024-04-05Provide suggestion to dereference closure tail if appropriateEsteban Küber-4/+210
When encoutnering a case like ```rust //@ run-rustfix use std::collections::HashMap; fn main() { let vs = vec![0, 0, 1, 1, 3, 4, 5, 6, 3, 3, 3]; let mut counts = HashMap::new(); for num in vs { let count = counts.entry(num).or_insert(0); *count += 1; } let _ = counts.iter().max_by_key(|(_, v)| v); ``` produce the following suggestion ``` error: lifetime may not live long enough --> $DIR/return-value-lifetime-error.rs:13:47 | LL | let _ = counts.iter().max_by_key(|(_, v)| v); | ------- ^ returning this value requires that `'1` must outlive `'2` | | | | | return type of closure is &'2 &i32 | has type `&'1 (&i32, &i32)` | help: dereference the return value | LL | let _ = counts.iter().max_by_key(|(_, v)| **v); | ++ ``` Fix #50195.
2024-04-03Rollup merge of #123419 - petrochenkov:zeroindex, r=compiler-errorsMatthias Krüger-1/+1
rustc_index: Add a `ZERO` constant to index types It is commonly used.
2024-04-03rustc_index: Add a `ZERO` constant to index typesVadim Petrochenkov-1/+1
It is commonly used.
2024-04-03rename `expose_addr` to `expose_provenance`joboet-2/+2
2024-04-02Rollup merge of #122935 - RalfJung:with-exposed-provenance, r=AmanieuJacob Pratt-2/+2
rename ptr::from_exposed_addr -> ptr::with_exposed_provenance As discussed on [Zulip](https://rust-lang.zulipchat.com/#narrow/stream/136281-t-opsem/topic/To.20expose.20or.20not.20to.20expose/near/427757066). The old name, `from_exposed_addr`, makes little sense as it's not the address that is exposed, it's the provenance. (`ptr.expose_addr()` stays unchanged as we haven't found a better option yet. The intended interpretation is "expose the provenance and return the address".) The new name nicely matches `ptr::without_provenance`.
2024-03-30Stop calling visitors VMichael Goulet-3/+12
2024-03-29Rollup merge of #123188 - klensy:clippy-me2, r=NilstriebMatthias Krüger-16/+15
compiler: fix few unused_peekable and needless_pass_by_ref_mut clippy lints This fixes few instances of `unused_peekable` and `needless_pass_by_ref_mut`. While i expected to fix more warnings, `needless_pass_by_ref_mut` produced too much for one PR, so i stopped here. Better reviewed commit by commit, as fixes splitted by chunks.
2024-03-29Auto merge of #123080 - Jules-Bertholet:mut-ref-mut, r=Nadrierilbors-10/+9
Match ergonomics 2024: implement mutable by-reference bindings Implements the mutable by-reference bindings portion of match ergonomics 2024 (#123076), with the `mut ref`/`mut ref mut` syntax, under feature gate `mut_ref`. r? `@Nadrieril` `@rustbot` label A-patterns A-edition-2024
2024-03-28and few moreklensy-16/+15
maybe bug here? warning: this argument is a mutable reference, but not used mutably --> compiler\rustc_borrowck\src\diagnostics\conflict_errors.rs:3857:35 | 3857 | pub(crate) fn emit(&self, cx: &mut MirBorrowckCtxt<'_, 'tcx>, diag: &mut Diag<'_>) -> String { | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider changing to: `&MirBorrowckCtxt<'_, 'tcx>` | = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#needless_pass_by_ref_mut warning: this argument is a mutable reference, but not used mutably --> compiler\rustc_borrowck\src\type_check\liveness\trace.rs:601:17 | 601 | typeck: &mut TypeChecker<'_, 'tcx>, | ^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider changing to: `&TypeChecker<'_, 'tcx>` | = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#needless_pass_by_ref_mut
2024-03-28Auto merge of #116891 - aliemjay:opaque-region-infer-rework-2, ↵bors-181/+253
r=compiler-errors,oli-obk rework opaque type region inference User-facing changes are documented in [this comment](https://github.com/rust-lang/rust/pull/116891#issuecomment-1973774412). The design document is in [this comment](https://github.com/rust-lang/rust/pull/116891#issuecomment-1836900102). --- \- Fix Ice in check_unique; ICE -> Error; fixes #122782. \- Ignore uncaptured lifetime args; ICE -> Pass; fixes #111906, fixes #110623, fixes #109059, fixes #122307 \- Except equal parameters from the uniqueness check; Pass -> Error; fixes #113916. \- Check RPITs for invalid args; Pass -> Error; fixes #111935; ICE -> Error; fixes #110726. \- Rework opaque types region inference; Pass -> Error; fixes #113971, fixes #112841. \- Reject external lifetimes as invalid args; Pass -> Error; fixes #105498. r? `@ghost`
2024-03-28simplify check_uniqueAli MJ Al-Nasrawy-70/+25
2024-03-28reject external lifetimes as invalid argumentsAli MJ Al-Nasrawy-4/+10
2024-03-28rework opaque types region inferenceAli MJ Al-Nasrawy-87/+72
2024-03-28convert all named regions in opaque types to nll varsAli MJ Al-Nasrawy-0/+16
Do it in typeck before entering region inference routines particularly because we will no longer be able to convert placeholders.
2024-03-28favor placeholders over existentials when choosing SCC representativesAli MJ Al-Nasrawy-12/+20
... even when the existential has the least RegionVid. universal regions (of root universe) > placeholders > existentials The previous behavior, that chooses the minimal RegionVid index, naturally prefers universal regions over others because they always have the least RegionVids, but there was no guranteed ordering between placeholders and existentials.
2024-03-28check RPITs for invalid argsAli MJ Al-Nasrawy-11/+1
2024-03-28ignore error paramsAli MJ Al-Nasrawy-0/+8
2024-03-28except equal parameters from the uniqueness checkAli MJ Al-Nasrawy-1/+97
2024-03-27chore: fix some commentsxiaoxiangxianzi-1/+1
Signed-off-by: xiaoxiangxianzi <zhaoyizheng@outlook.com>
2024-03-27Implement `mut ref`/`mut ref mut`Jules Bertholet-10/+9
2024-03-26Rollup merge of #122589 - wutchzone:121547, r=compiler-errorsMatthias Krüger-3/+13
Fix diagnostics for async block cloning Closes #121547 r? diagnostics
2024-03-26ignore uncaptured lifetimes when checking opaquesAli MJ Al-Nasrawy-12/+11
2024-03-26fix ICE in check_uniqueAli MJ Al-Nasrawy-2/+11
2024-03-25Rollup merge of #122970 - cuviper:use-chunk_by, r=Mark-SimulacrumMatthias Krüger-6/+5
Use `chunk_by` when building `ReverseSccGraph` With stable `chunk_by` in Rust 1.77, this code doesn't need `Itertools::group_by` anymore.
2024-03-23Rollup merge of #122969 - cuviper:borrowck-rposition, r=matthewjasperJubilee-11/+9
Simplify an iterator search in borrowck diag Rather than `.into_iter().rev().find_position(...)`, this case can simply call `.iter().rposition(...)`.
2024-03-23Use `chunk_by` when building `ReverseSccGraph`Josh Stone-6/+5
2024-03-23Simplify an iterator search in borrowck diagJosh Stone-11/+9
Rather than `.into_iter().rev().find_position(...)`, this case can simply call `.iter().rposition(...)`.
2024-03-23Auto merge of #122629 - RalfJung:assert-unsafe-precondition, r=saethlinbors-1/+1
refactor check_{lang,library}_ub: use a single intrinsic This enacts the plan I laid out [here](https://github.com/rust-lang/rust/pull/122282#issuecomment-1996917998): use a single intrinsic, called `ub_checks` (in aniticpation of https://github.com/rust-lang/compiler-team/issues/725), that just exposes the value of `debug_assertions` (consistently implemented in both codegen and the interpreter). Put the language vs library UB logic into the library. This makes it easier to do something like https://github.com/rust-lang/rust/pull/122282 in the future: that just slightly alters the semantics of `ub_checks` (making it more approximating when crates built with different flags are mixed), but it no longer affects whether these checks can happen in Miri or compile-time. The first commit just moves things around; I don't think these macros and functions belong into `intrinsics.rs` as they are not intrinsics. r? `@saethlin`
2024-03-23Fix typosDaniel Sedlak-3/+3
2024-03-23Fix diagnostics for async block cloningDaniel Sedlak-0/+10
2024-03-23refactor check_{lang,library}_ub: use a single intrinsic, put policy into ↵Ralf Jung-1/+1
library
2024-03-23Rollup merge of #122780 - GuillaumeGomez:rename-hir-local, r=oli-obkMatthias Krüger-6/+6
Rename `hir::Local` into `hir::LetStmt` Follow-up of #122776. As discussed on [zulip](https://rust-lang.zulipchat.com/#narrow/stream/131828-t-compiler/topic/Improve.20naming.20of.20.60ExprKind.3A.3ALet.60.3F). I made this change into a separate PR because I'm less sure about this change as is. For example, we have `visit_local` and `LocalSource` items. Is it fine to keep these two as is (I supposed it is but I prefer to ask) or not? Having `Node::Local(LetStmt)` makes things more explicit but is it going too far? r? ```@oli-obk```