about summary refs log tree commit diff
path: root/compiler/rustc_ast
diff options
context:
space:
mode:
authorEsteban Küber <esteban@kuber.com.ar>2021-05-15 14:56:28 -0700
committerEsteban Kuber <esteban@kuber.com.ar>2021-11-24 20:02:09 +0000
commit7190bc3097a3f84c9d0e07d149eba4b00e4f8917 (patch)
treec3c03074b83b4ca2c87fb6622ad3c7f0fd8ff393 /compiler/rustc_ast
parent311fa1f14dd8ffbbe83b229a94b17f7f1ecaf33b (diff)
downloadrust-7190bc3097a3f84c9d0e07d149eba4b00e4f8917.tar.gz
rust-7190bc3097a3f84c9d0e07d149eba4b00e4f8917.zip
Account for incorrect `impl Foo<const N: ty> {}` syntax
Fix #84946
Diffstat (limited to 'compiler/rustc_ast')
-rw-r--r--compiler/rustc_ast/src/ast.rs15
1 files changed, 15 insertions, 0 deletions
diff --git a/compiler/rustc_ast/src/ast.rs b/compiler/rustc_ast/src/ast.rs
index abfe8360987..55b243a84a9 100644
--- a/compiler/rustc_ast/src/ast.rs
+++ b/compiler/rustc_ast/src/ast.rs
@@ -405,6 +405,21 @@ pub struct GenericParam {
     pub kind: GenericParamKind,
 }
 
+impl GenericParam {
+    pub fn span(&self) -> Span {
+        match &self.kind {
+            GenericParamKind::Lifetime | GenericParamKind::Type { default: None } => {
+                self.ident.span
+            }
+            GenericParamKind::Type { default: Some(ty) } => self.ident.span.to(ty.span),
+            GenericParamKind::Const { kw_span, default: Some(default), .. } => {
+                kw_span.to(default.value.span)
+            }
+            GenericParamKind::Const { kw_span, default: None, ty } => kw_span.to(ty.span),
+        }
+    }
+}
+
 /// Represents lifetime, type and const parameters attached to a declaration of
 /// a function, enum, trait, etc.
 #[derive(Clone, Encodable, Decodable, Debug)]