Skip to content

Regression 1.66 "some_fn::{opaque#0}<'_> does not live long enough" #107426

Closed
@Dav1dde

Description

@Dav1dde
Contributor

Code

Unfortunately I couldn't minimize it further without using a dependency (code can be executed online here):

/*
[dependencies]
sycamore = "0.8.2"
web-sys = "0.3"

*/

use sycamore::prelude::{Scope, View, Html, DomNode, ReadSignal, GenericNode};

pub fn create_toggle_bool<'a>(cx: Scope<'a>, initial: bool) -> (&'a ReadSignal<bool>, impl Fn() + Copy + 'a) {
    // let open = sycamore::prelude::create_signal(cx, false);
    // let open_toggle = || open.set(!*open.get());
    // (open, open_toggle)
    (todo!(), || {})
}

pub fn Foo<G: Html>(cx: Scope) -> View<G> {
    let (open, open_toggle) = create_toggle_bool(cx, false);

    // Uncomment these 2 lines to make it compile (moved out of the function)
    // let open = sycamore::prelude::create_signal(cx, false);
    // let open_toggle = || open.set(!*open.get());

    let a = move |_: web_sys::Event| open_toggle();

    move || {
        let __el = DomNode::text_node("test");
        ::sycamore::generic_node::GenericNode::event(&__el, cx, "click", a);
        __el;
    };

    todo!()
}

fn main() {
}

The code compiles and runs with 1.66 but fails with 1.67:

error: `create_toggle_bool::{opaque#0}<'_>` does not live long enough
  --> src/main.rs:28:9
   |
28 |         ::sycamore::generic_node::GenericNode::event(&__el, cx, "click", a);
   |         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

I expect this code to still compile on 1.67

Version it worked on

1.66

Version with regression

1.67

rustc 1.67.0 (fc594f156 2023-01-24)
binary: rustc
commit-hash: fc594f15669680fa70d255faec3ca3fb507c3405
commit-date: 2023-01-24
host: x86_64-unknown-linux-gnu
release: 1.67.0
LLVM version: 15.0.6

Activity

added
C-bugCategory: This is a bug.
regression-untriagedUntriaged performance or correctness regression.
on Jan 28, 2023
added
I-prioritizeIssue: Indicates that prioritization has been requested for this issue.
on Jan 28, 2023
added
E-needs-bisectionCall for participation: This issue needs bisection: https://github.com/rust-lang/cargo-bisect-rustc
E-needs-mcveCall for participation: This issue has a repro, but needs a Minimal Complete and Verifiable Example
on Jan 28, 2023
Teapot4195

Teapot4195 commented on Jan 28, 2023

@Teapot4195
Contributor

searched nightlies: from nightly-2022-09-15 to nightly-2022-10-15
regressed nightly: nightly-2022-09-26
searched commit range: 3f83906...f5193a9
regressed commit: f5193a9

bisected with cargo-bisect-rustc v0.6.5

Host triple: x86_64-unknown-linux-gnu
Reproduce with:

cargo bisect-rustc --end=2022-10-15 

@rustbot label -E-needs-bisection

removed
E-needs-bisectionCall for participation: This issue needs bisection: https://github.com/rust-lang/cargo-bisect-rustc
on Jan 28, 2023
clubby789

clubby789 commented on Jan 28, 2023

@clubby789
Contributor

Minimized to:

use std::marker::PhantomData;
#[derive(Clone, Copy)]
pub struct Scope<'a>(&'a PhantomData<&'a mut &'a ()>);
fn event<'a, F: FnMut() + 'a>(_: Scope<'a>, _: F) {}
fn make_fn<'a>(_: Scope<'a>) -> impl Fn() + Copy + 'a {
    || {}
}

fn foo(cx: Scope) {
    let open_toggle = make_fn(cx);

    || event(cx, open_toggle);
}

fn main() {}

@rustbot label -E-needs-mcve

removed
E-needs-mcveCall for participation: This issue has a repro, but needs a Minimal Complete and Verifiable Example
on Jan 28, 2023
clubby789

clubby789 commented on Jan 28, 2023

@clubby789
Contributor

This is a breaking change but it is a necessary soundness fix

#95474

Noratrieb

Noratrieb commented on Jan 29, 2023

@Noratrieb
Member

Since the crater run there found no regressions I'm gonna @oli-obk anyways but I don't think there's anything to do here.

added
A-diagnosticsArea: Messages for errors, warnings, and lints
and removed
C-bugCategory: This is a bug.
I-prioritizeIssue: Indicates that prioritization has been requested for this issue.
regression-untriagedUntriaged performance or correctness regression.
on Jan 29, 2023

10 remaining items

Dav1dde

Dav1dde commented on Jan 31, 2023

@Dav1dde
ContributorAuthor

This is weird, this only broke on my CI because it was pinned to stable (-> 1.67), my local machine was still compiling and running the code fine on 1.66. Maybe the reduced example already regressed in 1.66 but my corner case only regresses in 1.67?

added
T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.
on Feb 24, 2023
aliemjay

aliemjay commented on Mar 3, 2023

@aliemjay
Member

This regression can indeed be mitigated (cc #108691), at least for the MCVE we have.
@rustbot label -A-diagonstics regression-from-stable-to-stable

added
regression-from-stable-to-stablePerformance or correctness regression from one stable version to another.
I-prioritizeIssue: Indicates that prioritization has been requested for this issue.
on Mar 3, 2023
apiraino

apiraino commented on Mar 7, 2023

@apiraino
Contributor

WG-prioritization assigning priority (Zulip discussion).

@rustbot label -I-prioritize +P-medium

added and removed
I-prioritizeIssue: Indicates that prioritization has been requested for this issue.
on Mar 7, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-impl-traitArea: `impl Trait`. Universally / existentially quantified anonymous types with static dispatch.P-mediumMedium priorityT-compilerRelevant to the compiler team, which will review and decide on the PR/issue.regression-from-stable-to-stablePerformance or correctness regression from one stable version to another.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

      Development

      Participants

      @Dav1dde@oli-obk@cjgillot@compiler-errors@steffahn

      Issue actions

        Regression 1.66 "`some_fn::{opaque#0}<'_>` does not live long enough" · Issue #107426 · rust-lang/rust