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

Document the fact that debug_handler doesn't work within impl blocks #1800

Merged

Conversation

jesjos
Copy link
Contributor

@jesjos jesjos commented Mar 2, 2023

Motivation

When upgrading from from axum 0.5.x to 0.6.x I encountered a breaking change to how the debug_handler macro works.

In 0.5.x, an associated function (not a method) could be used with debug_handler. In 0.6.x this yields confusing compilation errors.

As per @davidpdrsn on Discord:

ah yes I see why now. Basically in 0.6 FromRequest got a new (secret) type param M, which is used to work around some otherwise overlapping impls. But because of this we need to generate slightly different code in debug_handler, which doesn't work we're inside an impl would be good to document.

Solution

This PR attempts to document this behavior.

axum-macros/src/lib.rs Outdated Show resolved Hide resolved
axum-macros/src/lib.rs Outdated Show resolved Hide resolved
@davidpdrsn davidpdrsn added T-docs Topic: documentation A-axum-macros labels Mar 3, 2023
Comment on lines +545 to +546
/// This macro does not work for associated functions — functions defined in an `impl` block that
/// don't take `self`:
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
/// This macro does not work for associated functions — functions defined in an `impl` block that
/// don't take `self`:
/// This macro does not work for associated functions that aren't methods — functions defined in an `impl` block that
/// don't take `self`:

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

But an associated function is never a method 🤔

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I added this clarification @davidpdrsn — maybe I'm splitting hairs, but I think it pays to try and get it right

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

https://doc.rust-lang.org/reference/items/associated-items.html#methods

Associated functions whose first parameter is named self are called methods and may be invoked using the method call operator, for example, x.foo(), as well as the usual function call notation.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
/// This macro does not work for associated functions — functions defined in an `impl` block that
/// don't take `self`:
/// This macro does not work functions in an `impl` block that
/// don't have a `self` parameter:

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh, already merged 😅

@davidpdrsn davidpdrsn merged commit 67befbc into tokio-rs:main Mar 3, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-axum-macros T-docs Topic: documentation
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants