Skip to content

Commit 02a3a02

Browse files
committed
Auto merge of #8887 - Diggsey:comments, r=alexcrichton
Add some comments to the toml code
2 parents 4e32fba + 7559f96 commit 02a3a02

File tree

3 files changed

+28
-0
lines changed

3 files changed

+28
-0
lines changed

src/cargo/core/manifest.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,8 @@ pub enum EitherManifest {
2525
}
2626

2727
/// Contains all the information about a package, as loaded from a `Cargo.toml`.
28+
///
29+
/// This is deserialized using the [`TomlManifest`] type.
2830
#[derive(Clone, Debug)]
2931
pub struct Manifest {
3032
summary: Summary,

src/cargo/core/source/source_id.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@ lazy_static::lazy_static! {
1919
}
2020

2121
/// Unique identifier for a source of packages.
22+
///
23+
/// See also: [`SourceKind`].
2224
#[derive(Clone, Copy, Eq, Debug)]
2325
pub struct SourceId {
2426
inner: &'static SourceIdInner,

src/cargo/util/toml/mod.rs

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,14 @@ use crate::util::{self, paths, validate_package_name, Config, IntoUrl};
2828
mod targets;
2929
use self::targets::targets;
3030

31+
/// Loads a `Cargo.toml` from a file on disk.
32+
///
33+
/// This could result in a real or virtual manifest being returned.
34+
///
35+
/// A list of nested paths is also returned, one for each path dependency
36+
/// within the manfiest. For virtual manifests, these paths can only
37+
/// come from patched or replaced dependencies. These paths are not
38+
/// canonicalized.
3139
pub fn read_manifest(
3240
path: &Path,
3341
source_id: SourceId,
@@ -121,6 +129,12 @@ fn do_read_manifest(
121129
}
122130
}
123131

132+
/// Attempts to parse a string into a [`toml::Value`]. This is not specific to any
133+
/// particular kind of TOML file.
134+
///
135+
/// The purpose of this wrapper is to detect invalid TOML which was previously
136+
/// accepted and display a warning to the user in that case. The `file` and `config`
137+
/// parameters are only used by this fallback path.
124138
pub fn parse(toml: &str, file: &Path, config: &Config) -> CargoResult<toml::Value> {
125139
let first_error = match toml.parse() {
126140
Ok(ret) => return Ok(ret),
@@ -176,7 +190,12 @@ type TomlBenchTarget = TomlTarget;
176190
#[derive(Clone, Debug, Serialize)]
177191
#[serde(untagged)]
178192
pub enum TomlDependency {
193+
/// In the simple format, only a version is specified, eg.
194+
/// `package = "<version>"`
179195
Simple(String),
196+
/// The simple format is equivalent to a detailed dependency
197+
/// specifying only a version, eg.
198+
/// `package = { version = "<version>" }`
180199
Detailed(DetailedTomlDependency),
181200
}
182201

@@ -243,6 +262,7 @@ pub struct DetailedTomlDependency {
243262
public: Option<bool>,
244263
}
245264

265+
/// This type is used to deserialize `Cargo.toml` files.
246266
#[derive(Debug, Deserialize, Serialize)]
247267
#[serde(rename_all = "kebab-case")]
248268
pub struct TomlManifest {
@@ -847,6 +867,9 @@ struct Context<'a, 'b> {
847867
}
848868

849869
impl TomlManifest {
870+
/// Prepares the manfiest for publishing.
871+
// - Path and git components of dependency specifications are removed.
872+
// - License path is updated to point within the package.
850873
pub fn prepare_for_publish(
851874
&self,
852875
ws: &Workspace<'_>,
@@ -1489,6 +1512,7 @@ impl TomlManifest {
14891512
Ok(patch)
14901513
}
14911514

1515+
/// Returns the path to the build script if one exists for this crate.
14921516
fn maybe_custom_build(
14931517
&self,
14941518
build: &Option<StringOrBool>,

0 commit comments

Comments
 (0)