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

spurious "error: parameter Self is never used" for trivial trait T {}` #22598

Closed
cjsut opened this issue Feb 20, 2015 · 12 comments
Closed

spurious "error: parameter Self is never used" for trivial trait T {}` #22598

cjsut opened this issue Feb 20, 2015 · 12 comments
Labels
A-diagnostics Area: Messages for errors, warnings, and lints A-trait-system Area: Trait system

Comments

@cjsut
Copy link
Contributor

cjsut commented Feb 20, 2015

Given the input

trait T {}

rustc will complain:

<anon>:2:1: 2:11 error: parameter `Self` is never used
<anon>:2 trait T {}
         ^~~~~~~~~~
<anon>:2:1: 2:11 help: consider removing `Self` or using a marker such as `core::marker::PhantomFn`
<anon>:2 trait T {}
         ^~~~~~~~~~

This may just be a diagnostics issue, but I'll let someone more familiar with Rust make that judgement.

@cjsut cjsut changed the title spurious "error: parameter Self is never used for trivial trait T {}` spurious "error: parameter Self is never used" for trivial trait T {}` Feb 20, 2015
@alexcrichton
Copy link
Member

This is actually intended due to a recently merged RFC.

You can find some more info about this in the RFC as well.

@cjsut
Copy link
Contributor Author

cjsut commented Feb 20, 2015

This is still a diagnostics error. There is no parameter Self, so the error should explain why it thinks there is one.
As the RFC says,

The goal is to help users as concretely as possible.

The current error message is confusing and misleading. This does not help users.

@huonw huonw reopened this Feb 20, 2015
@huonw huonw added A-diagnostics Area: Messages for errors, warnings, and lints A-trait-system Area: Trait system labels Feb 20, 2015
@huonw
Copy link
Member

huonw commented Feb 20, 2015

Reopening to cover the error message.

@bluss
Copy link
Member

bluss commented Feb 22, 2015

I've had a useful trait stop working with this error:

pub trait Graphlike {
    type NodeId: Clone;
}
error: parameter `Self` is never used

Another example:

/// A graph's edge type determines whether is has directed edges or not.
pub trait EdgeType {
    fn is_directed() -> bool;
}

impl EdgeType for Directed {
    #[inline]
    fn is_directed() -> bool { true }
}

impl EdgeType for Undirected {
    #[inline]
    fn is_directed() -> bool { false }
}

@cjsut
Copy link
Contributor Author

cjsut commented Feb 22, 2015

@bluss, read the RFC linked by alexcrichton: you need to use PhantomFn.

@shepmaster
Copy link
Member

or better (from the docs):

use std::marker::MarkerTrait;
trait Graphlike : MarkerTrait { }

@apasel422
Copy link
Contributor

This can be closed, as the original example now compiles without error.

@cjsut
Copy link
Contributor Author

cjsut commented Apr 8, 2015

@apasel422 The playpen linked in the original post does not compile.

I still think that the suggestion to "consider removing Self" is completely bogus and confusing.

@cjsut cjsut closed this as completed Apr 8, 2015
@bluss
Copy link
Member

bluss commented Apr 8, 2015

It should compile in the nightly, even if playpen doesn't have that version. PhantomFn was deprecated after beta.

@cjsut
Copy link
Contributor Author

cjsut commented Apr 10, 2015

Huh, did I accidentally close this one?

@cjsut cjsut reopened this Apr 10, 2015
@apasel422
Copy link
Contributor

The issue no longer exists in the nightly builds.

On Thursday, April 9, 2015, Collin J. Sutton notifications@github.com
wrote:

Huh, did I accidentally close this one?


Reply to this email directly or view it on GitHub
#22598 (comment).

@cjsut
Copy link
Contributor Author

cjsut commented Apr 10, 2015

Oh! When did Playpen change the default version to "beta"? But now there's a different error...
Re-closing, in any case. :)

@cjsut cjsut closed this as completed Apr 10, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-diagnostics Area: Messages for errors, warnings, and lints A-trait-system Area: Trait system
Projects
None yet
Development

No branches or pull requests

6 participants