Skip to content

erroneous constant used note makes error really large #110891

Closed
@BoxyUwU

Description

@BoxyUwU

Code

#![feature(closure_lifetime_binder, inline_const)]

fn foo() {
    let a = for<'a> |b: &'a ()| -> &'a () {
        const {
            let awd = ();
            let _: &'a () = &awd;
        };
        b
    };
}

Current output

error[E0597]: `awd` does not live long enough
 --> src/lib.rs:7:29
  |
4 |     let a = for<'a> |b: &'a ()| -> &'a () {
  |                 -- lifetime `'a` defined here
...
7 |             let _: &'a () = &awd;
  |                    ------   ^^^^ borrowed value does not live long enough
  |                    |
  |                    type annotation requires that `awd` is borrowed for `'a`
8 |         };
  |         - `awd` dropped here while still borrowed

note: erroneous constant used
 --> src/lib.rs:5:9
  |
5 | /         const {
6 | |             let awd = ();
7 | |             let _: &'a () = &awd;
8 | |         };
  | |_________^

Desired output

error[E0597]: `awd` does not live long enough
 --> src/lib.rs:7:29
  |
4 |     let a = for<'a> |b: &'a ()| -> &'a () {
  |                 -- lifetime `'a` defined here
...
7 |             let _: &'a () = &awd;
  |                    ------   ^^^^ borrowed value does not live long enough
  |                    |
  |                    type annotation requires that `awd` is borrowed for `'a`
8 |         };
  |         - `awd` dropped here while still borrowed

Rationale and extra context

No response

Other cases

No response

Anything else?

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-diagnosticsArea: Messages for errors, warnings, and lintsF-closure_lifetime_binder`#![feature(closure_lifetime_binder)]`F-inline_constInline constants (aka: const blocks, const expressions, anonymous constants)T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions