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

Enforce that closure: 'a requires that closure_ret_ty: 'a holds #84385

Closed
wants to merge 3 commits into from

Commits on Oct 7, 2022

  1. Enforce that closure: 'a requires that closure_ret_ty: 'a holds

    RFC 1214 allows us to infer that `<T as Trait<P0, ... PN>>::Out: 'a`
    holds, so long as `T: 'a, P0: 'a, ..., PN: 'a` all hold.
    
    In order for this to be sound, we must ensure that whenever we need to
    prove `T: 'a` for some concrete type `T`, we also ensure that
    any type which could appear in the output type for an impl also outlives
    `'a`
    
    However, we failed to enforce this for closures. Specifically, we
    allowed `closure: 'a` to hold without requiring that `closure_ret_ty:
    'a` also holds. Since `closure_ret_ty` appears in the output of the
    `FnOnce` impl for closures, it was possible to extend a lifetime by
    causing rustc to assume that the closure return type outlived a lifetime
    based on the fact that the closure itself outlived a lifetime.
    
    This commit includes the closure return type as one of the 'components'
    used when computing outlives requirements. To minimize the extent of
    this breaking change, we do *not* include the arguments of the closure
    as 'components'. Doing so is still sound, but introduces an
    inconsistency with function pointers (which do treat their arguments as
    'components')
    
    Several uses of closures in libcore needed to be adjusted, all of them
    involving returning a closure via an `impl Fn` opaque type. In all
    cases, we needed to add extra lifetime bounds to generic parameters that
    ended up in the return type `R` of `impl Fn() -> R`.
    Aaron1011 committed Oct 7, 2022
    Configuration menu
    Copy the full SHA
    24a4650 View commit details
    Browse the repository at this point in the history
  2. Configuration menu
    Copy the full SHA
    1541392 View commit details
    Browse the repository at this point in the history
  3. Configuration menu
    Copy the full SHA
    70cec5d View commit details
    Browse the repository at this point in the history