Skip to content

Disappearing error in Rust 1.74 #138982

Description

@jonathanpallant

I tried this code:

$ git clone https://github.com/knurling-rs/derive-mmio
$ cd derive-mmio
$ git checkout weird-pub-issue
$ cargo +1.73 run --example array
...
error[E0446]: private type `Uart` in public interface
 --> examples/array.rs:1:10
  |
1 | #[derive(derive_mmio::Mmio)]
  |          ^^^^^^^^^^^^^^^^^ can't leak private type
2 | #[repr(C)]
3 | struct Uart {
  | ----------- `Uart` declared as private
  |
  = note: this error originates in the derive macro `derive_mmio::Mmio` (in Nightly builds, run with -Z macro-backtrace for more info)

For more information about this error, try `rustc --explain E0446`.
error: could not compile `derive-mmio` (example "array") due to previous error
$ cargo +1.74 run --example array
    Finished dev [unoptimized + debuginfo] target(s) in 4.20s
     Running `target/debug/examples/array`

I expected to see this happen: Both 1.73 and 1.74 would report the same error?

Instead, this happened: 1.74 builds without an error.

Is this because the offending function (pub fn ptr() -> PrivateType) was macro generated?

I think the fix is to change our macro so that fn ptr() is only pub if PrivateType is pub. But it was weird that the error went away.

Activity

  1. added
    needs-triageThis issue may need triage. Remove when done. See docs forge.rust-lang.org/release/issue-triaging
    on Mar 26, 2025
  2. Urgau commented on Mar 26, 2025

    @Urgau
    Member

    I believe this is expected, see #113126.

  3. jonathanpallant commented on Mar 26, 2025

    @jonathanpallant
    ContributorAuthor

    If I expand the macro (cargo expand) and write it out to a new file (and clean it up a bit), I get some warnings. Are the warnings elided because the code is macro generated?

    warning: type `Uart` is more private than the item `MmioUart::<'_>::ptr`
      --> src/main.rs:39:5
       |
    39 |     pub const unsafe fn ptr(&self) -> *mut Uart {
       |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ method `MmioUart::<'_>::ptr` is reachable at visibility `pub`
       |
    note: but type `Uart` is only usable at visibility `pub(crate)`
    
  4. Urgau commented on Mar 26, 2025

    @Urgau
    Member

    The private_interfaces lint and private_bounds lints (like most lints) are indeed silenced in macro generated code.

    Do you think it would make sense to also show these two lints in macro generated code?

  5. added
    A-lintsArea: Lints (warnings about flaws in source code) such as unused_mut.
    A-diagnosticsArea: Messages for errors, warnings, and lints
    T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.
    C-discussionCategory: Discussion or questions that doesn't represent real issues.
    and removed
    C-bugCategory: This is a bug.
    needs-triageThis issue may need triage. Remove when done. See docs forge.rust-lang.org/release/issue-triaging
    on Mar 26, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-diagnosticsArea: Messages for errors, warnings, and lintsA-lintsArea: Lints (warnings about flaws in source code) such as unused_mut.C-discussionCategory: Discussion or questions that doesn't represent real issues.T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions