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

A trait with a non-member function gives inconsistent and buggy results. #18570

Closed
paholg opened this issue Nov 3, 2014 · 2 comments
Closed

Comments

@paholg
Copy link

paholg commented Nov 3, 2014

Rust version (this is on Arch):

$ rustc --version=verbose
rustc 0.13.0-nightly (b87619e27 2014-11-02 23:27:10 +0000)
binary: rustc
commit-hash: b87619e2744a64da38996c1a618dc28db746848b
commit-date: 2014-11-02 23:27:10 +0000
host: x86_64-unknown-linux-gnu
release: 0.13.0-nightly

This code

trait SomeTrait {
    fn fun();
}
struct A;
impl SomeTrait for A {
    fn fun() { println!("Hello!"); }
}
fn main() {
    let mut v: Vec<Box<SomeTrait>> = Vec::new();
    v.push(box A);
}

produces the following compiler panic:

$ cargo run --verbose
   Compiling test v0.0.1 (file:///home/paho/projects/test)
     Running `rustc /home/paho/projects/test/src/main.rs --crate-name test --crate-type bin -g --out-dir /home/paho/projects/test/target --dep-info /home/paho/projects/test/target/.fingerprint/test-7768c6b1caa470a0/dep-bin-test -L /home/paho/projects/test/target -L /home/paho/projects/test/target/deps`
error: internal compiler error: unexpected panic
note: the compiler unexpectedly panicked. this is a bug.
note: we would appreciate a bug report: http://doc.rust-lang.org/complement-bugreport.html
note: run with `RUST_BACKTRACE=1` for a backtrace
task 'rustc' panicked at 'assertion failed: *start <= *end', /home/rustbuild/src/rust-buildbot/slave/nightly-linux/build/src/libcore/slice.rs:421


Could not compile `test`.

Caused by:
  Process didn't exit successfully: `rustc /home/paho/projects/test/src/main.rs --crate-name test --crate-type bin -g --out-dir /home/paho/projects/test/target --dep-info /home/paho/projects/test/target/.fingerprint/test-7768c6b1caa470a0/dep-bin-test -L /home/paho/projects/test/target -L /home/paho/projects/test/target/deps` (status=101)
FAIL: 101

In addition, trying to call A::fun() results in the compiler failing to find module A. Calling SomeTrait::fun() does not throw an error, and the print command is executed. However, if a second struct is defined also implementing SomeTrait, then SomeTrait::fun() throws an error as it is unable to infer enough type information. I am unable, then, to find a way to run either struct's version of fun().

I would guess that traits just shouldn't be allowed non-member functions and trying to define them should throw an error.

@strega-nil
Copy link
Contributor

I'm having exactly the same problem.

@sfackler
Copy link
Member

sfackler commented Nov 4, 2014

Dup of #18490

@sfackler sfackler closed this as completed Nov 4, 2014
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants