fix false positive len_zero in is_empty()
This commit is contained in:
15
src/utils.rs
15
src/utils.rs
@@ -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> {
|
||||
|
||||
Reference in New Issue
Block a user