Skip to content

Rejecting higher-kinded lifetime bounds is a breaking change #50555

Closed
@comex

Description

@comex
fn foo<'s, F>(s: &'s i32, f: F) where for<'a: 's> F: FnOnce(&'a i32) {
    f(s)
}

fn main() {
    foo(&42, |x| println!("{}", x));
}

Playground Link

This compiles on stable; on beta and above, it produces:

error: lifetime bounds cannot be used in this context

Apparently this is on purpose:

commit 49abd8748357012e5db10bf11077384f727e2177
Author: Ralf Jung <post@ralfj.de>
Date:   Tue Mar 6 11:22:24 2018 +0100

    make bounds on higher-kinded lifetimes a hard error in ast_validation
    
    Also move the check for not having type parameters into ast_validation.
    
    I was not sure what to do with compile-fail/issue-23046.rs: The issue looks like
    maybe the bounds actually played a role in triggering the ICE, but that seems
    unlikely given that the compiler seems to entirely ignore them.  However, I
    couldn't find a testcase without the bounds, so I figured the best I could do is
    to just remove the bounds and make sure at least that keeps working.

But it's still a gratuitous breaking change, which seems unfortunate… even if the lifetimes weren't being handled correctly before.

cc @RalfJung

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions