about summary refs log tree commit diff
path: root/src/librustc_parse
diff options
context:
space:
mode:
authorAyaz Hafiz <ayaz.hafiz.1@gmail.com>2020-06-21 15:49:56 -0700
committerAyaz Hafiz <ayaz.hafiz.1@gmail.com>2020-06-23 09:25:46 -0700
commit86f6c0e0861f4d223d00280107cd0b31b6ebb85b (patch)
tree3d46b2eff25f77be06040427cef588e1b4732a1e /src/librustc_parse
parent06e47688bf15d0215edbe05b21603062f6d2eb5d (diff)
downloadrust-86f6c0e0861f4d223d00280107cd0b31b6ebb85b.tar.gz
rust-86f6c0e0861f4d223d00280107cd0b31b6ebb85b.zip
Record span of `const` kw in GenericParamKind
Context: this is needed to fix https://github.com/rust-lang/rustfmt/issues/4263,
which currently records the span of a const generic param incorrectly
because the location of the `const` kw is not known.

I am not sure how to add tests for this; any guidance in how to do so
would be appreciated :slightly_smiling_face:
Diffstat (limited to 'src/librustc_parse')
-rw-r--r--src/librustc_parse/parser/generics.rs6
1 files changed, 3 insertions, 3 deletions
diff --git a/src/librustc_parse/parser/generics.rs b/src/librustc_parse/parser/generics.rs
index 04b64d93c70..47794746126 100644
--- a/src/librustc_parse/parser/generics.rs
+++ b/src/librustc_parse/parser/generics.rs
@@ -47,21 +47,21 @@ impl<'a> Parser<'a> {
     }
 
     fn parse_const_param(&mut self, preceding_attrs: Vec<Attribute>) -> PResult<'a, GenericParam> {
-        let lo = self.token.span;
+        let const_span = self.token.span;
 
         self.expect_keyword(kw::Const)?;
         let ident = self.parse_ident()?;
         self.expect(&token::Colon)?;
         let ty = self.parse_ty()?;
 
-        self.sess.gated_spans.gate(sym::const_generics, lo.to(self.prev_token.span));
+        self.sess.gated_spans.gate(sym::const_generics, const_span.to(self.prev_token.span));
 
         Ok(GenericParam {
             ident,
             id: ast::DUMMY_NODE_ID,
             attrs: preceding_attrs.into(),
             bounds: Vec::new(),
-            kind: GenericParamKind::Const { ty },
+            kind: GenericParamKind::Const { ty, kw_span: const_span },
             is_placeholder: false,
         })
     }