Skip to content

Confusing error: 'method read has 1 parameters' #5925

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

Closed
brson opened this issue Apr 18, 2013 · 5 comments
Closed

Confusing error: 'method read has 1 parameters' #5925

brson opened this issue Apr 18, 2013 · 5 comments
Labels
A-diagnostics Area: Messages for errors, warnings, and lints E-easy Call for participation: Easy difficulty. Experience needed to fix: Not much. Good first issue.

Comments

@brson
Copy link
Contributor

brson commented Apr 18, 2013

I am trying to implement my own trait called Reader, but I accidentally had a different Reader trait in scope.

/home/brian/dev/rust/src/libcore/rt/io/comm_adapters.rs:20:4: 20:67 error: method `read` has 1 parameters 
but the trait has 2
/home/brian/dev/rust/src/libcore/rt/io/comm_adapters.rs:20     fn read(&mut self, _buf: &mut [u8]) -> Option<uint> { fail!() }
                                                               ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

It took some time to figure out that rustc and I were looking at different traits. It could tell me the path to the trait it is trying to match. Even better, it could tell me about alternate traits with the same name.

@Xazax-hun
Copy link
Contributor

The following code is working:

fn main() {
let x = 5;
let x = 6;
println(fmt!("%?",x));
}

Apparently the second x creates a new variable that hides the first x that is in the same scope. Is it intentional?
It looks like Rust does not seems to handle name collosions and in my opinion this can be the source of several errors.

@jdm
Copy link
Contributor

jdm commented May 29, 2013

@Xazax-hun, that's intentional behaviour, and unrelated to the original issue report.

@alexcrichton
Copy link
Member

Here's a small code sample which exhibits this behavior:

use a::Reader;
use b::Reader;

mod a {
    pub trait Reader {
        fn foo(int);
    }
}

mod b {
    pub trait Reader {
        fn foo(int, int);
    }
}

struct A;

impl Reader for A {
    fn foo(_: int) {}
}

fn main() {
}

with the error

foo.rs:19:4: 19:21 error: method `foo` has 1 parameter but the trait has 2
foo.rs:19     fn foo(_: int) {}
              ^~~~~~~~~~~~~~~~~
error: aborting due to previous error

@jaeminMoon
Copy link
Contributor

I think, is it intentional?
first Reader(mod a) is removed by second Reader(mod b).

use b::Reader;
use a::Reader;

If you change code, it will be done.

@sanxiyn
Copy link
Member

sanxiyn commented Oct 24, 2013

The bug is about improving the error message. For example, instead of saying the trait, the error message could say the trait b::Reader``.

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 E-easy Call for participation: Easy difficulty. Experience needed to fix: Not much. Good first issue.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

7 participants