Suggest explicit lifetime parameter on some errors

Some types of error are caused by missing lifetime parameter on function
or method declaration. In such cases, this commit generates some
suggestion about what the function declaration could be. This does not
support method declaration yet.
This commit is contained in:
Kiet Tran
2014-02-15 01:26:51 -05:00
parent ed2b3a2f0b
commit 9faa2a58f2
5 changed files with 743 additions and 6 deletions

View File

@@ -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 {