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

impl Trait diagnostic/test cleanups #50943

Merged
merged 5 commits into from
May 24, 2018
Merged

impl Trait diagnostic/test cleanups #50943

merged 5 commits into from
May 24, 2018

Conversation

oli-obk
Copy link
Contributor

@oli-obk oli-obk commented May 21, 2018

No description provided.

@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 May 21, 2018
@rust-highfive

This comment has been minimized.

@rust-highfive
Copy link
Collaborator

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:43:24] ....................................................................................................
[00:43:27] ....................................................................................................
[00:43:31] ....................................................................................................
[00:43:34] ....................................................................................................
[00:43:39] ...............................................F....................................................
[00:43:48] ....................................................................................................
[00:43:53] ......................................................................i.............................
[00:43:58] ...............................................i....................................................
[00:44:02] ...................................................................ii...............................
---
[00:44:16] thread 'main' panicked at 'Some tests failed', tools/compiletest/src/main.rs:498:22
[00:44:16] ---- [ui] ui/impl-trait/impl-generic-mismatch.rs stdout ----
[00:44:16] diff of stderr:
[00:44:16] 
[00:44:16] 34 LL |     fn hash(&self, hasher: &mut impl Hasher) {}
[00:44:16] 35    |                                 ^^^^^^^^^^^ expected generic parameter, found `impl Trait`
[00:44:16] 36    | 
[00:44:16] -   ::: /home/oliver/Projects/rust/rust3/src/libcore/hash/mod.rs:185:13
[00:44:16] +   ::: /checkout/src/libcore/hash/mod.rs:185:13
[00:44:16] 38    |
[00:44:16] 39 LL |     fn hash<H: Hasher>(&self, state: &mut H);
[00:44:16] 40    |             - declaration in trait here
[00:44:16] 
[00:44:16] The actual stderr differed from the expected stderr.
[00:44:16] Actual stderr saved to /checkout/obj/build/x86_64-unknown-linux-gnu/test/ui/impl-trait/impl-generic-mismatch/impl-generic-mismatch.stderr
[00:44:16] Actual stderr saved to /checkout/obj/build/x86_64-unknown-linux-gnu/test/ui/impl-trait/impl-generic-mismatch/impl-generic-mismatch.stderr
[00:44:16] To update references, rerun the tests and pass the `--bless` flag
[00:44:16] To only update this specific test, also pass `--test-args impl-trait/impl-generic-mismatch.rs`
[00:44:16] error: 1 errors occurred comparing output.
[00:44:16] status: exit code: 101
[00:44:16] status: exit code: 101
[00:44:16] command: "/checkout/obj/build/x86_64-unknown-linux-gnu/stage2/bin/rustc" "/checkout/src/test/ui/impl-trait/impl-generic-mismatch.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/impl-trait/impl-generic-mismatch/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/impl-trait/impl-generic-mismatch/auxiliary" "-A" "unused"
[00:44:16] ------------------------------------------
[00:44:16] 
[00:44:16] ------------------------------------------
[00:44:16] stderr:
[00:44:16] stderr:
[00:44:16] ------------------------------------------
[00:44:16] {"message":"method `foo` has incompatible signature for trait","code":{"code":"E0643","explanation":"\nThis error indicates that there is a mismatch between generic parameters and\nimpl Trait parameters in a trait declaration versus its impl.\n\n```compile_fail,E0643\ntrait Foo {\n    fn foo(&self, _: &impl Iterator);\n}\nimpl Foo for () {\n    fn foo<U: Iterator>(&self, _: &U) { } // error method `foo` has incompatible\n                                          // signature for trait\n}\n```\n"},"level":"error","spans":[{"file_name":"/checkout/src/test/ui/impl-trait/impl-generic-mismatch.rs","byte_start":523,"byte_end":533,"line_start":14,"line_end":14,"column_start":23,"column_end":33,"is_primary":false,"text":[{"text":"    fn foo(&self, _: &impl Debug);","highlight_start":23,"highlight_end":33}],"label":"declaration in trait here","suggested_replacement":null,"expansion":null},{"file_name":"/checkout/src/test/ui/impl-trait/impl-generic-mismatch.rs","byte_start":568,"byte_end":569,"line_start":18,"line_end":18,"column_start":12,"column_end":13,"is_primary":true,"text":[{"text":"    fn foo<U: Debug>(&self, _: &U) { }","highlight_start":12,"highlight_end":13}],"label":"expected `impl Trait`, found generic parameter","suggested_replacement":null,"expansion":null}],"children":[{"message":"try removing the generic parameter and using `impl Trait` instead","code":null,"level":"help","spans":[{"file_name":"/checkout/src/test/ui/impl-trait/impl-generic-mismatch.rs","byte_start":567,"byte_end":577,"line_start":18,"line_end":18,"column_start":11,"column_end":21,"is_primary":true,"text":[{"text":"    fn foo<U: Debug>(&self, _: &U) { }","highlight_start":11,"highlight_end":21}],"label":null,"suggested_replacement":"","expansion":null},{"file_name":"/checkout/src/test/ui/impl-trait/impl-generic-mismatch.rs","byte_start":589,"byte_end":590,"line_start":18,"line_end":18,"column_start":33,"column_end":34,"is_primary":true,"text":[{"text":"    fn foo<U: Debug>(&self, _: &U) { }","highlight_start":33,"highlight_end":34}],"label":null,"suggested_replacement":"impl Debug","expansion":null}],"children":[],"rendered":null}],"rendered":"error[E0643]: method `foo` has incompatible signature for trait\n  --> /checkout/src/test/ui/impl-trait/impl-generic-mismatch.rs:18:12\n   |\nLL |     fn foo(&self, _: &impl Debug);\n   |                       ---------- declaration in trait here\n...\nLL |     fn foo<U: Debug>(&self, _: &U) { }\n   |            ^ expected `impl Trait`, found generic parameter\nhelp: try removing the generic parameter and using `impl Trait` instead\n   |\nLL |     fn foo(&self, _: &impl Debug) { }\n   |\n\n"}
[00:44:16] {"message":"method `bar` has incompatible signature for trait","code":{"code":"E0643","explanation":"\nThis error indicates that there is a mismatch between generic parameters and\nimpl Trait parameters in a trait declaration versus its impl.\n\n```compile_fail,E0643\ntrait Foo {\n    fn foo(&self, _: &impl Iterator);\n}\nimpl Foo for () {\n    fn foo<U: Iterator>(&self, _: &U) { } // error method `foo` has incompatible\n                                          // signature for trait\n}\n```\n"},"level":"error","spans":[{"file_name":"/checkout/src/test/ui/impl-trait/impl-generic-mismatch.rs","byte_start":687,"byte_end":688,"line_start":23,"line_end":23,"column_start":12,"column_end":13,"is_primary":false,"text":[{"text":"    fn bar<U: Debug>(&self, _: &U);","highlight_start":12,"highlight_end":13}],"label":"declaration in trait here","suggested_replacement":null,"expansion":null},{"file_name":"/checkout/src/test/ui/impl-trait/impl-generic-mismatch.rs","byte_start":755,"byte_end":765,"line_start":27,"line_end":27,"column_start":23,"column_end":33,"is_primary":true,"text":[{"text":"    fn bar(&self, _: &impl Debug) { }","highlight_start":23,"highlight_end":33}],"label":"expected generic parameter, found `impl Trait`","suggested_replacement":null,"expansion":null}],"children":[{"message":"try changing the `impl Trait` argument to a generic parameter","code":null,"level":"help","spans":[{"file_name":"/checkout/src/test/ui/impl-trait/impl-generic-mismatch.rs","byte_start":755,"byte_end":765,"line_start":27,"line_end":27,"column_start":23,"column_end":33,"is_primary":true,"text":[{"text":"    fn bar(&self, _: &impl Debug) { }","highlight_start":23,"highlight_end":33}],"label":null,"suggested_replacement":"U","expansion":null},{"file_name":"/checkout/src/test/ui/impl-trait/impl-generic-mismatch.rs","byte_start":686,"byte_end":686,"line_start":23,"line_end":23,"column_start":11,"column_end":11,"is_primary":true,"text":[{"text":"    fn bar<U: Debug>(&self, _: &U);","highlight_start":11,"highlight_end":11}],"label":null,"suggested_replacement":"<U: Debug>","expansion":null}],"children":[],"rendered":null}],"rendered":"error[E0643]: method `bar` has incompatible signature for trait\n  --> /checkout/src/test/ui/impl-trait/impl-generic-mismatch.rs:27:23\n   |\nLL |     fn bar<U: Debug>(&self, _: &U);\n   |            - declaration in trait here\n...\nLL |     fn bar(&self, _: &impl Debug) { }\n   |                       ^^^^^^^^^^ expected generic parameter, found `impl Trait`\nhelp: try changing the `impl Trait` argument to a generic parameter\n   |\nLL |     fn bar<U: Debug><U: Debug>(&self, _: &U);\nLL | }\nLL | \nLL | impl Bar for () {\nLL |     fn bar(&self, _: &U) { }\n   |\n\n"}
[00:44:16] {"message":"method `hash` has incompatible signature for trait","code":{"code":"E0643","explanation":"\nThis error indicates that there is a mismatch between generic parameters and\nimpl Trait parameters in a trait declaration versus its impl.\n\n```compile_fail,E0643\ntrait Foo {\n    fn foo(&self, _: &impl Iterator);\n}\nimpl Foo for () {\n    fn foo<U: Iterator>(&self, _: &U) { } // error method `foo` has incompatible\n                                          // signature for trait\n}\n```\n"},"level":"error","spans":[{"file_name":"/checkout/src/libcore/hash/mod.rs","byte_start":4730,"byte_end":4731,"line_start":185,"line_end":185,"column_start":13,"column_end":14,"is_primary":false,"text":[{"text":"    fn hash<H: Hasher>(&self, state: &mut H);","highlight_start":13,"highlight_end":14}],"label":"declaration in trait here","suggested_replacement":null,"expansion":null},{"file_name":"/checkout/src/test/ui/impl-trait/impl-generic-mismatch.rs","byte_start":967,"byte_end":978,"line_start":38,"line_end":38,"column_start":33,"column_end":44,"is_primary":true,"text":[{"text":"    fn hash(&self, hasher: &mut impl Hasher) {}","highlight_start":33,"highlight_end":44}],"label":"expected generic parameter, found `impl Trait`","suggested_replacement":null,"expansion":null}],"children":[],"rendered":"error[E0643]: method `hash` has incompatible signature for trait\n  --> /checkout/src/test/ui/impl-trait/impl-generic-mismatch.rs:38:33\n   |\nLL |     fn hash(&self, hasher: &mut impl Hasher) {}\n   |                                 ^^^^^^^^^^^ expected generic parameter, found `impl Trait`\n   | \n  ::: /checkout/src/libcore/hash/mod.rs:185:13\n   |\nLL |     fn hash<H: Hasher>(&self, state: &mut H);\n   |             - declaration in trait here\n\n"}
[00:44:16] {"message":"aborting due to 3 previous errors","code":null,"level":"error","spans":[],"children":[],"rendere-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:44:16] 
[00:44:16] 
[00:44:16] failed to run: /checkout/obj/build/bootstrap/debug/bootstrap test
[00:44:16] Build completed unsuccessfully in 0:02:14
[00:44:16] Build completed unsuccessfully in 0:02:14
[00:44:16] make: *** [check] Error 1
[00:44:16] Makefile:58: recipe for target 'check' failed

The command "stamp sh -x -c "$RUN_SCRIPT"" exited with 2.
travis_time:start:0480a4ca
$ 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)

@oli-obk
Copy link
Contributor Author

oli-obk commented May 21, 2018

O_o --bless seems to be exposing local paths?

@oli-obk
Copy link
Contributor Author

oli-obk commented May 21, 2018

Ah no. This is because it's a path into the libstd.

@oli-obk
Copy link
Contributor Author

oli-obk commented May 22, 2018

I adjusted compiletest to also normalize paths into the libstd/libcore

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.

Love it!

| ^^^^^^^^^^ expected generic parameter, found `impl Trait`
help: try changing the `impl Trait` argument to a generic parameter
|
LL | fn bar<U: Debug><U: Debug>(&self, _: &U);
Copy link
Contributor

Choose a reason for hiding this comment

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

Incorrect span for the suggestion. This should be in the bar for the impl Bar for ()

@estebank estebank 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 May 22, 2018
let new_generics_span = tcx
.sess
.codemap()
.generate_fn_name_span(impl_m.span)?
Copy link
Contributor

@estebank estebank May 23, 2018

Choose a reason for hiding this comment

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

Use impl_span here instead and the output will be correct.

This is because generate_fn_name_span looks backwards until it finds fn in the span, instead of checking wether the span starts with fn<WS>. When using impl_m.span, this starts in the fn..., so it goes backwards until it finds the previous piece of code that contains fn, which in this case is the trait's method. Using impl_span will break if any part of the snippet contains fn (like a method called my_fn).

