Skip to content

Commit

Permalink
Update features heuristic to include more unstable and private featur…
Browse files Browse the repository at this point in the history
…e name patterns (#463)

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

* improve names of variables

* improve test by making sure we are handling the prefix

* Update test_crates/features_simple/old/src/lib.rs

Co-authored-by: Predrag Gruevski <2348618+obi1kenobi@users.noreply.github.com>

* Update src/rustdoc_gen.rs

Co-authored-by: Predrag Gruevski <2348618+obi1kenobi@users.noreply.github.com>

* addressing comments on pr

* making sure we have a trailing line

* new trailing line properly

---------

Co-authored-by: Predrag Gruevski <2348618+obi1kenobi@users.noreply.github.com>
  • Loading branch information
era and obi1kenobi authored May 31, 2023
1 parent bb11e12 commit 817b1ff
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 5 deletions.
22 changes: 18 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:
/// - `_`
/// - `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,22 @@ 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!["_", "unstable-", "unstable_"];

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()
.any(|p| feature_name.starts_with(p))
};

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=[]
5 changes: 4 additions & 1 deletion 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() {}

0 comments on commit 817b1ff

Please sign in to comment.