about summary refs log tree commit diff
path: root/compiler/rustc_borrowck/src/diagnostics
AgeCommit message (Collapse)AuthorLines
2023-08-23Suggest mutable borrow on read only for-loop that should be mutableEsteban Küber-88/+91
``` error[E0596]: cannot borrow `*test` as mutable, as it is behind a `&` reference --> $DIR/suggest-mut-iterator.rs:22:9 | LL | for test in &tests { | ------ this iterator yields `&` references LL | test.add(2); | ^^^^ `test` is a `&` reference, so the data it refers to cannot be borrowed as mutable | help: use a mutable iterator instead | LL | for test in &mut tests { | +++ ``` Address #114311.
2023-08-23Remove the unhelpful let binding diag comes from FormatArgumentsyukang-13/+37
2023-08-08Rollup merge of #114566 - fmease:type-alias-laziness-is-crate-specific, ↵Matthias Krüger-1/+1
r=oli-obk Store the laziness of type aliases in their `DefKind` Previously, we would treat paths referring to type aliases as *lazy* type aliases if the current crate had lazy type aliases enabled independently of whether the crate which the alias was defined in had the feature enabled or not. With this PR, the laziness of a type alias depends on the crate it is defined in. This generally makes more sense to me especially if / once lazy type aliases become the default in a new edition and we need to think about *edition interoperability*: Consider the hypothetical case where the dependency crate has an older edition (and thus eager type aliases), it exports a type alias with bounds & a where-clause (which are void but technically valid), the dependent crate has the latest edition (and thus lazy type aliases) and it uses that type alias. Arguably, the bounds should *not* be checked since at any time, the dependency crate should be allowed to change the bounds at will with a *non*-major version bump & without negatively affecting downstream crates. As for the reverse case (dependency: lazy type aliases, dependent: eager type aliases), I guess it rules out anything from slight confusion to mild annoyance from upstream crate authors that would be caused by the compiler ignoring the bounds of their type aliases in downstream crates with older editions. --- This fixes #114468 since before, my assumption that the type alias associated with a given weak projection was lazy (and therefore had its variances computed) did not necessarily hold in cross-crate scenarios (which [I kinda had a hunch about](https://github.com/rust-lang/rust/pull/114253#discussion_r1278608099)) as outlined above. Now it does hold. `@rustbot` label F-lazy_type_alias r? `@oli-obk`
2023-08-07Store the laziness of type aliases in the DefKindLeón Orell Valerian Liehr-1/+1
2023-08-04Rollup merge of #114477 - estebank:arc-clone, r=compiler-errorsMatthias Krüger-1/+11
Account for `Rc` and `Arc` when suggesting to clone When suggesting to clone a reference-counted value, be less uncertain.
2023-08-04Account for `Rc` and `Arc` when suggesting to cloneEsteban Küber-1/+11
When suggesting to clone a reference-counted value, be less uncertain.
2023-08-04Improve spans for indexing expressionsNilstrieb-3/+3
Indexing is similar to method calls in having an arbitrary left-hand-side and then something on the right, which is the main part of the expression. Method calls already have a span for that right part, but indexing does not. This means that long method chains that use indexing have really bad spans, especially when the indexing panics and that span in coverted into a panic location. This does the same thing as method calls for the AST and HIR, storing an extra span which is then put into the `fn_span` field in THIR.
2023-08-02Rollup merge of #114079 - compiler-errors:closure-upvars, r=oli-obkNilstrieb-2/+3
Use `upvar_tys` in more places, make it return a list Just a cleanup that fell out of a PR that I was gonna write, but that PR kinda got stuck.
2023-08-01Use upvar_tys in more places, make it a listMichael Goulet-2/+3
2023-07-28Account for macros when suggesting a new let bindingEsteban Küber-1/+2
2023-07-25inline format!() args from rustc_codegen_llvm to the end (4)Matthias Krüger-47/+29
r? @WaffleLapkin
2023-07-17Rename arg_iter to iter_instantiatedMichael Goulet-1/+1
2023-07-14Rollup merge of #113599 - chenyukang:yukang-fix-use-maybe_body_owned_by, ↵Matthias Krüger-77/+61
r=cjgillot Use maybe_body_owned_by for multiple suggestions This is a continued work from https://github.com/rust-lang/rust/pull/113567 We have several other suggestions not working for closure, this PR use `maybe_body_owned_by` to fix them and add test cases for them.
2023-07-14refactor(rustc_middle): Substs -> GenericArgMahdi Dibaiee-66/+63
2023-07-14fix the issue of shorthand in suggest_cloningyukang-3/+15
2023-07-14use maybe_body_owned_by for closureyukang-74/+46
2023-07-12Re-format let-else per rustfmt updateMark Rousskov-54/+86
2023-07-10Fix another strange suggestion spanMichael Goulet-1/+1
2023-07-10Don't use method span on clone suggestionMichael Goulet-2/+2
2023-07-07Rename `adjustment::PointerCast` and variants using it to `PointerCoercion`Nilstrieb-2/+6
It makes it sound like the `ExprKind` and `Rvalue` are supposed to represent all pointer related casts, when in reality their just used to share a some enum variants. Make it clear there these are only coercion to make it clear why only some pointer related "casts" are in the enum.
2023-07-05Move `TyCtxt::mk_x` to `Ty::new_x` where applicableBoxy-2/+2
2023-07-01Rollup merge of #113174 - chenyukang:yukang-fix-102972-loop-next, ↵Matthias Krüger-2/+80
r=compiler-errors Better messages for next on a iterator inside for loops Fixes #102972
2023-06-30add typecheck for iteratoryukang-20/+17
2023-06-30Better messages for next in a iterator inside for loopsyukang-2/+83
2023-06-30Rollup merge of #111403 - y21:suggest-slice-swap, r=compiler-errorsMatthias Krüger-3/+4
suggest `slice::swap` for `mem::swap(&mut x[0], &mut x[1])` borrowck error Recently saw someone ask why this code (example slightly modified): ```rs fn main() { let mut foo = [1, 2]; std::mem::swap(&mut foo[0], &mut foo[1]); } ``` triggers this error and how to fix it: ``` error[E0499]: cannot borrow `foo[_]` as mutable more than once at a time --> src/main.rs:4:33 | 4 | std::mem::swap(&mut foo[0], &mut foo[1]); | -------------- ----------- ^^^^^^^^^^^ second mutable borrow occurs here | | | | | first mutable borrow occurs here | first borrow later used by call | = help: consider using `.split_at_mut(position)` or similar method to obtain two mutable non-overlapping sub-slices ``` The current help message is nice and goes in the right direction, but I think we can do better for this specific instance and suggest `slice::swap`, which makes this compile
2023-06-29add `slice::swap` suggestiony21-3/+4
2023-06-28don't suggest `move` for borrows that aren't closuresLukas Markeffsky-13/+14
2023-06-27Auto merge of #112938 - compiler-errors:clause-3, r=oli-obkbors-7/+7
Migrate `TyCtxt::predicates_of` and `ParamEnv::caller_bounds` to `Clause` The last big change in the series. I will follow-up with additional filed issues once this PR lands: - [ ] Investigate making `TypeFoldable<TyCtxt<'tcx>> for ty::Clause<'tcx>` implementation less weird: https://github.com/rust-lang/rust/blob/2efe09170530fa18e42ff05b8d9dd23f00b5c430/compiler/rustc_middle/src/ty/structural_impls.rs#L672 - [ ] Clean up the elaborator since it should only be emitting child clauses, not predicates - [ ] Rename identifiers like `pred` and `predicates` to `clause` if they're actually clauses around the codebase - [ ] Validate that all of the `ToPredicate` impls are acutally still needed, or prune them if they're not r? `@ghost` until the other branch lands
2023-06-27Auto merge of #112693 - ericmarkmartin:use-more-placeref, r=spastorinobors-7/+1
Use PlaceRef abstractions more often Associated issue: https://github.com/rust-lang/rust/issues/80647 r? `@spastorino`
2023-06-26Migrate predicates_of and caller_bounds to ClauseMichael Goulet-7/+7
2023-06-25use PlaceRef abstractions more consistentlyEric Mark Martin-7/+1
2023-06-22Migrate item_bounds to ty::ClauseMichael Goulet-1/+1
2023-06-21Rollup merge of #112772 - compiler-errors:clauses-1, r=lcnrNilstrieb-4/+4
Add a fully fledged `Clause` type, rename old `Clause` to `ClauseKind` Does two basic things before I put up a more delicate set of PRs (along the lines of #112714, but hopefully much cleaner) that migrate existing usages of `ty::Predicate` to `ty::Clause` (`predicates_of`/`item_bounds`/`ParamEnv::caller_bounds`). 1. Rename `Clause` to `ClauseKind`, so it's parallel with `PredicateKind`. 2. Add a new `Clause` type which is parallel to `Predicate`. * This type exposes `Clause::kind(self) -> Binder<'tcx, ClauseKind<'tcx>>` which is parallel to `Predicate::kind` 😸 The new `Clause` type essentially acts as a newtype wrapper around `Predicate` that asserts that it is specifically a `PredicateKind::Clause`. Turns out from experimentation[^1] that this is not negative performance-wise, which is wonderful, since this a much simpler design than something that requires encoding the discriminant into the alignment bits of a predicate kind, or something else like that... r? ``@lcnr`` or ``@oli-obk`` [^1]: https://github.com/rust-lang/rust/pull/112714#issuecomment-1595653910
2023-06-20address most easy commentsZiru Niu-4/+3
2023-06-20merge `BorrowKind::Unique` into `BorrowKind::Mut`Ziru Niu-20/+30
2023-06-19s/Clause/ClauseKindMichael Goulet-4/+4
2023-06-18Better error for non const `PartialEq` call generated by `match`Deadbeef-10/+19
2023-06-06Rollup merge of #112019 - jieyouxu:issue-111554, r=compiler-errorsMatthias Krüger-6/+22
Don't suggest changing `&self` and `&mut self` in function signature to be mutable when taking `&mut self` in closure Current suggestion for when taking a mutable reference to `self` in a closure (as an upvar) will produce a machine-applicable suggestion to change the `self` in the function signature to `mut self`, but does not account for the specialness of implicit self in that it can already have `&` and `&mut` (see #111554). This causes the function signature to become `test(&mut mut self)` which does not seem desirable. ``` error[E0596]: cannot borrow `self` as mutable, as it is not declared as mutable --> src/sound_player.rs:870:11 | 869 | pub fn test(&mut self) { | ---- help: consider changing this to be mutable: `mut self` 870 | || test2(&mut self); | ^^^^^^^^^ cannot borrow as mutable ``` This PR suppresses the "changing this to be mutable" suggestion if the implicit self is either `ImplicitSelfKind::ImmRef` or `ImplicitSelfKind::MutRef`. Fixes #111554.
2023-05-29Rename `tcx.mk_re_*` => `Region::new_*`Maybe Waffle-20/+21
2023-05-29Don't suggest changing {ImmRef,MutRef} implicit self to be mutable许杰友 Jieyou Xu (Joe)-6/+22
2023-05-25Remove DesugaringKind::Replace.Camille GILLOT-34/+1
2023-05-24Rollup merge of #111912 - WaffleLapkin:is_some_and_in_the_compiler, ↵Manish Goregaokar-13/+8
r=petrochenkov Use `Option::is_some_and` and `Result::is_ok_and` in the compiler `.is_some_and(..)`/`.is_ok_and(..)` replace `.map_or(false, ..)` and `.map(..).unwrap_or(false)`, making the code more readable. This PR is a sibling of https://github.com/rust-lang/rust/pull/111873#issuecomment-1561316515
2023-05-24Use ObligationCtxt in custom type opsMichael Goulet-1/+1
2023-05-24Use `is_some_and`/`is_ok_and` in less obvious spotsMaybe Waffle-10/+5
2023-05-24Use `Option::is_some_and` and `Result::is_ok_and` in the compilerMaybe Waffle-3/+3
2023-05-09Rollup merge of #110583 - Ezrashaw:tweak-make-mut-spans, r=estebankDylan DPC-245/+264
tweak "make mut" spans when assigning to locals Work towards fixing #106857 This PR just cleans up a lot of spans which is helpful before properly fixing the issues. Best reviewed commit-by-commit. r? `@estebank`
2023-05-08Rollup merge of #110827 - compiler-errors:issue-110761-followup, r=cjgillotDylan DPC-3/+13
Fix lifetime suggestion for type aliases with objects in them Fixes an issue identified in https://github.com/rust-lang/rust/issues/110761#issuecomment-1520678479 This suggestion, like many other borrowck suggestions, are very fragile and there are other ways to trigger strange behavior even after this PR, so this is just a small improvement and not a total rework :skull:
2023-05-05fix trait definition spans in "make mut" suggestionEzra Shaw-196/+197
2023-05-05implement review commentEzra Shaw-2/+2
Co-authored-by: Esteban Kuber <estebank@users.noreply.github.com>
2023-05-05tweak spans for `ref mut` suggestionEzra Shaw-7/+9