Skip to content

style: Remove macros#689

Merged
Pr0methean merged 9 commits intomasterfrom
remove-macros
Mar 1, 2026
Merged

style: Remove macros#689
Pr0methean merged 9 commits intomasterfrom
remove-macros

Conversation

@Its-Just-Nans
Copy link
Member

@Its-Just-Nans Its-Just-Nans commented Feb 21, 2026

I think the macros that we are using in macros.rs are not that useful, and add more complexity.

First commit removing cfg_if!
Second commit removing cfg_if_else!

@gemini-code-assist
Copy link
Contributor

Summary of Changes

Hello @Its-Just-Nans, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request streamlines the project's conditional compilation logic by eliminating custom cfg_if and cfg_if_expr macros. By transitioning to Rust's built-in #[cfg] attributes, the codebase becomes more straightforward and easier to understand, reducing reliance on internal macro implementations for feature-gated code paths.

Highlights

  • Macro Removal: The custom cfg_if and cfg_if_expr macros have been entirely removed from the codebase.
  • Conditional Compilation Refactor: All instances where these macros were used for conditional compilation based on features have been refactored to use native Rust #[cfg] attributes.
  • Code Simplification: This change simplifies the codebase by removing custom macro definitions and their usage, leading to more idiomatic Rust code.
Changelog
  • src/compression.rs
    • Removed cfg_if_expr import.
    • Refactored Default implementation for CompressionMethod to use #[cfg] attributes instead of cfg_if_expr!.
  • src/lib.rs
    • Removed the macros module and its re-exports.
  • src/macros.rs
    • Removed the entire file containing cfg_if! and cfg_if_expr! macro definitions.
  • src/read.rs
    • Removed cfg_if import.
    • Refactored is_ae2_encrypted method to use #[cfg] attributes instead of cfg_if!.
    • Restructured make_symlink to delegate platform-specific logic to new make_symlink_impl functions, each annotated with #[cfg(unix)] or #[cfg(windows)].
  • src/types.rs
    • Removed cfg_if_expr import.
    • Updated ZipFileData initialization to use #[cfg] attributes for determining encryption status instead of cfg_if_expr!.
  • src/write.rs
    • Refactored logic for calculating default deflate compression levels and creating deflate writers to use #[cfg] attributes instead of cfg_if_expr! and cfg_if!.
    • Adjusted deflate_compression_level_range to use #[cfg] attributes for feature-gated minimum and maximum values.
  • src/zipcrypto.rs
    • Removed cfg_if_expr import.
    • Modified the Debug implementation for ZipCryptoKeys to use #[cfg] attributes for conditional formatting.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Copy link
Contributor

@amazon-q-developer amazon-q-developer bot left a comment

Choose a reason for hiding this comment

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

This PR successfully removes the custom cfg_if and cfg_if_expr macros in favor of standard Rust conditional compilation syntax. The refactoring is clean and maintains functional equivalence across all changes. The macro removal simplifies the codebase without introducing any defects or regressions.


You can now have the agent implement changes and create commits directly on your pull request's source branch. Simply comment with /q followed by your request in natural language to ask the agent to make changes.

@Its-Just-Nans Its-Just-Nans self-assigned this Feb 21, 2026
Copy link
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request is a great improvement to the codebase. It successfully removes the custom cfg_if and cfg_if_expr macros from macros.rs and replaces their usage throughout the project with standard #[cfg] attributes. This refactoring enhances code clarity and maintainability by using built-in language features. The changes in src/compression.rs, src/read.rs, src/types.rs, src/write.rs, and src/zipcrypto.rs correctly preserve the original conditional compilation logic. The removal of src/macros.rs and the corresponding module registration in src/lib.rs completes this cleanup. Overall, this is a solid contribution that simplifies the code without altering functionality.

@Its-Just-Nans
Copy link
Member Author

Its-Just-Nans commented Feb 21, 2026

ON the function

zip2/src/read.rs

Lines 452 to 489 in 8896502

pub(crate) fn make_symlink<T>(
outpath: &Path,
target: &[u8],
#[cfg_attr(not(windows), allow(unused))] existing_files: &IndexMap<Box<str>, T>,
) -> ZipResult<()> {
#[cfg_attr(not(any(unix, windows)), allow(unused))]
let Ok(target_str) = std::str::from_utf8(target) else {
return Err(invalid!("Invalid UTF-8 as symlink target"));
};
cfg_if! {
if #[cfg(unix)] {
std::os::unix::fs::symlink(Path::new(&target_str), outpath)?;
} else if #[cfg(windows)] {
let target = Path::new(OsStr::new(&target_str));
let target_is_dir_from_archive =
existing_files.contains_key(target_str) && is_dir(target_str);
let target_is_dir = if target_is_dir_from_archive {
true
} else if let Ok(meta) = std::fs::metadata(target) {
meta.is_dir()
} else {
false
};
if target_is_dir {
std::os::windows::fs::symlink_dir(target, outpath)?;
} else {
std::os::windows::fs::symlink_file(target, outpath)?;
}
} else {
use std::fs::File;
let output = File::create(outpath);
output?.write_all(target)?;
}
}
Ok(())
}

why we are doing

let Ok(target_str) = std::str::from_utf8(target) else { 
     return Err(invalid!("Invalid UTF-8 as symlink target")); 
}; 

on every platform. But we don't use target_str on certain platform (line 482-484)

Copy link
Member

@Pr0methean Pr0methean left a comment

Choose a reason for hiding this comment

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

Overall good; I like how this manages to decrease the line count!

@Pr0methean Pr0methean changed the title Remove macros style: Remove macros Feb 22, 2026
Pr0methean
Pr0methean previously approved these changes Feb 22, 2026
Pr0methean
Pr0methean previously approved these changes Mar 1, 2026
@Pr0methean Pr0methean added this to the 8.2.0 milestone Mar 1, 2026
@Pr0methean Pr0methean added this pull request to the merge queue Mar 1, 2026
Merged via the queue into master with commit 7c2c6bd Mar 1, 2026
130 checks passed
@Pr0methean Pr0methean deleted the remove-macros branch March 1, 2026 21:46
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.

2 participants