Use adjustments table for allocation lint

This commit is contained in:
Seo Sanghyeon 2013-05-23 23:58:23 +09:00
parent f5d4ea84f5
commit 363e672736

View file

@ -892,14 +892,9 @@ fn lint_session(cx: @mut Context) -> visit::vt<()> {
} }
fn lint_unnecessary_allocations(cx: @mut Context) -> visit::vt<()> { fn lint_unnecessary_allocations(cx: @mut Context) -> visit::vt<()> {
// If the expression `e` has an allocated type, but `t` dictates that it's // Warn if string and vector literals with sigils are immediately borrowed.
// something like a slice (doesn't need allocation), emit a warning with the // Those can have the sigil removed.
// specified span. fn check(cx: @mut Context, e: @ast::expr) {
//
// Currently, this only applies to string and vector literals with sigils in
// front. Those can have the sigil removed to get a borrowed pointer
// automatically.
fn check(cx: @mut Context, e: @ast::expr, t: ty::t) {
match e.node { match e.node {
ast::expr_vstore(e2, ast::expr_vstore_uniq) | ast::expr_vstore(e2, ast::expr_vstore_uniq) |
ast::expr_vstore(e2, ast::expr_vstore_box) => { ast::expr_vstore(e2, ast::expr_vstore_box) => {
@ -914,9 +909,9 @@ fn lint_unnecessary_allocations(cx: @mut Context) -> visit::vt<()> {
_ => return _ => return
} }
match ty::get(t).sty { match cx.tcx.adjustments.find_copy(&e.id) {
ty::ty_estr(ty::vstore_slice(*)) | Some(@ty::AutoDerefRef(ty::AutoDerefRef {
ty::ty_evec(_, ty::vstore_slice(*)) => { autoref: Some(ty::AutoBorrowVec(*)), _ })) => {
cx.span_lint(unnecessary_allocation, cx.span_lint(unnecessary_allocation,
e.span, "unnecessary allocation, the sigil can be \ e.span, "unnecessary allocation, the sigil can be \
removed"); removed");
@ -927,23 +922,7 @@ fn lint_unnecessary_allocations(cx: @mut Context) -> visit::vt<()> {
} }
let visit_expr: @fn(@ast::expr) = |e| { let visit_expr: @fn(@ast::expr) = |e| {
match e.node { check(cx, e);
ast::expr_call(c, ref args, _) => {
let t = ty::node_id_to_type(cx.tcx, c.id);
let s = ty::ty_fn_sig(t);
for vec::each2(*args, s.inputs) |e, t| {
check(cx, *e, *t);
}
}
ast::expr_method_call(_, _, _, ref args, _) => {
let t = ty::node_id_to_type(cx.tcx, e.callee_id);
let s = ty::ty_fn_sig(t);
for vec::each2(*args, s.inputs) |e, t| {
check(cx, *e, *t);
}
}
_ => {}
}
}; };
visit::mk_simple_visitor(@visit::SimpleVisitor { visit::mk_simple_visitor(@visit::SimpleVisitor {