Skip to content

Commit 56e46a0

Browse files
committed
docs: Clarify specifying deps, PR feedback
1 parent 8255553 commit 56e46a0

File tree

1 file changed

+17
-14
lines changed

1 file changed

+17
-14
lines changed

src/doc/src/reference/specifying-dependencies.md

Lines changed: 17 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,9 @@ versions before 1.0.0. While SemVer says there is no compatibility before
5151
and `x > 0`.
5252

5353
It is possible to further tweak the logic for selecting compatible versions
54-
using special operators as described in the following section.
54+
using special operators as described in the [Version requirement syntax](#version-requirement-syntax) section.
55+
56+
Use the default version requirement strategy, e.g. `log = "1.2.3"` where possible to maximize compatibility.
5557

5658
## Version requirement syntax
5759

@@ -184,19 +186,20 @@ you need to specify is the location of the repository with the `git` key:
184186
regex = { git = "https://github.com/rust-lang/regex.git" }
185187
```
186188

187-
Cargo fetches the `git` repository at that location, then looks for
188-
`Cargo.toml` file for the requested crate anywhere inside the `git` repository.
189-
For example, `cpp` and `cpp_common` are members of `rust-cpp` repo
190-
and can be referred to by the repo's root URL (`https://github.com/mystor/rust-cpp`).
189+
Cargo fetches the `git` repository at that location and traverses the file tree to find
190+
`Cargo.toml` file for the requested crate anywhere inside the `git` repository.
191+
For example, `regex-lite` and `regex-syntax` are members of `rust-lang/regex` repo
192+
and can be referred to by the repo's root URL (`https://github.com/rust-lang/regex.git`)
193+
regardless of where in the file tree they reside.
191194

192195
```toml
193-
cpp = { git = "https://github.com/mystor/rust-cpp" }
194-
cpp_common = { git = "https://github.com/mystor/rust-cpp" }
196+
regex-lite = { git = "https://github.com/rust-lang/regex.git" }
197+
regex-syntax = { git = "https://github.com/rust-lang/regex.git" }
195198
```
196199

197-
The above rule does not apply to local paths specified via `path` attribute.
200+
The above rule does not apply to [`path` dependencies](#specifying-path-dependencies).
198201

199-
#### Choice of commit
202+
### Choice of commit
200203

201204
Cargo assumes that we intend to use the latest commit on the default branch to build
202205
our package if we only specify the repo URL, as in the examples above.
@@ -245,7 +248,7 @@ regex = { git = "https://github.com/rust-lang/regex.git#4c59b70", path = "../reg
245248
Cargo locks the commits of `git` dependencies in `Cargo.lock` file at the time of their addition
246249
and checks for updates only when you run `cargo update` command.
247250

248-
#### The role of _version_ key
251+
### The role of the `version` key
249252

250253
The `version` key always implies that the package is available in a registry,
251254
regardless of the presence of `git` or `path` keys.
@@ -271,7 +274,7 @@ See [Multiple locations](#multiple-locations) section below for detailed explana
271274
> locations](#multiple-locations) section for a fallback alternative for `git`
272275
> and `path` dependencies.
273276
274-
#### Accessing private Git repositories
277+
### Accessing private Git repositories
275278

276279
See [Git Authentication](../appendix/git-authentication.md) for help with Git authentication for private repos.
277280

@@ -303,7 +306,7 @@ in the `hello_utils` folder, relative to the `Cargo.toml` file it’s written in
303306
The next `cargo build` will automatically build `hello_utils` and
304307
all of its dependencies.
305308

306-
#### No local path traversal
309+
### No local path traversal
307310

308311
The local paths must point to the exact folder with the dependency's `Cargo.toml`.
309312
Unlike with `git` dependencies, Cargo does not traverse local paths.
@@ -322,7 +325,7 @@ cpp = { path = "../rust-cpp/cpp" }
322325
cpp_common = { path = "../rust-cpp/cpp_common" }
323326
```
324327

325-
#### Local paths in published crates
328+
### Local paths in published crates
326329

327330
Crates that use dependencies specified with only a path are not
328331
permitted on [crates.io].
@@ -336,7 +339,7 @@ as a separate crate and specify its version in the dependencies line of `hello_w
336339
hello_utils = { path = "hello_utils", version = "0.1.0" }
337340
```
338341

339-
The use of `path` and `version` keys together is explained in the next section.
342+
The use of `path` and `version` keys together is explained in the [Multiple locations](#multiple-locations) section.
340343

341344
> **Note**: [crates.io] does not allow packages to be published with
342345
> dependencies on code outside of [crates.io], except for [dev-dependencies].

0 commit comments

Comments
 (0)