mirror of
https://github.com/rust-lang/rust.git
synced 2025-01-26 06:35:27 +00:00
commit
b0d3659c29
@ -31,9 +31,9 @@ pub struct EscapePass;
|
||||
/// ```
|
||||
declare_lint!(pub BOXED_LOCAL, Warn, "using Box<T> where unnecessary");
|
||||
|
||||
fn is_box(ty: ty::Ty) -> bool {
|
||||
fn is_non_trait_box(ty: ty::Ty) -> bool {
|
||||
match ty.sty {
|
||||
ty::TyBox(..) => true,
|
||||
ty::TyBox(ref inner) => !inner.is_trait(),
|
||||
_ => false
|
||||
}
|
||||
}
|
||||
@ -90,7 +90,7 @@ impl<'a, 'tcx: 'a> Delegate<'tcx> for EscapeDelegate<'a, 'tcx> {
|
||||
if let Some(NodeExpr(..)) = map.find(map.get_parent_node(consume_pat.id)) {
|
||||
return;
|
||||
}
|
||||
if is_box(cmt.ty) {
|
||||
if is_non_trait_box(cmt.ty) {
|
||||
self.set.insert(consume_pat.id);
|
||||
}
|
||||
return;
|
||||
@ -101,7 +101,7 @@ impl<'a, 'tcx: 'a> Delegate<'tcx> for EscapeDelegate<'a, 'tcx> {
|
||||
if let DeclLocal(ref loc) = decl.node {
|
||||
if let Some(ref ex) = loc.init {
|
||||
if let ExprBox(..) = ex.node {
|
||||
if is_box(cmt.ty) {
|
||||
if is_non_trait_box(cmt.ty) {
|
||||
// let x = box (...)
|
||||
self.set.insert(consume_pat.id);
|
||||
}
|
||||
|
@ -11,9 +11,24 @@ impl A {
|
||||
fn foo(&self){}
|
||||
}
|
||||
|
||||
trait Z {
|
||||
fn bar(&self);
|
||||
}
|
||||
|
||||
impl Z for A {
|
||||
fn bar(&self) {
|
||||
//nothing
|
||||
}
|
||||
}
|
||||
|
||||
fn main() {
|
||||
}
|
||||
|
||||
fn ok_box_trait(boxed_trait: &Box<Z>) {
|
||||
let boxed_local = boxed_trait;
|
||||
// done
|
||||
}
|
||||
|
||||
fn warn_call() {
|
||||
let x = box A; //~ ERROR local variable
|
||||
x.foo();
|
||||
|
Loading…
Reference in New Issue
Block a user