Skip to content

const arguments have '_ resolved to 'static instead of infer vars #110931

Closed
@BoxyUwU

Description

@BoxyUwU

I tried this code:

fn foo() -> [(); {
    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/stable/error_codes/E0597.html): `a` does not live long enough
 --> src/lib.rs:3:24
  |
3 |     let b: &'_ usize = &a;
  |            ---------   ^^ borrowed value does not live long enough
  |            |
  |            type annotation requires that `a` is borrowed for `'static`
4 |     *b
5 | }] {
  | - `a` dropped here while still borrowed

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

Meta

playground version:

Nightly channel

Build using the Nightly version: 1.71.0-nightly

(2023-04-27 1a6ae3d692cfb52b21d0)

Metadata

Metadata

Assignees

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.

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions