oxidecomputer / oxidecomputer/ingot

Can't define headers in `fn` items (or doctests)

Open
#12 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Rust
Stars
13
Forks
2
PR merge metrics
No merged PRs in 30d

Description

Code like the following which attempts to define a header within a fn breaks horribly:

fn hello() {
    #[derive(Ingot)]
    pub struct Broken {
        pub fine: u8,
    }
}
error: cannot find type `BrokenRef` in this scope
   --> ingot/src/lib.rs:180:16
    |
180 |     pub struct Broken {
    |                ^^^^^^ names from parent modules are not accessible without an explicit import
    |
    = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
    = note: for more information, see issue #83583 <https://github.com/rust-lang/rust/issues/83583>
    = note: `#[deny(proc_macro_derive_resolution_fallback)]` on by default

Although the types in question are not defined in a mod, all of them are referenced within the implementation-private module created to hold a header's chunk types and other generated artefacts.

An unfortunate victim of this is that doctests cannot include packet definitions, since they compile to a fn.

Contributor guide

No contributing guide indexed for this repository

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

Start in ingot/src/lib.rs around line 180 and inspect the derive-generated implementation-private module and its references. Reproduce the shown nested fn example, then verify that a header defined inside a function and in a doctest compiles without the BrokenRef resolution error.

Written by the indexing model from the issue text.

Assessment

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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.