Closed
Description
fn invoke<'a, F>(x: &'a i32, f: F) -> &'a i32
where F: FnOnce(&'a i32, &i32) -> &'a i32
{
let y = 22;
f(x, &y)
}
fn foo<'a>(x: &'a i32) {
invoke(&x, |a, b| if a > b { a } else { b }); //~ ERROR E0495
}
This UI test was moved to compile-fail as the finer details of the error seemed to vary on different machines.
Following are the Logs
[01:35:31] failures:
[01:35:31]
[01:35:31] ---- [ui] ui/lifetime-errors/ex1-return-one-existing-name-if-else-using-closure.rs stdout ----
[01:35:31] ui: /checkout/src/test/ui/lifetime-errors/ex1-return-one-existing-name-if-else-using-closure.rs
[01:35:31] normalized stderr:
[01:35:31] error[E0495]: cannot infer an appropriate lifetime for lifetime parameter `'a` due to conflicting requirements
[01:35:31] --> $DIR/ex1-return-one-existing-name-if-else-using-closure.rs:19:5
[01:35:31] |
[01:35:31] 19 | invoke(&x, |a, b| if a > b { a } else { b });
[01:35:31] | ^^^^^^
[01:35:31] |
[01:35:31] note: first, the lifetime cannot outlive the anonymous lifetime #2 defined on the body at 19:16...
[01:35:31] --> $DIR/ex1-return-one-existing-name-if-else-using-closure.rs:19:16
[01:35:31] |
[01:35:31] 19 | invoke(&x, |a, b| if a > b { a } else { b });
[01:35:31] | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
[01:35:31] note: ...so that reference does not outlive borrowed content
[01:35:31] --> $DIR/ex1-return-one-existing-name-if-else-using-closure.rs:19:45
[01:35:31] |
[01:35:31] 19 | invoke(&x, |a, b| if a > b { a } else { b });
[01:35:31] | ^
[01:35:31] note: but, the lifetime must be valid for the call at 19:5...
[01:35:31] --> $DIR/ex1-return-one-existing-name-if-else-using-closure.rs:19:5
[01:35:31] |
[01:35:31] 19 | invoke(&x, |a, b| if a > b { a } else { b });
[01:35:31] | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
[01:35:31] note: ...so that argument is valid for the call
[01:35:31] --> $DIR/ex1-return-one-existing-name-if-else-using-closure.rs:19:12
[01:35:31] |
[01:35:31] 19 | invoke(&x, |a, b| if a > b { a } else { b });
[01:35:31] | ^^
[01:35:31]
[01:35:31] error: aborting due to previous error(s)
[01:35:31]
[01:35:31]
[01:35:31]
[01:35:31] expected stderr:
[01:35:31] error[E0495]: cannot infer an appropriate lifetime for lifetime parameter `'a` due to conflicting requirements
[01:35:31] --> $DIR/ex1-return-one-existing-name-if-else-using-closure.rs:19:5
[01:35:31] |
[01:35:31] 19 | invoke(&x, |a, b| if a > b { a } else { b });
[01:35:31] | ^^^^^^
[01:35:31] |
[01:35:31] note: first, the lifetime cannot outlive the anonymous lifetime #2 defined on the body at 19:16...
[01:35:31] --> $DIR/ex1-return-one-existing-name-if-else-using-closure.rs:19:16
[01:35:31] |
[01:35:31] 19 | invoke(&x, |a, b| if a > b { a } else { b });
[01:35:31] | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
[01:35:31] note: ...so that reference does not outlive borrowed content
[01:35:31] --> $DIR/ex1-return-one-existing-name-if-else-using-closure.rs:19:45
[01:35:31] |
[01:35:31] 19 | invoke(&x, |a, b| if a > b { a } else { b });
[01:35:31] | ^
[01:35:31] note: but, the lifetime must be valid for the expression at 19:5...
[01:35:31] --> $DIR/ex1-return-one-existing-name-if-else-using-closure.rs:19:5
[01:35:31] |
[01:35:31] 19 | invoke(&x, |a, b| if a > b { a } else { b });
[01:35:31] | ^^^^^^
[01:35:31] note: ...so that a type/lifetime parameter is in scope here
[01:35:31] --> $DIR/ex1-return-one-existing-name-if-else-using-closure.rs:19:5
[01:35:31] |
[01:35:31] 19 | invoke(&x, |a, b| if a > b { a } else { b });
[01:35:31] | ^^^^^^
[01:35:31]
[01:35:31] error: aborting due to previous error(s)
[01:35:31]
[01:35:31]
[01:35:31]
[01:35:31] diff of stderr:
[01:35:31]
[01:35:31] error[E0495]: cannot infer an appropriate lifetime for lifetime parameter `'a` due to conflicting requirements
[01:35:31] --> $DIR/ex1-return-one-existing-name-if-else-using-closure.rs:19:5
[01:35:31] |
[01:35:31] 19 | invoke(&x, |a, b| if a > b { a } else { b });
[01:35:31] | ^^^^^^
[01:35:31] |
[01:35:31] note: first, the lifetime cannot outlive the anonymous lifetime #2 defined on the body at 19:16...
[01:35:31] --> $DIR/ex1-return-one-existing-name-if-else-using-closure.rs:19:16
[01:35:31] |
[01:35:31] 19 | invoke(&x, |a, b| if a > b { a } else { b });
[01:35:31] | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
[01:35:31] note: ...so that reference does not outlive borrowed content
[01:35:31] --> $DIR/ex1-return-one-existing-name-if-else-using-closure.rs:19:45
[01:35:31] |
[01:35:31] 19 | invoke(&x, |a, b| if a > b { a } else { b });
[01:35:31] | ^
[01:35:31] -note: but, the lifetime must be valid for the expression at 19:5...
[01:35:31] +note: but, the lifetime must be valid for the call at 19:5...
[01:35:31] --> $DIR/ex1-return-one-existing-name-if-else-using-closure.rs:19:5
[01:35:31] |
[01:35:31] 19 | invoke(&x, |a, b| if a > b { a } else { b });
[01:35:31] - | ^^^^^^
[01:35:31] -note: ...so that a type/lifetime parameter is in scope here
[01:35:31] - --> $DIR/ex1-return-one-existing-name-if-else-using-closure.rs:19:5
[01:35:31] + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
[01:35:31] +note: ...so that argument is valid for the call
[01:35:31] + --> $DIR/ex1-return-one-existing-name-if-else-using-closure.rs:19:12
[01:35:31] |
[01:35:31] 19 | invoke(&x, |a, b| if a > b { a } else { b });
[01:35:31] - | ^^^^^^
[01:35:31] + | ^^
[01:35:31]
[01:35:31] error: aborting due to previous error(s)
Check here for more details