Skip to content

Commit 7730310

Browse files
committed
auto merge of #13583 : FlaPer87/rust/special-unsafe, r=nikomatsakis
This patch adds a special rule for `Unsafe<T>` and makes it `Share` regardless of whether T is `Share`. [breaking-change] Closes #13125 cc @nikomatsakis
2 parents c46c760 + 5b4d54e commit 7730310

File tree

2 files changed

+46
-1
lines changed

2 files changed

+46
-1
lines changed

src/librustc/middle/ty.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2214,7 +2214,9 @@ pub fn type_contents(cx: &ctxt, ty: t) -> TypeContents {
22142214
} else if Some(did) == cx.lang_items.no_share_bound() {
22152215
tc | TC::ReachesNoShare
22162216
} else if Some(did) == cx.lang_items.unsafe_type() {
2217-
tc | TC::InteriorUnsafe
2217+
// FIXME(#13231): This shouldn't be needed after
2218+
// opt-in built-in bounds are implemented.
2219+
(tc | TC::InteriorUnsafe) - TC::Nonsharable
22182220
} else {
22192221
tc
22202222
}
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
// Copyright 2014 The Rust Project Developers. See the COPYRIGHT
2+
// file at the top-level directory of this distribution and at
3+
// http://rust-lang.org/COPYRIGHT.
4+
//
5+
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6+
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7+
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8+
// option. This file may not be copied, modified, or distributed
9+
// except according to those terms.
10+
11+
// Verify that Unsafe is *always* share regardles `T` is share.
12+
13+
// ignore-tidy-linelength
14+
15+
use std::ty::Unsafe;
16+
use std::kinds::marker;
17+
18+
struct MyShare<T> {
19+
u: Unsafe<T>
20+
}
21+
22+
struct NoShare {
23+
m: marker::NoShare
24+
}
25+
26+
fn test<T: Share>(s: T){
27+
28+
}
29+
30+
fn main() {
31+
let us = Unsafe::new(MyShare{u: Unsafe::new(0)});
32+
test(us);
33+
34+
let uns = Unsafe::new(NoShare{m: marker::NoShare});
35+
test(uns);
36+
37+
let ms = MyShare{u: uns};
38+
test(ms);
39+
40+
let ns = NoShare{m: marker::NoShare};
41+
test(ns);
42+
//~^ ERROR instantiating a type parameter with an incompatible type `NoShare`, which does not fulfill `Share`
43+
}

0 commit comments

Comments
 (0)