Rustup to rustc 1.16.0-nightly (468227129
2017-01-03): Eliminate has_self util
This commit is contained in:
parent
5aea0b2062
commit
a262e3bb0b
2 changed files with 15 additions and 12 deletions
|
@ -4,8 +4,7 @@ use rustc::ty;
|
||||||
use rustc::hir::*;
|
use rustc::hir::*;
|
||||||
use syntax::ast::{Lit, LitKind, Name};
|
use syntax::ast::{Lit, LitKind, Name};
|
||||||
use syntax::codemap::{Span, Spanned};
|
use syntax::codemap::{Span, Spanned};
|
||||||
use utils::{get_item_name, in_macro, snippet, span_lint, span_lint_and_then, walk_ptrs_ty,
|
use utils::{get_item_name, in_macro, snippet, span_lint, span_lint_and_then, walk_ptrs_ty};
|
||||||
is_self, has_self};
|
|
||||||
|
|
||||||
/// **What it does:** Checks for getting the length of something via `.len()`
|
/// **What it does:** Checks for getting the length of something via `.len()`
|
||||||
/// just to compare to zero, and suggests using `.is_empty()` where applicable.
|
/// just to compare to zero, and suggests using `.is_empty()` where applicable.
|
||||||
|
@ -88,16 +87,23 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for LenZero {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn check_trait_items(cx: &LateContext, item: &Item, trait_items: &[TraitItem]) {
|
fn check_trait_items(cx: &LateContext, item: &Item, trait_items: &[TraitItemRef]) {
|
||||||
fn is_named_self(item: &TraitItem, name: &str) -> bool {
|
fn is_named_self(cx: &LateContext, item: &TraitItemRef, name: &str) -> bool {
|
||||||
if let TraitItemKind::Method(ref sig, _) = item.node {
|
&*item.name.as_str() == name &&
|
||||||
return has_self(&*sig.decl) && &*item.name.as_str() == name && sig.decl.inputs.len() == 1;
|
if let AssociatedItemKind::Method { has_self } = item.kind {
|
||||||
|
has_self &&
|
||||||
|
{
|
||||||
|
let did = cx.tcx.map.local_def_id(item.id.node_id);
|
||||||
|
let impl_ty = cx.tcx.item_type(did);
|
||||||
|
impl_ty.fn_args().skip_binder().len() == 1
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
false
|
||||||
}
|
}
|
||||||
false
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if !trait_items.iter().any(|i| is_named_self(i, "is_empty")) {
|
if !trait_items.iter().any(|i| is_named_self(cx, i, "is_empty")) {
|
||||||
if let Some(i) = trait_items.iter().find(|i| is_named_self(i, "len")) {
|
if let Some(i) = trait_items.iter().find(|i| is_named_self(cx, i, "len")) {
|
||||||
if cx.access_levels.is_exported(i.id) {
|
if cx.access_levels.is_exported(i.id) {
|
||||||
span_lint(cx,
|
span_lint(cx,
|
||||||
LEN_WITHOUT_IS_EMPTY,
|
LEN_WITHOUT_IS_EMPTY,
|
||||||
|
|
|
@ -906,6 +906,3 @@ pub fn is_self(slf: &Arg) -> bool {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn has_self(slf: &FnDecl) -> bool {
|
|
||||||
slf.inputs.get(0).map(|arg| is_self(&arg)).unwrap_or(false)
|
|
||||||
}
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue