Skip to content

assoc const equality anon consts have elided lifetimes set to 'static #110933

Closed
@BoxyUwU

Description

@BoxyUwU

I tried this code:

#![feature(associated_const_equality)]

trait Trait {
    const ASSOC: usize;
}

fn foo<T: Trait<ASSOC = {
    let a = 10_usize;
    let b: &'_ usize = &a;
    *b
}>>() {
    
}

I expected to see this happen: it compile

Instead, this happened: it errored

error[[E0597]](https://doc.rust-lang.org/nightly/error_codes/E0597.html): `a` does not live long enough
  --> src/lib.rs:9:24
   |
9  |     let b: &'_ usize = &a;
   |            ---------   ^^ borrowed value does not live long enough
   |            |
   |            type annotation requires that `a` is borrowed for `'static`
10 |     *b
11 | }>>() {
   | - `a` dropped here while still borrowed

For more information about this error, try `rustc --explain E0597`.
error: could not compile `playground` (lib) due to previous error

related issue: #110931

Meta

playground version:

Nightly channel

Build using the Nightly version: 1.71.0-nightly

(2023-04-27 1a6ae3d692cfb52b21d0)
Backtrace

<backtrace>

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-const-genericsArea: const generics (parameters and arguments)A-lifetimesArea: Lifetimes / regionsA-resolveArea: Name/path resolution done by `rustc_resolve` specificallyC-bugCategory: This is a bug.E-needs-testCall for participation: An issue has been fixed and does not reproduce, but no test has been added.F-associated_const_equality`#![feature(associated_const_equality)]`

    Type

    No type

    Projects

    Status

    Done

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions