]> git.lizzy.rs Git - rust.git/blobdiff - src/librustc_parse/parser/generics.rs
Auto merge of #69550 - RalfJung:scalar, r=oli-obk
[rust.git] / src / librustc_parse / parser / generics.rs
index 0984263bb283ebf56bd7f6c779ffd54d38900373..59fd5f7c4be1fc55f414cdb6dce37c985048f1c2 100644 (file)
@@ -1,10 +1,9 @@
 use super::Parser;
 
+use rustc_ast::ast::{self, Attribute, GenericBounds, GenericParam, GenericParamKind, WhereClause};
+use rustc_ast::token;
 use rustc_errors::PResult;
-use rustc_span::source_map::DUMMY_SP;
 use rustc_span::symbol::{kw, sym};
-use syntax::ast::{self, Attribute, GenericBounds, GenericParam, GenericParamKind, WhereClause};
-use syntax::token;
 
 impl<'a> Parser<'a> {
     /// Parses bounds of a lifetime parameter `BOUND + BOUND + BOUND`, possibly with trailing `+`.
@@ -30,7 +29,7 @@ fn parse_ty_param(&mut self, preceding_attrs: Vec<Attribute>) -> PResult<'a, Gen
 
         // Parse optional colon and param bounds.
         let bounds = if self.eat(&token::Colon) {
-            self.parse_generic_bounds(Some(self.prev_span))?
+            self.parse_generic_bounds(Some(self.prev_token.span))?
         } else {
             Vec::new()
         };
@@ -55,7 +54,7 @@ fn parse_const_param(&mut self, preceding_attrs: Vec<Attribute>) -> PResult<'a,
         self.expect(&token::Colon)?;
         let ty = self.parse_ty()?;
 
-        self.sess.gated_spans.gate(sym::const_generics, lo.to(self.prev_span));
+        self.sess.gated_spans.gate(sym::const_generics, lo.to(self.prev_token.span));
 
         Ok(GenericParam {
             ident,
@@ -121,15 +120,12 @@ pub(super) fn parse_generic_params(&mut self) -> PResult<'a, Vec<ast::GenericPar
                         .span_label(attrs[0].span, "attributes must go before parameters")
                         .emit();
                     } else {
-                        self.struct_span_err(
-                            attrs[0].span,
-                            &format!("attribute without generic parameters"),
-                        )
-                        .span_label(
-                            attrs[0].span,
-                            "attributes are only permitted when preceding parameters",
-                        )
-                        .emit();
+                        self.struct_span_err(attrs[0].span, "attribute without generic parameters")
+                            .span_label(
+                                attrs[0].span,
+                                "attributes are only permitted when preceding parameters",
+                            )
+                            .emit();
                     }
                 }
                 break;
@@ -154,13 +150,16 @@ pub(super) fn parse_generics(&mut self) -> PResult<'a, ast::Generics> {
         let (params, span) = if self.eat_lt() {
             let params = self.parse_generic_params()?;
             self.expect_gt()?;
-            (params, span_lo.to(self.prev_span))
+            (params, span_lo.to(self.prev_token.span))
         } else {
-            (vec![], self.prev_span.shrink_to_hi())
+            (vec![], self.prev_token.span.shrink_to_hi())
         };
         Ok(ast::Generics {
             params,
-            where_clause: WhereClause { predicates: Vec::new(), span: DUMMY_SP },
+            where_clause: WhereClause {
+                predicates: Vec::new(),
+                span: self.prev_token.span.shrink_to_hi(),
+            },
             span,
         })
     }
@@ -172,12 +171,12 @@ pub(super) fn parse_generics(&mut self) -> PResult<'a, ast::Generics> {
     /// ```
     pub(super) fn parse_where_clause(&mut self) -> PResult<'a, WhereClause> {
         let mut where_clause =
-            WhereClause { predicates: Vec::new(), span: self.prev_span.shrink_to_hi() };
+            WhereClause { predicates: Vec::new(), span: self.prev_token.span.shrink_to_hi() };
 
         if !self.eat_keyword(kw::Where) {
             return Ok(where_clause);
         }
-        let lo = self.prev_span;
+        let lo = self.prev_token.span;
 
         // We are considering adding generics to the `where` keyword as an alternative higher-rank
         // parameter syntax (as in `where<'a>` or `where<T>`. To avoid that being a breaking
@@ -200,7 +199,11 @@ pub(super) fn parse_where_clause(&mut self) -> PResult<'a, WhereClause> {
                 self.expect(&token::Colon)?;
                 let bounds = self.parse_lt_param_bounds();
                 where_clause.predicates.push(ast::WherePredicate::RegionPredicate(
-                    ast::WhereRegionPredicate { span: lo.to(self.prev_span), lifetime, bounds },
+                    ast::WhereRegionPredicate {
+                        span: lo.to(self.prev_token.span),
+                        lifetime,
+                        bounds,
+                    },
                 ));
             } else if self.check_type() {
                 where_clause.predicates.push(self.parse_ty_where_predicate()?);
@@ -213,7 +216,7 @@ pub(super) fn parse_where_clause(&mut self) -> PResult<'a, WhereClause> {
             }
         }
 
-        where_clause.span = lo.to(self.prev_span);
+        where_clause.span = lo.to(self.prev_token.span);
         Ok(where_clause)
     }
 
@@ -232,9 +235,9 @@ fn parse_ty_where_predicate(&mut self) -> PResult<'a, ast::WherePredicate> {
         // or with mandatory equality sign and the second type.
         let ty = self.parse_ty()?;
         if self.eat(&token::Colon) {
-            let bounds = self.parse_generic_bounds(Some(self.prev_span))?;
+            let bounds = self.parse_generic_bounds(Some(self.prev_token.span))?;
             Ok(ast::WherePredicate::BoundPredicate(ast::WhereBoundPredicate {
-                span: lo.to(self.prev_span),
+                span: lo.to(self.prev_token.span),
                 bound_generic_params: lifetime_defs,
                 bounded_ty: ty,
                 bounds,
@@ -244,7 +247,7 @@ fn parse_ty_where_predicate(&mut self) -> PResult<'a, ast::WherePredicate> {
         } else if self.eat(&token::Eq) || self.eat(&token::EqEq) {
             let rhs_ty = self.parse_ty()?;
             Ok(ast::WherePredicate::EqPredicate(ast::WhereEqPredicate {
-                span: lo.to(self.prev_span),
+                span: lo.to(self.prev_token.span),
                 lhs_ty: ty,
                 rhs_ty,
                 id: ast::DUMMY_NODE_ID,