In order to avoid this there are two options: changing generate_fn_name_span to peek at the first three chars of the passed span's snippet to see if the first two are fn and the third is whitespace, and if so assign span to prev_span and use _impl_m_span here instead, or synthesize a new span derived from _impl_m_span moving forward long enough to leave the fn<WS> outside of the new span. Either way, it would have to account for the potential leading whitespace and visibility (pub(crate), etc) text.

We really need to add spans to all idents, IMO. We keep having to do this kind of brittle span wrangling way too often.

@estebank
Copy link
Contributor

@bors r+

@oli-obk approving even though there's an incorrect suggestion. I can fix it as soon as it gets merged, but if you'll have the time to do it yourself, go ahead and stop bors from merging.

@bors
Copy link
Contributor

bors commented May 24, 2018

📌 Commit 849c565 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 May 24, 2018
@bors
Copy link
Contributor

bors commented May 24, 2018

⌛ Testing commit 849c565 with merge b4463d7...

bors added a commit that referenced this pull request May 24, 2018
impl Trait diagnostic/test cleanups
@oli-obk
Copy link
Contributor Author

oli-obk commented May 24, 2018

I was debugging this yesterday, but didn't get very far. I think the suggestion is correct, the issue is the renderer. We should probably make it a rustfix test so we can see the fixed output

@bors
Copy link
Contributor

bors commented May 24, 2018

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

@bors bors merged commit 849c565 into rust-lang:master May 24, 2018
estebank added a commit to estebank/rust that referenced this pull request May 24, 2018
kennytm added a commit to kennytm/rust that referenced this pull request May 26, 2018
…ions, r=petrochencov

Underline multiple suggested replacements in the same line

<img width="685" alt="screen shot 2018-05-22 at 21 06 48" src="https://user-images.githubusercontent.com/1606434/40403051-174f3180-5e04-11e8-86b6-261630c5ff80.png">

Follow up to rust-lang#50943.

Fix rust-lang#50977.
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