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

Feature request: determining early/late bound lifetime parameters #905

Closed
antonok-edm opened this issue Oct 9, 2020 · 1 comment
Closed

Comments

@antonok-edm
Copy link

I'm the author of the enum_dispatch procedural macro. Recently I added better support for generic parameters, but in some cases specifying them explicitly produces warnings like the following:

warning: cannot specify lifetime arguments explicitly if late bound lifetime parameters are present
  --> examples/late_dispatch.rs:11:1
   |
6  |     fn foo<'a>(&mut self) -> &'a u32 {
   |                - the late bound lifetime parameter is introduced here
...
11 | #[enum_dispatch(FooAPI)]
   | ^^^^^^^^^^^^^^^^^^^^^^^^
   |
   = note: `#[warn(late_bound_lifetime_arguments)]` on by default
   = 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 #42868 <https://github.com/rust-lang/rust/issues/42868>
   = note: this warning originates in an attribute macro (in Nightly builds, run with -Z macro-backtrace for more info)

The warning appears due to an explicitly specified lifetime parameter in the generated code:

--- 0.3.2.rs
+++ 0.3.3.rs
@@ -31,7 +31,7 @@
     #[inline]
     fn foo<'a>(&mut self) -> &'a u32 {
         match self {
-            Foo::Something(inner) => FooAPI::foo(inner),
+            Foo::Something(inner) => FooAPI::foo::<'a>(inner),
         }
     }

The explicit specification is useful in general, but begins causing issues when late-bound lifetime parameters are present in a method's signature (as they are here).

According to the linked issue, the recommendation is "Just removing the lifetime arguments pointed to by the lint". That's not an option in a procedural macro, which doesn't get to look at compiler warnings. That means I need some way to check if there are any late-bound lifetime parameters in a function signature when I'm generating its implementation.

What I'm proposing is something along the lines of syn::Signature::has_late_bound_lifetimes(&self) -> bool. The rules for determining early/late bound lifetimes are fairly complex, which is why I figure it would be nice to have a single canonical implementation in syn that is available to any procedural macro author.

More context: https://gitlab.com/antonok/enum_dispatch/-/issues/34

@antonok-edm antonok-edm changed the title Feature request: determining early/late bound lifetime arguments Feature request: determining early/late bound lifetime parameters Oct 9, 2020
@dtolnay
Copy link
Owner

dtolnay commented Mar 29, 2021

I think I would prefer not to build this into this crate.

@dtolnay dtolnay closed this as completed Mar 29, 2021
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

No branches or pull requests

2 participants