-
-
Notifications
You must be signed in to change notification settings - Fork 31
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
Fixes #104: correctly parse id repr for Rust 1.78+ #106
Merged
Merged
Changes from 1 commit
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
b61a2f8
Fixes #104: correctly parse id repr for Rust 1.78+
bnjbvr bec3685
Revert "test: disable nightly CI until #104 has been fixed"
bnjbvr f6cbf04
Add note about pkgid specification and cargo-util-schemas
bnjbvr 86d1486
clippy: fix new nightly clippy lint
bnjbvr File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -352,12 +352,51 @@ pub(crate) fn find_unused( | |
.nodes | ||
.iter() | ||
.find(|node| { | ||
// e.g. "aa 0.1.0 (path+file:///tmp/aa)" | ||
node.id | ||
.repr | ||
.split(' ') | ||
.next() // e.g. "aa" | ||
.map_or(false, |node_package_name| node_package_name == package_name) | ||
// Note: this is dependent on rustc, so it's a bit fragile, and may break with | ||
// nightly versions of the compiler (see cargo-machete issue #104). | ||
|
||
// The node id can have multiple representations: | ||
// - on rust 1.77 and before, something like "aa 0.1.0 (path+file:///tmp/aa)". | ||
// - on rust 1.78+, something like: | ||
// - "path+file:///home/ben/cargo-machete/integration-tests/aa#0.1.0" | ||
// - "path+file:///home/ben/cargo-machete/integration-tests/directory#[email protected]" | ||
let repr = &node.id.repr; | ||
|
||
let package_found = if repr.contains(' ') { | ||
// Rust < 1.78, take everything up to the space. | ||
node.id.repr.split(' ').next() // e.g. "aa" | ||
} else { | ||
// Rust >= 1.78. Oh boy. | ||
let mut temp = None; | ||
|
||
let mut slash_split = node.id.repr.split('/').peekable(); | ||
|
||
while let Some(subset) = slash_split.next() { | ||
// Continue until the last part of the path. | ||
if slash_split.peek().is_some() { | ||
continue; | ||
} | ||
|
||
// If there's no next slash separator, we've reached the end, and subset is | ||
// one of: | ||
// - aa#0.1.0 | ||
// - directory#[email protected] | ||
if subset.contains('@') { | ||
let mut hash_split = subset.split('#'); | ||
// Skip everything before the hash. | ||
hash_split.next(); | ||
// Now in the rest, take everything up to the @. | ||
temp = hash_split.next().and_then(|end| end.split('@').next()); | ||
} else { | ||
// Otherwise, take everything up to the #. | ||
temp = subset.split('#').next(); | ||
} | ||
} | ||
|
||
temp | ||
}; | ||
|
||
package_found.map_or(false, |node_package_name| node_package_name == package_name) | ||
}) | ||
.expect("the current package must be in the dependency graph") | ||
.deps | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Or you could use cargo_util_schemas::core::PackageIdSpec::parse and then extract the path from the URL. Then if we extend the
PackageIdSpec
syntax, its just a dependency update away.btw the spec for Specs is at https://doc.rust-lang.org/cargo/reference/pkgid-spec.html