about summary refs log tree commit diff
path: root/src/test/ui/borrowck
AgeCommit message (Collapse)AuthorLines
2022-02-12bless youDeadbeef-2/+3
2022-01-22[borrowck] Fix help on mutating &self in async fnsAlyssa Verkade-0/+26
Previously, when rustc was provided an async function that tried to mutate through a shared reference to an implicit self (as shown in the ui test), rustc would suggest modifying the parameter signature to `&mut` + the fully qualified name of the ty (in the case of the repro `S`). If a user modified their code to match the suggestion, the compiler would not accept it. This commit modifies the suggestion so that when rustc is provided the ui test that is also attached in this commit, it suggests (correctly) `&mut self`. We try to be careful about distinguishing between implicit and explicit self annotations, since the latter seem to be handled correctly already. Fixes rust-lang/rust#93093
2022-01-12Remove ui tests for LLVM-style inline assemblyTomasz Miąsko-164/+0
2021-12-28Added regression test for issue 92015chordtoll-0/+18
2021-12-10Suggest using a temporary variable to fix borrowck errorsNoah Lev-0/+170
In Rust, nesting method calls with both require `&mut` access to `self` produces a borrow-check error: error[E0499]: cannot borrow `*self` as mutable more than once at a time --> src/lib.rs:7:14 | 7 | self.foo(self.bar()); | ---------^^^^^^^^^^- | | | | | | | second mutable borrow occurs here | | first borrow later used by call | first mutable borrow occurs here That's because Rust has a left-to-right evaluation order, and the method receiver is passed first. Thus, the argument to the method cannot then mutate `self`. There's an easy solution to this error: just extract a local variable for the inner argument: let tmp = self.bar(); self.foo(tmp); However, the error doesn't give any suggestion of how to solve the problem. As a result, new users may assume that it's impossible to express their code correctly and get stuck. This commit adds a (non-structured) suggestion to extract a local variable for the inner argument to solve the error. The suggestion uses heuristics that eliminate most false positives, though there are a few false negatives (cases where the suggestion should be emitted but is not). Those other cases can be implemented in a future change.
2021-11-30Remove all migrate.nll.stderr filesLucas Kent-47/+13
2021-11-28Rollup merge of #90131 - camsteffen:fmt-args-span-fix, r=cjgillotMatthias Krüger-0/+14
Fix a format_args span to be expansion I found this while exploring solutions for rust-lang/rust-clippy#7843. r? `@m-ou-se`
2021-11-25Add test demonstrating no more ICEMichael Goulet-0/+27
2021-11-21Simplify for loop desugarCameron Steffen-3/+3
2021-11-20Point at bounds when comparing impl items to traitEsteban Kuber-2/+2
2021-11-18Move some tests to more reasonable directoriesCaio-0/+77
2021-11-16Rollup merge of #90936 - JohnTitor:issue-80772, r=Mark-SimulacrumYuki Okushi-0/+21
Add a regression test for #80772 Closes #80772
2021-11-16Add a regression test for #80772Yuki Okushi-0/+21
2021-11-14Move some tests to more reasonable directoriesCaio-0/+31
2021-11-06Move some tests to more reasonable directoriesCaio-0/+30
2021-10-29Fix a format_args span to be expansionCameron Steffen-0/+14
2021-10-15Bless testsCameron Steffen-1/+1
2021-10-14Auto merge of #88698 - Noble-Mushtak:master, r=nikomatsakis,oli-obkbors-0/+60
Add check that live_region is live in sanitize_promoted This pull request fixes #88434 by adding a check in `sanitize_promoted` to ensure that only regions which are actually live are added to the `liveness_constraints` of the `BorrowCheckContext`. To implement this change, I needed to add a method to `LivenessValues` which gets the elements contained by a region: /// Returns an iterator of all the elements contained by the region `r` crate fn get_elements(&self, row: N) -> impl Iterator<Item = Location> + '_ Then, inside `sanitize_promoted`, we check whether the iterator returned by this method is non-empty to ensure that the region is actually live at at least one location before adding that region to the `liveness_constraints` of the `BorrowCheckContext`. This is my first pull request to the Rust repo, so any feedback on how I can improve this pull request or if there is a better way to fix this issue would be very appreciated.
2021-10-13Remove textual span from diagnostic stringOli Scherer-4/+4
2021-10-07Add check that region is live in sanitize_promotedNoble-Mushtak-0/+60
2021-09-30Auto merge of #89110 - Aaron1011:adjustment-span, r=estebankbors-219/+178
Use larger span for adjustment THIR expressions Currently, we use a relatively 'small' span for THIR expressions generated by an 'adjustment' (e.g. an autoderef, autoborrow, unsizing). As a result, if a borrow generated by an adustment ends up causing a borrowcheck error, for example: ```rust let mut my_var = String::new(); let my_ref = &my_var my_var.push('a'); my_ref; ``` then the span for the mutable borrow may end up referring to only the base expression (e.g. `my_var`), rather than the method call which triggered the mutable borrow (e.g. `my_var.push('a')`) Due to a quirk of the MIR borrowck implementation, this doesn't always get exposed in migration mode, but it does in many cases. This commit makes THIR building consistently use 'larger' spans for adjustment expressions. These spans are recoded when we first create the adjustment during typecheck. For example, an autoref adjustment triggered by a method call will record the span of the entire method call. The intent of this change it make it clearer to users when it's the specific way in which a variable is used (for example, in a method call) that produdes a borrowcheck error. For example, an error message claiming that a 'mutable borrow occurs here' might be confusing if it just points at a usage of a variable (e.g. `my_var`), when no `&mut` is in sight. Pointing at the entire expression should help to emphasize that the method call itself is responsible for the mutable borrow. In several cases, this makes the `#![feature(nll)]` diagnostic output match up exactly with the default (migration mode) output. As a result, several `.nll.stderr` files end up getting removed entirely.
2021-09-26Remove box syntax from most places in src/test outside of the issues direst31-274/+258
2021-09-25Use larger span for adjustments on method callsAaron Hill-219/+178
Currently, we use a relatively 'small' span for THIR expressions generated by an 'adjustment' (e.g. an autoderef, autoborrow, unsizing). As a result, if a borrow generated by an adustment ends up causing a borrowcheck error, for example: ```rust let mut my_var = String::new(); let my_ref = &my_var my_var.push('a'); my_ref; ``` then the span for the mutable borrow may end up referring to only the base expression (e.g. `my_var`), rather than the method call which triggered the mutable borrow (e.g. `my_var.push('a')`) Due to a quirk of the MIR borrowck implementation, this doesn't always get exposed in migration mode, but it does in many cases. This commit makes THIR building consistently use 'larger' spans for adjustment expressions The intent of this change it make it clearer to users when it's the specific way in which a variable is used (for example, in a method call) that produdes a borrowcheck error. For example, an error message claiming that a 'mutable borrow occurs here' might be confusing if it just points at a usage of a variable (e.g. `my_var`), when no `&mut` is in sight. Pointing at the entire expression should help to emphasize that the method call itself is responsible for the mutable borrow. In several cases, this makes the `#![feature(nll)]` diagnostic output match up exactly with the default (migration mode) output. As a result, several `.nll.stderr` files end up getting removed entirely.
2021-09-20Use `ty::Error` for opaque types with errors in its bounds.Oli Scherer-15/+4
This reduces unhelpful diagnostics down the road.
2021-09-15Point to closure when emitting 'cannot move out' for captured variableFabian Wolff-15/+61
2021-09-11Auto merge of #88214 - notriddle:notriddle/for-loop-span-drop-temps-mut, ↵bors-0/+65
r=nagisa rustc: use more correct span data in for loop desugaring Fixes #82462 Before: help: consider adding semicolon after the expression so its temporaries are dropped sooner, before the local variables declared by the block are dropped | LL | for x in DroppingSlice(&*v).iter(); { | + After: help: consider adding semicolon after the expression so its temporaries are dropped sooner, before the local variables declared by the block are dropped | LL | }; | + This seems like a reasonable fix: since the desugared "expr_drop_temps_mut" contains the entire desugared loop construct, its span should contain the entire loop construct as well.
2021-09-09Ignore automatically derived impls of `Clone` and `Debug` in dead code analysisFabian Wolff-0/+1
2021-09-01Stop sorting bodies by span.Camille GILLOT-6/+6
The definition order is already close to the span order, and only differs in corner cases.
2021-08-29rebase: fix test outputEsteban Kuber-7/+10
2021-08-29Provide structured suggestion for removal of `&mut`Esteban Kuber-9/+6
2021-08-29Suggestion for call on immutable binding of mutable typeEsteban Küber-12/+80
When calling a method requiring a mutable self borrow on an inmutable to a mutable borrow of the type, suggest making the binding mutable. Fix #83241.
2021-08-28rustc: use more correct span data in for loop desugaringMichael Howell-0/+65
Before: help: consider adding semicolon after the expression so its temporaries are dropped sooner, before the local variables declared by the block are dropped | LL | for x in DroppingSlice(&*v).iter(); { | + After: help: consider adding semicolon after the expression so its temporaries are dropped sooner, before the local variables declared by the block are dropped | LL | }; | + This seems like a reasonable fix: since the desugared "expr_drop_temps_mut" contains the entire desugared loop construct, its span should contain the entire loop construct as well.
2021-08-25Fix debugger stepping behavior around `match` expressionsWesley Wiser-26/+24
Previously, we would set up the source lines for `match` expressions so that the code generated to perform the test of the scrutinee was matched to the line of the arm that required the test and then jump from the arm block to the "next" block was matched to all of the lines in the `match` expression. While that makes sense, it has the side effect of causing strange stepping behavior in debuggers. I've changed the source information so that all of the generated tests are sourced to `match {scrutinee}` and the jumps are sourced to the last line of the block they are inside. This resolves the weird stepping behavior in all debuggers and resolves some instances of "ambiguous symbol" errors in WinDbg preventing the user from setting breakpoints at `match` expressions.
2021-08-15Fix ui tests for llvm_asm! deprecationAmanieu d'Antras-7/+8
2021-08-11Modify structured suggestion outputEsteban Küber-22/+22
* On suggestions that include deletions, use a diff inspired output format * When suggesting addition, use `+` as underline * Color highlight modified span
2021-08-04Remove trailing whitespace from error messagesFabian Wolff-1/+1
2021-07-30Use multispan suggestions more oftenEsteban Küber-2/+2
* Use more accurate span for `async move` suggestion * Use more accurate span for deref suggestion * Use `multipart_suggestion` more often
2021-07-29Auto merge of #86998 - m-ou-se:const-panic-fmt-as-str, r=oli-obkbors-2/+3
Make const panic!("..") work in Rust 2021. During const eval, this replaces calls to core::panicking::panic_fmt and std::panicking::being_panic_fmt with a call to a new const fn: core::panicking::const_panic_fmt. That function uses fmt::Arguments::as_str() to get the str and calls panic_str with that instead. panic!() invocations with formatting arguments are still not accepted, as the creation of such a fmt::Arguments cannot be done in constant functions right now. r? `@RalfJung`
2021-07-28Add new const_format_args!() macro and use it in panics.Mara Bos-2/+12
2021-07-28Update test output for const fmt::Arguments constructor.Mara Bos-11/+2
2021-07-28Rollup merge of #87453 - ibraheemdev:i-68697, r=wesleywiserYuki Okushi-4/+7
Suggest removing unnecessary &mut as help message Closes #68697
2021-07-27Auto merge of #85305 - MarcusDunn:master, r=pnkfelixbors-18/+17
Stabilize bindings_after_at attempting to stabilze bindings_after_at [#65490](https://github.com/rust-lang/rust/issues/65490), im pretty new to the whole thing so any pointers are greatly appreciated.
2021-07-25fix help message for modification to &T created by &{t}ibraheemdev-1/+33
2021-07-25fix test/ui/borrowck/issue-33819ibraheemdev-1/+1
2021-07-25tidyibraheemdev-1/+1
2021-07-25suggest removing unnecessary \&mut as help messageibraheemdev-4/+7
2021-07-21Revert PR 81473 to resolve (on mainline) issues 81626 and 81658.Felix S. Klock II-1/+0
Revert "Add missing brace" This reverts commit 85ad773049536d7fed9a94ae0ac74f97135c8655. Revert "Simplify base_expr" This reverts commit 899aae465eb4ef295dc1eeb2603f744568e0768c. Revert "Warn write-only fields" This reverts commit d3c69a4c0dd98af2611b7553d1a65afef6a6ccb0.
2021-07-18Auto merge of #85686 - ptrojahn:loop_reinitialize, r=estebankbors-0/+102
Add help on reinitialization between move and access Fixes #83760
2021-07-07Add help on reinitialization between move and accessPaul Trojahn-0/+102
Fixes #83760
2021-07-02Improve error reporting for modifications behind `&` referencesFabian Wolff-13/+30