summary refs log tree commit diff
path: root/compiler/rustc_borrowck/src/diagnostics
AgeCommit message (Collapse)AuthorLines
2023-11-08rename `BorrowKind::Shallow` to `Fake`lcnr-8/+7
also adds some comments
2023-11-07Auto merge of #117511 - gurry:117406-err-packed-structs, r=compiler-errorsbors-1/+19
Emit explanatory note for move errors in packed struct derives Derive expansions for packed structs with non-`Copy` fields cause move errors because they prefer copying over borrowing since borrowing the fields of a packed struct can result in unaligned access. This underlying cause of the errors, however, is not apparent to the user. This PR adds a diagnostic note to make it clear to the user (the new note is on the second last line): ``` tests/ui/derives/deriving-with-repr-packed-move-errors.rs:13:16 | 12 | #[derive(Debug, PartialEq, Eq, PartialOrd, Ord, Hash, Clone, Default)] | ----- in this derive macro expansion 13 | struct StructA(String); | ^^^^^^ move occurs because `self.0` has type `String`, which does not implement the `Copy` trait | = note: `#[derive(Debug)]` triggers a move because taking references to the fields of a packed struct is undefined behaviour = note: this error originates in the derive macro `Debug` (in Nightly builds, run with -Z macro-backtrace for more info) ``` Fixes #117406 Partially addresses #110777
2023-11-03Emit explanatory note for move errors in packed struct derivesGurinder Singh-1/+19
Derive expansions for packed structs cause move errors because they prefer copying over borrowing since borrowing the fields of a packed struct can result in unaligned access and therefore undefined behaviour. This underlying cause of the errors, however, is not apparent to the user. We add a diagnostic note here to remedy that.
2023-11-02Minimize `pub` usage in `source_map.rs`.Nicholas Nethercote-3/+2
Most notably, this commit changes the `pub use crate::*;` in that file to `use crate::*;`. This requires a lot of `use` items in other crates to be adjusted, because everything defined within `rustc_span::*` was also available via `rustc_span::source_map::*`, which is bizarre. The commit also removes `SourceMap::span_to_relative_line_string`, which is unused.
2023-10-27Handle `move` generatorsOli Scherer-5/+11
2023-10-26Add hir::GeneratorKind::GenOli Scherer-0/+19
2023-10-25Rename `AsyncCoroutineKind` to `CoroutineSource`Oli Scherer-6/+6
similar to how we have `MatchSource`, it explains where the desugaring came from.
2023-10-24Auto merge of #116300 - cjgillot:split-move, r=petrochenkovbors-69/+95
Separate move path tracking between borrowck and drop elaboration. The primary goal of this PR is to skip creating a `MovePathIndex` for path that do not need dropping in drop elaboration. The 2 first commits are cleanups. The next 2 commits displace `move` errors from move-path builder to borrowck. Move-path builder keeps the same logic, but does not carry error information any more. The remaining commits allow to filter `MovePathIndex` creation according to types. This is used in drop elaboration, to avoid computing dataflow for paths that do not need dropping.
2023-10-23Rollup merge of #116859 - Nilstrieb:more-more-funny-pretty-printers, r=oli-obkMatthias Krüger-2/+4
Make `ty::print::Printer` take `&mut self` instead of `self` based on #116815 This simplifies the code by removing all the `self` assignments and makes the flow of data clearer - always into the printer. Especially in v0 mangling, which already used `&mut self` in some places, it gets a lot more uniform.
2023-10-21Stop computing error info in move path builder.Camille GILLOT-3/+22
2023-10-21Avoid using a magic value for untracked locals.Camille GILLOT-3/+4
2023-10-21Do not report errors from move path builder.Camille GILLOT-65/+71
2023-10-21Make `ty::print::Printer` take `&mut self` instead of `self`Nilstrieb-2/+4
This simplifies the code by removing all the `self` assignments and makes the flow of data clearer - always into the printer. Especially in v0 mangling, which already used `&mut self` in some places, it gets a lot more uniform.
2023-10-21Rollup merge of #116990 - estebank:issue-68445, r=cjgillotMatthias Krüger-0/+22
Mention `into_iter` on borrow errors suggestions when appropriate If we encounter a borrow error on `vec![1, 2, 3].iter()`, suggest `into_iter`. Fix #68445.
2023-10-20Rename `CoroutineKind::Gen` to `::Coroutine`Oli Scherer-2/+2
2023-10-20s/generator/coroutine/Oli Scherer-51/+51
2023-10-20s/Generator/Coroutine/Oli Scherer-36/+36
2023-10-20Mention `into_iter` on borrow errors suggestions when appropriateEsteban Küber-0/+22
If we encounter a borrow error on `vec![1, 2, 3].iter()`, suggest `into_iter`. Fix #68445.
2023-10-13Format all the let chains in compilerMichael Goulet-193/+177
2023-10-11Use structured suggestion for #113174Esteban Küber-23/+149
When encountering a for loop that is rejected by the borrow checker because it is being advanced within its body, provide a structured suggestion for `while let Some(pat) = iter.next()`.
2023-10-05Rollup merge of #116223 - catandcoder:master, r=cjgillotJubilee-3/+3
Fix misuses of a vs an Fixes the misuse of "a" vs "an", according to English grammatical expectations and using https://www.a-or-an.com/
2023-10-04Fix misuses of a vs ancui fliter-3/+3
Signed-off-by: cui fliter <imcusg@gmail.com>
2023-10-02Add docs, remove code, change subtyper codeouz-a-2/+3
2023-10-02subtyping_projectionsouz-a-0/+4
2023-09-27fix clippy::{redundant_guards, useless_format}Matthias Krüger-2/+2
2023-09-27Auto merge of #116163 - compiler-errors:lazyness, r=oli-obkbors-1/+1
Don't store lazyness in `DefKind::TyAlias` 1. Don't store lazyness of a type alias in its `DefKind`, but instead via a query. 2. This allows us to treat type aliases as lazy if `#[feature(lazy_type_alias)]` *OR* if the alias contains a TAIT, rather than having checks for both in separate parts of the codebase. r? `@oli-obk` cc `@fmease`
2023-09-26subst -> instantiatelcnr-2/+2
2023-09-26Don't store lazyness in DefKindMichael Goulet-1/+1
2023-09-24Remove span from BrAnon.Camille GILLOT-1/+1
2023-09-21Record asyncness span in HIRMichael Goulet-1/+1
2023-09-21rename mir::Constant -> mir::ConstOperand, mir::ConstKind -> mir::ConstRalf Jung-3/+3
2023-09-18Remove `RegionHighlightMode::tcx`.Nicholas Nethercote-4/+4
It's easier to pass it in to the one method that needs it (`highlighting_region_vid`) than to store it in the type. This means `RegionHighlightMode` can impl `Default`.
2023-09-11Auto merge of #115595 - surechen:114896, r=davidtwcobors-6/+78
Fix incorrect mutable suggestion information for binding in ref pattern like: `let &b = a;` fixes #114896 I find we have to get pat_span but not local_decl.source_info.span for suggestion. In `let &b = a;` pat_span is &b. I think check `let &b = a` in hir to make sure it is hir::Node::Local(hir::Local {pat: hir::Pat{kind: hir::PatKind::Ref(....... can distinguish it from other situation, but I'm not sure. If my processing method is not accurate, please guide me to modify it, thank you. r? `@davidtwco`
2023-09-11Auto merge of #115308 - chenyukang:yukang-fix-62387-iter-mut, r=davidtwcobors-1/+41
suggest iter_mut() where trying to modify elements from .iter() Fixes https://github.com/rust-lang/rust/issues/115259 Fixes https://github.com/rust-lang/rust/issues/62387
2023-09-07fixes #114896surechen-6/+78
2023-09-06Rollup merge of #114511 - chenyukang:yukang-fix-114374-fmt-args, r=b-naberMatthias Krüger-13/+37
Remove the unhelpful let binding diag comes from FormatArguments Fixes #114374
2023-09-07suggest iter_mut() where trying to modify elements from .iter()yukang-1/+41
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.