all: remove unneeded as_str() calls for ast::Name
Name has PartialEq and Display impls that do what we want.
This commit is contained in:
parent
f494f14aa6
commit
997f345046
@ -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.name.as_str()));
|
||||
ident.name));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -55,7 +55,7 @@ fn check_trait_items(cx: &Context, item: &Item, trait_items: &[P<TraitItem>]) {
|
||||
}
|
||||
|
||||
if !trait_items.iter().any(|i| is_named_self(i, "is_empty")) {
|
||||
//span_lint(cx, LEN_WITHOUT_IS_EMPTY, item.span, &format!("trait {}", item.ident.as_str()));
|
||||
//span_lint(cx, LEN_WITHOUT_IS_EMPTY, item.span, &format!("trait {}", item.ident));
|
||||
for i in trait_items {
|
||||
if is_named_self(i, "len") {
|
||||
span_lint(cx, LEN_WITHOUT_IS_EMPTY, i.span,
|
||||
@ -122,7 +122,7 @@ fn has_is_empty(cx: &Context, expr: &Expr) -> bool {
|
||||
if let &MethodTraitItemId(def_id) = id {
|
||||
if let ty::MethodTraitItem(ref method) =
|
||||
cx.tcx.impl_or_trait_item(def_id) {
|
||||
method.name.as_str() == "is_empty"
|
||||
method.name == "is_empty"
|
||||
&& method.fty.sig.skip_binder().inputs.len() == 1
|
||||
} else { false }
|
||||
} else { false }
|
||||
|
@ -153,7 +153,7 @@ struct RefVisitor(Vec<RefLt>);
|
||||
impl RefVisitor {
|
||||
fn record(&mut self, lifetime: &Option<Lifetime>) {
|
||||
if let &Some(ref lt) = lifetime {
|
||||
if lt.name.as_str() == "'static" {
|
||||
if lt.name == "'static" {
|
||||
self.0.push(Static);
|
||||
} else {
|
||||
self.0.push(Named(lt.name));
|
||||
|
@ -36,13 +36,12 @@ impl LintPass for LoopsPass {
|
||||
span_lint(cx, NEEDLESS_RANGE_LOOP, expr.span, &format!(
|
||||
"the loop variable `{}` is used to index `{}`. Consider using \
|
||||
`for ({}, item) in {}.iter().enumerate()` or similar iterators.",
|
||||
ident.node.name.as_str(), indexed.as_str(),
|
||||
ident.node.name.as_str(), indexed.as_str()));
|
||||
ident.node.name, indexed, ident.node.name, indexed));
|
||||
} else {
|
||||
span_lint(cx, NEEDLESS_RANGE_LOOP, expr.span, &format!(
|
||||
"the loop variable `{}` is only used to index `{}`. \
|
||||
Consider using `for item in &{}` or similar iterators.",
|
||||
ident.node.name.as_str(), indexed.as_str(), indexed.as_str()));
|
||||
ident.node.name, indexed, indexed));
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -52,7 +51,7 @@ impl LintPass for LoopsPass {
|
||||
if let ExprMethodCall(ref method, _, ref args) = arg.node {
|
||||
// just the receiver, no arguments to iter() or iter_mut()
|
||||
if args.len() == 1 {
|
||||
let method_name = method.node.name.as_str();
|
||||
let method_name = method.node.name;
|
||||
if method_name == "iter" {
|
||||
let object = snippet(cx, args[0].span, "_");
|
||||
span_lint(cx, EXPLICIT_ITER_LOOP, expr.span, &format!(
|
||||
|
@ -35,14 +35,14 @@ pub fn in_external_macro(cx: &Context, span: Span) -> bool {
|
||||
/// `match_def_path(cx, id, &["core", "option", "Option"])`
|
||||
pub fn match_def_path(cx: &Context, def_id: DefId, path: &[&str]) -> bool {
|
||||
cx.tcx.with_path(def_id, |iter| iter.map(|elem| elem.name())
|
||||
.zip(path.iter()).all(|(nm, p)| &nm.as_str() == p))
|
||||
.zip(path.iter()).all(|(nm, p)| nm == p))
|
||||
}
|
||||
|
||||
/// match a Path against a slice of segment string literals, e.g.
|
||||
/// `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.name.as_str() == b)
|
||||
|(a, b)| &a.identifier.name == b)
|
||||
}
|
||||
|
||||
/// convert a span to a code snippet if available, otherwise use default, e.g.
|
||||
|
Loading…
Reference in New Issue
Block a user