about summary refs log tree commit diff
diff options
context:
space:
mode:
authorMazdak Farrokhzad <twingoow@gmail.com>2019-12-08 12:29:05 +0100
committerMazdak Farrokhzad <twingoow@gmail.com>2019-12-21 19:20:41 +0100
commitf221b394def7e739c6c2b936afd12e032ee0f827 (patch)
tree1b8ae61e689353147cc7397624a41d1b1e31b5da
parentb5f00beaa5a77ff8bccbe4330ea0b5047661cbf5 (diff)
downloadrust-f221b394def7e739c6c2b936afd12e032ee0f827.tar.gz
rust-f221b394def7e739c6c2b936afd12e032ee0f827.zip
extract error_negative_bounds
-rw-r--r--src/librustc_parse/parser/ty.rs62
1 files changed, 35 insertions, 27 deletions
diff --git a/src/librustc_parse/parser/ty.rs b/src/librustc_parse/parser/ty.rs
index db9a0ada525..3877f3f9a62 100644
--- a/src/librustc_parse/parser/ty.rs
+++ b/src/librustc_parse/parser/ty.rs
@@ -371,33 +371,7 @@ impl<'a> Parser<'a> {
         }
 
         if !negative_bounds.is_empty() {
-            let negative_bounds_len = negative_bounds.len();
-            let last_span = *negative_bounds.last().unwrap();
-            let mut err = self.struct_span_err(
-                negative_bounds,
-                "negative bounds are not supported",
-            );
-            err.span_label(last_span, "negative 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();
-                if !bounds.is_empty() {
-                    let mut snippets = bounds.iter().map(|bound| bound.span())
-                        .map(|span| self.span_to_snippet(span));
-                    while let Some(Ok(snippet)) = snippets.next() {
-                        new_bound_list.push_str(" + ");
-                        new_bound_list.push_str(&snippet);
-                    }
-                    new_bound_list = new_bound_list.replacen(" +", ":", 1);
-                }
-                err.span_suggestion_hidden(
-                    bound_list,
-                    &format!("remove the bound{}", pluralize!(negative_bounds_len)),
-                    new_bound_list,
-                    Applicability::MachineApplicable,
-                );
-            }
-            err.emit();
+            self.error_negative_bounds(colon_span, &bounds, negative_bounds);
         }
 
         Ok(bounds)
@@ -414,6 +388,40 @@ impl<'a> Parser<'a> {
         || self.check(&token::OpenDelim(token::Paren))
     }
 
+    fn error_negative_bounds(
+        &self,
+        colon_span: Option<Span>,
+        bounds: &[GenericBound],
+        negative_bounds: Vec<Span>,
+    ) {
+        let negative_bounds_len = negative_bounds.len();
+        let last_span = *negative_bounds.last().unwrap();
+        let mut err = self.struct_span_err(
+            negative_bounds,
+            "negative bounds are not supported",
+        );
+        err.span_label(last_span, "negative 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();
+            if !bounds.is_empty() {
+                let mut snippets = bounds.iter().map(|bound| self.span_to_snippet(bound.span()));
+                while let Some(Ok(snippet)) = snippets.next() {
+                    new_bound_list.push_str(" + ");
+                    new_bound_list.push_str(&snippet);
+                }
+                new_bound_list = new_bound_list.replacen(" +", ":", 1);
+            }
+            err.span_suggestion_hidden(
+                bound_list,
+                &format!("remove the bound{}", pluralize!(negative_bounds_len)),
+                new_bound_list,
+                Applicability::MachineApplicable,
+            );
+        }
+        err.emit();
+    }
+
     /// Parses a bound according to the grammar:
     /// ```
     /// BOUND = TY_BOUND | LT_BOUND