about summary refs log tree commit diff
path: root/src/libsyntax
diff options
context:
space:
mode:
authorbors <bors@rust-lang.org>2014-03-13 09:41:35 -0700
committerbors <bors@rust-lang.org>2014-03-13 09:41:35 -0700
commit3fbee34a89c478f959046bf4b4e12a70e937c374 (patch)
treede26db2adf42af2da86e7f2a21bc1adec4fe9e19 /src/libsyntax
parent6ca57736ccd2b9d0c7288f997b31c0391dd1dbca (diff)
parent9faa2a58f2403165eed7caefbac30b17d93f0837 (diff)
downloadrust-3fbee34a89c478f959046bf4b4e12a70e937c374.tar.gz
rust-3fbee34a89c478f959046bf4b4e12a70e937c374.zip
auto merge of #12238 : ktt3ja/rust/lifetime-error-msg, r=nikomatsakis
For the following code snippet:

```rust
struct Foo { bar: int }
fn foo1(x: &Foo) -> &int {
    &x.bar
}
```

This PR generates the following error message:

```rust
test.rs:2:1: 4:2 note: consider using an explicit lifetime parameter as shown: fn foo1<'a>(x: &'a Foo) -> &'a int
test.rs:2 fn foo1(x: &Foo) -> &int {
test.rs:3     &x.bar
test.rs:4 }
test.rs:3:5: 3:11 error: cannot infer an appropriate lifetime for borrow expression due to conflicting requirements
test.rs:3     &x.bar
              ^~~~~~
```

Currently it does not support methods.
Diffstat (limited to 'src/libsyntax')
-rw-r--r--src/libsyntax/ast_util.rs21
1 files changed, 21 insertions, 0 deletions
diff --git a/src/libsyntax/ast_util.rs b/src/libsyntax/ast_util.rs
index d45ea206792..da6278aaae9 100644
--- a/src/libsyntax/ast_util.rs
+++ b/src/libsyntax/ast_util.rs
@@ -11,6 +11,7 @@
 use ast::*;
 use ast;
 use ast_util;
+use codemap;
 use codemap::Span;
 use opt_vec;
 use parse::token;
@@ -208,6 +209,12 @@ pub fn ident_to_pat(id: NodeId, s: Span, i: Ident) -> @Pat {
                 span: s }
 }
 
+pub fn name_to_dummy_lifetime(name: Name) -> Lifetime {
+    Lifetime { id: DUMMY_NODE_ID,
+               span: codemap::DUMMY_SP,
+               name: name }
+}
+
 pub fn is_unguarded(a: &Arm) -> bool {
     match a.guard {
       None => true,
@@ -684,6 +691,20 @@ pub fn lit_is_str(lit: @Lit) -> bool {
     }
 }
 
+pub fn get_inner_tys(ty: P<Ty>) -> Vec<P<Ty>> {
+    match ty.node {
+        ast::TyRptr(_, mut_ty) | ast::TyPtr(mut_ty) => {
+            vec!(mut_ty.ty)
+        }
+        ast::TyBox(ty)
+        | ast::TyVec(ty)
+        | ast::TyUniq(ty)
+        | ast::TyFixedLengthVec(ty, _) => vec!(ty),
+        ast::TyTup(ref tys) => tys.clone(),
+        _ => Vec::new()
+    }
+}
+
 
 #[cfg(test)]
 mod test {