diff options
| author | Flavio Percoco <flaper87@gmail.com> | 2014-04-17 22:02:16 +0200 |
|---|---|---|
| committer | Flavio Percoco <flaper87@gmail.com> | 2014-04-22 14:18:36 +0200 |
| commit | 5b4d54ee5be3166b662acd6fa0231c9851069e99 (patch) | |
| tree | 3ddbd6e84d70d8e27c76abf41a288b27d63c4c87 | |
| parent | ef1b929b2f732f96d6f9357467cf7b45b85c5413 (diff) | |
Specialize kinds inference for `Unsafe<T>`
This patch adds a special rule for `Unsafe<T>` and makes it `Share` regardless of whether T is `Share`. [breaking-change] Closes #13125
| -rw-r--r-- | src/librustc/middle/ty.rs | 4 | ||||
| -rw-r--r-- | src/test/compile-fail/typeck-unsafe-always-share.rs | 43 |
2 files changed, 46 insertions, 1 deletions
diff --git a/src/librustc/middle/ty.rs b/src/librustc/middle/ty.rs index 037182d8b7b..3428ee96c73 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 <LICENSE-APACHE or +// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license +// <LICENSE-MIT or http://opensource.org/licenses/MIT>, 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<T> { + u: Unsafe<T> +} + +struct NoShare { + m: marker::NoShare +} + +fn test<T: Share>(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` +} |
