diff options
| author | bors <bors@rust-lang.org> | 2014-03-26 19:32:01 -0700 |
|---|---|---|
| committer | bors <bors@rust-lang.org> | 2014-03-26 19:32:01 -0700 |
| commit | c329a17461b29da3c9f004154d32e4f153d727df (patch) | |
| tree | f30825fe03a00cb0d9740372e386a31bc9e6fd56 /src/libsyntax | |
| parent | c83994e0f492d5e416537cb7ce1063662c0e44e7 (diff) | |
| parent | 8118406ecf1fedf2949e8e6fa014086ac7b557e8 (diff) | |
| download | rust-c329a17461b29da3c9f004154d32e4f153d727df.tar.gz rust-c329a17461b29da3c9f004154d32e4f153d727df.zip | |
auto merge of #13079 : alexcrichton/rust/colons, r=cmr
The previous syntax was `Foo:Bound<trait-parameters>`, but this is a little ambiguous because it was being parsed as `Foo: (Bound<trait-parameters)` rather than `Foo: (Bound) <trait-parameters>` This commit changes the syntax to `Foo<trait-parameters>: Bound` in order to be clear where the trait parameters are going. Closes #9265
Diffstat (limited to 'src/libsyntax')
| -rw-r--r-- | src/libsyntax/parse/parser.rs | 73 | ||||
| -rw-r--r-- | src/libsyntax/print/pprust.rs | 16 |
2 files changed, 24 insertions, 65 deletions
diff --git a/src/libsyntax/parse/parser.rs b/src/libsyntax/parse/parser.rs index 9b12987361e..d6ccea7331d 100644 --- a/src/libsyntax/parse/parser.rs +++ b/src/libsyntax/parse/parser.rs @@ -111,13 +111,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<OwnedSlice<TyParamBound>>, -} - /// A path paired with optional type bounds. pub struct PathAndBounds { path: ast::Path, @@ -1514,24 +1507,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 } @@ -1548,13 +1531,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 @@ -1567,42 +1547,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 e1d6f821ba9..6309f83abdd 100644 --- a/src/libsyntax/print/pprust.rs +++ b/src/libsyntax/print/pprust.rs @@ -1526,7 +1526,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 { @@ -1535,14 +1535,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, "::")) @@ -1571,7 +1563,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, |
