Skip to content
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

Fix incorrect span in &mut suggestion #49931

Merged
merged 1 commit into from
Apr 16, 2018
Merged

Fix incorrect span in &mut suggestion #49931

merged 1 commit into from
Apr 16, 2018

Conversation

csmoe
Copy link
Member

@csmoe csmoe commented Apr 13, 2018

Fixes #49859

@rust-highfive
Copy link
Collaborator

r? @eddyb

(rust_highfive has picked a reviewer for you, use r? to override)

@rust-highfive rust-highfive added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Apr 13, 2018
@eddyb
Copy link
Member

eddyb commented Apr 13, 2018

r? @estebank

@rust-highfive rust-highfive assigned estebank and unassigned eddyb Apr 13, 2018
@rust-highfive
Copy link
Collaborator

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.
Resolving deltas: 100% (614190/614190), completed with 4873 local objects.
---
[00:00:42] configure: rust.quiet-tests     := True
---
[00:04:44] tidy error: /checkout/src/librustc_mir/borrow_check/mod.rs:1644: line longer than 100 chars
[00:04:46] some tidy checks failed
[00:04:46]
[00:04:46]
[00:04:46] 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:46] expected success, got: exit code: 1
[00:04:46]
[00:04:46]
[00:04:46] failed to run: /checkout/obj/build/bootstrap/debug/bootstrap test src/tools/tidy
[00:04:46] Build completed unsuccessfully in 0:02:01
[00:04:46] make: *** [tidy] Error 1
[00:04:46] Makefile:79: recipe for target 'tidy' failed
---
$ ls -lat $HOME/Library/Logs/DiagnosticReports/
ls: cannot access /home/travis/Library/Logs/DiagnosticReports/: No such file or directory
travis_time:end:10060fb9:start=1523628706776695028,finish=1523628706783779426,duration=7084398
travis_fold:end:after_failure.2
travis_fold:start:after_failure.3
travis_time:start:0129d1fa
$ find $HOME/Library/Logs/DiagnosticReports -type f -name '*.crash' -not -name '*.stage2-*.crash' -not -name 'com.apple.CoreSimulator.CoreSimulatorService-*.crash' -exec printf travis_fold":start:crashlog\n\033[31;1m%s\033[0m\n" {} \; -exec head -750 {} \; -exec echo travis_fold":"end:crashlog \; || true
find: `/home/travis/Library/Logs/DiagnosticReports': No such file or directory
travis_time:end:0129d1fa:start=1523628706789950102,finish=1523628706796191299,duration=6241197
travis_fold:end:after_failure.3
travis_fold:start:after_failure.4
travis_time:start:179425fb
$ dmesg | grep -i kill
[   10.942418] init: failsafe main process (1093) killed by TERM signal

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)

@csmoe csmoe force-pushed the end_span branch 2 times, most recently from f962bb6 to bb2e1b4 Compare April 13, 2018 14:54
@rust-highfive
Copy link
Collaborator

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.
Resolving deltas: 100% (614190/614190), completed with 4873 local objects.
---
[00:01:10] configure: rust.quiet-tests     := True
---
[00:39:03] ...............................................................................i....................
[00:39:09] ......................i.............................................................................
---
[00:39:47] ..................i.............................................F.............................i.....
[00:39:53] ....................................................................................................
[00:39:59] ........ii..........................................................................................
t":5,"highlight_end":22}],"label":"`fancy_ref` is a `&` reference, so the data it refers to cannot be written","suggested_replacement":null,"expansion":null}],"children":[{"message":"consider changing this to be a mutable reference: `&mut (&mut fancy)`","code":null,"level":"help","spans":[{"file_name":"/checkout/src/test/ui/nll/issue-47388.rs","byte_start":589,"byte_end":602,"line_start":17,"line_end":17,"column_start":21,"column_end":34,"is_primary":true,"text":[{"text":"    let fancy_ref = &(&mut fancy);","highlight_start":21,"highlight_end":34}],"label":null,"suggested_replacement":"","expansion":null}],"children":[],"rendered":null}],"rendered":"error[E0594]: cannot assign to data in a `&` reference\n  --> /checkout/src/test/ui/nll/issue-47388.rs:18:5\n   |\nLL |     fancy_ref.num = 6; //~ ERROR E0594\n   |     ^^^^^^^^^^^^^^^^^ `fancy_ref` is a `&` reference, so the data it refers to cannot be written\nhelp: consider changing this to be a mutable reference: `&mut (&mut fancy)`\n   |\nLL |     let fancy_ref = ;\n   | \n\n"}
[00:40:10] {"message":"aborting due to previous error","code":null,"level":"error","spans":[],"children":[],"rendered":"error: aborting due to previous error\n\n"}
[00:40:10] {"message":"For more information about this error, try `rustc --explain E0594`.","code":null,"level":"","spans":[],"children":[],"rendered":"For more information about this error, try `rustc --explain E0594`.\n"}
---
[00:40:10] 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 -Zmiri -Zunstable-options " "--target-rustcflags" "-Crpath -O -Zmiri -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"
[00:40:10] expected success, got: exit code: 101
[00:40:10]
[00:40:10]
[00:40:10] failed to run: /checkout/obj/build/bootstrap/debug/bootstrap test
[00:40:10] Build completed unsuccessfully in 0:02:10
[00:40:10] make: *** [check] Error 1
[00:40:10] Makefile:58: recipe for target 'check' failed
---
121748 ./obj/build/bootstrap/debug/incremental/bootstrap-351vorei3hhuv/s-f02y1pcv77-9ggsry-3ijxj2oqwtm6x
109928 ./obj/build/x86_64-unknown-linux-gnu/stage0-tools/x86_64-unknown-linux-gnu
109924 ./obj/build/x86_64-unknown-linux-gnu/stage0-tools/x86_64-unknown-linux-gnu/release
106044 ./obj/build/x86_64-unknown-linux-gnu/stage0-tools/x86_64-unknown-linux-gnu/release/deps
102808 ./obj/build/x86_64-unknown-linux-gnu/stage0/lib/rustlib/x86_64-unknown-linux-gnu/codegen-backends
102612 ./obj/build/x86_64-unknown-linux-gnu/stage1-std/x86_64-unknown-linux-gnu/release/incremental/core-31lccp6wy7orz
102608 ./obj/build/x86_64-unknown-linux-gnu/stage1-std/x86_64-unknown-linux-gnu/release/incremental/core-31lccp6wy7orz/s-f02yz8ngw0-uorcok-1wdf9ktk9nlt9
100736 ./obj/build/bootstrap/debug/incremental/bootstrap-zki88qpb4pjm
100732 ./obj/build/bootstrap/debug/incremental/bootstrap-zki88qpb4pjm/s-f02z1dktqh-154ep14-1fnjifxdmfg4c
---
$ ls -lat $HOME/Library/Logs/DiagnosticReports/
ls: cannot access /home/travis/Library/Logs/DiagnosticReports/: No such file or directory
travis_time:end:080d49bf:start=1523632468355886030,finish=1523632468362280230,duration=6394200
travis_fold:end:after_failure.2
travis_fold:start:after_failure.3
travis_time:start:06ccb565
$ find $HOME/Library/Logs/DiagnosticReports -type f -name '*.crash' -not -name '*.stage2-*.crash' -not -name 'com.apple.CoreSimulator.CoreSimulatorService-*.crash' -exec printf travis_fold":start:crashlog\n\033[31;1m%s\033[0m\n" {} \; -exec head -750 {} \; -exec echo travis_fold":"end:crashlog \; || true
find: `/home/travis/Library/Logs/DiagnosticReports': No such file or directory
travis_time:end:06ccb565:start=1523632468367257706,finish=1523632468372424697,duration=5166991
travis_fold:end:after_failure.3
travis_fold:start:after_failure.4
travis_time:start:054a132c
$ dmesg | grep -i kill
[    9.787893] init: failsafe main process (1095) killed by TERM signal

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)

