From 5b4d54ee5be3166b662acd6fa0231c9851069e99 Mon Sep 17 00:00:00 2001 From: Flavio Percoco Date: Thu, 17 Apr 2014 22:02:16 +0200 Subject: [PATCH] Specialize kinds inference for `Unsafe` This patch adds a special rule for `Unsafe` and makes it `Share` regardless of whether T is `Share`. [breaking-change] Closes #13125 --- src/librustc/middle/ty.rs | 4 +- .../typeck-unsafe-always-share.rs | 43 +++++++++++++++++++ 2 files changed, 46 insertions(+), 1 deletion(-) create mode 100644 src/test/compile-fail/typeck-unsafe-always-share.rs diff --git a/src/librustc/middle/ty.rs b/src/librustc/middle/ty.rs index 037182d8b7b80..3428ee96c7310 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 0000000000000..6dec86ddf622f --- /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` +}