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

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

Closed
BoxyUwU opened this issue Apr 28, 2023 · 3 comments · Fixed by #110984
Closed

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

BoxyUwU opened this issue Apr 28, 2023 · 3 comments · Fixed by #110984
Assignees
Labels
A-const-generics Area: const generics (parameters and arguments) A-lifetimes Area: Lifetimes / regions A-resolve Area: Name resolution C-bug Category: This is a bug.

Comments

@BoxyUwU
Copy link
Member

BoxyUwU commented Apr 28, 2023

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)

@BoxyUwU BoxyUwU added C-bug Category: This is a bug. A-const-generics Area: const generics (parameters and arguments) A-resolve Area: Name resolution A-lifetimes Area: Lifetimes / regions labels Apr 28, 2023
@BoxyUwU
Copy link
Member Author

BoxyUwU commented Apr 28, 2023

this is also present with repeat exprs:

fn main() {
    [(); {
        let a = 10_usize;
        let b: &'_ usize = &a;
        *b
    }]
}

@BoxyUwU
Copy link
Member Author

BoxyUwU commented Apr 28, 2023

cc @cjgillot and #97313

@cjgillot cjgillot self-assigned this Apr 28, 2023
@BoxyUwU
Copy link
Member Author

BoxyUwU commented Apr 29, 2023

error[[E0637]](https://doc.rust-lang.org/stable/error_codes/E0637.html): `'_` cannot be used here
 --> src/lib.rs:1:39
  |
1 | struct Foo<const N: usize = { let a: &'_ () = &(); 10 }>;
  |                                       ^^ `'_` is a reserved lifetime name

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

const generic defaults also are buggy around '_

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-const-generics Area: const generics (parameters and arguments) A-lifetimes Area: Lifetimes / regions A-resolve Area: Name resolution C-bug Category: This is a bug.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants