about summary refs log tree commit diff
path: root/src/libsyntax
diff options
context:
space:
mode:
authorbors <bors@rust-lang.org>2020-01-27 03:01:59 +0000
committerbors <bors@rust-lang.org>2020-01-27 03:01:59 +0000
commit320ada6479b3e29c7d9a66bc56ac44c2d2b57566 (patch)
treec7edaee29d68e3edeb458259ec88faefeff50d4b /src/libsyntax
parentc3681d62ee4bb849e87a2ec5d663afc34ac05d85 (diff)
parent697fdc568e28fbb376567eda4edb2c2a05db68de (diff)
Auto merge of #68447 - estebank:sugg-type-param, r=petrochenkov
Suggest defining type parameter when appropriate

```
error[E0412]: cannot find type `T` in this scope
 --> file.rs:3:12
  |
3 | impl Trait<T> for Struct {}
  |     -      ^ not found in this scope
  |     |
  |     help: you might be missing a type parameter: `<T>`
```

Fix #64298.
Diffstat (limited to 'src/libsyntax')
-rw-r--r--src/libsyntax/ast.rs14
1 files changed, 14 insertions, 0 deletions
diff --git a/src/libsyntax/ast.rs b/src/libsyntax/ast.rs
index 5f38ac4cc0f..5c64cc440ce 100644
--- a/src/libsyntax/ast.rs
+++ b/src/libsyntax/ast.rs
@@ -2655,6 +2655,20 @@ impl ItemKind {
             ItemKind::Mac(..) | ItemKind::MacroDef(..) | ItemKind::Impl { .. } => "item",
         }
     }
+
+    pub fn generics(&self) -> Option<&Generics> {
+        match self {
+            Self::Fn(_, generics, _)
+            | Self::TyAlias(_, generics)
+            | Self::Enum(_, generics)
+            | Self::Struct(_, generics)
+            | Self::Union(_, generics)
+            | Self::Trait(_, _, generics, ..)
+            | Self::TraitAlias(generics, _)
+            | Self::Impl { generics, .. } => Some(generics),
+            _ => None,
+        }
+    }
 }
 
 pub type ForeignItem = Item<ForeignItemKind>;