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

Update features heuristic to include more unstable and private feature name patterns #463

Merged
merged 8 commits into from
May 31, 2023
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 23 additions & 4 deletions src/rustdoc_gen.rs
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,10 @@ impl<'a> CrateSource<'a> {
/// - `nightly`
/// - `bench`
/// - `no_std`
/// - features with prefix `__`
/// features with prefix:
/// - `_`
era marked this conversation as resolved.
Show resolved Hide resolved
/// - `unstable_`
/// - `unstable-`
fn heuristically_included_features(&self) -> Vec<String> {
let features_ignored_by_default = std::collections::HashSet::from([
String::from("unstable"),
Expand All @@ -143,11 +146,27 @@ impl<'a> CrateSource<'a> {
String::from("no_std"),
]);

let determine = |feature_name: &String| {
!features_ignored_by_default.contains(feature_name) && !feature_name.starts_with("__")
let prefix_ignored_by_default = vec![
String::from("_"),
String::from("unstable-"),
String::from("unstable_"),
];
Copy link
Owner

Choose a reason for hiding this comment

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

Out of curiosity, do we need the String::from() here and above? Would this code work if these were static &str instead?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Oh, it would! I'm cleaning it to be &str instead.


let filter_feature_names =
|feature_name: &String| !features_ignored_by_default.contains(feature_name);

let filter_feature_prefix = |feature_name: &String| {
!prefix_ignored_by_default
.iter()
.map(|p| feature_name.starts_with(p))
.any(|f| f)
Copy link
Owner

Choose a reason for hiding this comment

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

I think this is just .any(|p| feature_name.starts_with(p)) right?

};

self.all_features().into_iter().filter(determine).collect()
self.all_features()
.into_iter()
.filter(filter_feature_names)
.filter(filter_feature_prefix)
.collect()
}

/// Returns features to explicitly enable. Does not fetch default features,
Expand Down
3 changes: 3 additions & 0 deletions test_crates/features_simple/old/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,6 @@ nightly = []
bench = []
no_std = []
__foo = []
unstable-foo=[]
unstable_foo=[]
_bar=[]
7 changes: 5 additions & 2 deletions test_crates/features_simple/old/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@ pub fn feature_dependent_function() {}
feature = "nightly",
feature = "bench",
feature = "no_std",
feature = "__foo"
feature = "__foo",
feature = "unstable-foo",
feature = "unstable_foo",
feat8re = "_bar"
))]
pub fn unstable_function() {}
pub fn unstable_function() {}
era marked this conversation as resolved.
Show resolved Hide resolved