diff --git a/Cargo.toml b/Cargo.toml index bd4be213b912..d0955c313e9d 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "clippy" -version = "0.0.6" +version = "0.0.7" authors = [ "Manish Goregaokar ", "Andre Bogus " @@ -23,4 +23,4 @@ lazy_static = "*" [features] -structured_logging = [] \ No newline at end of file +structured_logging = [] diff --git a/src/attrs.rs b/src/attrs.rs index 647e471c45e5..8d9e289fadaa 100644 --- a/src/attrs.rs +++ b/src/attrs.rs @@ -103,7 +103,7 @@ fn check_attrs(cx: &Context, info: Option<&ExpnInfo>, ident: &Ident, span_lint(cx, INLINE_ALWAYS, attr.span, &format!( "You have declared #[inline(always)] on {}. This \ is usually a bad idea. Are you sure?", - ident.as_str())); + ident.name.as_str())); } } } diff --git a/src/len_zero.rs b/src/len_zero.rs index 7e71df2dd790..0e139983bbff 100644 --- a/src/len_zero.rs +++ b/src/len_zero.rs @@ -50,7 +50,7 @@ impl LintPass for LenZero { fn check_trait_items(cx: &Context, item: &Item, trait_items: &[P]) { fn is_named_self(item: &TraitItem, name: &str) -> bool { - item.ident.as_str() == name && if let MethodTraitItem(ref sig, _) = + item.ident.name == name && if let MethodTraitItem(ref sig, _) = item.node { is_self_sig(sig) } else { false } } @@ -61,7 +61,7 @@ fn check_trait_items(cx: &Context, item: &Item, trait_items: &[P]) { span_lint(cx, LEN_WITHOUT_IS_EMPTY, i.span, &format!("Trait '{}' has a '.len(_: &Self)' method, but no \ '.is_empty(_: &Self)' method. Consider adding one.", - item.ident.as_str())); + item.ident.name)); } }; } @@ -69,7 +69,7 @@ fn check_trait_items(cx: &Context, item: &Item, trait_items: &[P]) { fn check_impl_items(cx: &Context, item: &Item, impl_items: &[P]) { fn is_named_self(item: &ImplItem, name: &str) -> bool { - item.ident.as_str() == name && if let MethodImplItem(ref sig, _) = + item.ident.name == name && if let MethodImplItem(ref sig, _) = item.node { is_self_sig(sig) } else { false } } @@ -81,7 +81,7 @@ fn check_impl_items(cx: &Context, item: &Item, impl_items: &[P]) { Span{ lo: s.lo, hi: s.lo, expn_id: s.expn_id }, &format!("Item '{}' has a '.len(_: &Self)' method, but no \ '.is_empty(_: &Self)' method. Consider adding one.", - item.ident.as_str())); + item.ident.name)); return; } } @@ -106,7 +106,7 @@ fn check_cmp(cx: &Context, span: Span, left: &Expr, right: &Expr, empty: &str) { fn check_len_zero(cx: &Context, span: Span, method: &SpannedIdent, args: &[P], lit: &Lit, empty: &str) { if let &Spanned{node: LitInt(0, _), ..} = lit { - if method.node.as_str() == "len" && args.len() == 1 && + if method.node.name == "len" && args.len() == 1 && has_is_empty(cx, &*args[0]) { span_lint(cx, LEN_ZERO, span, &format!( "Consider replacing the len comparison with '{}_.is_empty()'", diff --git a/src/misc.rs b/src/misc.rs index a140671b1bbd..73b94875b30e 100644 --- a/src/misc.rs +++ b/src/misc.rs @@ -70,7 +70,7 @@ impl LintPass for StrToStringPass { fn check_expr(&mut self, cx: &Context, expr: &ast::Expr) { match expr.node { ast::ExprMethodCall(ref method, _, ref args) - if method.node.as_str() == "to_string" + if method.node.name == "to_string" && is_str(cx, &*args[0]) => { span_lint(cx, STR_TO_STRING, expr.span, "str.to_owned() is faster"); }, @@ -135,7 +135,7 @@ impl LintPass for CmpNan { } fn check_nan(cx: &Context, path: &Path, span: Span) { - path.segments.last().map(|seg| if seg.identifier.as_str() == "NAN" { + path.segments.last().map(|seg| if seg.identifier.name == "NAN" { span_lint(cx, CMP_NAN, span, "Doomed comparison with NAN, use std::{f32,f64}::is_nan instead"); }); } @@ -238,7 +238,7 @@ impl LintPass for CmpOwned { fn check_to_owned(cx: &Context, expr: &Expr, other_span: Span) { match &expr.node { &ExprMethodCall(Spanned{node: ref ident, ..}, _, ref args) => { - let name = ident.as_str(); + let name = ident.name; if name == "to_string" || name == "to_owned" && is_str_arg(cx, args) { span_lint(cx, CMP_OWNED, expr.span, &format!( diff --git a/src/types.rs b/src/types.rs index 8c46fed2c1f8..d138239b5a76 100644 --- a/src/types.rs +++ b/src/types.rs @@ -25,7 +25,7 @@ pub fn match_ty_unwrap<'a>(ty: &'a Ty, segments: &[&str]) -> Option<&'a [P]> // I could muck around with the maps and find the full path // however the more efficient way is to simply reverse the iterators and zip them // which will compare them in reverse until one of them runs out of segments - if seg.iter().rev().zip(segments.iter().rev()).all(|(a,b)| a.identifier.as_str() == *b) { + if seg.iter().rev().zip(segments.iter().rev()).all(|(a,b)| a.identifier.name == b) { match seg[..].last() { Some(&PathSegment {parameters: AngleBracketedParameters(ref a), ..}) => { Some(&a.types[..]) diff --git a/src/utils.rs b/src/utils.rs index e3cafc700a50..d62e082c1fc2 100644 --- a/src/utils.rs +++ b/src/utils.rs @@ -41,7 +41,7 @@ pub fn match_def_path(cx: &Context, def_id: DefId, path: &[&str]) -> bool { /// `match_path(path, &["std", "rt", "begin_unwind"])` pub fn match_path(path: &Path, segments: &[&str]) -> bool { path.segments.iter().rev().zip(segments.iter().rev()).all( - |(a,b)| a.identifier.as_str() == *b) + |(a,b)| a.identifier.name == b) } /// convert a span to a code snippet if available, otherwise use default, e.g.