Skip to content

Unused generic parameter E0392 not emitted in recursive type that is behind Cell  #92561

Closed
@Noratrieb

Description

@Noratrieb

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:

playground

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-varianceArea: Variance (https://doc.rust-lang.org/nomicon/subtyping.html)C-bugCategory: This is a bug.D-confusingDiagnostics: Confusing error or lint that should be reworked.D-incorrectDiagnostics: A diagnostic that is giving misleading or incorrect information.D-newcomer-roadblockDiagnostics: Confusing error or lint; hard to understand for new users.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions