We are currently solving the following issue within our repository. Here is the issue text:
--- BEGIN ISSUE ---
rust hook requires `--path` attribute
Cargo has changed how packages get installed and requires an extra `--path <destination>` attribute.

Symptom:
```
[INFO] Initializing environment for https://github.com/nix-community/nixpkgs-fmt.
[INFO] Installing environment for https://github.com/nix-community/nixpkgs-fmt.
[INFO] Once installed this environment will be reused.
[INFO] This may take a few minutes...
An unexpected error has occurred: CalledProcessError: Command: ('/nix/store/fcc3x8zwq1c0667xjs7bkn6ay8j4fdpz-rust-1.38.0-nightly-2019-08-07-ad7c55e1f/bin/cargo', 'install', '--bins', '--root', '/home/zimbatm/.cache/pre-commit/repoeft6xm6t/rustenv-default')
Return code: 101
Expected return code: 0
Output: (none)
Errors: 
    error: Using `cargo install` to install the binaries for the package in current working directory is no longer supported, use `cargo install --path .` instead. Use `cargo build` if you want to simply build the package.
```

I guess the fix should be done where here: https://github.com/pre-commit/pre-commit/blob/9c6a1d80d6b94c86a1785a40a51389e83accac3e/pre_commit/languages/rust.py#L87

Do we want to make pre-commit compatible with multiple versions of cargo or just the latest one?

/cc @asottile @chriskuehl 

--- END ISSUE ---

Below are some code segments, each from a relevant file. One or more of these files may contain bugs.
--- BEGIN FILES ---
Path: `pre_commit/languages/rust.py`
Content:
```
1 from __future__ import unicode_literals
2 
3 import contextlib
4 import os.path
5 
6 import toml
7 
8 import pre_commit.constants as C
9 from pre_commit.envcontext import envcontext
10 from pre_commit.envcontext import Var
11 from pre_commit.languages import helpers
12 from pre_commit.util import clean_path_on_failure
13 from pre_commit.util import cmd_output
14 
15 
16 ENVIRONMENT_DIR = 'rustenv'
17 get_default_version = helpers.basic_get_default_version
18 healthy = helpers.basic_healthy
19 
20 
21 def get_env_patch(target_dir):
22     return (
23         (
24             'PATH',
25             (os.path.join(target_dir, 'bin'), os.pathsep, Var('PATH')),
26         ),
27     )
28 
29 
30 @contextlib.contextmanager
31 def in_env(prefix):
32     target_dir = prefix.path(
33         helpers.environment_dir(ENVIRONMENT_DIR, C.DEFAULT),
34     )
35     with envcontext(get_env_patch(target_dir)):
36         yield
37 
38 
39 def _add_dependencies(cargo_toml_path, additional_dependencies):
40     with open(cargo_toml_path, 'r+') as f:
41         cargo_toml = toml.load(f)
42         cargo_toml.setdefault('dependencies', {})
43         for dep in additional_dependencies:
44             name, _, spec = dep.partition(':')
45             cargo_toml['dependencies'][name] = spec or '*'
46         f.seek(0)
47         toml.dump(cargo_toml, f)
48         f.truncate()
49 
50 
51 def install_environment(prefix, version, additional_dependencies):
52     helpers.assert_version_default('rust', version)
53     directory = prefix.path(
54         helpers.environment_dir(ENVIRONMENT_DIR, C.DEFAULT),
55     )
56 
57     # There are two cases where we might want to specify more dependencies:
58     # as dependencies for the library being built, and as binary packages
59     # to be `cargo install`'d.
60     #
61     # Unlike e.g. Python, if we just `cargo install` a library, it won't be
62     # used for compilation. And if we add a crate providing a binary to the
63     # `Cargo.toml`, the binary won't be built.
64     #
65     # Because of this, we allow specifying "cli" dependencies by prefixing
66     # with 'cli:'.
67     cli_deps = {
68         dep for dep in additional_dependencies if dep.startswith('cli:')
69     }
70     lib_deps = set(additional_dependencies) - cli_deps
71 
72     if len(lib_deps) > 0:
73         _add_dependencies(prefix.path('Cargo.toml'), lib_deps)
74 
75     with clean_path_on_failure(directory):
76         packages_to_install = {()}
77         for cli_dep in cli_deps:
78             cli_dep = cli_dep[len('cli:'):]
79             package, _, version = cli_dep.partition(':')
80             if version != '':
81                 packages_to_install.add((package, '--version', version))
82             else:
83                 packages_to_install.add((package,))
84 
85         for package in packages_to_install:
86             cmd_output(
87                 'cargo', 'install', '--bins', '--root', directory, *package,
88                 cwd=prefix.prefix_dir
89             )
90 
91 
92 def run_hook(hook, file_args):
93     with in_env(hook.prefix):
94         return helpers.run_xargs(hook, helpers.to_cmd(hook), file_args)
95
```
--- END FILES ---

Please first localize the bug based on the issue statement, and then generate a patch according to the `git diff` format fenced by three backticks.

