summary refs log tree commit diff
path: root/src/test/ui/borrowck
AgeCommit message (Collapse)AuthorLines
2022-06-24Auto merge of #98109 - nikomatsakis:issue-98095, r=jackh726bors-68/+5
fix universes in the NLL type tests In the NLL code, we were not accommodating universes in the `type_test` logic. Fixes #98095. r? `@compiler-errors` This breaks some tests, however, so the purpose of this branch is more explanatory and perhaps to do a crater run.
2022-06-21Move some tests to more reasonable directoriesCaio-147/+0
2022-06-16 fix one more case of trailing spaceklensy-23/+23
2022-06-16diagnostics: fix trailing spaceklensy-3/+3
2022-06-15generalize the outlives obligation codeNiko Matsakis-68/+5
The code now accepts `Binder<OutlivesPredicate>` instead of just `OutlivesPredicate` and thus exercises the new, generalized `IfEqBound` codepaths. Note though that we never *produce* Binder<OutlivesPredicate>, so we are only testing a subset of those codepaths that excludes actual higher-ranked outlives bounds.
2022-06-14implement valtrees as the type-system representation for constant valuesb-naber-9/+51
2022-06-03Fully stabilize NLLJack Huey-448/+99
2022-06-01Add regression test for #71546Yuki Okushi-0/+39
2022-05-28Add regression test for #81899Yuki Okushi-0/+30
2022-05-22Use revisions for NLL in borrowckJack Huey-26/+121
2022-05-08Move some tests to more reasonable placesCaio-0/+25
2022-05-06Resolve vars in note_type_errJack Huey-22/+0
2022-04-20Remove mutable_borrow_reservation_conflict lintJack Huey-241/+72
2022-04-08suggest adding a local for vector to fix borrowck errorsTakayuki Maeda-0/+78
2022-03-09Auto merge of #94515 - estebank:tweak-move-error, r=davidtwcobors-15/+26
Tweak move error Point at method definition that causes type to be consumed. Fix #94056.
2022-03-07Update tests after feature stabilizationEric Holk-10/+8
2022-03-06Erase regions when checking for missing Copy predicatesMichael Goulet-0/+31
2022-03-03Tweak move errorEsteban Kuber-15/+26
Point at method definition that causes type to be consumed. Fix #94056.
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.