Skip to content

Suggest not mutably borrowing a mutable reference #51242

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jun 5, 2018

Conversation

ytausky
Copy link
Contributor

@ytausky ytausky commented May 31, 2018

This PR would (hopefully) solve #45392. I deviated a bit from @estebank's instructions since the error span only included the borrowed expression (e.g. the b in &mut b). I also didn't check the mutability of the local binding, since this whole case is concerned with an immutable local.

I can see two outstanding questions:

  1. note_immutability_blame is called in two places, but I only have one test case. I think it covers the call in report_bckerror, but I'm not sure how to trigger the call from report_aliasability_violation.
  2. There is one failing test, where the local binding is self: &mut Self. I'm not entirely sure what the correct output should be, but I think the new message should also apply. Unfortunately, since this parameter is parsed differently, its let_span covers both the pattern and the type, leading to a wrong suggestion text. I'm not sure how to correctly identify this case.

@rust-highfive
Copy link
Contributor

Thanks for the pull request, and welcome! The Rust team is excited to review your changes, and you should hear from @estebank (or someone else) soon.

If any changes to this PR are deemed necessary, please add them as extra commits. This ensures that the reviewer can see what has changed since they last reviewed the code. Due to the way GitHub handles out-of-date commits, this should also make it reasonably obvious what issues have or haven't been addressed. Large or tricky changes may require several passes of review and changes.

Please see the contribution instructions for more information.

@rust-highfive rust-highfive added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label May 31, 2018
@rust-highfive
Copy link
Contributor

The job x86_64-gnu-llvm-3.9 of your PR failed on Travis (raw log). Through arcane magic we have determined that the following fragments from the build log may contain information about the problem.

Click to expand the log.

[00:04:43] travis_fold:start:tidy
travis_time:start:tidy
tidy check
[00:04:44] tidy error: /checkout/src/test/ui/borrowck/mut-borrow-of-mut-ref.rs: incorrect license
[00:04:45] some tidy checks failed
[00:04:45] 
[00:04:45] 
[00:04:45] command did not execute successfully: "/checkout/obj/build/x86_64-unknown-linux-gnu/stage0-tools-bin/tidy" "/checkout/src" "/checkout/obj/build/x86_64-unknown-linux-gnu/stage0/bin/cargo" "--no-vendor" "--quiet"
[00:04:45] 
[00:04:45] 
[00:04:45] failed to run: /checkout/obj/build/bootstrap/debug/bootstrap test src/tools/tidy
[00:04:45] Build completed unsuccessfully in 0:01:47
[00:04:45] Build completed unsuccessfully in 0:01:47
[00:04:45] make: *** [tidy] Error 1
[00:04:45] Makefile:79: recipe for target 'tidy' failed

