about summary refs log tree commit diff
path: root/src/librustc_parse/parser
diff options
context:
space:
mode:
authorMazdak Farrokhzad <twingoow@gmail.com>2019-12-08 11:49:25 +0100
committerMazdak Farrokhzad <twingoow@gmail.com>2019-12-21 19:20:41 +0100
commitf215ca9be63ad7d7b916115e729bacf927621cb8 (patch)
treec3b5bc38a51827557d9bad184e9dc43b5b6c21f9 /src/librustc_parse/parser
parent4b073a1f4a61e69ed08ad116f5d545d4c553d235 (diff)
downloadrust-f215ca9be63ad7d7b916115e729bacf927621cb8.tar.gz
rust-f215ca9be63ad7d7b916115e729bacf927621cb8.zip
simplify negative bound diagnostic
Diffstat (limited to 'src/librustc_parse/parser')
-rw-r--r--src/librustc_parse/parser/ty.rs29
1 files changed, 8 insertions, 21 deletions
diff --git a/src/librustc_parse/parser/ty.rs b/src/librustc_parse/parser/ty.rs
index 905bc204b51..eadaf8ad716 100644
--- a/src/librustc_parse/parser/ty.rs
+++ b/src/librustc_parse/parser/ty.rs
@@ -360,36 +360,24 @@ impl<'a> Parser<'a> {
     ) -> PResult<'a, GenericBounds> {
         let mut bounds = Vec::new();
         let mut negative_bounds = Vec::new();
-        let mut last_plus_span = None;
-        let mut was_negative = false;
         while self.can_begin_bound() {
-            match self.parse_generic_bound(colon_span, last_plus_span)? {
+            match self.parse_generic_bound()? {
                 Ok(bound) => bounds.push(bound),
-                Err(neg_sp) => {
-                    was_negative = true;
-                    if let Some(neg_sp) = neg_sp {
-                        negative_bounds.push(neg_sp);
-                    }
-                }
+                Err(neg_sp) => negative_bounds.push(neg_sp),
             }
-
             if !allow_plus || !self.eat_plus() {
                 break
-            } else {
-                last_plus_span = Some(self.prev_span);
             }
         }
 
-        if !negative_bounds.is_empty() || was_negative {
+        if !negative_bounds.is_empty() {
             let negative_bounds_len = negative_bounds.len();
-            let last_span = negative_bounds.last().map(|sp| *sp);
+            let last_span = *negative_bounds.last().unwrap();
             let mut err = self.struct_span_err(
                 negative_bounds,
                 "negative trait bounds are not supported",
             );
-            if let Some(sp) = last_span {
-                err.span_label(sp, "negative trait bounds are not supported");
-            }
+            err.span_label(last_span, "negative trait bounds are not supported");
             if let Some(bound_list) = colon_span {
                 let bound_list = bound_list.to(self.prev_span);
                 let mut new_bound_list = String::new();
@@ -432,9 +420,8 @@ impl<'a> Parser<'a> {
     /// ```
     fn parse_generic_bound(
         &mut self,
-        colon_span: Option<Span>,
-        last_plus_span: Option<Span>,
-    ) -> PResult<'a, Result<GenericBound, Option<Span>>> {
+    ) -> PResult<'a, Result<GenericBound, Span>> {
+        let anchor_lo = self.prev_span;
         let lo = self.token.span;
         let has_parens = self.eat(&token::OpenDelim(token::Paren));
         let inner_lo = self.token.span;
@@ -445,7 +432,7 @@ impl<'a> Parser<'a> {
         } else {
             let (poly_span, bound) = self.parse_generic_ty_bound(lo, has_parens, question)?;
             if is_negative {
-                Ok(Err(last_plus_span.or(colon_span).map(|sp| sp.to(poly_span))))
+                Ok(Err(anchor_lo.to(poly_span)))
             } else {
                 Ok(Ok(bound))
             }