Skip to content

Rust: use all features by default #19551

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

Open
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

redsun82
Copy link
Contributor

This makes rust analysis turn on all features by default. A more restricted set of features can be specified via the cargo_features extractor option. In particular setting it to default will use default features instead (no features if no default is set for a crate).

Notice that this implementation currently does not allow to turn off all features for crates that have a non-empty default. It's to be discussed if we want to allow that, but we could use a special value like - or ! for that.

@github-actions github-actions bot added the Rust Pull requests that update Rust code label May 21, 2025
@redsun82 redsun82 marked this pull request as ready for review May 22, 2025 09:29
@Copilot Copilot AI review requested due to automatic review settings May 22, 2025 09:29
@redsun82 redsun82 requested a review from a team as a code owner May 22, 2025 09:29
Copy link
Contributor

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

Enables all Cargo features by default in the extractor and lets users restrict features via the cargo_features option, with tests and docs updated accordingly.

  • Introduces a cargo_features() helper to centralize default/all/selected feature logic and uses it in to_cargo_config.
  • Expands integration tests to cover combinations of default, explicit features, and crates with non-empty default lists.
  • Updates extractor option documentation to reflect that all features are enabled by default and default must be explicitly specified to limit to default features.

Reviewed Changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated 3 comments.

File Description
rust/ql/integration-tests/options/features/test_features_option.py Adds new test cases and marks to cover default-feature scenarios and crates with defaults
rust/extractor/src/config.rs Adds cargo_features() helper and replaces inline logic in to_cargo_config
rust/codeql-extractor.yml Updates cargo_features option description to match new default behavior
Comments suppressed due to low confidence (1)

rust/extractor/src/config.rs:129

  • [nitpick] Method name cargo_features shadows the cargo_features field and could be confusing; consider renaming it to compute_cargo_features.
fn cargo_features(&self) -> CargoFeatures {

@@ -126,6 +126,23 @@ impl Config {
}
}

Copy link
Preview

Copilot AI May 22, 2025

Choose a reason for hiding this comment

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

Add a doc comment for cargo_features() to explain its behavior, particularly how default features and the deprecated '*' wildcard are handled.

Suggested change
/// Determines the Cargo features to be used based on the configuration.
///
/// - If the `cargo_features` list is empty or contains the deprecated `'*'` wildcard,
/// all features are enabled (`CargoFeatures::All`).
/// - Otherwise, a subset of features is selected (`CargoFeatures::Selected`):
/// - The `features` list excludes the `default` feature.
/// - The `no_default_features` flag is set to `true` if the `default` feature is not present
/// in the `cargo_features` list.
///
/// # Note
/// The `'*'` wildcard is deprecated but retained for backward compatibility.

Copilot uses AI. Check for mistakes.

Copy link
Contributor

@aibaars aibaars left a comment

Choose a reason for hiding this comment

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

Looks good to me. One typo that needs fixing, but otherwise OK.

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
@redsun82 redsun82 requested a review from aibaars May 27, 2025 12:57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Rust Pull requests that update Rust code
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy