Skip to content

Guarantee comm primitives are not Freeze #11111

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Dec 23, 2013
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions src/libstd/comm/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -292,6 +292,7 @@ impl<T: Send> Consumer<T>{

/// The receiving-half of Rust's channel type. This half can only be owned by
/// one task
#[no_freeze] // can't share ports in an arc
pub struct Port<T> {
priv queue: Consumer<T>,
}
Expand All @@ -305,12 +306,15 @@ pub struct PortIterator<'a, T> {

/// The sending-half of Rust's channel type. This half can only be owned by one
/// task
#[no_freeze] // can't share chans in an arc
pub struct Chan<T> {
priv queue: spsc::Producer<T, Packet>,
}

/// The sending-half of Rust's channel type. This half can be shared among many
/// tasks by creating copies of itself through the `clone` method.
#[no_freeze] // technically this implementation is shareable, but it shouldn't
// be required to be shareable in an arc
pub struct SharedChan<T> {
priv queue: mpsc::Producer<T, Packet>,
}
Expand Down
17 changes: 17 additions & 0 deletions src/test/compile-fail/comm-not-freeze.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
// Copyright 2013 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.

fn test<T: Freeze>() {}

fn main() {
test::<Chan<int>>(); //~ ERROR: does not fulfill `Freeze`
test::<Port<int>>(); //~ ERROR: does not fulfill `Freeze`
test::<SharedChan<int>>(); //~ ERROR: does not fulfill `Freeze`
}