diff --git a/src/libsyntax/parse/parser.rs b/src/libsyntax/parse/parser.rs index c8492cc4113f..57b2c21e03b8 100644 --- a/src/libsyntax/parse/parser.rs +++ b/src/libsyntax/parse/parser.rs @@ -112,13 +112,6 @@ pub enum PathParsingMode { LifetimeAndTypesAndBounds, } -/// A pair of a path segment and group of type parameter bounds. (See `ast.rs` -/// for the definition of a path segment.) -struct PathSegmentAndBoundSet { - segment: ast::PathSegment, - bound_set: Option>, -} - /// A path paired with optional type bounds. pub struct PathAndBounds { path: ast::Path, @@ -1515,24 +1508,14 @@ impl<'a> Parser<'a> { // First, parse an identifier. let identifier = self.parse_ident(); - // Next, parse a colon and bounded type parameters, if applicable. - let bound_set = if mode == LifetimeAndTypesAndBounds { - self.parse_optional_ty_param_bounds() - } else { - None - }; - // Parse the '::' before type parameters if it's required. If // it is required and wasn't present, then we're done. if mode == LifetimeAndTypesWithColons && !self.eat(&token::MOD_SEP) { - segments.push(PathSegmentAndBoundSet { - segment: ast::PathSegment { - identifier: identifier, - lifetimes: Vec::new(), - types: OwnedSlice::empty(), - }, - bound_set: bound_set + segments.push(ast::PathSegment { + identifier: identifier, + lifetimes: Vec::new(), + types: OwnedSlice::empty(), }); break } @@ -1549,13 +1532,10 @@ impl<'a> Parser<'a> { }; // Assemble and push the result. - segments.push(PathSegmentAndBoundSet { - segment: ast::PathSegment { - identifier: identifier, - lifetimes: lifetimes, - types: types, - }, - bound_set: bound_set + segments.push(ast::PathSegment { + identifier: identifier, + lifetimes: lifetimes, + types: types, }); // We're done if we don't see a '::', unless the mode required @@ -1568,42 +1548,25 @@ impl<'a> Parser<'a> { } } + // Next, parse a colon and bounded type parameters, if applicable. + let bounds = if mode == LifetimeAndTypesAndBounds { + self.parse_optional_ty_param_bounds() + } else { + None + }; + // Assemble the span. let span = mk_sp(lo, self.last_span.hi); - // Assemble the path segments. - let mut path_segments = Vec::new(); - let mut bounds = None; - let last_segment_index = segments.len() - 1; - for (i, segment_and_bounds) in segments.move_iter().enumerate() { - let PathSegmentAndBoundSet { - segment: segment, - bound_set: bound_set - } = segment_and_bounds; - path_segments.push(segment); - - if bound_set.is_some() { - if i != last_segment_index { - self.span_err(span, - "type parameter bounds are allowed only \ - before the last segment in a path") - } - - bounds = bound_set - } - } - // Assemble the result. - let path_and_bounds = PathAndBounds { + PathAndBounds { path: ast::Path { span: span, global: is_global, - segments: path_segments, + segments: segments, }, bounds: bounds, - }; - - path_and_bounds + } } /// parses 0 or 1 lifetime diff --git a/src/libsyntax/print/pprust.rs b/src/libsyntax/print/pprust.rs index 9cecd5f6c2b5..655cde3cbed8 100644 --- a/src/libsyntax/print/pprust.rs +++ b/src/libsyntax/print/pprust.rs @@ -1525,7 +1525,7 @@ impl<'a> State<'a> { } let mut first = true; - for (i, segment) in path.segments.iter().enumerate() { + for segment in path.segments.iter() { if first { first = false } else { @@ -1534,14 +1534,6 @@ impl<'a> State<'a> { try!(self.print_ident(segment.identifier)); - // If this is the last segment, print the bounds. - if i == path.segments.len() - 1 { - match *opt_bounds { - None => {} - Some(ref bounds) => try!(self.print_bounds(bounds, true)), - } - } - if !segment.lifetimes.is_empty() || !segment.types.is_empty() { if colons_before_params { try!(word(&mut self.s, "::")) @@ -1570,7 +1562,11 @@ impl<'a> State<'a> { try!(word(&mut self.s, ">")) } } - Ok(()) + + match *opt_bounds { + None => Ok(()), + Some(ref bounds) => self.print_bounds(bounds, true), + } } fn print_path(&mut self, path: &ast::Path, diff --git a/src/test/compile-fail/kindck-owned-trait-contains.rs b/src/test/compile-fail/kindck-owned-trait-contains.rs index ed1725f3240f..e2005cbae918 100644 --- a/src/test/compile-fail/kindck-owned-trait-contains.rs +++ b/src/test/compile-fail/kindck-owned-trait-contains.rs @@ -14,8 +14,8 @@ impl Repeat for A { fn get(&self) -> A { self.clone() } } -fn repeater(v: A) -> ~Repeat: { - ~v as ~Repeat: // No +fn repeater(v: A) -> ~Repeat: { + ~v as ~Repeat: // No } fn main() { diff --git a/src/test/run-pass/alignment-gep-tup-like-1.rs b/src/test/run-pass/alignment-gep-tup-like-1.rs index a0233360a7cc..2c71d791cd48 100644 --- a/src/test/run-pass/alignment-gep-tup-like-1.rs +++ b/src/test/run-pass/alignment-gep-tup-like-1.rs @@ -27,11 +27,11 @@ impl Invokable for Invoker { } } -fn f(a: A, b: u16) -> ~Invokable: { +fn f(a: A, b: u16) -> ~Invokable: { ~Invoker { a: a, b: b, - } as ~Invokable: + } as ~Invokable: } pub fn main() { diff --git a/src/test/run-pass/close-over-big-then-small-data.rs b/src/test/run-pass/close-over-big-then-small-data.rs index ea75ae2fc5c5..c57b6fdf3849 100644 --- a/src/test/run-pass/close-over-big-then-small-data.rs +++ b/src/test/run-pass/close-over-big-then-small-data.rs @@ -31,11 +31,11 @@ impl Invokable for Invoker { } } -fn f(a: A, b: u16) -> ~Invokable: { +fn f(a: A, b: u16) -> ~Invokable: { ~Invoker { a: a, b: b, - } as ~Invokable: + } as ~Invokable: } pub fn main() { diff --git a/src/test/run-pass/kindck-owned-trait-contains-1.rs b/src/test/run-pass/kindck-owned-trait-contains-1.rs index 0a7e164ca5b9..e4a7e7af14f7 100644 --- a/src/test/run-pass/kindck-owned-trait-contains-1.rs +++ b/src/test/run-pass/kindck-owned-trait-contains-1.rs @@ -16,9 +16,9 @@ impl repeat for ~A { } } -fn repeater(v: ~A) -> ~repeat: { +fn repeater(v: ~A) -> ~repeat: { // Note: owned kind is not necessary as A appears in the trait type - ~v as ~repeat: // No + ~v as ~repeat: // No } pub fn main() { diff --git a/src/test/run-pass/parameterized-trait-with-bounds.rs b/src/test/run-pass/parameterized-trait-with-bounds.rs new file mode 100644 index 000000000000..6200d04c8028 --- /dev/null +++ b/src/test/run-pass/parameterized-trait-with-bounds.rs @@ -0,0 +1,27 @@ +// Copyright 2014 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 or the MIT license +// , at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. + +#[allow(dead_code)]; + +trait A {} +trait B {} +trait C<'a, U> {} + +mod foo { + pub trait D<'a, T> {} +} + +fn foo1(_: &A: Send) {} +fn foo2(_: ~A: Send + Share) {} +fn foo3(_: ~B: 'static) {} +fn foo4<'a, T>(_: ~C<'a, T>: 'static + Send) {} +fn foo5<'a, T>(_: ~foo::D<'a, T>: 'static + Send) {} + +pub fn main() {}