Open
Description
Given the following code:
use std::cell::RefCell;
use std::io::Read;
fn main() {
let foo: &[u8] = &[0, 1];
inner(foo);
}
fn inner(mut foo: &[u8]) {
//let mut foo: &[u8] = &[0, 1]; // uncommenting this line gives an improved error message
let refcell = RefCell::new(&mut foo);
let read = &refcell as &RefCell<dyn Read>;
read_thing(read);
}
fn read_thing(refcell: &RefCell<dyn Read>) {
}
The current output is:
Compiling foo_rust v0.1.0 (/home/rukai/Foo/foo_rust)
error[E0621]: explicit lifetime required in the type of `foo`
--> src/main.rs:14:16
|
14 | read_thing(read);
| ^^^^ lifetime `'static` required
Ideally the output should look like:
error[E0621]: explicit lifetime required in the type of `foo`
--> $DIR/issue-90600.rs:10:16
|
LL | fn inner(mut foo: &[u8]) {
| ----- the type of `foo` does not have lifetime `'static'`
...
|
LL | let refcell = RefCell::new(&mut foo);
| ---------------------- the type of `refcell` takes the lifetime of type of `foo` here
...
LL | read_thing(read);
| ^^^^ lifetime `'static` required
Problem occurs on both latest stable and latest nightly. (1.56 and 2021-11-04}