fix false positive len_zero in is_empty()

This commit is contained in:
Andre Bogus
2015-09-06 20:57:06 +02:00
parent 1569fd8c55
commit 87e6099ad7
3 changed files with 33 additions and 25 deletions

View File

@@ -2,7 +2,7 @@ use rustc::lint::*;
use rustc_front::hir::*;
use reexport::*;
use syntax::codemap::{ExpnInfo, Span, ExpnFormat};
use rustc::front::map::Node::NodeExpr;
use rustc::front::map::Node::*;
use rustc::middle::def_id::DefId;
use rustc::middle::ty;
use std::borrow::Cow;
@@ -100,6 +100,19 @@ pub fn match_path(path: &Path, segments: &[&str]) -> bool {
|(a, b)| &a.identifier.name == b)
}
pub fn with_item_name<T, F>(cx: &Context, expr: &Expr, f: F) -> Option<T>
where F: FnOnce(Name) -> T {
let parent_id = cx.tcx.map.get_parent(expr.id);
match cx.tcx.map.find(parent_id) {
Some(NodeItem(&Item{ ref ident, .. })) |
Some(NodeTraitItem(&TraitItem{ id: _, ref ident, .. })) |
Some(NodeImplItem(&ImplItem{ id: _, ref ident, .. })) => {
Some(f(ident.name))
},
_ => None,
}
}
/// convert a span to a code snippet if available, otherwise use default, e.g.
/// `snippet(cx, expr.span, "..")`
pub fn snippet<'a>(cx: &Context, span: Span, default: &'a str) -> Cow<'a, str> {