Skip to content

librustc: Separate the rest of the trait bounds with + and stop parsing space-separated ones. rs=plussing #5069

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

Closed
wants to merge 1 commit into from
Closed
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: 2 additions & 2 deletions doc/tutorial.md
Original file line number Diff line number Diff line change
Expand Up @@ -2072,12 +2072,12 @@ on values of type `T` inside the function. It will also cause a
compile-time error when anyone tries to call `print_all` on an array
whose element type does not have a `Printable` implementation.

Type parameters can have multiple bounds by separating them with spaces,
Type parameters can have multiple bounds by separating them with `+`,
as in this version of `print_all` that copies elements.

~~~
# trait Printable { fn print(&self); }
fn print_all<T: Printable Copy>(printable_things: ~[T]) {
fn print_all<T: Printable + Copy>(printable_things: ~[T]) {
let mut i = 0;
while i < printable_things.len() {
let copy_of_thing = printable_things[i];
Expand Down
4 changes: 2 additions & 2 deletions src/libcore/pipes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1213,8 +1213,8 @@ pub trait Select2<T:Owned,U:Owned> {

impl<T: Owned,
U: Owned,
Left: Selectable GenericPort<T>,
Right: Selectable GenericPort<U>>
Left: Selectable + GenericPort<T>,
Right: Selectable + GenericPort<U>>
Select2<T,U> for (Left, Right) {
fn select() -> Either<T, U> {
match self {
Expand Down
28 changes: 14 additions & 14 deletions src/librustc/middle/typeck/infer/lattice.rs
Original file line number Diff line number Diff line change
Expand Up @@ -72,8 +72,8 @@ pub impl LatticeValue for ty::t {
}

pub impl CombineFields {
fn var_sub_var<T:Copy InferStr LatticeValue,
V:Copy Eq ToStr Vid UnifyVid<Bounds<T>>>(
fn var_sub_var<T:Copy + InferStr + LatticeValue,
V:Copy + Eq + ToStr + Vid + UnifyVid<Bounds<T>>>(
&self,
+a_id: V,
+b_id: V) -> ures
Expand Down Expand Up @@ -125,8 +125,8 @@ pub impl CombineFields {
}

/// make variable a subtype of T
fn var_sub_t<T:Copy InferStr LatticeValue,
V:Copy Eq ToStr Vid UnifyVid<Bounds<T>>>(
fn var_sub_t<T:Copy + InferStr + LatticeValue,
V:Copy + Eq + ToStr + Vid + UnifyVid<Bounds<T>>>(
&self,
+a_id: V,
+b: T) -> ures
Expand All @@ -149,8 +149,8 @@ pub impl CombineFields {
a_id, a_bounds, b_bounds, node_a.rank)
}

fn t_sub_var<T:Copy InferStr LatticeValue,
V:Copy Eq ToStr Vid UnifyVid<Bounds<T>>>(
fn t_sub_var<T:Copy + InferStr + LatticeValue,
V:Copy + Eq + ToStr + Vid + UnifyVid<Bounds<T>>>(
&self,
+a: T,
+b_id: V) -> ures
Expand Down Expand Up @@ -201,8 +201,8 @@ pub impl CombineFields {
}
}

fn set_var_to_merged_bounds<T:Copy InferStr LatticeValue,
V:Copy Eq ToStr Vid UnifyVid<Bounds<T>>>(
fn set_var_to_merged_bounds<T:Copy + InferStr + LatticeValue,
V:Copy+Eq+ToStr+Vid+UnifyVid<Bounds<T>>>(
&self,
+v_id: V,
a: &Bounds<T>,
Expand Down Expand Up @@ -395,9 +395,9 @@ pub enum LatticeVarResult<V,T> {
* the variables and return the unified variable, in which case the
* result is a variable. This is indicated with a `VarResult`
* return. */
pub fn lattice_vars<L:LatticeDir Combine,
T:Copy InferStr LatticeValue,
V:Copy Eq ToStr Vid UnifyVid<Bounds<T>>>(
pub fn lattice_vars<L:LatticeDir + Combine,
T:Copy + InferStr + LatticeValue,
V:Copy + Eq + ToStr + Vid + UnifyVid<Bounds<T>>>(
self: &L, // defines whether we want LUB or GLB
+a_vid: V, // first variable
+b_vid: V, // second variable
Expand Down Expand Up @@ -441,9 +441,9 @@ pub fn lattice_vars<L:LatticeDir Combine,
}
}

pub fn lattice_var_and_t<L:LatticeDir Combine,
T:Copy InferStr LatticeValue,
V:Copy Eq ToStr Vid UnifyVid<Bounds<T>>>(
pub fn lattice_var_and_t<L:LatticeDir + Combine,
T:Copy + InferStr + LatticeValue,
V:Copy + Eq + ToStr + Vid + UnifyVid<Bounds<T>>>(
self: &L,
+a_id: V,
b: &T,
Expand Down
8 changes: 4 additions & 4 deletions src/librustc/middle/typeck/infer/unify.rs
Original file line number Diff line number Diff line change
Expand Up @@ -163,8 +163,8 @@ pub fn mk_err<T:SimplyUnifiable>(+a_is_expected: bool,
}

pub impl InferCtxt {
fn simple_vars<T:Copy Eq InferStr SimplyUnifiable,
V:Copy Eq Vid ToStr UnifyVid<Option<T>>>(
fn simple_vars<T:Copy + Eq + InferStr + SimplyUnifiable,
V:Copy + Eq + Vid + ToStr + UnifyVid<Option<T>>>(
&mut self,
+a_is_expected: bool,
+a_id: V,
Expand Down Expand Up @@ -201,8 +201,8 @@ pub impl InferCtxt {
return uok();
}

fn simple_var_t<T:Copy Eq InferStr SimplyUnifiable,
V:Copy Eq Vid ToStr UnifyVid<Option<T>>>(
fn simple_var_t<T:Copy + Eq + InferStr + SimplyUnifiable,
V:Copy + Eq + Vid + ToStr + UnifyVid<Option<T>>>(
&mut self,
+a_is_expected: bool,
+a_id: V,
Expand Down
10 changes: 5 additions & 5 deletions src/libstd/flatpipes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ pub mod serial {
}

/// Create a pair of `FlatChan` and `FlatPort`, backed by pipes
pub fn pipe_stream<T: Encodable<DefaultEncoder>
pub fn pipe_stream<T: Encodable<DefaultEncoder> +
Decodable<DefaultDecoder>>(
) -> (PipePort<T>, PipeChan<T>) {
let (port, chan) = pipes::stream();
Expand Down Expand Up @@ -443,17 +443,17 @@ pub mod flatteners {
SerializingFlattener
*/

pub fn deserialize_buffer<D: Decoder FromReader,
T: Decodable<D>>(buf: &[u8]) -> T {
pub fn deserialize_buffer<D: Decoder + FromReader,
T: Decodable<D>>(buf: &[u8]) -> T {
let buf = vec::from_slice(buf);
let buf_reader = @BufReader::new(buf);
let reader = buf_reader as @Reader;
let deser: D = FromReader::from_reader(reader);
Decodable::decode(&deser)
}

pub fn serialize_value<D: Encoder FromWriter,
T: Encodable<D>>(val: &T) -> ~[u8] {
pub fn serialize_value<D: Encoder + FromWriter,
T: Encodable<D>>(val: &T) -> ~[u8] {
let bytes_writer = @BytesWriter();
let writer = bytes_writer as @Writer;
let ser = FromWriter::from_writer(writer);
Expand Down
28 changes: 8 additions & 20 deletions src/libstd/workcache.rs
Original file line number Diff line number Diff line change
Expand Up @@ -260,9 +260,7 @@ impl Context {
Context{db: db, logger: lg, cfg: cfg, freshness: LinearMap::new()}
}
fn prep<T:Owned
Encodable<json::Encoder>
Decodable<json::Decoder>>(
fn prep<T:Owned + Encodable<json::Encoder> + Decodable<json::Decoder>>(
@self,
fn_name:&str,
blk: fn(@Mut<Prep>)->Work<T>) -> Work<T> {
Expand All @@ -278,9 +276,8 @@ trait TPrep {
fn declare_input(&self, kind:&str, name:&str, val:&str);
fn is_fresh(&self, cat:&str, kind:&str, name:&str, val:&str) -> bool;
fn all_fresh(&self, cat:&str, map:&WorkMap) -> bool;
fn exec<T:Owned
Encodable<json::Encoder>
Decodable<json::Decoder>>(&self, blk: ~fn(&Exec) -> T) -> Work<T>;
fn exec<T:Owned + Encodable<json::Encoder> + Decodable<json::Decoder>>(
&self, blk: ~fn(&Exec) -> T) -> Work<T>;
}
impl TPrep for @Mut<Prep> {
Expand Down Expand Up @@ -318,11 +315,8 @@ impl TPrep for @Mut<Prep> {
return true;
}

fn exec<T:Owned
Encodable<json::Encoder>
Decodable<json::Decoder>>(&self,
blk: ~fn(&Exec) -> T) -> Work<T> {

fn exec<T:Owned + Encodable<json::Encoder> + Decodable<json::Decoder>>(
&self, blk: ~fn(&Exec) -> T) -> Work<T> {
let mut bo = Some(blk);

do self.borrow_imm |p| {
Expand Down Expand Up @@ -360,20 +354,15 @@ impl TPrep for @Mut<Prep> {
}
}

impl<T:Owned
Encodable<json::Encoder>
Decodable<json::Decoder>>
Work<T> {
impl<T:Owned + Encodable<json::Encoder> + Decodable<json::Decoder>> Work<T> {
static fn new(p: @Mut<Prep>, e: Either<T,PortOne<(Exec,T)>>) -> Work<T> {
Work { prep: p, res: Some(e) }
}
}

// FIXME (#3724): movable self. This should be in impl Work.
fn unwrap<T:Owned
Encodable<json::Encoder>
Decodable<json::Decoder>>(w: Work<T>) -> T {

fn unwrap<T:Owned + Encodable<json::Encoder> + Decodable<json::Decoder>>(
w: Work<T>) -> T {
let mut ww = w;
let mut s = None;

Expand All @@ -383,7 +372,6 @@ fn unwrap<T:Owned
None => fail!(),
Some(Left(v)) => v,
Some(Right(port)) => {

let (exe, v) = match recv(port) {
oneshot::send(data) => data
};
Expand Down
9 changes: 7 additions & 2 deletions src/libsyntax/parse/obsolete.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,8 @@ pub enum ObsoleteSyntax {
ObsoleteBinaryMove,
ObsoleteUnsafeBlock,
ObsoleteUnenforcedBound,
ObsoleteImplSyntax
ObsoleteImplSyntax,
ObsoleteTraitBoundSeparator,
}

pub impl to_bytes::IterBytes for ObsoleteSyntax {
Expand Down Expand Up @@ -120,7 +121,11 @@ pub impl Parser {
ObsoleteImplSyntax => (
"colon-separated impl syntax",
"write `impl Trait for Type`"
)
),
ObsoleteTraitBoundSeparator => (
"space-separated trait bounds",
"write `+` between trait bounds"
),
};

self.report(sp, kind, kind_str, desc);
Expand Down
8 changes: 7 additions & 1 deletion src/libsyntax/parse/parser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ use parse::obsolete::{ObsoleteMoveInit, ObsoleteBinaryMove};
use parse::obsolete::{ObsoleteStructCtor, ObsoleteWith};
use parse::obsolete::{ObsoleteSyntax, ObsoleteLowerCaseKindBounds};
use parse::obsolete::{ObsoleteUnsafeBlock, ObsoleteImplSyntax};
use parse::obsolete::{ObsoleteTraitBoundSeparator};
use parse::prec::{as_prec, token_to_binop};
use parse::token::{can_begin_expr, is_ident, is_ident_or_path};
use parse::token::{is_plain_ident, INTERPOLATED, special_idents};
Expand Down Expand Up @@ -2676,7 +2677,12 @@ pub impl Parser {
}

if self.eat(token::BINOP(token::PLUS)) {
// Should be `break;` but that isn't backwards compatible.
loop;
}

if is_ident_or_path(self.token) {
self.obsolete(copy self.span,
ObsoleteTraitBoundSeparator);
}
}
}
Expand Down
4 changes: 2 additions & 2 deletions src/test/run-pass/auto-encode.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,8 @@ fn test_prettyprint<A:Encodable<prettyprint::Serializer>>(
}

fn test_ebml<A:
Eq
Encodable<EBWriter::Encoder>
Eq +
Encodable<EBWriter::Encoder> +
Decodable<EBReader::Decoder>
>(a1: &A) {
let bytes = do io::with_bytes_writer |wr| {
Expand Down
2 changes: 1 addition & 1 deletion src/test/run-pass/issue-2904.rs
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ fn square_from_char(c: char) -> square {
}
}

fn read_board_grid<rdr: &static io::Reader>(+in: rdr) -> ~[~[square]] {
fn read_board_grid<rdr: &static + io::Reader>(+in: rdr) -> ~[~[square]] {
let in = (in) as io::Reader;
let mut grid = ~[];
for in.each_line |line| {
Expand Down