Copy link
Contributor

@estebank estebank left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the fix!

Small changes needed before being able to merge it. Once they are addressed, r=me.

@@ -1654,7 +1662,7 @@ impl<'cx, 'gcx, 'tcx> MirBorrowckCtxt<'cx, 'gcx, 'tcx> {

if let Some((err_help_span, err_help_stmt, item_msg, sec_span)) = err_info {
let mut err = self.tcx.cannot_assign(span, &item_msg, Origin::Mir);
err.span_suggestion(err_help_span, err_help_stmt, format!(""));
err.span_suggestion(err_help_span, &err_help_stmt, format!(""));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you look below, the third argument is the code content that will be suggested. Because here an empty String is being passed, the suggestion effectively tells the user to remove the code.

self.tcx.sess.codemap().span_to_snippet(sp) {
help_stmt = format!(
"consider changing this to be a \
mutable reference: `&mut {}`", &src[1..]);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The help message doesn't need to incorporate the suggested code, this is passed as the third argument to span_suggestion and the diagnostic machinery deals with this as appropriate.

help_stmt = format!(
"consider changing this to be a \
mutable reference: `&mut {}`", &src[1..]);
};
err_info = Some((
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

err_info will need to include the contents of &src[1..] above in order to supply to use it in the suggestion.

LL | fancy_ref.num = 6; //~ ERROR E0594
| ^^^^^^^^^^^^^^^^^ `fancy_ref` is a `&` reference, so the data it refers to cannot be written
help: consider changing this to be a mutable reference: `&mut (&mut fancy)`
|
LL | let fancy_ref = ;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can see what I'm referring to in the previous comments here: let fancy_ref = ; should be

help: consider changing this to be a mutable reference
   |
LL |     let fancy_ref = &mut (&mut fancy);

span_suggestion deals with this correctly automatically.

@csmoe
Copy link
Member Author

csmoe commented Apr 14, 2018

Advice addressed. r @estebank

@rust-highfive
Copy link
Collaborator

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.
Resolving deltas: 100% (614320/614320), completed with 4875 local objects.
---
[00:00:42] configure: rust.quiet-tests     := True
---
[00:04:45] tidy error: /checkout/src/librustc_mir/borrow_check/mod.rs:1663: line longer than 100 chars
[00:04:45] tidy error: /checkout/src/librustc_mir/borrow_check/mod.rs:1665: line longer than 100 chars
[00:04:47] some tidy checks failed
[00:04:47]
[00:04:47]
[00:04:47] 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:47] expected success, got: exit code: 1
[00:04:47]
[00:04:47]
[00:04:47] failed to run: /checkout/obj/build/bootstrap/debug/bootstrap test src/tools/tidy
[00:04:47] Build completed unsuccessfully in 0:01:55
[00:04:47] Makefile:79: recipe for target 'tidy' failed
[00:04:47] make: *** [tidy] Error 1

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

[00:04:45] tidy error: /checkout/src/librustc_mir/borrow_check/mod.rs:1663: line longer than 100 chars
[00:04:45] tidy error: /checkout/src/librustc_mir/borrow_check/mod.rs:1665: line longer than 100 chars

@rust-highfive
Copy link
Collaborator

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.
Resolving deltas: 100% (614320/614320), completed with 4875 local objects.
---
[00:00:44] configure: rust.quiet-tests     := True
---
[00:04:39] tidy error: /checkout/src/librustc_mir/borrow_check/mod.rs:1663: line longer than 100 chars
[00:04:41] some tidy checks failed
[00:04:41]
[00:04:41]
[00:04:41] 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:41] expected success, got: exit code: 1
[00:04:41]
[00:04:41]
[00:04:41] failed to run: /checkout/obj/build/bootstrap/debug/bootstrap test src/tools/tidy
[00:04:41] Build completed unsuccessfully in 0:01:53
[00:04:41] make: *** [tidy] Error 1
[00:04:41] Makefile:79: recipe for target 'tidy' failed

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

@bors r+ rollup

@bors
Copy link
Contributor

bors commented Apr 14, 2018

📌 Commit 6f5a16b 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 Apr 14, 2018
kennytm added a commit to kennytm/rust that referenced this pull request Apr 16, 2018
Fix incorrect span in `&mut` suggestion

Fixes rust-lang#49859
bors added a commit that referenced this pull request Apr 16, 2018
Rollup of 8 pull requests

Successful merges:

 - #49555 (Inline most of the code paths for conversions with boxed slices)
 - #49606 (Prevent broken pipes causing ICEs)
 - #49646 (Use box syntax instead of Box::new in Mutex::remutex on Windows)
 - #49647 (Remove `underscore_lifetimes` and `match_default_bindings` from active feature list)
 - #49931 (Fix incorrect span in `&mut` suggestion)
 - #49959 (rustbuild: allow building tools with debuginfo)
 - #49965 (Remove warning about f64->f32 cast being potential UB)
 - #49994 (Remove unnecessary indentation in rustdoc book codeblock.)

Failed merges:
@bors bors merged commit 6f5a16b into rust-lang:master Apr 16, 2018
@csmoe csmoe deleted the end_span branch July 13, 2018 08:44
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.

5 participants