The command "stamp sh -x -c "$RUN_SCRIPT"" exited with 2.
travis_time:start:12a8f498
$ date && (curl -fs --head https://google.com | grep ^Date: | sed 's/Date: //g' || true)

I'm a bot! I can only do what humans tell me to, so if this was not helpful or you have suggestions for improvements, please ping or otherwise contact @TimNN. (Feature Requests)

@rust-highfive
Copy link
Contributor

The job x86_64-gnu-llvm-3.9 of your PR failed on Travis (raw log). Through arcane magic we have determined that the following fragments from the build log may contain information about the problem.

Click to expand the log.
travis_time:start:test_ui
Check compiletest suite=ui mode=ui (x86_64-unknown-linux-gnu -> x86_64-unknown-linux-gnu)
[00:42:12] 
[00:42:12] running 1481 tests
[00:42:16] ..............................................F...........................................i.........
[00:42:21] ................................................i................F..................................
[00:42:29] ....................................................................................................
[00:42:32] ....................................................................................................
[00:42:35] ....................................................................................................
[00:42:40] ....................................................................................................
[00:42:40] ....................................................................................................
[00:42:44] ....................................................................................................
[00:42:49] ....................................................................................................
[00:42:54] ..............................................................................................i.....
[00:42:59] .......................................................................i............................
[00:43:04] ....................................................................................................
[00:43:09] ....................................................................................................
[00:43:15] ....................................................................................................
[00:43:19] ...i.................iiiiiiiii...................................................
[00:43:19] 
[00:43:19] ---- [ui] ui/borrowck/mut-borrow-of-mut-ref.rs stdout ----
[00:43:19] diff of stderr:
[00:43:19] 
[00:43:19] 
[00:43:19] 1 error[E0596]: cannot borrow immutable argument `b` as mutable
[00:43:19] +   --> $DIR/mut-borrow-of-mut-ref.rs:18:12
[00:43:19] 3    |
[00:43:19] 3    |
[00:43:19] 4 LL |     g(&mut b) //~ ERROR cannot borrow
[00:43:19] 5    |            ^ cannot borrow mutably
[00:43:19] 
[00:43:19] The actual stderr differed from the expected stderr.
[00:43:19] The actual stderr differed from the expected stderr.
[00:43:19] Actual stderr saved to /checkout/obj/build/x86_64-unknown-linux-gnu/test/ui/borrowck/mut-borrow-of-mut-ref/mut-borrow-of-mut-ref.stderr
[00:43:19] To update references, rerun the tests and pass the `--bless` flag
[00:43:19] To only update this specific test, also pass `--test-args borrowck/mut-borrow-of-mut-ref.rs`
[00:43:19] error: 1 errors occurred comparing output.
[00:43:19] status: exit code: 101
[00:43:19] status: exit code: 101
[00:43:19] command: "/checkout/obj/build/x86_64-unknown-linux-gnu/stage2/bin/rustc" "/checkout/src/test/ui/borrowck/mut-borrow-of-mut-ref.rs" "--target=x86_64-unknown-linux-gnu" "--error-format" "json" "-Zui-testing" "-C" "prefer-dynamic" "-o" "/checkout/obj/build/x86_64-unknown-linux-gnu/test/ui/borrowck/mut-borrow-of-mut-ref/a" "-Crpath" "-O" "-Zunstable-options" "-Lnative=/checkout/obj/build/x86_64-unknown-linux-gnu/native/rust-test-helpers" "-L" "/checkout/obj/build/x86_64-unknown-linux-gnu/test/ui/borrowck/mut-borrow-of-mut-ref/auxiliary" "-A" "unused"
[00:43:19] ------------------------------------------
[00:43:19] 
[00:43:19] ------------------------------------------
[00:43:19] stderr:
[00:43:19] stderr:
[00:43:19] ------------------------------------------
[00:43:19] {"message":"cannot borrow immutable argument `b` as mutable","code":{"code":"E0596","explanation":"\nThis error occurs because you tried to mutably borrow a non-mutable variable.\n\nExample of erroneous code:\n\n```compile_fail,E0596\nlet x = 1;\nlet y = &mut x; // error: cannot borrow mutably\n```\n\nIn here, `x` isn't mutable, so when we try to mutably borrow it in `y`, it\nfails. To fix this error, you need to make `x` mutable:\n\n```\nlet mut x = 1;\nlet y = &mut x; // ok!\n```\n"},"level":"error","spans":[{"file_name":"/checkout/src/test/ui/borrowck/mut-borrow-of-mut-ref.rs","byte_start":581,"byte_end":582,"line_start":18,"line_end":18,"column_start":12,"column_end":13,"is_primary":true,"text":[{"text":"    g(&mut b) //~ ERROR cannot borrow","highlight_start":12,"highlight_end":13}],"label":"cannot borrow mutably","suggested_replacement":null,"suggestion_applicability":null,"expansion":null}],"children":[{"message":"consider removing the `&mut`, as it is an immutable binding to a mutable reference","code":null,"level":"help","spans":[{"file_name":"/checkout/src/test/ui/borrowck/mut-borrow-of-mut-ref.rs","byte_start":576,"byte_end":582,"line_start":18,"line_end":18,"column_start":7,"column_end":13,"is_primary":true,"text":[{"text":"    g(&mut b) //~ ERROR cannot borrow","highlight_start":7,"highlight_end":13}],"label":null,"suggested_replacement":"b","suggestion_applicability":"Unspecified","expansion":null}],"children":[],"rendered":null}],"rendered":"error[E0596]: cannot borrow immutable argument `b` as mutable\n  --> /checkout/src/test/ui/borrowck/mut-borrow-of-mut-ref.rs:18:12\n   |\nLL |     g(&mut b) //~ ERROR cannot borrow\n   |            ^ cannot borrow mutably\nhelp: consider removing the `&mut`, as it is an immutable binding to a mutable reference\n   |\nLL |     g(b) //~ ERROR cannot borrow\n   |       ^\n\n"}
[00:43:19] {"message":"aborting due to previous error","code":null,"level":"error","spans":[],"children":[],"rendered":"error: aborting due to previous error\n\n"}
[00:43:19] {"message":"For more information about this error, try `rustc --explain E0596`.","code":null,"level":"","spans":[],"children":[],"rendered":"For more information about this error, try `rustc --explain E0596`.\n"}
[00:43:19] ------------------------------------------
[00:43:19] 
[00:43:19] thread '[ui] ui/borrowck/mut-borrow-of-mut-ref.rs' panicked at 'explicit panic', tools/compiletest/src/runtest.rs:3096:9
[00:43:19] note: Run with `RUST_BACKTRACE=1` for a backtrace.
[00:43:19] note: Run with `RUST_BACKTRACE=1` for a backtrace.
[00:43:19] 
[00:43:19] ---- [ui] ui/did_you_mean/issue-31424.rs stdout ----
[00:43:19] diff of stderr:
[00:43:19] 
[00:43:19] 10 error[E0596]: cannot borrow immutable argument `self` as mutable
[00:43:19] 11   --> $DIR/issue-31424.rs:23:15
[00:43:19] 12    |
[00:43:19] - LL |     fn bar(self: &mut Self) {
[00:43:19] -    |            --------------- consider changing this to `mut self: &mut Self`
[00:43:19] 15 LL |         (&mut self).bar(); //~ ERROR cannot borrow
[00:43:19] 16    |               ^^^^ cannot borrow mutably
[00:43:19] + help: consider removing the `&mut`, as it is an immutable binding to a mutable reference
[00:43:19] +    |
[00:43:19] + LL |         self: &mut Self.bar(); //~ ERROR cannot borrow
[00:43:19] 17 
[00:43:19] 18 error: aborting due to 2 previous errors
[00:43:19] 19 
[00:43:19] 
[00:43:19] 
[00:43:19] 
[00:43:19] The actual stderr differed from the expected stderr.
[00:43:19] Actual stderr saved to /checkout/obj/build/x86_64-unknown-linux-gnu/test/ui/did_you_mean/issue-31424/issue-31424.stderr
[00:43:19] To update references, rerun the tests and pass the `--bless` flag
[00:43:19] To only update this specific test, also pass `--test-args did_you_mean/issue-31424.rs`
[00:43:19] 
[00:43:19] error: 1 errors occurred c reborrow mutably","suggested_replacement":null,"suggestion_applicability":null,"expansion":null},{"file_name":"/checkout/src/test/ui/did_you_mean/issue-31424.rs","byte_start":568,"byte_end":572,"line_start":17,"line_end":17,"column_start":15,"column_end":19,"is_primary":true,"text":[{"text":"        (&mut self).bar(); //~ ERROR cannot borrow","highlight_start":15,"highlight_end":19}],"label":"try removing `&mut` here","suggested_replacement":null,"suggestion_applicability":null,"expansion":null}],"children":[],"rendered":"error[E0596]: cannot borrow immutable argument `self` as mutable\n  --> /checkout/src/test/ui/did_you_mean/issue-31424.rs:17:15\n   |\nLL |         (&mut self).bar(); //~ ERROR cannot borrow\n   |               ^^^^\n   |               |\n   |               cannot reborrow mutably\n   |               try removing `&mut` here\n\n"}
[00:43:19] {"message":"cannot borrow immutable argument `self` as mutable","code":{"code":"E0596","explanation":"\nThis error occurs because you tried to mutably borrow a non-mutable variable.\n\nExample of erroneous code:\n\n```compile_fail,E0596\nlet x = 1;\nlet y = &mut x; // error: cannot borrow mutably\n```\n\nIn here, `x` isn't mutable, so when we try to mutably borrow it in `y`, it\nfails. To fix this error, you need to make `x` mutable:\n\n```\nlet mut x = 1;\nlet y = &mut x; // ok!\n```\n"},"level":"error","spans":[{"file_name":"/checkout/src/test/ui/did_you_mean/issue-31424.rs","byte_start":791,"byte_end":795,"line_start":23,"line_end":23,"column_start":15,"column_end":19,"is_primary":true,"text":[{"text":"        (&mut self).bar(); //~ ERROR cannot borrow","highlight_start":15,"highlight_end":19}],"label":"cannot borrow mutably","suggested_replacement":null,"suggestion_applicability":null,"expansion":null}],"children":[{"message":"consider removing the `&mut`, as it is an immutable binding to a mutable reference","code":null,"level":"help","spans":[{"file_name":"/checkout/src/test/ui/did_you_mean/issue-31424.rs","byte_start":785,"byte_end":796,"line_start":23,"line_end":23,"column_start":9,"column_end":20,"is_primary":true,"text":[{"text":"        (&mut self).bar(); //~ ERROR cannot borrow","highlight_start":9,"highlight_end":20}],"label":null,"suggested_replacement":"self: &mut Self","suggestion_applicability":"Unspecified","expansion":null}],"children":[],"rendered":null}],"rendered":"error[E0596]: cannot borrow immutable argument `self` as mutable\n  --> /checkout/src/test/ui/did_you_mean/issue-31424.rs:23:15\n   |\nLL |         (&mut self).bar(); //~ ERROR cannot borrow\n   |               ^^^^ cannot borrow mutably\nhelp: consider removing the `&mut`, as it is an immutable binding to a mutable reference\n   |\nLL |         self: &mut Self.bar(); //~ ERROR cannot borrow\n   |         ^^^^^^^^^^^^^^^\n\n"}
[00:43:19] {"message":"aborting due to 2 previous errors","code":null,"level":"error","spans":[],"children":[],"rendered":"error: aborting due to 2 previous errors\n\n"}
[00:43:19] {"message":"For more information about this error, try `rustc --explain E0596`.","code":null,"level":"","spans":[],"children":[],"rendered":"For more information about this error, try `rustc --explain E0596`.\n"}
[00:43:19] ------------------------------------------
[00:43:19] 
[00:43:19] thread '[ui] ui/did_you_mean/issue-31424.rs' panicked at 'explicit panic', tools/compiletest/src/runtest.rs:3096:9
[00:43:19] 
---
[00:43:19] test result: FAILED. 1465 passed; 2 failed; 14 ignored; 0 measured; 0 filtered out
[00:43:19] 
[00:43:19] 
[00:43:19] 
[00:43:19] command did not execute successfully: "/checkout/obj/build/x86_64-unknown-linux-gnu/stage0-tools-bin/compiletest" "--compile-lib-path" "/checkout/obj/build/x86_64-unknown-linux-gnu/stage2/lib" "--run-lib-path" "/checkout/obj/build/x86_64-unknown-linux-gnu/stage2/lib/rustlib/x86_64-unknown-linux-gnu/lib" "--rustc-path" "/checkout/obj/build/x86_64-unknown-linux-gnu/stage2/bin/rustc" "--src-base" "/checkout/src/test/ui" "--build-base" "/checkout/obj/build/x86_64-unknown-linux-gnu/test/ui" "--stage-id" "stage2-x86_64-unknown-linux-gnu" "--mode" "ui" "--target" "x86_64-unknown-linux-gnu" "--host" "x86_64-unknown-linux-gnu" "--llvm-filecheck" "/usr/lib/llvm-3.9/bin/FileCheck" "--host-rustcflags" "-Crpath -O -Zunstable-options " "--target-rustcflags" "-Crpath -O -Zunstable-options  -Lnative=/checkout/obj/build/x86_64-unknown-linux-gnu/native/rust-test-helpers" "--docck-python" "/usr/bin/python2.7" "--lldb-python" "/usr/bin/python2.7" "--gdb" "/usr/bin/gdb" "--quiet" "--llvm-version" "3.9.1\n" "--system-llvm" "--cc" "" "--cxx" "" "--cflags" "" "--llvm-components" "" "--llvm-cxxflags" "" "--adb-path" "adb" ./.git/modules/src/libcompiler_builtins
32156 ./.git/modules/src/libcompiler_builtins/modules/compiler-rt
31728 ./.git/modules/src/libcompiler_builtins/modules/compiler-rt/objects
31720 ./.git/modules/src/libcompiler_builtins/modules/compiler-rt/objects/pack
31532 ./src/libcompiler_builtins/compiler-rt/test

I'm a bot! I can only do what humans tell me to, so if this was not helpful or you have suggestions for improvements, please ping or otherwise contact @TimNN. (Feature Requests)

@estebank
Copy link
Contributor

estebank commented Jun 1, 2018

LGTM, fix the outstanding broken test.

@rust-highfive
Copy link
Contributor

The job x86_64-gnu-llvm-3.9 of your PR failed on Travis (raw log). Through arcane magic we have determined that the following fragments from the build log may contain information about the problem.

Click to expand the log.
[00:48:44] ...........................................................................i........................
[00:48:49] ....................................................................................................
[00:48:54] ....................................................................................................
[00:49:00] ....................................................................................................
[00:49:05] .......i.................iiiiiiiii...................................................
[00:49:05] 
[00:49:05] travis_fold:start:test_ui_nll
travis_time:start:test_ui_nll
Check compiletest suite=ui mode=ui compare_mode=nll (x86_64-unknown-linux-gnu -> x86_64-unknown-linux-gnu)
Check compiletest suite=ui mode=ui compare_mode=nll (x86_64-unknown-linux-gnu -> x86_64-unknown-linux-gnu)
[00:49:05] 
[00:49:05] running 1485 tests
[00:49:09] ...............................................F...........................................i........
[00:49:19] ....................................................................................................
[00:49:22] ....................................................................................................
[00:49:26] ....................................................................................................
[00:49:29] ....................................................................................................
---
[00:49:54] ...........................................................................i........................
[00:49:59] ....................................................................................................
[00:50:03] ....................................................................................................
[00:50:09] ....................................................................................................
[00:50:13] .......i.................iiiiiiiii...................................................
[00:50:13] 
[00:50:13] ---- [ui (nll)] ui/borrowck/mut-borrow-of-mut-ref.rs stdout ----
[00:50:13] diff of stderr:
[00:50:13] 
[00:50:13] 
[00:50:13] - error[E0596]: cannot borrow immutable argument `b` as mutable
[00:50:13] -   --> $DIR/mut-borrow-of-mut-ref.rs:18:12
[00:50:13] + error[E0596]: cannot borrow immutable item `b` as mutable
[00:50:13] +   --> $DIR/mut-borrow-of-mut-ref.rs:18:7
[00:50:13] 3    |
[00:50:13] 4 LL |     g(&mut b) //~ ERROR cannot borrow
[00:50:13] -    |            ^ cannot borrow mutably
[00:50:13] - help: consider removing the `&mut`, as it is an immutable bindingnnot borrow immutable item `b` as mutable","code":{"code":"E0596","explanation":"\nThis error occurs because you tried to mutably borrow a non-mutable variable.\n\nExample of erroneous code:\n\n```compile_fail,E0596\nlet x = 1;\nlet y = &mut x; // error: cannot borrow mutably\n```\n\nIn here, `x` isn't mutable, so when we try to mutably borrow it in `y`, it\nfails. To fix this error, you need to make `x` mutable:\n\n```\nlet mut x = 1;\nlet y = &mut x; // ok!\n```\n"},"level":"error","spans":[{"file_name":"/checkout/src/test/ui/borrowck/mut-borrow-of-mut-ref.rs","byte_start":576,"byte_end":582,"line_start":18,"line_end":18,"column_start":7,"column_end":13,"is_primary":true,"text":[{"text":"    g(&mut b) //~ ERROR cannot borrow","highlight_start":7,"highlight_end":13}],"label":"cannot borrow as mutable","suggested_replacement":null,"suggestion_applicability":null,"expansion":null}],"children":[],"rendered":"error[E0596]: cannot borrow immutable item `b` as mutable\n  --> /checkout/src/test/ui/borrowck/mut-borrow-of-mut-ref.rs:18:7\n   |\nLL |     g(&mut b) //~ ERROR cannot borrow\n   |       ^^^^^^ cannot borrow as mutable\n\n"}
[00:50:13] {"message":"aborting due to previous error","code":null,"level":"error","spans":[],"children":[],"rendered":"error: aborting due to previous error\n\n"}
[00:50:13] {"message":"For more information about this error, try `rustc --explain E0596`.","code":null,"level":"","spans":[],"children":[],"rendered":"For more information about this error, try `rustc --explain E0596`.\n"}
[00:50:13] ------------------------------------------
[00:50:13] 
[00:50:13] thread '[ui (nll)] ui/borrowck/mut-borrow-of-mut-ref.rs' panicked at 'explicit panic', tools/compiletest/src/runtest.rs:3096:9
[00:50:13] note: Run with `RUST_BACKTRACE=1` for a backtrace.
---
[00:50:13] 
[00:50:13] thread 'main' panicked at 'Some tests failed', tools/compiletest/src/main.rs:498:22
[00:50:13] 
[00:50:13] 
[00:50:13] command did not execute successfully: "/checkout/obj/build/x86_64-unknown-linux-gnu/stage0-tools-bin/compiletest" "--compile-lib-path" "/checkout/obj/build/x86_64-unknown-linux-gnu/stage2/lib" "--run-lib-path" "/checkout/obj/build/x86_64-unknown-linux-gnu/stage2/lib/rustlib/x86_64-unknown-linux-gnu/lib" "--rustc-path" "/checkout/obj/build/x86_64-unknown-linux-gnu/stage2/bin/rustc" "--src-base" "/checkout/src/test/ui" "--build-base" "/checkout/obj/build/x86_64-unknown-linux-gnu/test/ui" "--stage-id" "stage2-x86_64-unknown-linux-gnu" "--mode" "ui" "--target" "x86_64-unknown-linux-gnu" "--host" "x86_64-unknown-linux-gnu" "--llvm-filecheck" "/usr/lib/llvm-3.9/bin/FileCheck" "--host-rustcflags" "-Crpath -O -Zunstable-options " "--target-rustcflags" "-Crpath -O -Zunstable-options  -Lnative=/checkout/obj/build/x86_64-unknown-linux-gnu/native/rust-test-helpers" "--docck-python" "/usr/bin/python2.7" "--lldb-python" "/usr/bin/python2.7" "--gdb" "/usr/bin/gdb" "--quiet" "--llvm-version" "3.9.1\n" "--system-llvm" "--cc" "" "--cxx" "" "--cflags" "" "--llvm-components" "" "--llvm-cxxflags" "" "--adb-path" "adb" "--adb-test-dir" "/data/tmp/work" "--android-cross-path" "" "--color" "always" "--compare-mode" "nll"
[00:50:13] 
[00:50:13] 
[00:50:13] failed to run: /checkout/obj/build/bootstrap/debug/bootstrap test
[00:50:13] Build completed unsuccessfully in 0:03:55
[00:50:13] Build completed unsuccessfully in 0:03:55
[00:50:13] make: *** [check] Error 1
[00:50:13] Makefile:58: recipe for target 'check' failed

The command "stamp sh -x -c "$RUN_SCRIPT"" exited with 2.
travis_time:start:07553010
$ date && (curl -fs --head https://google.com | grep ^Date: | sed 's/Date: //g' || true)

I'm a bot! I can only do what humans tell me to, so if this was not helpful or you have suggestions for improvements, please ping or otherwise contact @TimNN. (Feature Requests)

@estebank
Copy link
Contributor

estebank commented Jun 1, 2018

Could you squash your commits? It makes it easier when researching changes after the fact.

This commit is concerned with the case where the user tries to mutably
borrow a mutable reference, thereby triggering an error. Instead of the
existing suggestion to make the binding mutable, the compiler will now
suggest to avoid borrowing altogether.
@ytausky
Copy link
Contributor Author

ytausky commented Jun 4, 2018

I think it’s ready now, unless there are changes required.

@estebank
Copy link
Contributor

estebank commented Jun 4, 2018

@bors r+ rollup

@bors
Copy link
Collaborator

bors commented Jun 4, 2018

📌 Commit 3303e68 has been approved by estebank

@bors bors added S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Jun 4, 2018
@bors
Copy link
Collaborator

bors commented Jun 5, 2018

⌛ Testing commit 3303e68 with merge f9157f5...

bors added a commit that referenced this pull request Jun 5, 2018
Suggest not mutably borrowing a mutable reference

This PR would (hopefully) solve #45392. I deviated a bit from @estebank's instructions since the error span only included the borrowed expression (e.g. the `b` in `&mut b`). I also didn't check the mutability of the local binding, since this whole case is concerned with an immutable local.

I can see two outstanding questions:
1. `note_immutability_blame` is called in two places, but I only have one test case. I think it covers the call in `report_bckerror`, but I'm not sure how to trigger the call from `report_aliasability_violation`.
2. There is one failing test, where the local binding is `self: &mut Self`. I'm not entirely sure what the correct output should be, but I think the new message should also apply. Unfortunately, since this parameter is parsed differently, its `let_span` covers both the pattern and the type, leading to a wrong suggestion text. I'm not sure how to correctly identify this case.
@bors
Copy link
Collaborator

bors commented Jun 5, 2018

☀️ Test successful - status-appveyor, status-travis
Approved by: estebank
Pushing f9157f5 to master...

@bors bors merged commit 3303e68 into rust-lang:master Jun 5, 2018
@ytausky ytausky deleted the mut-ref branch June 5, 2018 09:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants