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

Unused trait parameter error recommends deprecated PhantomFn #24164

Closed
lilyball opened this issue Apr 7, 2015 · 3 comments
Closed

Unused trait parameter error recommends deprecated PhantomFn #24164

lilyball opened this issue Apr 7, 2015 · 3 comments
Labels
A-typesystem Area: The type system

Comments

@lilyball
Copy link
Contributor

lilyball commented Apr 7, 2015

The error message for a trait with an unused parameter recommends the use of PhantomFn even though it's deprecated. It should presumably recommend PhantomData instead, and the documentation on PhantomData should be updated to include an example of how to use it with a trait.

Example (play):

trait Foo<T> {
    fn foo(&self);
}

yields

<anon>:1:11: 1:12 error: parameter `T` is never used
<anon>:1 trait Foo<T> {
                   ^
<anon>:1:12: 1:12 help: consider removing `T` or using a marker such as `core::marker::PhantomFn`
error: aborting due to previous error

You also get the same error today (suggesting PhantomFn) when using a "marker-like" trait with no functions, which is filed as #22598 (it needs a better error message).

@lilyball
Copy link
Contributor Author

lilyball commented Apr 7, 2015

I admit to being slightly confused as to why PhantomFn and MarkerTrait are deprecated. This happened in #23938 (Remove variances from traits and deprecate PhantomFn/MarkerTrait). But MarkerTrait is still used as the super trait of the other markers (Send, Sized, and Reflect).

As near as I can tell, without using either of these two deprecated traits, the only way to declare a marker-like trait (e.g. one that doesn't use Self) is to use an associated type with PhantomData, e.g.

trait Foo {
    type _phantom = PhantomData<Self>;
}

And it's not even clear if this is "correct". #23938 says that traits no longer have variance, so I guess it's ok? But I don't actually know.

/cc @nikomatsakis

@apasel422
Copy link
Contributor

What version of rustc are you using? The following compiles successfully with rustc 1.0.0-nightly (083b8a404 2015-04-05) (built 2015-04-05)

trait Foo<T> {
    fn foo(&self);
}

fn main() {}

@steveklabnik steveklabnik added the A-typesystem Area: The type system label Apr 7, 2015
@lilyball
Copy link
Contributor Author

lilyball commented Apr 7, 2015

Huh, you're right. I apparently had the beta on my system (it seems rustup.sh started installing that by default), and I'm not sure what version play.rust-lang.org is using right now (Edit: I'm told it's also on the beta).

Anyway, it seems PhantomFn stopped being recommended as of #23938.

@lilyball lilyball closed this as completed Apr 7, 2015
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
Projects
None yet
Development

No branches or pull requests

3 participants