1
Fork 0

Fix span for closure return type when annotated.

This commit 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.
This commit is contained in:
David Wood 2019-02-05 09:03:39 +01:00
parent 8ae730a442
commit b377d0b14c
No known key found for this signature in database
GPG key ID: 01760B4F9F53F154
3 changed files with 39 additions and 2 deletions

View file

@ -681,10 +681,13 @@ impl<'tcx> RegionInferenceContext<'tcx> {
let (return_span, mir_description) = match tcx.hir().get(mir_node_id) {
hir::Node::Expr(hir::Expr {
node: hir::ExprKind::Closure(_, _, _, span, gen_move),
node: hir::ExprKind::Closure(_, return_ty, _, span, gen_move),
..
}) => (
tcx.sess.source_map().end_point(*span),
match return_ty.output {
hir::FunctionRetTy::DefaultReturn(_) => tcx.sess.source_map().end_point(*span),
hir::FunctionRetTy::Return(_) => return_ty.output.span(),
},
if gen_move.is_some() {
" of generator"
} else {

View file

@ -0,0 +1,14 @@
#![allow(warnings)]
#![feature(nll)]
fn main() {
let i = &3;
let f = |x: &i32| -> &i32 { x };
//~^ ERROR lifetime may not live long enough
let j = f(i);
let g = |x: &i32| { x };
//~^ ERROR lifetime may not live long enough
let k = g(i);
}

View file

@ -0,0 +1,20 @@
error: lifetime may not live long enough
--> $DIR/issue-58053.rs:7:33
|
LL | 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`
error: lifetime may not live long enough
--> $DIR/issue-58053.rs:11:25
|
LL | let g = |x: &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`
error: aborting due to 2 previous errors