diff options
| author | Esteban Küber <esteban@kuber.com.ar> | 2016-10-26 20:51:49 -0700 |
|---|---|---|
| committer | Esteban Küber <esteban@kuber.com.ar> | 2016-11-08 14:17:18 -0800 |
| commit | 3edb4fc56345ba2d33a04e952e1d402b08bc676c (patch) | |
| tree | 417fc24e1e68f842d207b3738890876466cb6652 /src/libsyntax | |
| parent | b5f6d7ec2d4e231b9ef0c8a9e8e7ec8a7f67d2ae (diff) | |
| download | rust-3edb4fc56345ba2d33a04e952e1d402b08bc676c.tar.gz rust-3edb4fc56345ba2d33a04e952e1d402b08bc676c.zip | |
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
```
Diffstat (limited to 'src/libsyntax')
| -rw-r--r-- | src/libsyntax/ast.rs | 8 |
1 files changed, 8 insertions, 0 deletions
diff --git a/src/libsyntax/ast.rs b/src/libsyntax/ast.rs index 30fc4c3dd80..cc39e81fdae 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 { |
