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

Handle ItemEnum kind case where function is a method #344

Merged
merged 1 commit into from
Oct 9, 2024

Conversation

donmai-me
Copy link
Contributor

While reading how Pavex works I found this todo that's low hanging. Using the fact that self is a reserved keyword and only appears as the first parameter in a method.

Hope it's ok that I don't put my real name in CONTRIBUTORS.md. Love your book btw thanks!

@LukeMathWalker
Copy link
Owner

While reading how Pavex works I found this todo that's low hanging. Using the fact that self is a reserved keyword and only appears as the first parameter in a method.

That's a good heuristic!
Does it work even if the function takes &self/&mut self? It'd be ideal to have a test covering this.

Hope it's ok that I don't put my real name in CONTRIBUTORS.md. Love your book btw thanks!

That's fine!

@donmai-me
Copy link
Contributor Author

Does it work even if the function takes &self/&mut self? It'd be ideal to have a test covering this.

Yes only the type of self changes. I used this sample code

use std::pin::Pin;

pub struct Foo {
    bar: u32,
}

impl Foo {
    pub fn new(bar: u32) -> Self {
        Self { bar }
    }

    pub fn self_ref(&self) {
        println!("self_ref: {}", self.bar);
    }

    pub fn self_mut_ref(&mut self) {
        println!("self_mut_ref: {}", self.bar);
    }

    pub fn self_take(self) {
        println!("self_take: {}", self.bar);
    }

    pub fn self_take_box(self: Box<Self>) {
        println!("self_take_box: {}", self.bar);
    }

    pub fn self_pin_ref(self: Pin<&Self>) {
        println!("self_pin_ref: {}", self.bar);
    }
}

and the rustdoc generated the following inputs for the methods

"inputs":[["self",{"borrowed_ref":{"lifetime":null,"is_mutable":false,"type":{"generic":"Self"}}}]]
...
"inputs":[["self",{"borrowed_ref":{"lifetime":null,"is_mutable":true,"type":{"generic":"Self"}}}]]
...
"inputs":[["self",{"generic":"Self"}]]
...
"inputs":[["self",{"resolved_path":{"name":"Box","id":"5:324:2510","args":{"angle_bracketed":{"args":[{"type":{"generic":"Self"}}]
...
"inputs":[["self",{"resolved_path":{"name":"Pin","id":"2:37066:2499","args":{"angle_bracketed":{"args":[{"type":{"borrowed_ref":{"lifetime":null,"is_mutable":false,"type":{"generic":"Self"}}}}]

I don't exactly know how to do a test that would call rustdoc and check the json output, and how to make it fit with the rest of pavex's tests. If you can give some guidance that would be appreciated.

@LukeMathWalker
Copy link
Owner

It'd be a bit contrived for this specific case, so we can skip it. Nice to see that it works for more complex self types too, such as Box and Pin!

@LukeMathWalker
Copy link
Owner

/ok-to-test sha=31601ab

@LukeMathWalker LukeMathWalker merged commit 69a2ea5 into LukeMathWalker:main Oct 9, 2024
15 checks passed
@pavex-releaser pavex-releaser bot mentioned this pull request Oct 23, 2024
LukeMathWalker added a commit that referenced this pull request Oct 23, 2024
## 🤖 New release
* `pavex`: 0.1.48 -> 0.1.49
* `pavex_bp_schema`: 0.1.48 -> 0.1.49
* `pavex_reflection`: 0.1.48 -> 0.1.49
* `pavex_macros`: 0.1.48 -> 0.1.49
* `persist_if_changed`: 0.1.48 -> 0.1.49
* `pavex_tracing`: 0.1.48 -> 0.1.49
* `pavex_cli`: 0.1.48 -> 0.1.49
* `pavex_cli_deps`: 0.1.48 -> 0.1.49
* `pavex_miette`: 0.1.48 -> 0.1.49
* `pavexc_cli_client`: 0.1.48 -> 0.1.49
* `pavexc`: 0.1.48 -> 0.1.49
* `pavex_cli_client`: 0.1.48 -> 0.1.49
* `pavex_session`: 0.1.48 -> 0.1.49
* `pavex_session_memory_store`: 0.1.48 -> 0.1.49
* `pavexc_cli`: 0.1.48 -> 0.1.49
* `generate_from_path`: 0.1.48 -> 0.1.49

<details><summary><i><b>Changelog</b></i></summary><p>

## `pavex`
<blockquote>

##
[0.1.49](0.1.48...0.1.49)
- 2024-10-23

### Added

- Distinguish between methods and functions in error messages
([#344](#344))
- Start caching path dependencies. Use the hash of their contents to
avoid serving stale data
- Pavex deduplicates diagnostics, thus reducing visual noise when code
generation fails

### Fixed

- Pavex always uses a public path to refer to public items, even if they
are defined in a private module
- Detect infinite paths and break early to avoid stalls when generating
server SDK crates
- Ensure error observers are correctly added when dealing with errors in
the call graph of a middleware of any kind
- Perform cross-call-graph analysis to determine if additional .clone()
statements are needed before invoking a middleware.
- Don't discard spans if they match the provided log filter in pavexc

### Other

- update Cargo.toml dependencies
- Disable workspace hack before a release
- Formatting
- Speed up UI tests
([#342](#342))
- Update to latest cargo-deny
([#339](#339))
- HTTP sessions
([#338](#338))
- Update dependencies to latest possible version. In particular, update
'rustdoc-types' and the nightly version used by 'pavexc'
</blockquote>


</p></details>

---
This PR was generated with
[release-plz](https://github.com/MarcoIeni/release-plz/).

---------

Co-authored-by: pavex-releaser[bot] <[email protected]>
Co-authored-by: pavex-releaser[bot] <167640712+pavex-releaser[bot]@users.noreply.github.com>
Co-authored-by: Luca Palmieri <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants