Skip to content

Commit 975e816

Browse files
committed
refactor(toml): Indent block in prep for changes
1 parent 9d66d13 commit 975e816

File tree

1 file changed

+37
-35
lines changed

1 file changed

+37
-35
lines changed

src/cargo/util/toml/targets.rs

Lines changed: 37 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -131,46 +131,48 @@ pub fn normalize_lib(
131131
edition: Edition,
132132
warnings: &mut Vec<String>,
133133
) -> CargoResult<Option<TomlLibTarget>> {
134-
let inferred = inferred_lib(package_root);
135-
let lib = original_lib.cloned().or_else(|| {
136-
inferred.as_ref().map(|lib| TomlTarget {
137-
path: Some(PathValue(lib.clone())),
138-
..TomlTarget::new()
139-
})
140-
});
141-
let Some(mut lib) = lib else { return Ok(None) };
142-
lib.name
143-
.get_or_insert_with(|| package_name.replace("-", "_"));
144-
145-
// Check early to improve error messages
146-
validate_lib_name(&lib, warnings)?;
147-
148-
validate_proc_macro(&lib, "library", edition, warnings)?;
149-
validate_crate_types(&lib, "library", edition, warnings)?;
150-
151-
if lib.path.is_none() {
152-
if let Some(inferred) = inferred {
153-
lib.path = Some(PathValue(inferred));
154-
} else {
155-
let name = name_or_panic(&lib);
156-
let legacy_path = Path::new("src").join(format!("{name}.rs"));
157-
if edition == Edition::Edition2015 && package_root.join(&legacy_path).exists() {
158-
warnings.push(format!(
159-
"path `{}` was erroneously implicitly accepted for library `{name}`,\n\
160-
please rename the file to `src/lib.rs` or set lib.path in Cargo.toml",
161-
legacy_path.display(),
162-
));
163-
lib.path = Some(PathValue(legacy_path));
134+
{
135+
let inferred = inferred_lib(package_root);
136+
let lib = original_lib.cloned().or_else(|| {
137+
inferred.as_ref().map(|lib| TomlTarget {
138+
path: Some(PathValue(lib.clone())),
139+
..TomlTarget::new()
140+
})
141+
});
142+
let Some(mut lib) = lib else { return Ok(None) };
143+
lib.name
144+
.get_or_insert_with(|| package_name.replace("-", "_"));
145+
146+
// Check early to improve error messages
147+
validate_lib_name(&lib, warnings)?;
148+
149+
validate_proc_macro(&lib, "library", edition, warnings)?;
150+
validate_crate_types(&lib, "library", edition, warnings)?;
151+
152+
if lib.path.is_none() {
153+
if let Some(inferred) = inferred {
154+
lib.path = Some(PathValue(inferred));
164155
} else {
165-
anyhow::bail!(
166-
"can't find library `{name}`, \
156+
let name = name_or_panic(&lib);
157+
let legacy_path = Path::new("src").join(format!("{name}.rs"));
158+
if edition == Edition::Edition2015 && package_root.join(&legacy_path).exists() {
159+
warnings.push(format!(
160+
"path `{}` was erroneously implicitly accepted for library `{name}`,\n\
161+
please rename the file to `src/lib.rs` or set lib.path in Cargo.toml",
162+
legacy_path.display(),
163+
));
164+
lib.path = Some(PathValue(legacy_path));
165+
} else {
166+
anyhow::bail!(
167+
"can't find library `{name}`, \
167168
rename file to `src/lib.rs` or specify lib.path",
168-
)
169+
)
170+
}
169171
}
170172
}
171-
}
172173

173-
Ok(Some(lib))
174+
Ok(Some(lib))
175+
}
174176
}
175177

176178
#[tracing::instrument(skip_all)]

0 commit comments

Comments
 (0)