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

Trait object (e.g. impl Any) inherent methods can't be used in another crate #19056

Closed
japaric opened this issue Nov 18, 2014 · 3 comments · Fixed by #20385
Closed

Trait object (e.g. impl Any) inherent methods can't be used in another crate #19056

japaric opened this issue Nov 18, 2014 · 3 comments · Fixed by #20385
Assignees

Comments

@japaric
Copy link
Member

japaric commented Nov 18, 2014

STR

// any.rs
pub trait Any: 'static {}

impl<T> Any for T where T: 'static {}

impl Any {
    pub fn is<T: 'static>(&self) -> bool { true }
}

#[test]
fn is() {
    let b: Box<bool> = box true;
    let a: Box<Any> = b as Box<Any>;
    assert!(a.is::<bool>());

    let b: &bool = &true;
    let a: &Any = b as &Any;
    assert!(a.is::<bool>());
}
// app.rs
extern crate any;

use any::Any;

fn main() {
    let b: Box<bool> = box true;
    let a: Box<Any> = b as Box<Any>;
    assert!(a.is::<bool>());

    let b: &bool = &true;
    let a: &Any = b as &Any;
    assert!(a.is::<bool>());
}
$ rustc --test any.rs && ./any
running 1 test
test is ... ok

test result: ok. 1 passed; 0 failed; 0 ignored; 0 measured
$ rustc --crate-type=lib any.rs && rustc -L . app.rs
app.rs:9:15: 9:27 error: type `Box<any::Any+'static>` does not implement any method in scope named `is`
app.rs:9     assert!(a.is::<bool>());
                       ^~~~~~~~~~~~
app.rs:13:15: 13:27 error: type `&any::Any+'static` does not implement any method in scope named `is`
app.rs:13     assert!(a.is::<bool>());
                        ^~~~~~~~~~~~
error: aborting due to 2 previous errors

Version

88c743d


cc @nick29581

@reem
Copy link
Contributor

reem commented Dec 27, 2014

This is breaking rust-error and clients (including Iron) because of important inherent implementations on the Error trait object.

@s-panferov
Copy link

Is this hard to fix? It blocks entire https://github.com/rustless/rustless without workarounds.

@nrc
Copy link
Member

nrc commented Dec 30, 2014

I can probably look at this today

@nrc nrc self-assigned this Dec 30, 2014
nrc added a commit to nrc/rust that referenced this issue Jan 1, 2015
alexcrichton added a commit to alexcrichton/rust that referenced this issue Jan 2, 2015
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

Successfully merging a pull request may close this issue.

4 participants