style: format workspace with Rust 1.97
This commit is contained in:
@@ -32,7 +32,14 @@ fn take_runtime_owners_in_dependency_order<Instance, Validation, Surface, Device
|
||||
instance.take();
|
||||
}
|
||||
|
||||
fn take_runtime_children_with_validation_snapshot<Surface, Device, Swapchain, Validation, Snapshot, Capture>(
|
||||
fn take_runtime_children_with_validation_snapshot<
|
||||
Surface,
|
||||
Device,
|
||||
Swapchain,
|
||||
Validation,
|
||||
Snapshot,
|
||||
Capture,
|
||||
>(
|
||||
surface: &mut Option<Surface>,
|
||||
device: &mut Option<Device>,
|
||||
swapchain: &mut Option<Swapchain>,
|
||||
|
||||
@@ -634,15 +634,13 @@ pub fn prepare_mission_assets_with_repository<R: ResourceRepository>(
|
||||
root_prototype_spans: &[std::ops::Range<usize>],
|
||||
prototypes: &[EffectivePrototype],
|
||||
) -> Result<MissionAssets, AssetError> {
|
||||
Ok(
|
||||
prepare_mission_assets_profiled_with_repository(
|
||||
repository,
|
||||
root_prototype_spans,
|
||||
prototypes,
|
||||
AssetPreparationLimits::default(),
|
||||
)?
|
||||
.0,
|
||||
)
|
||||
Ok(prepare_mission_assets_profiled_with_repository(
|
||||
repository,
|
||||
root_prototype_spans,
|
||||
prototypes,
|
||||
AssetPreparationLimits::default(),
|
||||
)?
|
||||
.0)
|
||||
}
|
||||
|
||||
/// Builds mission assets while enforcing explicit preparation limits.
|
||||
|
||||
@@ -894,7 +894,11 @@ mod tests {
|
||||
fs::write(root.join("WORLD/MAP/land.map"), build_nres(&[])).expect("land map");
|
||||
let manifest = CorpusManifest {
|
||||
kind: CorpusKind::Unknown,
|
||||
files: vec![manifest_entry("WORLD/MAP/land.map", 16, sha256(b"land.map"))],
|
||||
files: vec![manifest_entry(
|
||||
"WORLD/MAP/land.map",
|
||||
16,
|
||||
sha256(b"land.map"),
|
||||
)],
|
||||
casefold_collisions: Vec::new(),
|
||||
};
|
||||
|
||||
@@ -913,7 +917,11 @@ mod tests {
|
||||
fs::write(root.join("WORLD/MAP/land.msh"), build_nres(&[])).expect("land msh");
|
||||
let manifest = CorpusManifest {
|
||||
kind: CorpusKind::Unknown,
|
||||
files: vec![manifest_entry("WORLD/MAP/land.msh", 16, sha256(b"land.msh"))],
|
||||
files: vec![manifest_entry(
|
||||
"WORLD/MAP/land.msh",
|
||||
16,
|
||||
sha256(b"land.msh"),
|
||||
)],
|
||||
casefold_collisions: Vec::new(),
|
||||
};
|
||||
|
||||
|
||||
@@ -137,7 +137,8 @@ pub enum LandFileKind {
|
||||
///
|
||||
/// Returns a string error when the archive cannot be read or decoded.
|
||||
pub fn inspect_archive_file(path: &Path, sample_limit: usize) -> Result<ArchiveInspection, String> {
|
||||
inspect_archive_file_diagnostic(path, sample_limit).map_err(|diagnostic| render_human(&diagnostic))
|
||||
inspect_archive_file_diagnostic(path, sample_limit)
|
||||
.map_err(|diagnostic| render_human(&diagnostic))
|
||||
}
|
||||
|
||||
/// Inspects a format archive and returns a structured diagnostic on failure.
|
||||
@@ -215,7 +216,9 @@ fn inspect_archive_bytes(
|
||||
Arc::from(bytes.to_vec().into_boxed_slice()),
|
||||
ReadProfile::Compatible,
|
||||
)
|
||||
.map_err(|err| archive_parse_diagnostic("S1.NRES.DECODE", source, bytes, err.to_string()))?;
|
||||
.map_err(|err| {
|
||||
archive_parse_diagnostic("S1.NRES.DECODE", source, bytes, err.to_string())
|
||||
})?;
|
||||
let mut sample = Vec::new();
|
||||
for entry in document.entries().iter().take(sample_limit) {
|
||||
sample.push(NresEntrySummary {
|
||||
@@ -234,7 +237,9 @@ fn inspect_archive_bytes(
|
||||
Arc::from(bytes.to_vec().into_boxed_slice()),
|
||||
fparkan_rsli::ReadProfile::Compatible,
|
||||
)
|
||||
.map_err(|err| archive_parse_diagnostic("S1.RSLI.DECODE", source, bytes, err.to_string()))?;
|
||||
.map_err(|err| {
|
||||
archive_parse_diagnostic("S1.RSLI.DECODE", source, bytes, err.to_string())
|
||||
})?;
|
||||
Ok(ArchiveInspection::Rsli {
|
||||
entries: document.entries().len(),
|
||||
})
|
||||
@@ -259,8 +264,8 @@ pub fn inspect_model_from_root(
|
||||
archive: &str,
|
||||
resource: &str,
|
||||
) -> Result<ModelInspection, String> {
|
||||
let bytes =
|
||||
read_resource_bytes_diagnostic(root, archive, resource).map_err(|err| render_human(&err))?;
|
||||
let bytes = read_resource_bytes_diagnostic(root, archive, resource)
|
||||
.map_err(|err| render_human(&err))?;
|
||||
let document = decode_nres(bytes.clone(), ReadProfile::Compatible).map_err(|err| {
|
||||
render_human(&resource_parse_diagnostic(
|
||||
"S1.NRES.DECODE",
|
||||
@@ -293,10 +298,8 @@ pub fn load_model_from_root(
|
||||
archive: &str,
|
||||
resource: &str,
|
||||
) -> Result<ModelAsset, String> {
|
||||
let document =
|
||||
load_model_document_from_root_diagnostic(root, archive, resource).map_err(|err| {
|
||||
render_human(&err)
|
||||
})?;
|
||||
let document = load_model_document_from_root_diagnostic(root, archive, resource)
|
||||
.map_err(|err| render_human(&err))?;
|
||||
let msh = decode_msh(&document).map_err(|err| err.to_string())?;
|
||||
validate_msh(&msh).map_err(|err| err.to_string())
|
||||
}
|
||||
@@ -312,8 +315,8 @@ pub fn inspect_texture_from_root(
|
||||
archive: &str,
|
||||
resource: &str,
|
||||
) -> Result<TextureInspection, String> {
|
||||
let bytes =
|
||||
read_resource_bytes_diagnostic(root, archive, resource).map_err(|err| render_human(&err))?;
|
||||
let bytes = read_resource_bytes_diagnostic(root, archive, resource)
|
||||
.map_err(|err| render_human(&err))?;
|
||||
let document = decode_texm(bytes).map_err(|err| err.to_string())?;
|
||||
Ok(TextureInspection {
|
||||
width: document.width(),
|
||||
@@ -385,18 +388,16 @@ fn read_resource_bytes_diagnostic(
|
||||
)
|
||||
})?;
|
||||
let resource_name = resource_name(name.as_bytes());
|
||||
let archive_handle = repository
|
||||
.open_archive(&archive_path)
|
||||
.map_err(|err| {
|
||||
diagnostic(DiagnosticCode("S1.RESOURCE.OPEN_ARCHIVE"), err.to_string()).with_context(
|
||||
DiagnosticContext {
|
||||
phase: Some(Phase::Read),
|
||||
path: Some(archive.to_string()),
|
||||
archive_entry: Some(name.to_string()),
|
||||
..DiagnosticContext::default()
|
||||
},
|
||||
)
|
||||
})?;
|
||||
let archive_handle = repository.open_archive(&archive_path).map_err(|err| {
|
||||
diagnostic(DiagnosticCode("S1.RESOURCE.OPEN_ARCHIVE"), err.to_string()).with_context(
|
||||
DiagnosticContext {
|
||||
phase: Some(Phase::Read),
|
||||
path: Some(archive.to_string()),
|
||||
archive_entry: Some(name.to_string()),
|
||||
..DiagnosticContext::default()
|
||||
},
|
||||
)
|
||||
})?;
|
||||
let Some(handle) = repository
|
||||
.find(archive_handle, &resource_name)
|
||||
.map_err(|err| {
|
||||
@@ -410,21 +411,19 @@ fn read_resource_bytes_diagnostic(
|
||||
)
|
||||
})?
|
||||
else {
|
||||
return Err(
|
||||
diagnostic(
|
||||
DiagnosticCode("S1.RESOURCE.MISSING_ENTRY"),
|
||||
format!(
|
||||
"resource not found: {archive}/{}",
|
||||
String::from_utf8_lossy(name.as_bytes())
|
||||
),
|
||||
)
|
||||
.with_context(DiagnosticContext {
|
||||
phase: Some(Phase::Resolve),
|
||||
path: Some(archive.to_string()),
|
||||
archive_entry: Some(name.to_string()),
|
||||
..DiagnosticContext::default()
|
||||
}),
|
||||
);
|
||||
return Err(diagnostic(
|
||||
DiagnosticCode("S1.RESOURCE.MISSING_ENTRY"),
|
||||
format!(
|
||||
"resource not found: {archive}/{}",
|
||||
String::from_utf8_lossy(name.as_bytes())
|
||||
),
|
||||
)
|
||||
.with_context(DiagnosticContext {
|
||||
phase: Some(Phase::Resolve),
|
||||
path: Some(archive.to_string()),
|
||||
archive_entry: Some(name.to_string()),
|
||||
..DiagnosticContext::default()
|
||||
}));
|
||||
};
|
||||
let bytes = repository.read(handle).map_err(|err| {
|
||||
diagnostic(DiagnosticCode("S1.RESOURCE.READ"), err.to_string()).with_context(
|
||||
@@ -514,8 +513,7 @@ mod tests {
|
||||
let path = dir.join("broken.nres");
|
||||
fs::write(&path, b"NRes").expect("broken nres");
|
||||
|
||||
let diagnostic =
|
||||
inspect_archive_file_diagnostic(&path, 0).expect_err("diagnostic failure");
|
||||
let diagnostic = inspect_archive_file_diagnostic(&path, 0).expect_err("diagnostic failure");
|
||||
|
||||
assert_eq!(diagnostic.code.0, "S1.NRES.DECODE");
|
||||
let expected_path = path.display().to_string();
|
||||
@@ -555,7 +553,10 @@ mod tests {
|
||||
assert_eq!(diagnostic.code.0, "S1.NRES.DECODE");
|
||||
assert_eq!(diagnostic.context.phase, Some(Phase::Parse));
|
||||
assert_eq!(diagnostic.context.path.as_deref(), Some("models.rlb"));
|
||||
assert_eq!(diagnostic.context.archive_entry.as_deref(), Some("BROKEN.MSH"));
|
||||
assert_eq!(
|
||||
diagnostic.context.archive_entry.as_deref(),
|
||||
Some("BROKEN.MSH")
|
||||
);
|
||||
assert_eq!(
|
||||
diagnostic.context.span,
|
||||
Some(SourceSpan {
|
||||
|
||||
@@ -802,10 +802,8 @@ fn parse_entries(
|
||||
header: &NresHeader,
|
||||
limits: DecodeLimits,
|
||||
) -> Result<Vec<NresEntry>, NresError> {
|
||||
let capacity = checked_allocation_len(
|
||||
u64::from(header.entry_count),
|
||||
u64::from(limits.max_entries),
|
||||
)?;
|
||||
let capacity =
|
||||
checked_allocation_len(u64::from(header.entry_count), u64::from(limits.max_entries))?;
|
||||
let mut entries = Vec::with_capacity(capacity);
|
||||
let directory_offset =
|
||||
usize::try_from(header.directory_offset).map_err(|_| DecodeError::IntegerOverflow)?;
|
||||
@@ -1629,7 +1627,10 @@ mod tests {
|
||||
..DecodeLimits::default()
|
||||
}
|
||||
),
|
||||
Err(NresError::Binary(DecodeError::LimitExceeded { count: 2, limit: 1 }))
|
||||
Err(NresError::Binary(DecodeError::LimitExceeded {
|
||||
count: 2,
|
||||
limit: 1
|
||||
}))
|
||||
));
|
||||
}
|
||||
|
||||
|
||||
@@ -209,7 +209,11 @@ pub struct PrototypeGraphNode {
|
||||
impl PrototypeGraphNode {
|
||||
/// Creates a typed resource node.
|
||||
#[must_use]
|
||||
pub fn resource(kind: PrototypeGraphNodeKind, resource: ResourceKey, id: PrototypeGraphNodeId) -> Self {
|
||||
pub fn resource(
|
||||
kind: PrototypeGraphNodeKind,
|
||||
resource: ResourceKey,
|
||||
id: PrototypeGraphNodeId,
|
||||
) -> Self {
|
||||
Self {
|
||||
id,
|
||||
kind,
|
||||
@@ -1656,15 +1660,24 @@ mod tests {
|
||||
fn malformed_unit_dat_failure_is_classified_on_unit_edge() {
|
||||
let mut vfs = MemoryVfs::default();
|
||||
let dat_path = resource_archive_path(b"UNITS/AUTO/bad.dat").expect("dat path");
|
||||
vfs.insert(dat_path, Arc::from([1_u8, 2, 3].to_vec().into_boxed_slice()));
|
||||
vfs.insert(
|
||||
dat_path,
|
||||
Arc::from([1_u8, 2, 3].to_vec().into_boxed_slice()),
|
||||
);
|
||||
let vfs = Arc::new(vfs);
|
||||
let repo = CachedResourceRepository::new(vfs.clone());
|
||||
|
||||
let (_graph, _resolved, report) =
|
||||
build_prototype_graph_report(&repo, vfs.as_ref(), &[resource_name(b"UNITS/AUTO/bad.dat")]);
|
||||
let (_graph, _resolved, report) = build_prototype_graph_report(
|
||||
&repo,
|
||||
vfs.as_ref(),
|
||||
&[resource_name(b"UNITS/AUTO/bad.dat")],
|
||||
);
|
||||
|
||||
assert_eq!(report.failures.len(), 1);
|
||||
assert_eq!(report.failures[0].edge, PrototypeGraphEdge::MissionToUnitDat);
|
||||
assert_eq!(
|
||||
report.failures[0].edge,
|
||||
PrototypeGraphEdge::MissionToUnitDat
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
@@ -1690,7 +1703,10 @@ mod tests {
|
||||
);
|
||||
|
||||
assert_eq!(report.failures.len(), 1);
|
||||
assert_eq!(report.failures[0].edge, PrototypeGraphEdge::UnitDatToComponent);
|
||||
assert_eq!(
|
||||
report.failures[0].edge,
|
||||
PrototypeGraphEdge::UnitDatToComponent
|
||||
);
|
||||
assert!(report.failures[0].message.contains("missing_component"));
|
||||
}
|
||||
|
||||
@@ -2007,10 +2023,7 @@ mod tests {
|
||||
|
||||
assert_eq!(report.failures.len(), 1);
|
||||
assert_eq!(report.failures[0].resource_raw, b"broken");
|
||||
assert_eq!(
|
||||
report.failures[0].edge,
|
||||
PrototypeGraphEdge::PrototypeToMesh
|
||||
);
|
||||
assert_eq!(report.failures[0].edge, PrototypeGraphEdge::PrototypeToMesh);
|
||||
assert!(report.failures[0].message.contains("broken"));
|
||||
assert!(report.failures[0]
|
||||
.message
|
||||
|
||||
@@ -636,7 +636,11 @@ impl RsliDocument {
|
||||
///
|
||||
/// Returns [`RsliError`] when the packed payload exceeds configured
|
||||
/// limits, `id` is invalid, or the payload cannot be decoded.
|
||||
pub fn load_with_limits(&self, id: EntryId, limits: DecodeLimits) -> Result<Vec<u8>, RsliError> {
|
||||
pub fn load_with_limits(
|
||||
&self,
|
||||
id: EntryId,
|
||||
limits: DecodeLimits,
|
||||
) -> Result<Vec<u8>, RsliError> {
|
||||
let record = self.record_by_id(id)?;
|
||||
let packed = self.packed_slice(id, record)?;
|
||||
decode_payload(
|
||||
@@ -1208,12 +1212,18 @@ fn validate_lookup_order(records: &[EntryRecord]) -> Result<(), RsliError> {
|
||||
.map_err(|_| RsliError::IntegerOverflow)?;
|
||||
let left = records
|
||||
.get(left_original)
|
||||
.ok_or(RsliError::CorruptEntryTable("sort_to_original is not a permutation"))?;
|
||||
.ok_or(RsliError::CorruptEntryTable(
|
||||
"sort_to_original is not a permutation",
|
||||
))?;
|
||||
let right = records
|
||||
.get(right_original)
|
||||
.ok_or(RsliError::CorruptEntryTable("sort_to_original is not a permutation"))?;
|
||||
if cmp_c_string(c_name_bytes(&left.meta.name_raw), c_name_bytes(&right.meta.name_raw))
|
||||
== std::cmp::Ordering::Greater
|
||||
.ok_or(RsliError::CorruptEntryTable(
|
||||
"sort_to_original is not a permutation",
|
||||
))?;
|
||||
if cmp_c_string(
|
||||
c_name_bytes(&left.meta.name_raw),
|
||||
c_name_bytes(&right.meta.name_raw),
|
||||
) == std::cmp::Ordering::Greater
|
||||
{
|
||||
return Err(RsliError::CorruptEntryTable(
|
||||
"presorted lookup names are not sorted",
|
||||
@@ -1906,7 +1916,9 @@ mod tests {
|
||||
|
||||
assert!(matches!(
|
||||
decode(arc(bytes.clone()), ReadProfile::Strict),
|
||||
Err(RsliError::CorruptEntryTable("presorted lookup names are not sorted"))
|
||||
Err(RsliError::CorruptEntryTable(
|
||||
"presorted lookup names are not sorted"
|
||||
))
|
||||
));
|
||||
|
||||
let doc = decode(arc(bytes), ReadProfile::Compatible).expect("compatible fallback");
|
||||
@@ -2418,14 +2430,23 @@ mod tests {
|
||||
..DecodeLimits::default()
|
||||
}
|
||||
),
|
||||
Err(RsliError::Binary(DecodeError::LimitExceeded { count: 2, limit: 1 }))
|
||||
Err(RsliError::Binary(DecodeError::LimitExceeded {
|
||||
count: 2,
|
||||
limit: 1
|
||||
}))
|
||||
));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn stored_entries_require_exact_packed_size() {
|
||||
let bytes = synthetic_rsli(
|
||||
&[SyntheticEntry::with_payload(b"A", 0x000, 0, b"ok", b"ok!".to_vec())],
|
||||
&[SyntheticEntry::with_payload(
|
||||
b"A",
|
||||
0x000,
|
||||
0,
|
||||
b"ok",
|
||||
b"ok!".to_vec(),
|
||||
)],
|
||||
true,
|
||||
0x7782,
|
||||
None,
|
||||
@@ -2434,7 +2455,10 @@ mod tests {
|
||||
|
||||
assert!(matches!(
|
||||
doc.load(EntryId(0)),
|
||||
Err(RsliError::OutputSizeMismatch { expected: 2, got: 3 })
|
||||
Err(RsliError::OutputSizeMismatch {
|
||||
expected: 2,
|
||||
got: 3
|
||||
})
|
||||
));
|
||||
}
|
||||
|
||||
@@ -2457,7 +2481,10 @@ mod tests {
|
||||
..DecodeLimits::default()
|
||||
}
|
||||
),
|
||||
Err(RsliError::Binary(DecodeError::LimitExceeded { count: 5, limit: 4 }))
|
||||
Err(RsliError::Binary(DecodeError::LimitExceeded {
|
||||
count: 5,
|
||||
limit: 4
|
||||
}))
|
||||
));
|
||||
}
|
||||
|
||||
|
||||
@@ -257,11 +257,7 @@ fn select_casefolded_match(
|
||||
}
|
||||
}
|
||||
|
||||
fn list_recursive(
|
||||
root: &Path,
|
||||
dir: &Path,
|
||||
out: &mut Vec<VfsEntry>,
|
||||
) -> Result<(), VfsError> {
|
||||
fn list_recursive(root: &Path, dir: &Path, out: &mut Vec<VfsEntry>) -> Result<(), VfsError> {
|
||||
let read_dir = fs::read_dir(dir).map_err(VfsError::Io)?;
|
||||
let mut children = Vec::new();
|
||||
for entry in read_dir {
|
||||
@@ -286,11 +282,9 @@ fn list_recursive(
|
||||
let rel_bytes = rel.as_os_str().as_bytes();
|
||||
#[cfg(not(unix))]
|
||||
let rel_bytes = rel.to_str().ok_or(VfsError::Path)?.as_bytes();
|
||||
let path = fparkan_path::normalize_relative(
|
||||
rel_bytes,
|
||||
fparkan_path::PathPolicy::HostCompatible,
|
||||
)
|
||||
.map_err(|_| VfsError::Path)?;
|
||||
let path =
|
||||
fparkan_path::normalize_relative(rel_bytes, fparkan_path::PathPolicy::HostCompatible)
|
||||
.map_err(|_| VfsError::Path)?;
|
||||
out.push(VfsEntry {
|
||||
path,
|
||||
metadata: metadata_from_host_file(&child, &metadata)?,
|
||||
@@ -299,10 +293,7 @@ fn list_recursive(
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn metadata_from_host_file(
|
||||
path: &Path,
|
||||
metadata: &fs::Metadata,
|
||||
) -> Result<VfsMetadata, VfsError> {
|
||||
fn metadata_from_host_file(path: &Path, metadata: &fs::Metadata) -> Result<VfsMetadata, VfsError> {
|
||||
if !metadata.is_file() {
|
||||
return Err(VfsError::Path);
|
||||
}
|
||||
@@ -659,8 +650,7 @@ mod tests {
|
||||
}
|
||||
|
||||
let vfs = DirectoryVfs::new(&root);
|
||||
let path =
|
||||
normalize_relative(b"data/\xFF.bin", PathPolicy::HostCompatible).expect("path");
|
||||
let path = normalize_relative(b"data/\xFF.bin", PathPolicy::HostCompatible).expect("path");
|
||||
|
||||
assert_eq!(vfs.read(&path).expect("read raw path").as_ref(), b"raw");
|
||||
let entries = vfs
|
||||
@@ -770,8 +760,14 @@ mod tests {
|
||||
let entries = overlay.list(&prefix).expect("list");
|
||||
|
||||
assert_eq!(entries.len(), 2);
|
||||
assert_eq!(entries[0].path.display_lossy(), entries[1].path.display_lossy());
|
||||
assert_ne!(entries[0].path.identity_bytes(), entries[1].path.identity_bytes());
|
||||
assert_eq!(
|
||||
entries[0].path.display_lossy(),
|
||||
entries[1].path.display_lossy()
|
||||
);
|
||||
assert_ne!(
|
||||
entries[0].path.identity_bytes(),
|
||||
entries[1].path.identity_bytes()
|
||||
);
|
||||
}
|
||||
|
||||
fn unique_test_dir(name: &str) -> PathBuf {
|
||||
|
||||
Reference in New Issue
Block a user