Skip to content

Commit 8a32ee7

Browse files
committedMar 12, 2014
auto merge of #12774 : alexcrichton/rust/proc-bounds, r=pcwalton
This is needed to make progress on #10296 as the default bounds will no longer include Send. I believe that this was the originally intended syntax for procs, and it just hasn't been necessary up until now.
2 parents 0aa3b88 + 7b4ee5c commit 8a32ee7

File tree

3 files changed

+62
-1
lines changed

3 files changed

+62
-1
lines changed
 

‎src/libsyntax/parse/parser.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -893,13 +893,14 @@ impl Parser {
893893
// Parses a procedure type (`proc`). The initial `proc` keyword must
894894
// already have been parsed.
895895
pub fn parse_proc_type(&mut self) -> Ty_ {
896+
let bounds = self.parse_optional_ty_param_bounds();
896897
let (decl, lifetimes) = self.parse_ty_fn_decl(false);
897898
TyClosure(@ClosureTy {
898899
sigil: OwnedSigil,
899900
region: None,
900901
purity: ImpureFn,
901902
onceness: Once,
902-
bounds: None,
903+
bounds: bounds,
903904
decl: decl,
904905
lifetimes: lifetimes,
905906
})

‎src/test/compile-fail/proc-bounds.rs

+25
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
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+
fn is_send<T: Send>() {}
12+
fn is_freeze<T: Freeze>() {}
13+
fn is_static<T: 'static>() {}
14+
15+
fn main() {
16+
is_send::<proc:()>();
17+
//~^ ERROR: instantiating a type parameter with an incompatible type
18+
19+
is_freeze::<proc:()>();
20+
//~^ ERROR: instantiating a type parameter with an incompatible type
21+
22+
is_static::<proc:()>();
23+
//~^ ERROR: instantiating a type parameter with an incompatible type
24+
}
25+

‎src/test/run-pass/proc-bounds.rs

+35
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
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+
fn foo<T>() {}
12+
fn bar<T>(_: T) {}
13+
14+
fn is_send<T: Send>() {}
15+
fn is_freeze<T: Freeze>() {}
16+
fn is_static<T: 'static>() {}
17+
18+
pub fn main() {
19+
foo::<proc()>();
20+
foo::<proc:()>();
21+
foo::<proc:Send()>();
22+
foo::<proc:Send + Freeze()>();
23+
foo::<proc:'static + Send + Freeze()>();
24+
25+
is_send::<proc:Send()>();
26+
is_freeze::<proc:Freeze()>();
27+
is_static::<proc:'static()>();
28+
29+
30+
let a = 3;
31+
bar::<proc:()>(proc() {
32+
let b = &a;
33+
println!("{}", *b);
34+
});
35+
}

0 commit comments

Comments
 (0)
Please sign in to comment.