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

Custom hooks with RPIT no longer compile in Rust 2024 #3774

Open
1 of 3 tasks
kawadakk opened this issue Dec 12, 2024 · 1 comment
Open
1 of 3 tasks

Custom hooks with RPIT no longer compile in Rust 2024 #3774

kawadakk opened this issue Dec 12, 2024 · 1 comment
Labels

Comments

@kawadakk
Copy link
Contributor

kawadakk commented Dec 12, 2024

Problem
#[hook] generates code that no longer compiles under Lifetime Capture Rules 2024 (RFC 3498).

Steps To Reproduce

# Cargo.toml
[package]
name = "foo"
edition = "2024"

[dependencies]
yew = { version = "0.21.0", features = ["csr"] }
// src/lib.rs
use yew::prelude::*;

#[hook]
pub fn use_foo() -> impl Sized {
    42
}
$ cargo +nightly-2024-12-12 check
error: lifetime may not live long enough
 --> src/lib.rs:3:1
  |
3 | #[hook]
  | -^^^^^-
  | |     |
  | |     return type of closure `impl Sized` contains a lifetime `'2`
  | let's call the lifetime of this reference `'1`
  | returning this value requires that `'1` must outlive `'2`
  |
  = note: this error originates in the attribute macro `hook` (in Nightly builds, run with -Z macro-backtrace for more info)

Expected behavior
Successful compilation as in Rust 2021

Screenshots
If applicable, add screenshots to help explain your problem.

Environment:

  • Yew version: 0.21.0
  • Rust version: nightly-2024-12-12
  • Target, if relevant: N/A
  • Build tool, if relevant: N/A
  • OS, if relevant: N/A
  • Browser and version, if relevant: N/A

Questionnaire

  • I'm interested in fixing this myself but don't know where to start
  • I would like to fix and I have a solution
  • I don't have time to fix this right now, but maybe later
@kawadakk kawadakk added the bug label Dec 12, 2024
@kawadakk
Copy link
Contributor Author

kawadakk commented Dec 17, 2024

A possible work-around is to manually list all type and lifetime parameters in scope by + use<...>. Example:

#[hook]
// pub fn use_foo() -> impl Sized {
pub fn use_foo() -> impl Sized + use<> {
    42
}

#[hook]
// pub fn use_bar(x: &impl Clone) -> impl Clone {
pub fn use_bar<'a, X: Clone>(x: &'a X) -> impl Clone + use<'a, X> {
    42
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant