Skip to content
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

Disappearing error in Rust 1.74 #138982

Open
jonathanpallant opened this issue Mar 26, 2025 · 3 comments
Open

Disappearing error in Rust 1.74 #138982

jonathanpallant opened this issue Mar 26, 2025 · 3 comments
Labels
A-diagnostics Area: Messages for errors, warnings, and lints A-lints Area: Lints (warnings about flaws in source code) such as unused_mut. C-discussion Category: Discussion or questions that doesn't represent real issues. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@jonathanpallant
Copy link
Contributor

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.

@jonathanpallant jonathanpallant added the C-bug Category: This is a bug. label Mar 26, 2025
@rustbot rustbot added the needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. label Mar 26, 2025
@Urgau
Copy link
Member

Urgau commented Mar 26, 2025

I believe this is expected, see #113126.

@jonathanpallant
Copy link
Contributor Author

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)`

@Urgau
Copy link
Member

Urgau commented Mar 26, 2025

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?

@Urgau Urgau added A-lints Area: Lints (warnings about flaws in source code) such as unused_mut. A-diagnostics Area: Messages for errors, warnings, and lints T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. C-discussion Category: Discussion or questions that doesn't represent real issues. and removed C-bug Category: This is a bug. needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. labels Mar 26, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-diagnostics Area: Messages for errors, warnings, and lints A-lints Area: Lints (warnings about flaws in source code) such as unused_mut. C-discussion Category: Discussion or questions that doesn't represent real issues. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

No branches or pull requests

3 participants