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

#53359: putting multiple unresolved import on single line #53565

Merged
merged 1 commit into from
Sep 10, 2018

Conversation

PramodBisht
Copy link
Contributor

r? @estebank
Here is WIP implementation of #53359
this PR have clubbed multiple unresolved imports into a single line.
I think still two things need to improve like giving specific label message for each span of multi_span(how we can do this?) and second we are getting a warning while compiling, stating something like E0432 have been passed before.

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

this PR have clubbed multiple unresolved imports into a single line.

I feel it might be slightly less disruptive to third party tools to only unify those unresolved imports that are part of the same path (baz and qux in foo::bar::{baz, qux}).

I think still two things need to improve like giving specific label message for each span of
multi_span(how we can do this?)

You need to give one label to each span and it should work.

and second we are getting a warning while compiling, stating something like E0432 have been passed before.

That is because a span_err with a given number can only be used once, and you're reusing that error code here. You should look into where that error is being emitted now and unify them.

@bors

This comment has been minimized.

@pietroalbini pietroalbini 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 Aug 27, 2018
@PramodBisht PramodBisht force-pushed the issue/53359_b branch 2 times, most recently from 18b7296 to e8dda23 Compare August 31, 2018 15:50
@rust-highfive

This comment has been minimized.

@PramodBisht PramodBisht force-pushed the issue/53359_b branch 2 times, most recently from b3aaae6 to 9006adc Compare August 31, 2018 16:26
@rust-highfive
Copy link
Collaborator

The job x86_64-gnu-llvm-5.0 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:17:09]    Compiling rustc_lint v0.0.0 (file:///checkout/src/librustc_lint)
[00:17:09]    Compiling rustc_passes v0.0.0 (file:///checkout/src/librustc_passes)
[00:17:13]    Compiling rustc_plugin v0.0.0 (file:///checkout/src/librustc_plugin)
[00:17:23]    Compiling rustc_resolve v0.0.0 (file:///checkout/src/librustc_resolve)
[00:17:24] warning: diagnostic code E0432 already used
[00:17:24]     |
[00:17:24]     |
[00:17:24] 365 |             let mut err = struct_span_err!(resolver.session, span, E0432, "{}", msg);
[00:17:24]     |
[00:17:24] note: previous invocation
[00:17:24]    --> librustc_resolve/resolve_imports.rs:799:23
[00:17:24]     |
[00:17:24]     |
[00:17:24] 799 |           let mut err = struct_span_err!(self.resolver.session,
[00:17:24]     |  _______________________^
[00:17:24] 800 | |                                        multi_span.clone(), E0432, "{}", &msg);
[00:17:24]     = note: this error originates in a macro outside of the current crate (in Nightly builds, run with -Z external-macro-backtrace for more info)
[00:17:24] 
[00:18:37]    Compiling rustc-main v0.0.0 (file:///checkout/src/rustc)
[00:18:37]     Finished release [optimized] target(s) in 13m 16s
---
[00:31:53]    Compiling rustc_privacy v0.0.0 (file:///checkout/src/librustc_privacy)
[00:32:09]    Compiling rustc_save_analysis v0.0.0 (file:///checkout/src/librustc_save_analysis)
[00:32:58]    Compiling rustc_resolve v0.0.0 (file:///checkout/src/librustc_resolve)
[00:32:58]    Compiling rustc_plugin v0.0.0 (file:///checkout/src/librustc_plugin)
[00:32:59] warning: diagnostic code E0432 already used
[00:32:59]     |
[00:32:59]     |
[00:32:59] 365 |             let mut err = struct_span_err!(resolver.session, span, E0432, "{}", msg);
[00:32:59]     |
[00:32:59] note: previous invocation
[00:32:59]    --> librustc_resolve/resolve_imports.rs:799:23
[00:32:59]     |
[00:32:59]     |
[00:32:59] 799 |           let mut err = struct_span_err!(self.resolver.session,
[00:32:59]     |  _______________________^
[00:32:59] 800 | |                                        multi_span.clone(), E0432, "{}", &msg);
[00:32:59]     = note: this error originates in a macro outside of the current crate (in Nightly builds, run with -Z external-macro-backtrace for more info)
[00:32:59] 
[00:33:04]    Compiling rustc_codegen_utils v0.0.0 (file:///checkout/src/librustc_codegen_utils)
[00:33:04]    Compiling rustc_passes v0.0.0 (file:///checkout/src/librustc_passes)
---
[00:44:22] ....................................................................................................
[00:44:24] ....................................................................................................
[00:44:27] i..................................................................i................................
[00:44:30] ....................................................................................................
[00:44:33] ........................................F...........................................................
[00:44:38] ....................................................................................................
[00:44:41] ....................................................................................................
[00:44:44] ....................................................................................................
[00:44:47] ....................................................................................................
---
[00:45:46] 
[00:45:46] ---- [ui] ui/issue-53565.rs stdout ----
[00:45:46] diff of stderr:
[00:45:46] 
[00:45:46] 1 error[E0432]: unresolved imports `std::time::foo`, `std::time::bar`, `std::time::buzz`
[00:45:46] +   --> $DIR/issue-53565.rs:10:17
[00:45:46] 3    |
[00:45:46] 3    |
[00:45:46] 4 LL | use std::time::{foo, bar, buzz};
[00:45:46] 5    |                 ^^^  ^^^  ^^^^ no `buzz` in `time`
[00:45:46] 
[00:45:46] 8    |                 no `foo` in `time`
[00:45:46] 9 
[00:45:46] 10 error[E0432]: unresolved imports `std::time::abc`, `std::time::def`
[00:45:46] +   --> $DIR/issue-53565.rs:11:17
[00:45:46] 12    |
[00:45:46] 12    |
[00:45:46] 13 LL | use std::time::{abc, def};
[00:45:46] 14    |                 ^^^  ^^^ no `def` in `time`
[00:45:46] 
[00:45:46] The actual stderr differed from the expected stderr.
[00:45:46] Actual stderr saved to /checkout/obj/build/x86_64-unknown-linux-gnu/test/ui/issue-53565/issue-53565.stderr
[00:45:46] Actual stderr saved to /checkout/obj/build/x86_64-unknown-linux-gnu/test/ui/issue-53565/issue-53565.stderr
[00:45:46] To update references, rerun the tests and pass the `--bless` flag
[00:45:46] To only update this specific test, also pass `--test-args issue-53565.rs`
[00:45:46] error: 1 errors occurred comparing output.
[00:45:46] status: exit code: 1
[00:45:46] status: exit code: 1
[00:45:46] command: "/checkout/obj/build/x86_64-unknown-linux-gnu/stage2/bin/rustc" "/checkout/src/test/ui/issue-53565.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/issue-53565/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/issue-53565/auxiliary" "-A" "unused"
[00:45:46] ------------------------------------------
[00:45:46] 
[00:45:46] ------------------------------------------
[00:45:46] stderr:
[00:45:46] stderr:
[00:45:46] ------------------------------------------
[00:45:46] {"message":"unresolved imports `std::time::foo`, `std::time::bar`, `std::time::buzz`","code":{"code":"E0432","explanation":"\nAn import was unresolved.\n\nErroneous code example:\n\n```compile_fail,E0432\nuse something::Foo; // error: unresolved import `something::Foo`.\n```\n\nPaths in `use` statements are relative to the crate root. To import items\nrelative to the current and parent modules, use the `self::` and `super::`\nprefixes, respectively. Also verify that you didn't misspell the import\nname and that the import exists in the module from where you tried to\nimport it. Example:\n\n```\nuse self::something::Foo; // ok!\n\nmod something {\n    pub struct Foo;\n}\n# fn main() {}\n```\n\nOr, if you tried to use a module from an external crate, you may have missed\nthe `extern crate` declaration (which is usually placed in the crate root):\n\n```\nextern crate core; // Required to use the `core` crate\n\nuse core::any;\n# fn main() {}\n```\n"},"level":"error","spans":[{"file_name":"/checkout/src/test/ui/issue-53565.rs","byte_start":482,"byte_end":485,"line_start":10,"line_end":10,"column_start":17,"column_end":20,"is_primary":true,"text":[{"text":"use std::time::{foo, bar, buzz};","highlight_start":17,"highlight_end":20}],"label":"no `foo` in `time`","suggested_replacement":null,"suggestion_applicability":null,"expansion":null},{"file_name":"/checkout/src/test/ui/issue-53565.rs","byte_start":487,"byte_end":490,"line_start":10,"line_end":10,"column_start":22,"column_end":25,"is_primary":true,"text":[{"text":"use std::time::{foo, bar, buzz};","highlight_start":22,"highlight_end":25}],"label":"no `bar` in `time`","suggested_replacement":null,"suggestion_applicability":null,"expansion":null},{"file_name":"/checkout/src/test/ui/issue-53565.rs","byte_start":492,"byte_end":496,"line_start":10,"line_end":10,"column_start":27,"column_end":31,"is_primary":true,"text":[{"text":"use std::tessfully in 0:03:03
[00:45:46] make: *** [check] Error 1
[00:45:46] Makefile:58: recipe for target 'check' failed

The command "stamp sh -x -c "$RUN_SCRIPT"" exited with 2.
travis_time:start:23adbb39
$ date && (curl -fs --head https://google.com | grep ^Date: | sed 's/Date: //g' || true)
---
151200 ./src/tools/clang
149120 ./src/llvm-emscripten/test
148964 ./obj/build/bootstrap/debug/incremental
134532 ./obj/build/bootstrap/debug/incremental/bootstrap-11nz4fw202v9g
134528 ./obj/build/bootstrap/debug/incremental/bootstrap-11nz4fw202v9g/s-f4dehdm17m-1ighvpz-3aquzm2prkry8
129812 ./obj/build/x86_64-unknown-linux-gnu/stage0-bootstrap-tools/x86_64-unknown-linux-gnu
1or CORE in obj/cores/core.*; do EXE=$(echo $CORE | sed 's|obj/cores/core\.[0-9]*\.!checkout!\(.*\)|\1|;y|!|/|'); if [ -f "$EXE" ]; then printf travis_fold":start:crashlog\n\033[31;1m%s\033[0m\n" "$CORE"; gdb -q -c "$CORE" "$EXE" -iex 'set auto-load off' -iex 'dir src/' -iex 'set sysroot .' -ex bt -ex q; echo travis_fold":"end:crashlog; fi; done || true
travis_fold:end:after_failure.4
travis_fold:start:after_failure.5
travis_time:start:009c58e8
travis_time:start:009c58e8
$ cat ./obj/build/x86_64-unknown-linux-gnu/native/asan/build/lib/asan/clang_rt.asan-dynamic-i386.vers || true
cat: ./obj/build/x86_64-unknown-linux-gnu/native/asan/build/lib/asan/clang_rt.asan-dynamic-i386.vers: No such file or directory
travis_fold:end:after_failure.5
travis_fold:start:after_failure.6
travis_time:start:10ff9758
$ dmesg | grep -i kill

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)

let msg = format!("unresolved import{} {}",
if path_vec.len() > 1 { "s" } else { "" }, path);
let mut err = struct_span_err!(self.resolver.session,
multi_span.clone(), E0432, "{}", &msg);
Copy link
Contributor

Choose a reason for hiding this comment

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

To avoid the error you're seeing in travis you need to extract this to a method called from both here and the other occurrence of E0432.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@estebank Sure!

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@estebank Challenge here is to create a generic function which can take any one of Span or MultiSpan as a type of argument. I think creating a traits and implementing it both for Span and MultiSpan is one way but I am bit reluctant toward this approach. Let me know what are your thoughts on that.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I think I have found other way for this.

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 use where S: Into<MultiSpan> and have your method accept a sp: S. Span implements it, so your method can take either and inside your method you operate with a MultiSpan always.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done!

--> $DIR/issue-53565.rs:1:17
|
LL | use std::time::{foo, bar, buzz};
| ^^^ ^^^ ^^^^ no `buzz` in `time`
Copy link
Contributor

Choose a reason for hiding this comment

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

It might be nice for this to be

no `buzz` in `std::time`

but I'm not too worried one way or another.

@rust-highfive

This comment has been minimized.

@PramodBisht PramodBisht force-pushed the issue/53359_b branch 3 times, most recently from fc471ba to 527ad26 Compare September 3, 2018 17:59
// in case of new import line, throw diagnostic message
// for previous line.
self.throw_unresolved_import_error(error_vec.clone(), None);
error_vec.clear();
Copy link
Contributor

Choose a reason for hiding this comment

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

Here I feel using std::mem::swap would be a better idea:

let mut empty_vec = vec![];
swap(empty_vec, error_vec);
self.throw_unresolved_import_error(empty_vec, None);

That way you're not cloning error_vec just to discard its contents immediately after.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done!

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.

Other than the nitpicks inline, r=me.

let (span,msg) = match error_vec.is_empty() {
true => (span.unwrap(), "unresolved import".to_string()),
false => {
let span = MultiSpan::from_spans(error_vec.clone().into_iter()
Copy link
Contributor

Choose a reason for hiding this comment

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

Clean up indentation in this block.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I don't get it, what's wrong with indentation here.

let path_vec: Vec<String> = error_vec.clone().into_iter()
.map(|elem: (Span, String, String)| { format!("`{}`", elem.1) }
).collect();
let path = path_vec.join(", ");
Copy link
Contributor

Choose a reason for hiding this comment

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

It'd be a good idea to bound this list to a maximum size, to avoid having a ridiculous amount of text. The limit should be high enough that it is rarely hit, but must be present in case somebody is writing non-stylistic code.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@estebank What should be upper limit of path_vec here ?

Copy link
Contributor

Choose a reason for hiding this comment

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

Any number would be arbitrary, but let's say... 10?

Copy link
Contributor Author

@PramodBisht PramodBisht Sep 7, 2018

Choose a reason for hiding this comment

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

@estebank: or should we simply emit message once vector size reaches 10 or new import line? However, in that case we would not be able to avoid ridiculous amount of data.

Copy link
Contributor

Choose a reason for hiding this comment

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

I think the ideal would be something similar to the unexpected token error, where the error message lists all of the tokens that could have applied (theoretically unbounded list), while the label after a certain number (don't recall the threshold) is just "expected one of N tokens here".

Copy link
Contributor

Choose a reason for hiding this comment

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

This is what I'm thinking of

error: expected one of `)`, `,`, `-`, `.`, `<`, `?`, `break`, `continue`, `false`, `for`, `if`, `loop`, `match`, `move`, `return`, `static`, `true`, `unsafe`, `while`, `yield`, or an operator, found `;`
  --> $DIR/token-error-correct.rs:14:13
   |
LL |     foo(bar(;
   |            --
   |            ||
   |            |expected one of 21 possible tokens here
   |            |help: ...the missing `)` may belong here
   |            if you meant to close this...

In this case you'd have multiple spans, so the output would be a bit more cluttered, which makes me think we might want to remove the labels...

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@estebank done! now I have set an upper limit on a number of span_label for each diagnostic msg.

…one diagnostic

Addressed estebank's comments for 53359
@PramodBisht
Copy link
Contributor Author

r? @estebank

@estebank
Copy link
Contributor

estebank commented Sep 9, 2018

@bors r+

❤️

@bors
Copy link
Contributor

bors commented Sep 9, 2018

📋 Looks like this PR is still in progress, ignoring approval.

Hint: Remove WIP from this PR's title when it is ready for review.

@PramodBisht PramodBisht changed the title WIP - #53359: putting multiple unresolved import on single line #53359: putting multiple unresolved import on single line Sep 9, 2018
@PramodBisht
Copy link
Contributor Author

@estebank you may have to r+ it again :)

@estebank
Copy link
Contributor

estebank commented Sep 9, 2018

@bors r+

@bors
Copy link
Contributor

bors commented Sep 9, 2018

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

bors commented Sep 9, 2018

⌛ Testing commit 21ba03e with merge 4fdc118a89e0acbf5e753e627845ba2e310657d3...

@bors
Copy link
Contributor

bors commented Sep 10, 2018

💔 Test failed - status-travis

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

The job arm-android 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.
[01:42:07] test time::tests::system_time_elapsed ... ok
[01:42:07] test time::tests::system_time_math ... ok
[01:42:13] test sync::mpsc::tests::stress_recv_timeout_two_threads ... ok
[01:42:14] test collections::hash::map::test_map::test_lots_of_insertions ... ok
[01:42:50] test process::tests::test_process_output_fail_to_start ... test process::tests::test_process_output_fail_to_start has been running for over 60 seconds
No output has been received in the last 30m0s, this potentially indicates a stalled build or something wrong with the build itself.
Check the details on how to adjust your build configuration on: https://docs.travis-ci.com/user/common-build-problems/#Build-times-out-because-no-output-was-received
The build has been terminated

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)

@kennytm
Copy link
Member

kennytm commented Sep 10, 2018

@bors retry #43283

@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 Sep 10, 2018
@bors
Copy link
Contributor

bors commented Sep 10, 2018

⌛ Testing commit 21ba03e with merge b8d45da...

bors added a commit that referenced this pull request Sep 10, 2018
#53359: putting multiple unresolved import on single line

r? @estebank
Here is WIP implementation of #53359
this PR have clubbed multiple unresolved imports into a single line.
I think still two things need to improve like giving specific `label message` for each span of multi_span(how we can do this?) and second we are getting a warning while compiling, stating something like `E0432` have been passed before.
@bors
Copy link
Contributor

bors commented Sep 10, 2018

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

@bors bors merged commit 21ba03e into rust-lang:master Sep 10, 2018
@PramodBisht PramodBisht deleted the issue/53359_b branch September 10, 2018 13:20
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.

6 participants