1
Fork 0

libsyntax: Stop parsing + with no bounds after it.

This will break code that looks like `Box<Trait+>`. Change that code to
`Box<Trait>` instead.

Closes #14925.

[breaking-change]
This commit is contained in:
Patrick Walton 2014-06-20 10:49:54 -07:00
parent 6750eb5a05
commit ae067477fb
9 changed files with 33 additions and 14 deletions

View file

@ -1646,6 +1646,12 @@ impl<'a> Parser<'a> {
let bounds = { let bounds = {
if self.eat(&token::BINOP(token::PLUS)) { if self.eat(&token::BINOP(token::PLUS)) {
let (_, bounds) = self.parse_ty_param_bounds(false); let (_, bounds) = self.parse_ty_param_bounds(false);
if bounds.len() == 0 {
let last_span = self.last_span;
self.span_err(last_span,
"at least one type parameter bound \
must be specified after the `+`");
}
Some(bounds) Some(bounds)
} else { } else {
None None

View file

@ -40,7 +40,7 @@ fn test<'a,T,U:Send>(_: &'a int) {
assert_send::<&'static Dummy>(); //~ ERROR does not fulfill `Send` assert_send::<&'static Dummy>(); //~ ERROR does not fulfill `Send`
assert_send::<&'a Dummy>(); //~ ERROR does not fulfill `Send` assert_send::<&'a Dummy>(); //~ ERROR does not fulfill `Send`
assert_send::<&'a Dummy+Send>(); //~ ERROR does not fulfill `Send` assert_send::<&'a Dummy+Send>(); //~ ERROR does not fulfill `Send`
assert_send::<Box<Dummy+>>(); //~ ERROR does not fulfill `Send` assert_send::<Box<Dummy>>(); //~ ERROR does not fulfill `Send`
// ...unless they are properly bounded // ...unless they are properly bounded
assert_send::<&'static Dummy+Send>(); assert_send::<&'static Dummy+Send>();

View file

@ -0,0 +1,18 @@
// Copyright 2012 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.
use std::fmt::Show;
fn main() {
let x: Box<Show+> = box 3 as Box<Show+>;
//~^ ERROR at least one type parameter bound must be specified
//~^^ ERROR at least one type parameter bound must be specified
}

View file

@ -19,7 +19,7 @@ fn c(x: Box<Foo+Share+Send>) {
a(x); a(x);
} }
fn d(x: Box<Foo+>) { fn d(x: Box<Foo>) {
a(x); //~ ERROR found no bounds a(x); //~ ERROR found no bounds
} }

View file

@ -33,11 +33,11 @@ impl<A:Clone> Invokable<A> for Invoker<A> {
} }
} }
fn f<A:Clone + 'static>(a: A, b: u16) -> Box<Invokable<A>+> { fn f<A:Clone + 'static>(a: A, b: u16) -> Box<Invokable<A>> {
box Invoker { box Invoker {
a: a, a: a,
b: b, b: b,
} as (Box<Invokable<A>>+) } as (Box<Invokable<A>>)
} }
pub fn main() { pub fn main() {

View file

@ -59,7 +59,6 @@ fn bar<'b>() {
foo::< <'a>|int, f32, &'a int|:'b + Share -> &'a int>(); foo::< <'a>|int, f32, &'a int|:'b + Share -> &'a int>();
foo::<proc()>(); foo::<proc()>();
foo::<proc() -> ()>(); foo::<proc() -> ()>();
foo::<proc():>();
foo::<proc():'static>(); foo::<proc():'static>();
foo::<proc():Share>(); foo::<proc():Share>();
foo::<proc<'a>(int, f32, &'a int):'static + Share -> &'a int>(); foo::<proc<'a>(int, f32, &'a int):'static + Share -> &'a int>();

View file

@ -20,6 +20,5 @@ pub fn main() {}
trait A {} trait A {}
impl<T: 'static> A for T {} impl<T: 'static> A for T {}
fn owned1<T: 'static>(a: T) { box a as Box<A+>; } /* note `:` */
fn owned2<T: 'static>(a: Box<T>) { a as Box<A>; } fn owned2<T: 'static>(a: Box<T>) { a as Box<A>; }
fn owned3<T: 'static>(a: Box<T>) { box a as Box<A>; } fn owned3<T: 'static>(a: Box<T>) { box a as Box<A>; }

View file

@ -28,7 +28,7 @@ pub fn main() {
let a = 3; let a = 3;
bar::<proc():>(proc() { bar::<proc()>(proc() {
let b = &a; let b = &a;
println!("{}", *b); println!("{}", *b);
}); });

View file

@ -12,22 +12,19 @@
trait Foo { trait Foo {
} }
fn a(_x: Box<Foo+>) {
}
fn b(_x: Box<Foo+Send>) { fn b(_x: Box<Foo+Send>) {
} }
fn c(x: Box<Foo+Share+Send>) { fn c(x: Box<Foo+Share+Send>) {
a(x); e(x);
} }
fn d(x: Box<Foo+Send>) { fn d(x: Box<Foo+Send>) {
b(x); e(x);
} }
fn e(x: Box<Foo>) { // sugar for Box<Foo+Owned> fn e(x: Box<Foo>) {
a(x); e(x);
} }
pub fn main() { } pub fn main() { }