rust/src/test/ui/codemap_tests
Noah Lev e27315268b Suggest using a temporary variable to fix borrowck errors
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-12-10 14:34:00 -08:00
..
bad-format-args.rs Improve recovery on malformed format call 2020-09-02 13:18:19 +02:00
bad-format-args.stderr Bless tests 2021-10-15 02:36:58 -05:00
coherence-overlapping-inherent-impl-trait.rs Update ui test suite to use dyn 2019-05-29 00:57:31 -04:00
coherence-overlapping-inherent-impl-trait.stderr Use smaller def span for functions 2020-08-22 18:41:49 -04:00
empty_span.rs introduce negative_impls feature gate and document 2020-03-26 06:52:55 -04:00
empty_span.stderr pretty: trim paths of unique symbols 2020-09-02 22:26:37 +03:00
huge_multispan_highlight.rs Remove licenses 2018-12-25 21:08:33 -07:00
huge_multispan_highlight.stderr update tests for migrate mode by default 2019-04-22 08:40:08 +01:00
issue-11715.rs Remove licenses 2018-12-25 21:08:33 -07:00
issue-11715.stderr Use larger span for adjustments on method calls 2021-09-25 10:00:41 -05:00
issue-28308.rs Remove licenses 2018-12-25 21:08:33 -07:00
issue-28308.stderr Bless tests 2021-10-15 02:36:58 -05:00
one_line.rs Remove licenses 2018-12-25 21:08:33 -07:00
one_line.stderr Suggest using a temporary variable to fix borrowck errors 2021-12-10 14:34:00 -08:00
overlapping_inherent_impls.rs Remove licenses 2018-12-25 21:08:33 -07:00
overlapping_inherent_impls.stderr Use smaller def span for functions 2020-08-22 18:41:49 -04:00
tab.rs Remove licenses 2018-12-25 21:08:33 -07:00
tab.stderr Surround types with backticks in type errors 2019-11-18 11:03:04 -08:00
tab_2.rs Remove licenses 2018-12-25 21:08:33 -07:00
tab_2.stderr Update UI tests 2020-06-21 16:40:36 +02:00
tab_3.rs update tests for migrate mode by default 2019-04-22 08:40:08 +01:00
tab_3.stderr Fix a format_args span to be expansion 2021-10-29 17:13:15 -05:00
two_files.rs Remove licenses 2018-12-25 21:08:33 -07:00
two_files.stderr Add a suggestion when using a type alias instead of trait alias 2021-04-01 09:53:46 +09:00
two_files_data.rs Update ui test suite to use dyn 2019-05-29 00:57:31 -04:00
unicode.rs Remove licenses 2018-12-25 21:08:33 -07:00
unicode.stderr rustc: Add a new wasm ABI 2021-04-08 08:03:18 -07:00
unicode_2.rs Stablize non_ascii_idents feature. 2021-04-08 02:52:00 +08:00
unicode_2.stderr Stablize non_ascii_idents feature. 2021-04-08 02:52:00 +08:00
unicode_3.rs Moving more build-pass tests to check-pass 2020-04-23 20:21:38 -07:00
unicode_3.stderr rustc: Add a warning count upon completion 2020-04-11 16:15:24 +02:00