Here is an example:

```diff
diff --git a/examples/server_async.py b/examples/server_async.py
--- a/examples/server_async.py
+++ b/examples/server_async.py
@@ -313,4 +313,4 @@
 
 
 if __name__ == "__main__":
-    asyncio.run(run_async_server("."), debug=True)
+    asyncio.run(run_async_server(), debug=True)
diff --git a/examples/server_sync.py b/examples/server_sync.py
--- a/examples/server_sync.py
+++ b/examples/server_sync.py
@@ -313,5 +313,5 @@
 
 
 if __name__ == "__main__":
-    server = run_sync_server(".")
+    server = run_sync_server()
     server.shutdown()

```

diff --git a/pre_commit/languages/rust.py b/pre_commit/languages/rust.py
--- a/pre_commit/languages/rust.py
+++ b/pre_commit/languages/rust.py
@@ -73,7 +73,7 @@
         _add_dependencies(prefix.path('Cargo.toml'), lib_deps)
 
     with clean_path_on_failure(directory):
-        packages_to_install = {()}
+        packages_to_install = {('--path', '.')}
         for cli_dep in cli_deps:
             cli_dep = cli_dep[len('cli:'):]
             package, _, version = cli_dep.partition(':')

{"golden_diff": "diff --git a/pre_commit/languages/rust.py b/pre_commit/languages/rust.py\n--- a/pre_commit/languages/rust.py\n+++ b/pre_commit/languages/rust.py\n@@ -73,7 +73,7 @@\n         _add_dependencies(prefix.path('Cargo.toml'), lib_deps)\n \n     with clean_path_on_failure(directory):\n-        packages_to_install = {()}\n+        packages_to_install = {('--path', '.')}\n         for cli_dep in cli_deps:\n             cli_dep = cli_dep[len('cli:'):]\n             package, _, version = cli_dep.partition(':')\n", "issue": "rust hook requires `--path` attribute\nCargo has changed how packages get installed and requires an extra `--path <destination>` attribute.\r\n\r\nSymptom:\r\n```\r\n[INFO] Initializing environment for https://github.com/nix-community/nixpkgs-fmt.\r\n[INFO] Installing environment for https://github.com/nix-community/nixpkgs-fmt.\r\n[INFO] Once installed this environment will be reused.\r\n[INFO] This may take a few minutes...\r\nAn unexpected error has occurred: CalledProcessError: Command: ('/nix/store/fcc3x8zwq1c0667xjs7bkn6ay8j4fdpz-rust-1.38.0-nightly-2019-08-07-ad7c55e1f/bin/cargo', 'install', '--bins', '--root', '/home/zimbatm/.cache/pre-commit/repoeft6xm6t/rustenv-default')\r\nReturn code: 101\r\nExpected return code: 0\r\nOutput: (none)\r\nErrors: \r\n    error: Using `cargo install` to install the binaries for the package in current working directory is no longer supported, use `cargo install --path .` instead. Use `cargo build` if you want to simply build the package.\r\n```\r\n\r\nI guess the fix should be done where here: https://github.com/pre-commit/pre-commit/blob/9c6a1d80d6b94c86a1785a40a51389e83accac3e/pre_commit/languages/rust.py#L87\r\n\r\nDo we want to make pre-commit compatible with multiple versions of cargo or just the latest one?\r\n\r\n/cc @asottile @chriskuehl \n", "before_files": [{"content": "from __future__ import unicode_literals\n\nimport contextlib\nimport os.path\n\nimport toml\n\nimport pre_commit.constants as C\nfrom pre_commit.envcontext import envcontext\nfrom pre_commit.envcontext import Var\nfrom pre_commit.languages import helpers\nfrom pre_commit.util import clean_path_on_failure\nfrom pre_commit.util import cmd_output\n\n\nENVIRONMENT_DIR = 'rustenv'\nget_default_version = helpers.basic_get_default_version\nhealthy = helpers.basic_healthy\n\n\ndef get_env_patch(target_dir):\n    return (\n        (\n            'PATH',\n            (os.path.join(target_dir, 'bin'), os.pathsep, Var('PATH')),\n        ),\n    )\n\n\n@contextlib.contextmanager\ndef in_env(prefix):\n    target_dir = prefix.path(\n        helpers.environment_dir(ENVIRONMENT_DIR, C.DEFAULT),\n    )\n    with envcontext(get_env_patch(target_dir)):\n        yield\n\n\ndef _add_dependencies(cargo_toml_path, additional_dependencies):\n    with open(cargo_toml_path, 'r+') as f:\n        cargo_toml = toml.load(f)\n        cargo_toml.setdefault('dependencies', {})\n        for dep in additional_dependencies:\n            name, _, spec = dep.partition(':')\n            cargo_toml['dependencies'][name] = spec or '*'\n        f.seek(0)\n        toml.dump(cargo_toml, f)\n        f.truncate()\n\n\ndef install_environment(prefix, version, additional_dependencies):\n    helpers.assert_version_default('rust', version)\n    directory = prefix.path(\n        helpers.environment_dir(ENVIRONMENT_DIR, C.DEFAULT),\n    )\n\n    # There are two cases where we might want to specify more dependencies:\n    # as dependencies for the library being built, and as binary packages\n    # to be `cargo install`'d.\n    #\n    # Unlike e.g. Python, if we just `cargo install` a library, it won't be\n    # used for compilation. And if we add a crate providing a binary to the\n    # `Cargo.toml`, the binary won't be built.\n    #\n    # Because of this, we allow specifying \"cli\" dependencies by prefixing\n    # with 'cli:'.\n    cli_deps = {\n        dep for dep in additional_dependencies if dep.startswith('cli:')\n    }\n    lib_deps = set(additional_dependencies) - cli_deps\n\n    if len(lib_deps) > 0:\n        _add_dependencies(prefix.path('Cargo.toml'), lib_deps)\n\n    with clean_path_on_failure(directory):\n        packages_to_install = {()}\n        for cli_dep in cli_deps:\n            cli_dep = cli_dep[len('cli:'):]\n            package, _, version = cli_dep.partition(':')\n            if version != '':\n                packages_to_install.add((package, '--version', version))\n            else:\n                packages_to_install.add((package,))\n\n        for package in packages_to_install:\n            cmd_output(\n                'cargo', 'install', '--bins', '--root', directory, *package,\n                cwd=prefix.prefix_dir\n            )\n\n\ndef run_hook(hook, file_args):\n    with in_env(hook.prefix):\n        return helpers.run_xargs(hook, helpers.to_cmd(hook), file_args)\n", "path": "pre_commit/languages/rust.py"}], "after_files": [{"content": "from __future__ import unicode_literals\n\nimport contextlib\nimport os.path\n\nimport toml\n\nimport pre_commit.constants as C\nfrom pre_commit.envcontext import envcontext\nfrom pre_commit.envcontext import Var\nfrom pre_commit.languages import helpers\nfrom pre_commit.util import clean_path_on_failure\nfrom pre_commit.util import cmd_output\n\n\nENVIRONMENT_DIR = 'rustenv'\nget_default_version = helpers.basic_get_default_version\nhealthy = helpers.basic_healthy\n\n\ndef get_env_patch(target_dir):\n    return (\n        (\n            'PATH',\n            (os.path.join(target_dir, 'bin'), os.pathsep, Var('PATH')),\n        ),\n    )\n\n\n@contextlib.contextmanager\ndef in_env(prefix):\n    target_dir = prefix.path(\n        helpers.environment_dir(ENVIRONMENT_DIR, C.DEFAULT),\n    )\n    with envcontext(get_env_patch(target_dir)):\n        yield\n\n\ndef _add_dependencies(cargo_toml_path, additional_dependencies):\n    with open(cargo_toml_path, 'r+') as f:\n        cargo_toml = toml.load(f)\n        cargo_toml.setdefault('dependencies', {})\n        for dep in additional_dependencies:\n            name, _, spec = dep.partition(':')\n            cargo_toml['dependencies'][name] = spec or '*'\n        f.seek(0)\n        toml.dump(cargo_toml, f)\n        f.truncate()\n\n\ndef install_environment(prefix, version, additional_dependencies):\n    helpers.assert_version_default('rust', version)\n    directory = prefix.path(\n        helpers.environment_dir(ENVIRONMENT_DIR, C.DEFAULT),\n    )\n\n    # There are two cases where we might want to specify more dependencies:\n    # as dependencies for the library being built, and as binary packages\n    # to be `cargo install`'d.\n    #\n    # Unlike e.g. Python, if we just `cargo install` a library, it won't be\n    # used for compilation. And if we add a crate providing a binary to the\n    # `Cargo.toml`, the binary won't be built.\n    #\n    # Because of this, we allow specifying \"cli\" dependencies by prefixing\n    # with 'cli:'.\n    cli_deps = {\n        dep for dep in additional_dependencies if dep.startswith('cli:')\n    }\n    lib_deps = set(additional_dependencies) - cli_deps\n\n    if len(lib_deps) > 0:\n        _add_dependencies(prefix.path('Cargo.toml'), lib_deps)\n\n    with clean_path_on_failure(directory):\n        packages_to_install = {('--path', '.')}\n        for cli_dep in cli_deps:\n            cli_dep = cli_dep[len('cli:'):]\n            package, _, version = cli_dep.partition(':')\n            if version != '':\n                packages_to_install.add((package, '--version', version))\n            else:\n                packages_to_install.add((package,))\n\n        for package in packages_to_install:\n            cmd_output(\n                'cargo', 'install', '--bins', '--root', directory, *package,\n                cwd=prefix.prefix_dir\n            )\n\n\ndef run_hook(hook, file_args):\n    with in_env(hook.prefix):\n        return helpers.run_xargs(hook, helpers.to_cmd(hook), file_args)\n", "path": "pre_commit/languages/rust.py"}]}