Skip to content

Commit

Permalink
fix(rustup): rustc 1.0.0-nightly (ea8b82e90)
Browse files Browse the repository at this point in the history
This commit fixes `cargo build` and `cargo test`.

Method lookup on traits seems to have changed to force
`impl TraitName` expressions to be more specific. That means that
`method` will not be found anymore on an object of type `&Trait+Send`,
unless you provide an `impl Trait+Send`.

Now `NetworkStream` and `HeaderFormat` trait implementations
are done against `* + Send`, which helps the compiler to find the
respective `downcast*` method implementations once again.
  • Loading branch information
Byron committed Mar 20, 2015
1 parent 1f0bc95 commit 8181de2
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 7 deletions.
2 changes: 1 addition & 1 deletion src/header/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ impl<T: HeaderFormat + Send + Sync + Clone> HeaderClone for T {
}
}

impl HeaderFormat {
impl HeaderFormat + Send + Sync {
#[inline]
unsafe fn downcast_ref_unchecked<T: 'static>(&self) -> &T {
mem::transmute(mem::transmute::<&HeaderFormat, raw::TraitObject>(self).data)
Expand Down
12 changes: 6 additions & 6 deletions src/net.rs
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ impl Clone for Box<NetworkStream + Send> {
fn clone(&self) -> Box<NetworkStream + Send> { self.clone_box() }
}

impl NetworkStream {
impl NetworkStream + Send {
unsafe fn downcast_ref_unchecked<T: 'static>(&self) -> &T {
mem::transmute(mem::transmute::<&NetworkStream,
raw::TraitObject>(self).data)
Expand All @@ -108,13 +108,13 @@ impl NetworkStream {
raw::TraitObject>(self).data)
}

unsafe fn downcast_unchecked<T: 'static>(self: Box<NetworkStream>) -> Box<T> {
mem::transmute(mem::transmute::<Box<NetworkStream>,
unsafe fn downcast_unchecked<T: 'static>(self: Box<NetworkStream + Send>) -> Box<T> {
mem::transmute(mem::transmute::<Box<NetworkStream + Send>,
raw::TraitObject>(self).data)
}
}

impl NetworkStream {
impl NetworkStream + Send {
/// Is the underlying type in this trait object a T?
#[inline]
pub fn is<T: 'static>(&self) -> bool {
Expand Down Expand Up @@ -143,8 +143,8 @@ impl NetworkStream {
}

/// If the underlying type is T, extract it.
pub fn downcast<T: 'static>(self: Box<NetworkStream>)
-> Result<Box<T>, Box<NetworkStream>> {
pub fn downcast<T: 'static>(self: Box<NetworkStream + Send>)
-> Result<Box<T>, Box<NetworkStream + Send>> {
if self.is::<T>() {
Ok(unsafe { self.downcast_unchecked() })
} else {
Expand Down

0 comments on commit 8181de2

Please sign in to comment.