Skip to content

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

Open
@kawadakk

Description

@kawadakk

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions