Auto merge of #41624 - RalfJung:mutexguard-sync, r=alexcrichton
MutexGuard<T> may be Sync only if T is Sync Fixes #41622 This is a breaking change. Does that imply any further process? I am not sure whether I wrote that "compilation must fail"-test correctly, but at least it is passing here with the patch applied. Same for the `since = "1.18.0"`, I just picked it because I had to pick something.
This commit is contained in:
commit
0634f0a30f
2 changed files with 25 additions and 5 deletions
|
@ -10,7 +10,6 @@
|
||||||
|
|
||||||
use cell::UnsafeCell;
|
use cell::UnsafeCell;
|
||||||
use fmt;
|
use fmt;
|
||||||
use marker;
|
|
||||||
use mem;
|
use mem;
|
||||||
use ops::{Deref, DerefMut};
|
use ops::{Deref, DerefMut};
|
||||||
use ptr;
|
use ptr;
|
||||||
|
@ -153,7 +152,9 @@ pub struct MutexGuard<'a, T: ?Sized + 'a> {
|
||||||
}
|
}
|
||||||
|
|
||||||
#[stable(feature = "rust1", since = "1.0.0")]
|
#[stable(feature = "rust1", since = "1.0.0")]
|
||||||
impl<'a, T: ?Sized> !marker::Send for MutexGuard<'a, T> {}
|
impl<'a, T: ?Sized> !Send for MutexGuard<'a, T> { }
|
||||||
|
#[stable(feature = "mutexguard", since = "1.18.0")]
|
||||||
|
unsafe impl<'a, T: ?Sized + Sync> Sync for MutexGuard<'a, T> { }
|
||||||
|
|
||||||
impl<T> Mutex<T> {
|
impl<T> Mutex<T> {
|
||||||
/// Creates a new mutex in an unlocked state ready for use.
|
/// Creates a new mutex in an unlocked state ready for use.
|
||||||
|
@ -459,9 +460,6 @@ mod tests {
|
||||||
#[derive(Eq, PartialEq, Debug)]
|
#[derive(Eq, PartialEq, Debug)]
|
||||||
struct NonCopy(i32);
|
struct NonCopy(i32);
|
||||||
|
|
||||||
unsafe impl<T: Send> Send for Packet<T> {}
|
|
||||||
unsafe impl<T> Sync for Packet<T> {}
|
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn smoke() {
|
fn smoke() {
|
||||||
let m = Mutex::new(());
|
let m = Mutex::new(());
|
||||||
|
|
22
src/test/compile-fail/mutexguard-sync.rs
Normal file
22
src/test/compile-fail/mutexguard-sync.rs
Normal file
|
@ -0,0 +1,22 @@
|
||||||
|
// Copyright 2017 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.
|
||||||
|
|
||||||
|
// MutexGuard<Cell<i32>> must not be Sync, that would be unsound.
|
||||||
|
use std::sync::Mutex;
|
||||||
|
use std::cell::Cell;
|
||||||
|
|
||||||
|
fn test_sync<T: Sync>(_t: T) {}
|
||||||
|
|
||||||
|
fn main()
|
||||||
|
{
|
||||||
|
let m = Mutex::new(Cell::new(0i32));
|
||||||
|
let guard = m.lock().unwrap();
|
||||||
|
test_sync(guard); //~ ERROR the trait bound
|
||||||
|
}
|
Loading…
Add table
Add a link
Reference in a new issue