Closed
Description
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
cc @nick29581
Metadata
Metadata
Assignees
Labels
No labels