Skip to content

"parameter T is never used" with recursive type #26283

Closed
@eefriedman

Description

@eefriedman

Testcase:

enum Foo<T> {
    F(Option<Box<Foo<Box<T>>>>)
}
fn main() { }

Gives:

<anon>:16:10: 16:11 error: parameter `T` is never used [E0392]
<anon>:16 enum Foo<T> {
                   ^
<anon>:16:10: 16:11 help: consider removing `T` or using a marker such as `core::marker::PhantomData`

Not sure if this is really something rustc should actually support (I imagine trying to prove recursive properties about it is extremely awkward), but the error message makes no sense.

More related testcases:

// Crashes rustc with a stack overflow
use std::marker::PhantomData;
enum Foo<T> {
    F(Option<Box<Foo<Box<T>>>>, PhantomData<T>)
}
fn takesfoo<T>(f:&Foo<T>) {
    match f {
        &Foo::F(Some(ref b), PhantomData) => takesfoo(&**b),
        &Foo::F(None, PhantomData) => ()
    }
}
fn main() { }
// Gives "error: overflow while adding drop-check rules for Foo<i32>"
use std::marker::PhantomData;
enum Foo<T> {
    F(Option<Box<Foo<Box<T>>>>, PhantomData<T>)
}
fn main() { let _f = Foo::F::<i32>(None, PhantomData); }

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-type-systemArea: Type systemC-enhancementCategory: An issue proposing an enhancement or a PR with one.T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions