Closed
Description
When you have an unused lifetime (or type) parameter, it is a hard error. If you "use" that parameter by having a recursive type,
rustc
still notices that it's unused and gives the error. But if that recursion goes through Cell
(also works with RefCell
), the error is not emitted and the program works fine.
Maybe this should be a diagnostics issue, but I put this under bug since it causes programs to compile that shouldn't under the normal rules.
I tried this code:
use std::cell::Cell;
struct GivesAnError<'a> {
same: Box<GivesAnError<'a>>,
}
#[derive(Debug, Default)]
struct NoError<'a> {
same: Box<Cell<NoError<'a>>>,
}
I expected to see this happen:
E0392, because the lifetime is actually not used
Instead, this happened:
No error, and the program compiled
Meta
This happens on the latest nightly-2022-01-04
on the playground