diff --git a/src/librustc/middle/ty.rs b/src/librustc/middle/ty.rs index 7745b0cc08f..cdd6ced427e 100644 --- a/src/librustc/middle/ty.rs +++ b/src/librustc/middle/ty.rs @@ -2214,7 +2214,9 @@ pub fn type_contents(cx: &ctxt, ty: t) -> TypeContents { } else if Some(did) == cx.lang_items.no_share_bound() { tc | TC::ReachesNoShare } else if Some(did) == cx.lang_items.unsafe_type() { - tc | TC::InteriorUnsafe + // FIXME(#13231): This shouldn't be needed after + // opt-in built-in bounds are implemented. + (tc | TC::InteriorUnsafe) - TC::Nonsharable } else { tc } diff --git a/src/test/compile-fail/typeck-unsafe-always-share.rs b/src/test/compile-fail/typeck-unsafe-always-share.rs new file mode 100644 index 00000000000..6dec86ddf62 --- /dev/null +++ b/src/test/compile-fail/typeck-unsafe-always-share.rs @@ -0,0 +1,43 @@ +// Copyright 2014 The Rust Project Developers. See the COPYRIGHT +// file at the top-level directory of this distribution and at +// http://rust-lang.org/COPYRIGHT. +// +// Licensed under the Apache License, Version 2.0 or the MIT license +// , at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. + +// Verify that Unsafe is *always* share regardles `T` is share. + +// ignore-tidy-linelength + +use std::ty::Unsafe; +use std::kinds::marker; + +struct MyShare { + u: Unsafe +} + +struct NoShare { + m: marker::NoShare +} + +fn test(s: T){ + +} + +fn main() { + let us = Unsafe::new(MyShare{u: Unsafe::new(0)}); + test(us); + + let uns = Unsafe::new(NoShare{m: marker::NoShare}); + test(uns); + + let ms = MyShare{u: uns}; + test(ms); + + let ns = NoShare{m: marker::NoShare}; + test(ns); + //~^ ERROR instantiating a type parameter with an incompatible type `NoShare`, which does not fulfill `Share` +}