Skip to content

Use reason specifier in allow - #179

Merged
mulkieran merged 1 commit into
stratis-storage:masterfrom
mulkieran:use-reason-in-allow
Dec 11, 2025
Merged

mulkieran merged 1 commit into
stratis-storage:masterfrom
mulkieran:use-reason-in-allow

Conversation

@mulkieran

@mulkieran mulkieran commented Jan 2, 2025 •

Copy link
Copy Markdown
Member

Related stratis-storage/project#713

Summary by CodeRabbit

  • Chores
    • Updated internal code attributes for enhanced clarity and maintainability. No changes to functionality or user experience.

✏️ Tip: You can customize this high-level summary in your review settings.

@mulkieran

Copy link
Copy Markdown
Member Author

Ok. Still experimental.

@mulkieran
mulkieran force-pushed the use-reason-in-allow branch from 36d5d82 to 389bf05 Compare April 25, 2025 16:56
@mulkieran

Copy link
Copy Markdown
Member Author

still experimental

@mulkieran
mulkieran force-pushed the use-reason-in-allow branch from 389bf05 to 724aeda Compare August 13, 2025 15:50
@coderabbitai

coderabbitai Bot commented Aug 13, 2025 •

Copy link
Copy Markdown

Walkthrough

This pull request adds reason metadata to compiler allow attributes in src/devno.rs. Three public functions have their #[allow(unused_unsafe)] annotations updated to include explanatory reasons referencing the libc versions where unsafe calls became unnecessary.

Changes

Cohort / File(s) Summary
Attribute metadata documentation
src/devno.rs
Updated #[allow(unused_unsafe)] attributes on from_device_numbers, major, and minor functions to include reason = "..." metadata. Added libc version-specific explanations: libc 0.2.133 for from_device_numbers, libc 0.2.171 for major and minor.

Estimated code review effort

🎯 1 (Trivial) | ⏱️ ~3 minutes

  • Single file with repetitive attribute updates across three functions
  • No functional or logic changes
  • Purely documentation-focused compiler directives

Poem

🐰 Three unsafe calls now have their tale,
With libc versions to never pale,
Metadata marks why warnings cease,
Documentation brings us peace! ✨

Pre-merge checks and finishing touches

✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title 'Use reason specifier in allow' directly describes the main change: adding reason metadata to #[allow()] attributes in the codebase.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@packit-as-a-service

Copy link
Copy Markdown

Congratulations! One of the builds has completed. 🍾

You can install the built RPMs by following these steps:

  • sudo yum install -y dnf-plugins-core on RHEL 8
  • sudo dnf install -y dnf-plugins-core on Fedora
  • dnf copr enable packit/stratis-storage-libblkid-rs-179
  • And now you can install the packages.

Please note that the RPMs should be used only in a testing environment.

1 similar comment
@packit-as-a-service

Copy link
Copy Markdown

Congratulations! One of the builds has completed. 🍾

You can install the built RPMs by following these steps:

  • sudo yum install -y dnf-plugins-core on RHEL 8
  • sudo dnf install -y dnf-plugins-core on Fedora
  • dnf copr enable packit/stratis-storage-libblkid-rs-179
  • And now you can install the packages.

Please note that the RPMs should be used only in a testing environment.

@mulkieran

Copy link
Copy Markdown
Member Author

Still not available.

@packit-as-a-service

Copy link
Copy Markdown

Congratulations! One of the builds has completed. 🍾

You can install the built RPMs by following these steps:

  • sudo dnf install -y 'dnf*-command(copr)'
  • dnf copr enable packit/stratis-storage-libblkid-rs-179
  • And now you can install the packages.

Please note that the RPMs should be used only in a testing environment.

Signed-off-by: mulhern <amulhern@redhat.com>
@mulkieran mulkieran removed this from tracking Dec 11, 2025
@mulkieran mulkieran moved this to In Review in 2025December Dec 11, 2025
@mulkieran
mulkieran marked this pull request as ready for review December 11, 2025 18:00

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Actionable comments posted: 1

♻️ Duplicate comments (1)
src/devno.rs (1)

61-61: Version verification needed (same as major).

The reason references libc 0.2.171 for libc::minor, consistent with the major function. Please verify this version number as part of the verification requested for line 53.

📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 53ffe8a and f083558.

📒 Files selected for processing (1)
  • src/devno.rs (1 hunks)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (32)
  • GitHub Check: rpm-build:fedora-41-x86_64:copr_pull
  • GitHub Check: rpm-build:fedora-42-x86_64:copr_pull
  • GitHub Check: rpm-build:fedora-43-x86_64:copr_pull
  • GitHub Check: rpm-build:fedora-41-x86_64:copr_pull
  • GitHub Check: rpm-build:fedora-42-x86_64:copr_pull
  • GitHub Check: rpm-build:fedora-rawhide-x86_64:copr_pull
  • GitHub Check: rpm-build:fedora-43-x86_64:copr_pull
  • GitHub Check: rpm-build:fedora-rawhide-x86_64:copr_pull
  • GitHub Check: rpm-build:fedora-42-x86_64:copr_pull
  • GitHub Check: rpm-build:fedora-43-x86_64:copr_pull
  • GitHub Check: rpm-build:fedora-41-x86_64:copr_pull
  • GitHub Check: rpm-build:fedora-42-x86_64:copr_pull
  • GitHub Check: rpm-build:fedora-43-x86_64:copr_pull
  • GitHub Check: rpm-build:fedora-rawhide-x86_64:copr_pull
  • GitHub Check: rpm-build:fedora-rawhide-x86_64:copr_pull
  • GitHub Check: rpm-build:fedora-41-x86_64:copr_pull
  • GitHub Check: rpm-build:fedora-43-x86_64:copr_pull
  • GitHub Check: rpm-build:fedora-43-x86_64:copr_pull
  • GitHub Check: rpm-build:fedora-42-x86_64:copr_pull
  • GitHub Check: rpm-build:fedora-rawhide-x86_64:copr_pull
  • GitHub Check: rpm-build:fedora-rawhide-x86_64:copr_pull
  • GitHub Check: rpm-build:fedora-41-x86_64:copr_pull
  • GitHub Check: rpm-build:fedora-41-x86_64:copr_pull
  • GitHub Check: rpm-build:fedora-42-x86_64:copr_pull
  • GitHub Check: rpm-build:fedora-41-x86_64:copr_pull
  • GitHub Check: rpm-build:fedora-rawhide-x86_64:copr_pull
  • GitHub Check: rpm-build:fedora-43-x86_64:copr_pull
  • GitHub Check: rpm-build:fedora-42-x86_64:copr_pull
  • GitHub Check: rpm-build:fedora-42-x86_64:copr_pull
  • GitHub Check: rpm-build:fedora-41-x86_64:copr_pull
  • GitHub Check: rpm-build:fedora-43-x86_64:copr_pull
  • GitHub Check: rpm-build:fedora-rawhide-x86_64:copr_pull
🔇 Additional comments (1)
src/devno.rs (1)

47-47: The reason parameter in allow attributes is not an unstable feature and does not require a feature gate.

The lint_reasons feature was stabilized in Rust 1.81.0. Since this project requires Rust 1.82.0 or later (per rust-version in Cargo.toml), the reason parameter is fully supported without needing #![feature(lint_reasons)].

The version references in the reasons (libc 0.2.133 and 0.2.171) are forward-looking documentation of when these unsafe blocks may become unnecessary as the libc crate evolves. The project currently uses libc 0.2.121, so these annotations serve as a record for future dependency upgrades.

Comment thread src/devno.rs
/// Get the major number.
pub fn major(&self) -> maj_t {
#[allow(unused_unsafe)]
#[allow(unused_unsafe, reason = "No longer unsafe in libc 0.2.171")]

@coderabbitai coderabbitai Bot Dec 11, 2025 •

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟡 Minor

🧩 Analysis chain

🌐 Web query:

libc crate changelog major minor functions safe version history

💡 Result:

Summary — what libc is and its version history

  • libc is the Rust crate providing raw, platform-specific FFI bindings (types, constants, extern "C" function signatures). It is intentionally a thin, unsafe binding layer — callers are responsible for safe usage. [1][2]
  • The crate moved from 0.1 → 0.2 (RFC 1291) with API/typedef changes (e.g., top-level exports, size_t/ssize_t defined as usize/isize on main platforms). The project maintains a long 0.2.x series while preparing a planned 1.0 (roadmap on the repo). [3][4]
  • Current published releases (many 0.2.x releases; recently active: 0.2.17x…/0.2.174 etc. and 1.0.0-alpha releases on the registry). See the releases list for precise version history. [2]

About “major / minor / functions / safe”

  • Semantic versioning: libc has stayed at 0.2.* for a long time (breaking changes were made when moving from 0.1 → 0.2). A future 1.0 is planned and may introduce breaking changes; maintainers have discussed migration strategy. [3][4]
  • Function safety: libc exposes raw C APIs (extern "C" fn signatures) and thus their use is generally unsafe in Rust — the crate itself does not generally provide safe wrappers. In other words, calling most libc functions requires unsafe or a safe wrapper in a higher-level crate. The README and design rationale describe libc as raw FFI bindings. [1][2]
  • Changes making things “safe”: there is no broad history of libc converting C functions into safe Rust APIs inside the crate — safe, ergonomic wrappers are normally provided by other crates (or by application code). libc’s scope is to match platform APIs faithfully rather than to wrap them in safe abstractions. [1][3]

Where to get the authoritative changelog / releases

  • GitHub repo (source, CHANGELOG, issues, roadmap, v1.0 branch): rust-lang/libc. Use the Releases/tags and commits for specific change details. [1]
  • Crate/release listing (crates.io / lib.rs) shows published versions and dates (0.2.x history and recent alpha 1.0 pre-releases). Check the crate page for exact release timestamps. [2]

If you want, I can:

  • fetch the precise 5 most important changelog entries (with dates) from the GitHub Releases/CHANGELOG, or
  • list which 0.2.x releases contain specific changes (e.g., 0.2.169 matching rustc c_char changes). Which would you prefer?

🏁 Script executed:

#!/bin/bash
# Check the crate registry info for libc version history
curl -s "https://crates.io/api/v1/crates/libc" | jq '.versions[] | select(.num | test("0.2.17[01]")) | {num: .num, created_at: .created_at}' | head -20

Repository: stratis-storage/libblkid-rs

Length of output: 210


🏁 Script executed:

#!/bin/bash
# Try to fetch libc changelog from crates.io or check the GitHub release info
curl -s "https://api.github.com/repos/rust-lang/libc/releases" | jq '.[] | select(.tag_name | test("0.2.171")) | {tag_name: .tag_name, body: .body}' | head -50

Repository: stratis-storage/libblkid-rs

Length of output: 3976


Remove or correct the reason attribute — major/minor are still unsafe.

In libc 0.2.171, major, minor, and makedev became const fn (#4208), not safe functions. The #[allow(unused_unsafe)] reason is inaccurate: these functions remain unsafe to call. Either remove the reason or update it to reflect why the unsafe block is genuinely needed.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟡 Minor
🧩 Analysis chain

Remove or correct the reason attribute — major/minor are still unsafe.

In libc 0.2.171, major, minor, and makedev became const fn (#4208), not safe functions. The #[allow(unused_unsafe)] reason is inaccurate: these functions remain unsafe to call. Either remove the reason or update it to reflect why the unsafe block is genuinely needed.

Developers disagree w/ you and agree w/ me: bdrung/3cpio@52827a6 .

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🧩 Analysis chain

🏁 Script executed:

#!/bin/bash
# Fetch the commit that the user referenced
curl -s "https://api.github.com/repos/bdrung/3cpio/commits/52827a6e8136453a19805dd6e1e27fd932d24bfd" | jq -r '.commit.message, .files[].patch' | head -100

Length of output: 987


🏁 Script executed:

#!/bin/bash
# Check libc changelog for makedev/major/minor becoming safe
curl -s "https://raw.githubusercontent.com/rust-lang/libc/main/CHANGELOG.md" | grep -A 5 -B 5 -i "makedev\|major\|minor" | grep -A 5 -B 5 "0.2.1[37]"

Length of output: 0


🏁 Script executed:

#!/bin/bash
# Check the libc PR that made these const fn to see if they also became safe
curl -s "https://api.github.com/repos/rust-lang/libc/pulls/4208" | jq -r '.title, .body'

Length of output: 1443


@mulkieran, you're absolutely right, and I apologize for the incorrect analysis.

The evidence from the commit you linked and the libc PR #4208 clearly shows that makedev, major, and minor were changed to safe const fn in those versions, not just const fn. As the PR description states: "makedev, major and minor are macros on most Unixes, there is no need for them to be unsafe."

Your reason attributes are accurate:

  • These functions are no longer unsafe to call
  • The #[allow(unused_unsafe)] is the correct way to handle the now-unnecessary unsafe blocks
  • The version information in your reasons is correct

Thank you for the correction and the reference!

🐰💭
/_/
( o.o )

^ <
(thinking...)


🧬 Code Graph Analysis Results

[src/devno.rs] lines (approximate extraction)

  1. from_device_numbers
    """
    pub fn from_device_numbers(major: maj_t, minor: min_t) -> Self {
    #[allow(unused_unsafe, reason = "No longer unsafe in libc 0.2.133")]
    BlkidDevno(unsafe { libc::makedev(major, minor) })
    }
    """
  • Description: Creates a BlkidDevno from major and minor numbers using libc::makedev. Note the allow attribute with a specific libc version reason.
  1. major()
    """
    pub fn major(&self) -> maj_t {
    #[allow(unused_unsafe, reason = "No longer unsafe in libc 0.2.171")]
    unsafe {
    libc::major(self.0)
    }
    }
    """
  • Description: Retrieves the major number from the device number. Uses unsafe block with a libc version-based reason.
  1. minor()
    """
    pub fn minor(&self) -> min_t {
    #[allow(unused_unsafe, reason = "No longer unsafe in libc 0.2.171")]
    unsafe {
    libc::minor(self.0)
    }
    }
    """
  • Description: Retrieves the minor number from the device number. Uses unsafe block with a libc version-based reason.

@mulkieran
mulkieran merged commit 40d3e07 into stratis-storage:master Dec 11, 2025
18 of 19 checks passed
@github-project-automation github-project-automation Bot moved this from In Review to Done in 2025December Dec 11, 2025
@mulkieran
mulkieran deleted the use-reason-in-allow branch December 11, 2025 18:14
@mulkieran mulkieran moved this from Done to Done(1) in 2025December Dec 16, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

No open projects
Status: Done(1)

Development

Successfully merging this pull request may close these issues.

1 participant