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

Modify compile-fail/E0389 error message WIP #48914

Merged
merged 24 commits into from
Apr 10, 2018
Merged

Conversation

gaurikholkar-zz
Copy link

@gaurikholkar-zz gaurikholkar-zz commented Mar 10, 2018

This fixes #47388

cc @nikomatsakis @estebank

r? @nikomatsakis

Certain ui tests were failing locally. I'll check if the same happens here too.

@rust-highfive
Copy link
Collaborator

r? @estebank

(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 Mar 10, 2018
@gaurikholkar-zz gaurikholkar-zz changed the title Modify comiple-fail/E0389 error message Modify compile-fail/E0389 error message Mar 10, 2018
@gaurikholkar-zz gaurikholkar-zz changed the title Modify compile-fail/E0389 error message Modify compile-fail/E0389 error message WIP Mar 10, 2018
@@ -70,5 +70,5 @@ fn main() {
};
s[2] = 20;
//[ast]~^ ERROR cannot assign to immutable indexed content
//[mir]~^^ ERROR cannot assign to immutable item
//[mir]~^^ ERROR cannot assign through immutable item
Copy link
Author

Choose a reason for hiding this comment

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

I'm not sure about the look of this test though.

Copy link
Contributor

Choose a reason for hiding this comment

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

This one seems ok-ish to me, but we might be able to improve upon it. I'll think about it.

@gaurikholkar-zz
Copy link
Author

This is how the error message looks like

error[E0594]: cannot assign through `&`-reference fancy_ref
  --> src/test/compile-fail/E0389.rs:18:5
   |
17 |     let fancy_ref = &(&mut fancy);
   |                     ------------- help: consider changing this to be a mutable reference: `&mut`
18 |     fancy_ref.num = 6; //~ ERROR E0389
   |     ^^^^^^^^^^^^^^^^^ cannot assign to field of `&`-reference

Do I need to add a ui test for this? There's an already existing compile-fail test

@estebank
Copy link
Contributor

Do I need to add a ui test for this? There's an already existing compile-fail test

Could you move the file from compile-fail to ui?

let item_msg = match self.describe_place(place) {
Some(name) => format!("immutable item `{}`", name),
None => "immutable item".to_owned(),
let err_info = match *place_err {
Copy link
Contributor

Choose a reason for hiding this comment

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

Given how deeply nested this is, it might make sense to move it to its own method, or at least adding a comment on top describing what the code is supposed to be doing.

@kennytm kennytm added S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Mar 10, 2018
Some(name) => format!("immutable item `{}`", name),
None => "immutable item".to_owned(),
let err_info = match *place_err {
Place::Projection(ref proj) => {
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 match on multiple levels to avoid deeply nested structures:

enum Foo {
    A { f: Bar },
    B(Bar),
}
enum Bar {
    X,
    Y,
}
let x = Foo::B(Bar::X);
match x {
    Foo::A { f: Bar::Y } => 1,
    _ => 0,
}

_ => None,
}
}
_ => None,
Copy link
Contributor

Choose a reason for hiding this comment

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

Given how many branches there are here, it might make sense to make err_info mutable with a default value of None, and override where applicable, but this might not be needed if the amount of branches is reduced.

}
err.emit()
}else{
Copy link
Contributor

Choose a reason for hiding this comment

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

spaces around else

err.span_label(span, "cannot mutate");
if place != place_err {
if let Some(name) = self.describe_place(place_err) {
err.note(&format!("Value not mutable causing this error: `{}`",
Copy link
Contributor

Choose a reason for hiding this comment

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

lowercase sentences: value not mutable

@@ -39,6 +39,7 @@ Rust MIR: a lowered representation of Rust. Also: an experiment!
#![feature(collection_placement)]
#![feature(nonzero)]
#![feature(underscore_lifetimes)]
#![feature(crate_visibility_modifier)]
Copy link
Contributor

Choose a reason for hiding this comment

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

Was this needed?

Copy link
Author

@gaurikholkar-zz gaurikholkar-zz Mar 10, 2018

Choose a reason for hiding this comment

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

yes, due to the usage here crate trait FindAssignments { in collect_writes.rs

@@ -70,5 +70,5 @@ fn main() {
};
s[2] = 20;
//[ast]~^ ERROR cannot assign to immutable indexed content
//[mir]~^^ ERROR cannot assign to immutable item
//[mir]~^^ ERROR cannot assign through immutable item
Copy link
Contributor

Choose a reason for hiding this comment

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

This one seems ok-ish to me, but we might be able to improve upon it. I'll think about it.

@@ -27,7 +27,7 @@ fn indirect_write_to_imm_box() {
let y: Box<_> = box &mut x;
let p = &y;
***p = 2; //[ast]~ ERROR cannot assign to data in a `&` reference
//[mir]~^ ERROR cannot assign to immutable item `***p`
//[mir]~^ ERROR cannot assign through `&`-reference `p`
Copy link
Contributor

Choose a reason for hiding this comment

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

Not convinced about this change...

Copy link
Contributor

Choose a reason for hiding this comment

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

certainly better than it was ("imutable item"), but not I think perfect yet -- and not necessarily better than AST variant, I don't think

Copy link
Contributor

Choose a reason for hiding this comment

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

The AST based error is this:

error[E0389]: cannot assign to data in a `&` reference
 --> src/main.rs:8:5
  |
8 |     ***p = 2;
  |     ^^^^^^^^ assignment into an immutable reference

which I think has too much jargon, but some promising elements. This also intersects your style guide @estebank. Personally, my preference is that the "main" message is kind of generic and formal, like it is here, telling you nothing of the program itself, but that those details are revealed in the "underlines" and in a "conversational" tone. Maybe something like this?

error[E0389]: cannot assign to data in a `&` reference
 --> src/main.rs:8:5
  |
8 |     ***p = 2;
  |     ^^^^^^^^ `p` is a `&` reference, so the data it refers to cannot be written

Copy link
Author

Choose a reason for hiding this comment

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

Is this the common message for all such cases or just for the above case?

Copy link
Author

Choose a reason for hiding this comment

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

error[E0594]: cannot assign to data in a `&` reference
  --> src/test/compile-fail/borrowck/borrowck-issue-14498.rs:29:5
   |
28 |     let p = &y;
   |             -- help: consider changing this to be a mutable reference: `&mut`
29 |     ***p = 2;
   |     ^^^^^^^^ `p` is a `&` reference, so the data it refers to cannot be written

is how the message looks like now @nikomatsakis

@nikomatsakis nikomatsakis self-assigned this Mar 13, 2018
Copy link
Contributor

@nikomatsakis nikomatsakis left a comment

Choose a reason for hiding this comment

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

Left a few nits, to start.

let mut err = self.tcx
.cannot_borrow_path_as_mutable(span, &item_msg, Origin::Mir);
err.span_label(span, "cannot borrow as mutable");

if place != place_err {
if let Some(name) = self.describe_place(place_err) {
err.note(&format!("Value not mutable causing this error: `{}`", name));
err.note(&format!("value not mutable causing this error: `{}`", name));
Copy link
Contributor

Choose a reason for hiding this comment

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

Pre-existing, but this message is not particularly grammatical. In fact, I have a hard time even understanding it -- I guess it is saying that "the value which is causing this path not to be mutable is..."?


crate trait FindAssignments {
fn find_assignments(&self, local: Local) -> Vec<Location>;
}
Copy link
Contributor

Choose a reason for hiding this comment

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

Nit: formatting

// fn super_local()
}

crate trait FindAssignments {
Copy link
Contributor

Choose a reason for hiding this comment

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

I would move this to the top of the file -- this is what readers care about. Also, I would add a comment to the method:


Finds all statements that assign directly to local (i.e., X = ...) and returns their locations.


// The Visitor walks the MIR to return the assignment statements corresponding
// to a Local.
pub struct FindLocalAssignmentVisitor {
Copy link
Contributor

Choose a reason for hiding this comment

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

This does not need to be public, it is an impl detail. Just make it private.

let item_msg = if error_reported {
if let Some(name) =
self.describe_place(place_err) {
let var = str::replace(&name, "*", "");
Copy link
Contributor

Choose a reason for hiding this comment

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

Hmm, I'm not crazy about the string munging =) Maybe we should just do describe_place(&place.base)?

let var = str::replace(&name, "*", "");
format!("`&`-reference `{}`", var)
} else {
self.get_main_error_message(place)
Copy link
Contributor

Choose a reason for hiding this comment

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

I would pull this into a helper function and I would change these get_main_error_message cases to just return None. The helper would be something like:

fn specialized_description(..) -> Option<String>

then if it is None you can use get_main_error_message(place).

@bors
Copy link
Contributor

bors commented Mar 15, 2018

☔ The latest upstream changes (presumably #47630) made this pull request unmergeable. Please resolve the merge conflicts.

@pietroalbini
Copy link
Member

@gaurikholkar ping from triage! There are a few comments from the reviewer, could you address them?

@TimNN
Copy link
Contributor

TimNN commented Apr 6, 2018

Your PR failed on Travis. 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% (612610/612610), completed with 4869 local objects.
---
[00:00:39] configure: rust.quiet-tests     := True
---
[00:44:32] ..........................................................................i.........................
[00:44:38] .................i..................................................................................
---
[00:45:14] ..............................................................................................i.....
[00:45:22] .......................................F.............................i..............................
[00:45:28] ....................................................................................................
[00:45:35] ....................................................................................................
[00:45:43] ....................................................................................................
`&`-reference `fancy_ref` [E0594]"
---
[00:45:44]         msg: "E0594"
---
[00:45:44] 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:45:44] expected success, got: exit code: 101
[00:45:44]
[00:45:44]
[00:45:44] failed to run: /checkout/obj/build/bootstrap/debug/bootstrap test
[00:45:44] Build completed unsuccessfully in 0:02:29
[00:45:44] Makefile:58: recipe for target 'check' failed
[00:45:44] make: *** [check] 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.

@gaurikholkar-zz
Copy link
Author

@estebank @nikomatsakis repoened the issue

@TimNN
Copy link
Contributor

TimNN commented Apr 7, 2018

Your PR failed on Travis. 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% (612665/612665), completed with 4869 local objects.
---
[00:00:52] configure: rust.quiet-tests     := 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.

@gaurikholkar-zz
Copy link
Author

Not sure why tidy checks are failing. Couldn't find any trailing whitespace.

@TimNN
Copy link
Contributor

TimNN commented Apr 7, 2018

Your PR failed on Travis. 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% (612667/612667), completed with 4869 local objects.
---
[00:01:04] configure: rust.quiet-tests     := True
---
[00:04:35] tidy error: /checkout/src/librustc_mir/borrow_check/mod.rs:1578: trailing whitespace
[00:04:35] tidy error: /checkout/src/librustc_mir/borrow_check/mod.rs:1582: trailing whitespace
[00:04:35] tidy error: /checkout/src/librustc_mir/borrow_check/mod.rs:1644: trailing whitespace
[00:04:36] some tidy checks failed
[00:04:36]
[00:04:36]
[00:04:36] 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:36] expected success, got: exit code: 1
[00:04:36]
[00:04:36]
[00:04:36] failed to run: /checkout/obj/build/bootstrap/debug/bootstrap test src/tools/tidy
[00:04:36] Build completed unsuccessfully in 0:01:54
[00:04:36] Makefile:79: recipe for target 'tidy' failed
[00:04:36] make: *** [tidy] Error 1
---
$ ls -lat $HOME/Library/Logs/DiagnosticReports/
ls: cannot access /home/travis/Library/Logs/DiagnosticReports/: No such file or directory
travis_time:end:159c8622:start=1523087670093303512,finish=1523087670099866766,duration=6563254
travis_fold:end:after_failure.2
travis_fold:start:after_failure.3
travis_time:start:28befa78
$ 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:28befa78:start=1523087670105669571,finish=1523087670112459931,duration=6790360
travis_fold:end:after_failure.3
travis_fold:start:after_failure.4
travis_time:start:05e4a96c
$ dmesg | grep -i kill
[   10.173691] init: failsafe main process (1094) 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.

} else {
self.get_default_err_msg(place)
};

Copy link
Member

Choose a reason for hiding this comment

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

A line consisting of only spaces is also considered "trailing whitespaces".

Copy link
Author

Choose a reason for hiding this comment

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

thanks @kennytm :)

Copy link
Author

Choose a reason for hiding this comment

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

@kennytm can you help out with the fixes for the tidy errors? I've tried certain things but they don't seem to work. One of the errors is also in the previously written code.

Copy link
Member

Choose a reason for hiding this comment

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

@gaurikholkar The line numbers seems wrong. You could run tidy locally by

./x.py test src/tools/tidy

The lines with trailing whitespaces are:

tidy error: src/librustc_mir/borrow_check/mod.rs:1532: trailing whitespace
tidy error: src/librustc_mir/borrow_check/mod.rs:1536: trailing whitespace
tidy error: src/librustc_mir/borrow_check/mod.rs:1595: trailing whitespace

Copy link
Author

Choose a reason for hiding this comment

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

Thanks you @kennytm . Yeah the line nos were wrong. My local tidy script panics -> logs

Copy link
Member

Choose a reason for hiding this comment

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

@gaurikholkar you should just remove the entire binaryen folder, it is no longer used.

@TimNN
Copy link
Contributor

TimNN commented Apr 7, 2018

Your PR failed on Travis. 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% (613151/613151), completed with 4866 local objects.
---
[00:00:50] configure: rust.quiet-tests     := 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.

@shepmaster shepmaster added S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. and removed S-inactive Status: Inactive and waiting on the author. This is often applied to closed PRs. labels Apr 7, 2018
@TimNN
Copy link
Contributor

TimNN commented Apr 8, 2018

Your PR failed on Travis. 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% (612769/612769), completed with 4866 local objects.
---
[00:00:42] configure: rust.quiet-tests     := True
---
[00:05:01] tidy error: /checkout/src/librustc_mir/borrow_check/mod.rs:1578: trailing whitespace
[00:05:01] tidy error: /checkout/src/librustc_mir/borrow_check/mod.rs:1582: trailing whitespace
[00:05:01] tidy error: /checkout/src/librustc_mir/borrow_check/mod.rs:1641: trailing whitespace
[00:05:02] some tidy checks failed
[00:05:02]
[00:05:02]
[00:05:02] 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:05:02] expected success, got: exit code: 1
[00:05:02]
[00:05:02]
[00:05:02] failed to run: /checkout/obj/build/bootstrap/debug/bootstrap test src/tools/tidy
[00:05:02] Build completed unsuccessfully in 0:02:00
[00:05:02] Makefile:79: recipe for target 'tidy' failed
[00:05:02] make: *** [tidy] Error 1
---
$ ls -lat $HOME/Library/Logs/DiagnosticReports/
ls: canno

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.

@nikomatsakis
Copy link
Contributor

This is looking pretty good to me! Let's land it. We can always tinker more.

@bors r+

Nice job @gaurikholkar

@bors
Copy link
Contributor

bors commented Apr 10, 2018

📌 Commit c792d1e has been approved by nikomatsakis

@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-author Status: This is awaiting some action (such as code changes or more information) from the author. labels Apr 10, 2018
@bors
Copy link
Contributor

bors commented Apr 10, 2018

⌛ Testing commit c792d1e with merge 0b72d48...

bors added a commit that referenced this pull request Apr 10, 2018
Modify compile-fail/E0389 error message WIP

This fixes #47388

cc @nikomatsakis @estebank

r? @nikomatsakis

Certain ui tests were failing locally. I'll check if the same happens here too.
--> $DIR/issue-47388.rs:18:5
|
LL | let fancy_ref = &(&mut fancy);
| ------------- help: consider changing this to be a mutable reference: `&mut`
Copy link
Contributor

Choose a reason for hiding this comment

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

I believe either the span or the suggestion text might be incorrect. It should either suggest &mut (&mut fancy) for this span, or use a span only selecting the &.

Copy link
Contributor

Choose a reason for hiding this comment

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

Filed #49859

@bors
Copy link
Contributor

bors commented Apr 10, 2018

☀️ Test successful - status-appveyor, status-travis
Approved by: nikomatsakis
Pushing 0b72d48 to master...

@bors bors merged commit c792d1e into rust-lang:master Apr 10, 2018
@pietroalbini
Copy link
Member

@estebank I guess now we need another PR for that...

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.

[NLL] E0389 error message uses the term immutable item inappropriately
10 participants