about summary refs log tree commit diff
path: root/src/libsyntax
diff options
context:
space:
mode:
authorEduard-Mihai Burtescu <edy.burt@gmail.com>2016-11-09 20:51:16 +0200
committerGitHub <noreply@github.com>2016-11-09 20:51:16 +0200
commitbd9969fb1138d3a0aef0e860173a5f221a74e7ab (patch)
treebe8c2ef9dc91f2a1232f8df2fa84ea272148720d /src/libsyntax
parent7f2853fda3773d4f9ec28484ba3592d5e825ca59 (diff)
parent3edb4fc56345ba2d33a04e952e1d402b08bc676c (diff)
downloadrust-bd9969fb1138d3a0aef0e860173a5f221a74e7ab.tar.gz
rust-bd9969fb1138d3a0aef0e860173a5f221a74e7ab.zip
Rollup merge of #37428 - estebank:generic-type-error-span, r=sanxiyn
Point to type argument span when used as trait

Given the following code:

``` rust
struct Foo<T: Clone>(T);

use std::ops::Add;

impl<T: Clone, Add> Add for Foo<T> {
  type Output = usize;

  fn add(self, rhs: Self) -> Self::Output {
    unimplemented!();
  }
}
```

present the following output:

``` nocode
error[E0404]: `Add` is not a trait
 --> file3.rs:5:21
  |
5 | impl<T: Clone, Add> Add for Okok<T> {
  |                ---  ^^^ expected trait, found type parameter
  |                |
  |                type parameter defined here
```

Fixes #35987.
Diffstat (limited to 'src/libsyntax')
-rw-r--r--src/libsyntax/ast.rs8
1 files changed, 8 insertions, 0 deletions
diff --git a/src/libsyntax/ast.rs b/src/libsyntax/ast.rs
index f7581924eb1..9751ad6aa43 100644
--- a/src/libsyntax/ast.rs
+++ b/src/libsyntax/ast.rs
@@ -399,6 +399,14 @@ impl Generics {
     pub fn is_parameterized(&self) -> bool {
         self.is_lt_parameterized() || self.is_type_parameterized()
     }
+    pub fn span_for_name(&self, name: &str) -> Option<Span> {
+        for t in &self.ty_params {
+            if t.ident.name.as_str() == name {
+                return Some(t.span);
+            }
+        }
+        None
+    }
 }
 
 impl Default for Generics {