diff options
| author | Alex Crichton <alex@alexcrichton.com> | 2014-03-22 09:20:22 -0700 |
|---|---|---|
| committer | Alex Crichton <alex@alexcrichton.com> | 2014-03-26 14:51:41 -0700 |
| commit | 8118406ecf1fedf2949e8e6fa014086ac7b557e8 (patch) | |
| tree | 9424dc0d698a79d5b3c8d99b5972f731e789fabc /src/libsyntax/parse/parser.rs | |
| parent | e233a43f5a0e14ceb322b955b16c8967adb2f4a8 (diff) | |
| download | rust-8118406ecf1fedf2949e8e6fa014086ac7b557e8.tar.gz rust-8118406ecf1fedf2949e8e6fa014086ac7b557e8.zip | |
syntax: Tweak parsing bounds on generics paths
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/parse/parser.rs')
| -rw-r--r-- | src/libsyntax/parse/parser.rs | 73 |
1 files changed, 18 insertions, 55 deletions
diff --git a/src/libsyntax/parse/parser.rs b/src/libsyntax/parse/parser.rs index c8492cc4113..57b2c21e03b 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<OwnedSlice<TyParamBound>>, -} - /// 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 |
