-use rustc::lint::*;
use rustc::front::map::Node::{NodeExpr, NodeStmt};
-use rustc_front::hir::*;
-use rustc_front::intravisit as visit;
-use rustc::middle::ty;
-use rustc::middle::ty::adjustment::AutoAdjustment;
+use rustc::lint::*;
use rustc::middle::expr_use_visitor::*;
-use rustc::middle::infer;
+use rustc::infer;
use rustc::middle::mem_categorization::{cmt, Categorization};
+use rustc::traits::ProjectionMode;
+use rustc::ty::adjustment::AutoAdjustment;
+use rustc::ty;
use rustc::util::nodemap::NodeSet;
+use rustc_front::hir::*;
+use rustc_front::intravisit as visit;
use syntax::ast::NodeId;
use syntax::codemap::Span;
use utils::span_lint;
pub struct EscapePass;
-/// **What it does:** This lint checks for usage of `Box<T>` where an unboxed `T` would work fine. It is `Warn` by default.
+/// **What it does:** This lint checks for usage of `Box<T>` where an unboxed `T` would work fine.
///
/// **Why is this bad?** This is an unnecessary allocation, and bad for performance. It is only necessary to allocate if you wish to move the box into something.
///
/// println!("{}", *x);
/// }
/// ```
-declare_lint!(pub BOXED_LOCAL, Warn, "using Box<T> where unnecessary");
+declare_lint! {
+ pub BOXED_LOCAL, Warn, "using Box<T> where unnecessary"
+}
fn is_non_trait_box(ty: ty::Ty) -> bool {
match ty.sty {
impl LateLintPass for EscapePass {
fn check_fn(&mut self, cx: &LateContext, _: visit::FnKind, decl: &FnDecl, body: &Block, _: Span, id: NodeId) {
let param_env = ty::ParameterEnvironment::for_item(cx.tcx, id);
- let infcx = infer::new_infer_ctxt(cx.tcx, &cx.tcx.tables, Some(param_env));
+ let infcx = infer::new_infer_ctxt(cx.tcx, &cx.tcx.tables, Some(param_env), ProjectionMode::Any);
let mut v = EscapeDelegate {
cx: cx,
set: NodeSet(),
.get(&borrow_id) {
if LoanCause::AutoRef == loan_cause {
// x.foo()
- if adj.autoderefs <= 0 {
+ if adj.autoderefs == 0 {
self.set.remove(&lid); // Used without autodereffing (i.e. x.clone())
}
} else {
- self.cx.sess().span_bug(cmt.span, "Unknown adjusted AutoRef");
+ span_bug!(cmt.span, "Unknown adjusted AutoRef");
}
} else if LoanCause::AddrOf == loan_cause {
// &x