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

Allow to dispatch fn traits depending on number of parameters #55986

Merged
merged 7 commits into from Jan 4, 2019

Conversation

Projects
None yet
7 participants
@cjgillot
Copy link
Contributor

cjgillot commented Nov 15, 2018

Hello,

By following @eddyb's advise on issue #45510, I managed to have the snippets of code in #45510 and #18952 passing without breaking older diagnostics.

EDIT: the codegen tests breakage I experienced is due to the poor quality of my laptop.

If any kind reviewer has any advice, you are very welcome.

@rust-highfive

This comment has been minimized.

Copy link
Collaborator

rust-highfive commented Nov 15, 2018

Thanks for the pull request, and welcome! The Rust team is excited to review your changes, and you should hear from @cramertj (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.

@eddyb

This comment has been minimized.

Copy link
Member

eddyb commented Nov 15, 2018

@bors

This comment has been minimized.

Copy link
Contributor

bors commented Nov 19, 2018

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

@nikomatsakis
Copy link
Contributor

nikomatsakis left a comment

Looks good! Can you add the comment and explain that one case?

Show resolved Hide resolved src/librustc_typeck/check/callee.rs

@cjgillot cjgillot force-pushed the cjgillot:issue-45510 branch from ab168ba to 2ab7a74 Nov 21, 2018

@cjgillot cjgillot changed the title WIP: Allow to dispatch fn traits depending on number of parameters Allow to dispatch fn traits depending on number of parameters Nov 25, 2018

@nikomatsakis
Copy link
Contributor

nikomatsakis left a comment

can we tweak the tests a bit to show that we are actually calling the fn as expected etc?

Show resolved Hide resolved src/test/ui/issue-18952.rs Outdated
Show resolved Hide resolved src/test/ui/issue-45510.rs Outdated
@rust-highfive

This comment has been minimized.

Copy link
Collaborator

rust-highfive commented Nov 28, 2018

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.
travis_time:end:1598c091:start=1543407844229716095,finish=1543407901626499970,duration=57396783875
$ git checkout -qf FETCH_HEAD
travis_fold:end:git.checkout

Encrypted environment variables have been removed for security reasons.
See https://docs.travis-ci.com/user/pull-requests/#Pull-Requests-and-Security-Restrictions
$ export SCCACHE_BUCKET=rust-lang-ci-sccache2
$ export SCCACHE_REGION=us-west-1
Setting environment variables from .travis.yml
$ export IMAGE=x86_64-gnu-llvm-5.0
---
[00:48:25] .................................................................................................... 100/5065
[00:48:28] .................................................................................................... 200/5065
[00:48:30] .............................ii............................................ii...................ii.. 300/5065
[00:48:33] ..............................................................................................iii... 400/5065
[00:48:36] .....iiiiiiii.iii............................iii...........................................i........ 500/5065
[00:48:42] .................................................................................................... 700/5065
[00:48:48] ................................................................................................i... 800/5065
[00:48:52] ........i........................................................................................... 900/5065
[00:48:55] ...............iiiii..................ii.iiii....................................................... 1000/5065
---
[00:49:33] .................................................................................................... 2300/5065
[00:49:37] .................................................................................................... 2400/5065
[00:49:41] .................................................................................................... 2500/5065
[00:49:45] .................................................................................................... 2600/5065
[00:49:48] ........iiiiiiiii................................................................................... 2700/5065
[00:49:54] .................................................................................................... 2900/5065
[00:49:58] .................................................................................................... 3000/5065
[00:50:01] .......................................................................i............................ 3100/5065
[00:50:04] .................................................................................................... 3200/5065
---
[00:51:57] .................................................................................................... 600/2889
[00:52:11] .................................................................................................... 700/2889
[00:52:22] .................................................................................................... 800/2889
[00:52:31] .................................................................................................... 900/2889
[00:52:46] ..............................................................................F..................... 1000/2889
[00:53:06] .................................................................................................... 1200/2889
[00:53:14] .................................................................................................... 1300/2889
[00:53:26] .................................................................................i.................. 1400/2889
[00:53:37] .................................................................................................... 1500/2889
---
[00:55:55] .................................................................................................... 2500/2889
[00:56:25] .................................................................................................... 2600/2889
[00:56:35] .................................................................................................... 2700/2889
[00:56:43] .................................................................................................... 2800/2889
/obj/build/x86_64-unknown-linux-gnu/native/rust-test-helpers" "-L" "/checkout/obj/build/x86_64-unknown-linux-gnu/test/run-pass/issue-45510/auxiliary"
[00:56:55] ------------------------------------------
[00:56:55] 
[00:56:55] ------------------------------------------
[00:56:55] stderr:
[00:56:55] stderr:
[00:56:55] ------------------------------------------
[00:56:55] {"message":"can't compare `Ishmael` with `Ishmael`","code":{"code":"E0277","explanation":"\nYou tried to use a type which doesn't implement some trait in a place which\nexpected that trait. Erroneous code example:\n\n```compile_fail,E0277\n// here we declare the Foo trait with a bar method\ntrait Foo {\n    fn bar(&self);\n}\n\n// we now declare a function which takes an object implementing the Foo trait\nfn some_func<T: Foo>(foo: T) {\n    foo.bar();\n}\n\nfn main() {\n    // we now call the method with the i32 type, which doesn't implement\n    // the Foo trait\n    some_func(5i32); // error: the trait bound `i32 : Foo` is not satisfied\n}\n```\n\nIn order to fix this error, verify that the type you're using does implement\nthe trait. Example:\n\n```\ntrait Foo {\n    fn bar(&self);\n}\n\nfn some_func<T: Foo>(foo: T) {\n    foo.bar(); // we can now use this method since i32 implements the\n               // Foo trait\n}\n\n// we implement the trait on the i32 type\nimpl Foo for i32 {\n    fn bar(&self) {}\n}\n\nfn main() {\n    some_func(5i32); // ok!\n}\n```\n\nOr in a generic context, an erroneous code example would look like:\n\n```compile_fail,E0277\nfn some_func<T>(foo: T) {\n    println!(\"{:?}\", foo); // error: the trait `core::fmt::Debug` is not\n                           //        implemented for the type `T`\n}\n\nfn main() {\n    // We now call the method with the i32 type,\n    // which *does* implement the Debug trait.\n    some_func(5i32);\n}\n```\n\nNote that the error here is in the definition of the generic function: Although\nwe only call it with a parameter that does implement `Debug`, the compiler\nstill rejects the function: It must work with all possible input types. In\norder to make this example compile, we need to restrict the generic type we're\naccepting:\n\n```\nuse std::fmt;\n\n// Restrict the input type to types that implement Debug.\nfn some_func<T: fmt::Debug>(foo: T) {\n    println!(\"{:?}\", foo);\n}\n\nfn main() {\n    // Calling the method is still fine, as i32 implements Debug.\n    some_func(5i32);\n\n    // This would fail to compile now:\n    // struct WithoutDebug;\n    // some_func(WithoutDebug);\n}\n```\n\nRust only looks at the signature of the called function, as such it must\nalready specify all requirements that will be used for every type parameter.\n"},"level":"error","spans":[{"file_name":"/checkout/src/test/run-pass/issue-45510.rs","byte_start":127,"byte_end":129,"line_start":7,"line_end":7,"column_start":17,"column_end":19,"is_primary":true,"text":[{"text":"#[derive(Debug, Eq)]","highlight_start":17,"highlight_end":19}],"label":"no implementation for `Ishmael == Ishmael`","suggested_replacement":null,"suggestion_applicability":null,"expansion":{"span":{"file_name":"/checkout/src/test/run-pass/issue-45510.rs","byte_start":127,"byte_end":129,"line_start":7,"line_end":7,"column_start":17,"column_end":19,"is_primary":falsee implement the trait on the i32 type\nimpl Foo for i32 {\n    fn bar(&self) {}\n}\n\nfn main() {\n    some_func(5i32); // ok!\n}\n```\n\nOr in a generic context, an erroneous code example would look like:\n\n```compile_fail,E0277\nfn some_func<T>(foo: T) {\n    println!(\"{:?}\", foo); // error: the trait `core::fmt::Debug` is not\n                           //        implemented for the type `T`\n}\n\nfn main() {\n    // We now call the method with the i32 type,\n    // which *does* implement the Debug trait.\n    some_func(5i32);\n}\n```\n\nNote that the error here is in the definition of the generic function: Although\nwe only call it with a parameter that does implement `Debug`, the compiler\nstill rejects the function: It must work with all possible input types. In\norder to make this example compile, we need to restrict the generic type we're\naccepting:\n\n```\nuse std::fmt;\n\n// Restrict the input type to types that implement Debug.\nfn some_func<T: fmt::Debug>(foo: T) {\n    println!(\"{:?}\", foo);\n}\n\nfn main() {\n    // Calling the method is still fine, as i32 implements Debug.\n    some_func(5i32);\n\n    // This would fail to compile now:\n    // struct WithoutDebug;\n    // some_func(WithoutDebug);\n}\n```\n\nRust only looks at the signature of the called function, as such it must\nalready specify all requirements that will be used for every type parameter.\n"},"level":"error","spans":[{"file_name":"/checkout/src/test/run-pass/issue-45510.rs","byte_start":164,"byte_end":166,"line_start":9,"line_end":9,"column_start":17,"column_end":19,"is_primary":true,"text":[{"text":"#[derive(Debug, Eq)]","highlight_start":17,"highlight_end":19}],"label":"no implementation for `Maybe == Maybe`","suggested_replacement":null,"suggestion_applicability":null,"expansion":{"span":{"file_name":"/checkout/src/test/run-pass/issue-45510.rs","byte_start":164,"byte_end":166,"line_start":9,"line_end":9,"column_start":17,"column_end":19,"is_primary":false,"text":[{"text":"#[derive(Debug, Eq)]","highlight_start":17,"highlight_end":19}],"label":null,"suggested_replacement":null,"suggestion_applicability":null,"expansion":null},"macro_decl_name":"#[derive(Eq)]","def_site_span":null}}],"children":[{"message":"the trait `std::cmp::PartialEq` is not implemented for `Maybe`","code":null,"level":"help","spans":[],"children":[],"rendered":null}],"rendered":"error[E0277]: can't compare `Maybe` with `Maybe`\n  --> /checkout/src/test/run-pass/issue-45510.rs:9:17\n   |\nLL | #[derive(Debug, Eq)]\n   |                 ^^ no implementation for `Maybe == Maybe`\n   |\n   = help: the trait `std::cmp::PartialEq` is not implemented for `Maybe`\n\n"}
[00:56:55] {"message":"aborting due to 2 previous errors","code":null,"level":"error","spans":[],"children":[],"rendered":"error: aborting due to 2 previous errors\n\n"}
[00:56:55] {"message":"For more information about this error, try `rustc --explain E0277`.","code":null,"level":"","spans":[],"children":[],"rendered":"For more information about this error, try `rustc --explain E0277`.\n"}
[00:56:55] ------------------------------------------
[00:56:55] 
[00:56:55] thread '[run-pass] run-pass/issue-45510.rs' panicked at 'explicit panic', src/tools/compiletest/src/runtest.rs:3282:9
[00:56:55] note: Run with `RUST_BACKTRACE=1` for a backtrace.
---
[00:56:55] 
[00:56:55] thread 'main' panicked at 'Some tests failed', src/tools/compiletest/src/main.rs:503:22
[00:56:55] 
[00:56:55] 
[00:56:55] 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/run-pass" "--build-base" "/checkout/obj/build/x86_64-unknown-linux-gnu/test/run-pass" "--stage-id" "stage2-x86_64-unknown-linux-gnu" "--mode" "run-pass" "--target" "x86_64-unknown-linux-gnu" "--host" "x86_64-unknown-linux-gnu" "--llvm-filecheck" "/usr/lib/llvm-5.0/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" "5.0.0\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:56:55] 
[00:56:55] 
[00:56:55] failed to run: /checkout/obj/build/bootstrap/debug/bootstrap test
[00:56:55] Build completed unsuccessfully in 0:12:20
[00:56:55] Build completed unsuccessfully in 0:12:20
[00:56:55] Makefile:58: recipe for target 'check' failed
[00:56:55] 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. (Feature Requests)

@cjgillot cjgillot force-pushed the cjgillot:issue-45510 branch from 49ed503 to bea0ae6 Dec 1, 2018

@bors

This comment has been minimized.

Copy link
Contributor

bors commented Dec 7, 2018

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

@cjgillot cjgillot force-pushed the cjgillot:issue-45510 branch from bea0ae6 to ee1c962 Dec 8, 2018

@bors

This comment has been minimized.

Copy link
Contributor

bors commented Dec 16, 2018

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

@cjgillot cjgillot force-pushed the cjgillot:issue-45510 branch from ee1c962 to 4522900 Dec 18, 2018

@bors

This comment has been minimized.

Copy link
Contributor

bors commented Dec 20, 2018

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

cjgillot added some commits Nov 4, 2018

test: Add test for issues 45510 and 18952.
Those tests are directly taken from the comments on the bug reports.
rustc_typeck: Implement resolution advised in issue 45510.
When resolving Fn traits, the compiler failed to take into account
overloaded implementations.  To resolve this, we inform the trait dispatch
code that the arguments will becoming as a tuple of correct arity.
Change return types and check return values in tests.
This allows to verify that we handle
different types as return types,
and that we call the expected functions.

@cjgillot cjgillot force-pushed the cjgillot:issue-45510 branch from 4522900 to 91c155b Dec 30, 2018

@nikomatsakis

This comment has been minimized.

Copy link
Contributor

nikomatsakis commented Jan 2, 2019

@bors r+

@bors

This comment has been minimized.

Copy link
Contributor

bors commented Jan 2, 2019

📌 Commit 91c155b has been approved by nikomatsakis

@bors

This comment has been minimized.

Copy link
Contributor

bors commented Jan 3, 2019

⌛️ Testing commit 91c155b with merge cbacd34...

bors added a commit that referenced this pull request Jan 3, 2019

Auto merge of #55986 - cjgillot:issue-45510, r=nikomatsakis
Allow to dispatch fn traits depending on number of parameters

Hello,

By following @eddyb's advise on issue #45510, I managed to have the snippets of code in #45510 and #18952 passing without breaking older diagnostics.

EDIT: the codegen tests breakage I experienced is due to the poor quality of my laptop.

If any kind reviewer has any advice, you are very welcome.
@bors

This comment has been minimized.

Copy link
Contributor

bors commented Jan 3, 2019

💔 Test failed - status-travis

@rust-highfive

This comment has been minimized.

Copy link
Collaborator

rust-highfive commented Jan 3, 2019

The job x86_64-gnu-aux 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:47:45] test workspaces::ws_warn_path ... ok
[01:47:45] test workspaces::you_cannot_generate_lockfile_for_empty_workspaces ... ok
[01:47:45] test workspaces::workspace_with_transitive_dev_deps ... ok
[01:47:46] test workspaces::ws_warn_unused ... ok
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

This comment has been minimized.

Copy link
Member

kennytm commented Jan 3, 2019

@bors retry

Mark-Simulacrum added a commit to Mark-Simulacrum/rust that referenced this pull request Jan 3, 2019

Rollup merge of rust-lang#55986 - cjgillot:issue-45510, r=nikomatsakis
Allow to dispatch fn traits depending on number of parameters

Hello,

By following @eddyb's advise on issue rust-lang#45510, I managed to have the snippets of code in rust-lang#45510 and rust-lang#18952 passing without breaking older diagnostics.

EDIT: the codegen tests breakage I experienced is due to the poor quality of my laptop.

If any kind reviewer has any advice, you are very welcome.
@bors

This comment has been minimized.

Copy link
Contributor

bors commented Jan 4, 2019

⌛️ Testing commit 91c155b with merge a602f13...

bors added a commit that referenced this pull request Jan 4, 2019

Auto merge of #55986 - cjgillot:issue-45510, r=nikomatsakis
Allow to dispatch fn traits depending on number of parameters

Hello,

By following @eddyb's advise on issue #45510, I managed to have the snippets of code in #45510 and #18952 passing without breaking older diagnostics.

EDIT: the codegen tests breakage I experienced is due to the poor quality of my laptop.

If any kind reviewer has any advice, you are very welcome.
@bors

This comment has been minimized.

Copy link
Contributor

bors commented Jan 4, 2019

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

@bors bors merged commit 91c155b into rust-lang:master Jan 4, 2019

2 checks passed

continuous-integration/travis-ci/pr The Travis CI build passed
Details
homu Test successful
Details

@bors bors referenced this pull request Jan 4, 2019

Closed

Format Rust code #57318

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment