Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
eefriedman opened this issue Jun 13, 2015 · 5 comments · Fixed by #127871
Closed

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

eefriedman opened this issue Jun 13, 2015 · 5 comments · Fixed by #127871
Labels
A-typesystem Area: The type system C-enhancement Category: An issue proposing an enhancement or a PR with one. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@eefriedman
Copy link
Contributor

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); }
@arielb1
Copy link
Contributor

arielb1 commented Jun 13, 2015

These are called "non-regular ADT-s" and are not supported (you should get an overflow complaint). We shouldn't stack-overflow through.

@arielb1
Copy link
Contributor

arielb1 commented Jun 13, 2015

Your second example somehow survived type checking wow (you really shouldn't have gone that far). I guess we stopped using type_contents for pretty much anything.

I think we should add an actual check for this somewhere (althrough it won't prevent examples using associated types, which can strike in trans, but we should have a limit for that).

@steveklabnik steveklabnik added the A-typesystem Area: The type system label Jun 15, 2015
@steveklabnik
Copy link
Member

Triage: no change

@Mark-Simulacrum Mark-Simulacrum added the C-enhancement Category: An issue proposing an enhancement or a PR with one. label Jul 22, 2017
@leoyvens
Copy link
Contributor

leoyvens commented Jun 1, 2018

Triage: Examples 2 now compiles, but if you try to use takefoo then the same error as the third example happens.

@Spoonbender
Copy link

Triage: no change from latest check

@Noratrieb Noratrieb added the T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. label Apr 5, 2023
@bors bors closed this as completed in 65de5d0 Jul 19, 2024
rust-timer added a commit to rust-lang-ci/rust that referenced this issue Jul 19, 2024
Rollup merge of rust-lang#127871 - compiler-errors:recursive, r=estebank

Mention that type parameters are used recursively on bivariance error

Right now when a type parameter is used recursively, even with indirection (so it has a finite size) we say that the type parameter is unused:

```
struct B<T>(Box<B<T>>);
```

This is confusing, because the type parameter is *used*, it just doesn't have its variance constrained. This PR tweaks that message to mention that it must be used *non-recursively*.

Not sure if we should actually mention "variance" here, but also I'd somewhat prefer we don't keep the power users in the dark w.r.t the real underlying issue, which is that the variance isn't constrained. That technical detail is reserved for a note, though.

cc `@fee1-dead`

Fixes rust-lang#118976
Fixes rust-lang#26283
Fixes rust-lang#53191
Fixes rust-lang#105740
Fixes rust-lang#110466
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-typesystem Area: The type system C-enhancement Category: An issue proposing an enhancement or a PR with one. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

7 participants