rust-lang / rust-lang/rust

Disappearing error in Rust 1.74

Open
#138,982 3 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

A-diagnostics A-lints C-discussion T-compiler
Dominant language
Rust
Stars
119k
Forks
16.1k
PR merge metrics
PR metrics pending

Description

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.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Reproduce the difference in the knurling-rs/derive-mmio repository by checking out weird-pub-issue and running the array example with cargo +1.73 and cargo +1.74. Start by examining the generated derive_mmio::Mmio code around the offending pub fn ptr() -> PrivateType; done means explaining the changed E0446 behavior and identifying the appropriate compiler or macro-side fix.

Written by the indexing model from the issue text.

Assessment

Tech stack
rust
Domain
compilers
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.