about summary refs log tree commit diff
path: root/compiler/rustc_borrowck/src/diagnostics
AgeCommit message (Collapse)AuthorLines
2025-01-06point out unblamed constraints from `Copy`/`Sized` bounds in region errorsdianne-0/+24
2025-01-06make outlives constraints from generic arguments less boringdianne-2/+3
2025-01-06remove the unused `ConstraintCategory::ClosureBounds`dianne-1/+0
2025-01-06`best_blame_constraint`: avoid blaming assignments without user-provided typesdianne-4/+4
2025-01-06cleanup: remove `ExtraConstraintInfo`dianne-102/+63
`ExtraConstraintInfo` was used only for a single subdiagnostic, so this moves the logic for that to its own function and eliminates the indirection. In order to do so cleanly, this also changes the arguments to `BorrowExplanation::add_explanation_to_diagnostic`, which happens to simplify its call sites.
2025-01-06Remove CallKind::Deref hack from UseSpansMichael Goulet-9/+0
It's not really necessary
2025-01-06Improve span when temporary receiver is dropped in edition 2024Michael Goulet-0/+34
2025-01-04turn hir::ItemKind::Fn into a named-field variantRalf Jung-2/+6
2025-01-01move `find_assignments` to its only use siteRémy Rakic-2/+34
this is to remove the entire `util` module
2025-01-01Rollup merge of #134945 - compiler-errors:map-mutate-nits, r=estebankStuart Cook-7/+10
Some small nits to the borrowck suggestions for mutating a map through index 1. Suggesting users to either use `.insert` or `.get_mut` (which do totally different things) can be a bit of a footgun, so let's make that a bit more nuanced. 2. I find the suggestion of `.get_mut(|val| { *val = whatever; })` to be a bit awkward. I changed this to be an if-let instead. 3. Fix a bug which was suppressing the structured suggestion for some mutations via the index operator on `HashMap`/`BTreeMap`. r? estebank or reassign
2024-12-31Rollup merge of #133486 - dianne:fix-move-error-suggestion, r=estebankTrevor Gross-39/+118
borrowck diagnostics: make `add_move_error_suggestions` use the HIR rather than `SourceMap` This PR aims to fix #132806 by rewriting `add_move_error_suggestions`[^1]. Previously, it manually scanned the source text to find a leading `&`, which isn't always going to produce a correct result (see: that issue). Admittedly, the HIR visitor in this PR introduces a lot of boilerplate, but hopefully the logic at its core isn't too complicated (I go over it in the comments). I also tried a simpler version that didn't use a HIR visitor and suggested adding `ref` always, but the `&ref x` suggestions really didn't look good. As a bonus for the added complexity though, it's now able to produce nice `&`-removing suggestions in more cases. I tried to do this such that it avoids edition-dependent checks and its suggestions can be applied together with those from the match ergonomics 2024 migration lint. I haven't added tests for that since the details of match ergonomics 2024 are still being sorted out, but I can try if desired once that's finalized. [^1]: In brief, it fires on patterns where users try to bind by-value in such a way that moves out of a reference to a non-Copy type (including slice references with non-copy elements). The suggestions are to change the binding's mode to be by-reference, either by removing[^2] an enclosing `&`/`&mut` or adding `ref` to the binding. [^2]: Incidentally, I find the terminology of "consider removing the borrow" a bit confusing for a suggestion to remove a `&` pattern in order to make bindings borrow rather than move. I'm not sure what a good, concise way to explain that would be though, and that should go in a separate PR anyway.
2024-12-31Fix span for IndexMut method call on HashMap/BTreeMapMichael Goulet-2/+2
2024-12-31Use if-let in structured suggestion instead of Option::mapMichael Goulet-6/+9
2024-12-31Explain how to mutate a HashMap/BTreeMap with more nuanceMichael Goulet-1/+1
2024-12-30rename `diags` fieldRémy Rakic-12/+12
2024-12-30clean up `BorrowckDiags`Rémy Rakic-17/+6
- rename it to what it does, buffer diagnostics - remove single-use functions - use derives
2024-12-30merge `diags` module into `diagnostics`Rémy Rakic-2/+136
it's a more natural place for diagnostics-related structures and functions
2024-12-27Fix typoschloefeal-1/+1
Signed-off-by: chloefeal <188809157+chloefeal@users.noreply.github.com>
2024-12-18introduce `LateParamRegionKind`lcnr-7/+7
2024-12-18Re-export more `rustc_span::symbol` things from `rustc_span`.Nicholas Nethercote-14/+7
`rustc_span::symbol` defines some things that are re-exported from `rustc_span`, such as `Symbol` and `sym`. But it doesn't re-export some closely related things such as `Ident` and `kw`. So you can do `use rustc_span::{Symbol, sym}` but you have to do `use rustc_span::symbol::{Ident, kw}`, which is inconsistent for no good reason. This commit re-exports `Ident`, `kw`, and `MacroRulesNormalizedIdent`, and changes many `rustc_span::symbol::` qualifiers in `compiler/` to `rustc_span::`. This is a 200+ net line of code reduction, mostly because many files with two `use rustc_span` items can be reduced to one.
2024-12-17Rollup merge of #134412 - lcnr:borrowck-cleanup-trivial, r=jackh726Jacob Pratt-11/+13
small borrowck cleanup the already approved parts of #133909 and #133961 r? `@jackh726`
2024-12-17Rollup merge of #134397 - Enselic:raw-mut, r=compiler-errorsJacob Pratt-10/+20
rustc_borrowck: Suggest changing `&raw const` to `&raw mut` if applicable Closes #127562 For reference, here is the diff compared to the original error reported in that issue before #134244 stopped suggesting the invalid syntax: ``` diff --git a/tests/ui/borrowck/no-invalid-mut-suggestion-for-raw-pointer-issue-127562.stderr b/tests/ui/borrowck/no-invalid-mut-suggestion-for-raw-pointer-issue-127562.stderr index 0da5d15cf7f..dbe834b6b78 100644 --- a/tests/ui/borrowck/no-invalid-mut-suggestion-for-raw-pointer-issue-127562.stderr +++ b/tests/ui/borrowck/no-invalid-mut-suggestion-for-raw-pointer-issue-127562.stderr ``@@`` -6,8 +6,8 ``@@`` LL | unsafe { *ptr = 3; } | help: consider changing this to be a mutable pointer | -LL | let ptr = &mut raw const val; - | +++ +LL | let ptr = &raw mut val; + | ~~~ error: aborting due to 1 previous error ```
2024-12-17small refactor to region error handlinglcnr-11/+13
2024-12-16rustc_borrowck: Suggest changing `&raw const` to `&raw mut` if applicableMartin Nordholts-4/+15
2024-12-16rustc_borrowck: suggest_ampmut(): Inline unneeded local varMartin Nordholts-2/+1
Since the previos commit renamed `assignment_rhs_span` to just `rhs_span` there is no need for a variable just to shorten the expression on the next line. Inline the variable.
2024-12-16rustc_borrowck: suggest_ampmut(): Just rename some variablesMartin Nordholts-6/+6
By making the variable names more descriptive it becomes easier to understand the code. Especially with the more complicated code in the next commit.
2024-12-16Avoid wrapping a trivially defaultable type in `Option`Oli Scherer-6/+3
2024-12-13rustc_borrowck: Convert suggest_ampmut() 4-tuple to struct for readabilityMartin Nordholts-13/+46
2024-12-13rustc_borrowck: Stop suggesting the invalid syntax `&mut raw const`Martin Nordholts-0/+5
A legitimate suggestion would be to change from &raw const val to &raw mut val But until we have figured out how to make that happen we should at least stop suggesting invalid syntax.
2024-12-13rustc_borrowck: Make suggest_ampmut() return type match its useMartin Nordholts-9/+8
So that it becomes easy for a later commit to return `None`.
2024-12-09Introduce `default_field_values` featureEsteban Küber-2/+6
Initial implementation of `#[feature(default_field_values]`, proposed in https://github.com/rust-lang/rfcs/pull/3681. Support default fields in enum struct variant Allow default values in an enum struct variant definition: ```rust pub enum Bar { Foo { bar: S = S, baz: i32 = 42 + 3, } } ``` Allow using `..` without a base on an enum struct variant ```rust Bar::Foo { .. } ``` `#[derive(Default)]` doesn't account for these as it is still gating `#[default]` only being allowed on unit variants. Support `#[derive(Default)]` on enum struct variants with all defaulted fields ```rust pub enum Bar { #[default] Foo { bar: S = S, baz: i32 = 42 + 3, } } ``` Check for missing fields in typeck instead of mir_build. Expand test with `const` param case (needs `generic_const_exprs` enabled). Properly instantiate MIR const The following works: ```rust struct S<A> { a: Vec<A> = Vec::new(), } S::<i32> { .. } ``` Add lint for default fields that will always fail const-eval We *allow* this to happen for API writers that might want to rely on users' getting a compile error when using the default field, different to the error that they would get when the field isn't default. We could change this to *always* error instead of being a lint, if we wanted. This will *not* catch errors for partially evaluated consts, like when the expression relies on a const parameter. Suggestions when encountering `Foo { .. }` without `#[feature(default_field_values)]`: - Suggest adding a base expression if there are missing fields. - Suggest enabling the feature if all the missing fields have optional values. - Suggest removing `..` if there are no missing fields.
2024-12-07Mention type parameter in more cases and don't suggest ~const bound already ↵Esteban Küber-3/+4
there
2024-11-25`add_move_error_suggestions`: use a HIR visitor rather than `SourceMap`dianne-39/+118
2024-11-25Refactor `where` predicates, and reserve for attributes supportFrank King-11/+7
2024-11-19Put `param_env` into `infcx`.Nicholas Nethercote-31/+34
Because they get passed around together a lot.
2024-11-18reviewlcnr-1/+3
2024-11-18use `TypingEnv` when no `infcx` is availablelcnr-7/+16
the behavior of the type system not only depends on the current assumptions, but also the currentnphase of the compiler. This is mostly necessary as we need to decide whether and how to reveal opaque types. We track this via the `TypingMode`.
2024-11-17`suggest_borrow_generic_arg`: instantiate clauses properlydianne-16/+10
Fixes issue 133118. This also modifies `tests/ui/moves/moved-value-on-as-ref-arg.rs` to have more useful bounds on the tests for suggestions to borrow `Borrow` and `BorrowMut` arguments. With its old tautological `T: BorrowMut<T>` bound, this fix would make it suggest a shared borrow for that argument.
2024-11-13Suggest borrowing arguments in generic positions when trait bounds are satisfieddianne-159/+157
This subsumes the suggestions to borrow arguments with `AsRef`/`Borrow` bounds and those to borrow arguments with `Fn` and `FnMut` bounds. It works for other traits implemented on references as well, such as `std::io::Read`, `std::io::Write`, and `core::fmt::Write`. Incidentally, by making the logic for suggesting borrowing closures general, this removes some spurious suggestions to mutably borrow `FnMut` closures in assignments, as well as an unhelpful suggestion to add a `Clone` constraint to an `impl Fn` argument.
2024-11-13Use a common subdiagnostic format for generic borrowsdianne-5/+10
This is setup for unifing the logic for suggestions to borrow arguments in generic positions. As of this commit, it's still special cases for `AsRef`/`Borrow`-like traits and `Fn`-like traits.
2024-11-13Provide borrow-instead-of-move suggestions for calls of fn-like items from ↵dianne-39/+40
other crates This also downgrades its applicability to MaybeIncorrect. Its suggestion can result in ill-typed code when the type parameter it suggests providing a different generic argument for appears elsewhere in the callee's signature or predicates.
2024-11-09Dont suggest use<APIT>Michael Goulet-26/+45
2024-11-05Auto merge of #132580 - compiler-errors:globs, r=Noratriebbors-5/+5
Remove unnecessary pub enum glob-imports from `rustc_middle::ty` We used to have an idiom in the compiler where we'd prefix or suffix all the variants of an enum, for example `BoundRegionKind`, with something like `Br`, and then *glob-import* that enum variant directly. `@noratrieb` brought this up, and I think that it's easier to read when we just use the normal style `EnumName::Variant`. This PR is a bit large, but it's just naming. The only somewhat opinionated change that this PR does is rename `BorrowKind::Imm` to `BorrowKind::Immutable` and same for the other variants. I think these enums are used sparingly enough that the extra length is fine. r? `@noratrieb` or reassign
2024-11-04Rollup merge of #131153 - VulnBandit:copy_impl_vuln, r=compiler-errorsJubilee-0/+17
Improve duplicate derive Copy/Clone diagnostics Improve duplicate derive Copy/Clone diagnostics. Closes #131083
2024-11-04Remove `ToUniverseInfo` impl for `CanonicalQueryInput<CustomTypeOp>`.Nicholas Nethercote-9/+0
It's unused.
2024-11-04Merge `UniverseInfo` and `UniverseInfoInner`.Nicholas Nethercote-25/+13
It's strange to have a struct that contains a single anonymous field that is an enum. This commit merges them. This does require increasing the visibility of `TypeOfInfo` to `pub(crate)`, but that seems worthwhile.
2024-11-04Tidy up comments and some formatting.Nicholas Nethercote-38/+48
Mostly by wrapping overly long comment lines, plus a few other things.
2024-11-04ty::BrK -> ty::BoundRegionKind::KMichael Goulet-4/+4
2024-11-04Remove BorrowKind glob, make names longerMichael Goulet-1/+1
2024-11-04Reduce visibilities.Nicholas Nethercote-1/+1