Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix logic for marking crate as "multi" #71

Merged

Conversation

louisdewar
Copy link
Contributor

Checklist

  • I have read the Contributor Guide
  • I have read and agree to the Code of Conduct
  • I have added a description of my changes and why I'd like them included in the section below

Description of Changes

Fixed the logic that marks crates as "multi" (i.e. crates that are included multiple times under different names). Previously the code used "chunks" to iterate over a node's dependencies, which would yield non-overlapping pairs of dependencies. The issue arises in the following situation:

ab|b'c|de|

Here the dependency b is included twice but the chunking means that a&b are compared, and so are b'&c, but never b&b'.

The new code uses a sliding window checking pairs like:

ab|bb'|b'c|cd|de

Due to Rust's mutability rules we have to use indexes rather than a nice iterator since no &mut windows() method exists (as it would be unsound).

Related Issues

#69 (in particular see: #69 (comment))

Testing

I've cloned cargo-deny locally and set the krates dependency to my local version and then ran it on my project (using cargo run -- --manifest-path ~/my/to/my/rust/project/Cargo.toml check advisories) and it worked. I then set the krates dependency back to 0.16 and then re-ran the command and it failed with:

internal error: entered unreachable code: unable to locate sensitive-headers for crate tower-http 0.4.4 (registry+https://github.com/rust-lang/crates.io-index) features(["default", "trace", "tracing"])
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace

So I'm confident my change has fixed the issue I was facing.

Fixed the logic that marks crates as "multi" (i.e. crates that are
included multiple times under different names). Previously the code used
"chunks" to iterate over a node's dependencies, which would yield
non-overlapping pairs of dependencies. The issue arises in the following
situation:

ab|b'c|de|

Here the dependency `b` is included twice but the chunking means that
a&b are compared, and so are b'&c, but never b&b'.

The new code uses a sliding window checking pairs like:

ab|bb'|b'c|cd|de

Due to Rust's mutability rules we have to use indexes rather than a nice
iterator since no `&mut windows()` method exists (as it would be
unsound).
Copy link
Member

@Jake-Shadle Jake-Shadle left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks!

@Jake-Shadle Jake-Shadle merged commit 469ae0e into EmbarkStudios:main Jan 22, 2024
6 checks passed
@louisdewar louisdewar deleted the ldw/issue-69/crates-with-same-name branch January 22, 2024 11:09
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants