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

NLL: closure return-type highlighting does not handle annotation right #58053

Closed
pnkfelix opened this issue Feb 1, 2019 · 0 comments
Closed
Assignees
Labels
A-closures Area: Closures (`|…| { … }`) A-diagnostics Area: Messages for errors, warnings, and lints C-bug Category: This is a bug.

Comments

@pnkfelix
Copy link
Member

pnkfelix commented Feb 1, 2019

Code (play):

#![feature(nll)]

fn main() {
    let f = |x: &i32| -> &i32 { x };
    let i = &3;
    let j = f(i);
}

yields:

error: lifetime may not live long enough
 --> src/main.rs:4:33
  |
4 |     let f = |x: &i32| -> &i32 { x };
  |                 -           -   ^ returning this value requires that `'1` must outlive `'2`
  |                 |           |
  |                 |           return type of closure is &'2 i32
  |                 let's call the lifetime of this reference `'1`

but I would have expected it to use the span:

error: lifetime may not live long enough
 --> src/main.rs:4:33
  |
4 |     let f = |x: &i32| -> &i32 { x };
  |                 -        -      ^ returning this value requires that `'1` must outlive `'2`
  |                 |        |
  |                 |        return type of closure is &'2 i32
  |                 let's call the lifetime of this reference `'1`
@estebank estebank added A-diagnostics Area: Messages for errors, warnings, and lints A-closures Area: Closures (`|…| { … }`) C-bug Category: This is a bug. labels Feb 1, 2019
@davidtwco davidtwco self-assigned this Feb 5, 2019
bors added a commit that referenced this issue Feb 12, 2019
Fix span for closure return type when annotated.

Fixes #58053.

This PR adjusts the span used to label closure return types so that
if the user specifies the return type, i.e. `|_| -> X {}` instead of
`|_| {}`, we correctly highlight all of it and not just the last
character.

r? @pnkfelix
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-closures Area: Closures (`|…| { … }`) A-diagnostics Area: Messages for errors, warnings, and lints C-bug Category: This is a bug.
Projects
None yet
Development

No branches or pull requests

3 participants