1
Fork 0
This commit is contained in:
Mateusz Mikuła 2018-06-28 15:46:58 +02:00
parent b7d95f486b
commit 48cb6e273e
48 changed files with 186 additions and 178 deletions

View file

@ -195,13 +195,13 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for AttrPass {
fn check_impl_item(&mut self, cx: &LateContext<'a, 'tcx>, item: &'tcx ImplItem) { fn check_impl_item(&mut self, cx: &LateContext<'a, 'tcx>, item: &'tcx ImplItem) {
if is_relevant_impl(cx.tcx, item) { if is_relevant_impl(cx.tcx, item) {
check_attrs(cx, item.span, item.name, &item.attrs) check_attrs(cx, item.span, item.ident.name, &item.attrs)
} }
} }
fn check_trait_item(&mut self, cx: &LateContext<'a, 'tcx>, item: &'tcx TraitItem) { fn check_trait_item(&mut self, cx: &LateContext<'a, 'tcx>, item: &'tcx TraitItem) {
if is_relevant_trait(cx.tcx, item) { if is_relevant_trait(cx.tcx, item) {
check_attrs(cx, item.span, item.name, &item.attrs) check_attrs(cx, item.span, item.ident.name, &item.attrs)
} }
} }
} }

View file

@ -41,13 +41,13 @@ impl LintPass for BlackListedName {
impl<'a, 'tcx> LateLintPass<'a, 'tcx> for BlackListedName { impl<'a, 'tcx> LateLintPass<'a, 'tcx> for BlackListedName {
fn check_pat(&mut self, cx: &LateContext<'a, 'tcx>, pat: &'tcx Pat) { fn check_pat(&mut self, cx: &LateContext<'a, 'tcx>, pat: &'tcx Pat) {
if let PatKind::Binding(_, _, ref ident, _) = pat.node { if let PatKind::Binding(_, _, ident, _) = pat.node {
if self.blacklist.iter().any(|s| ident.node == *s) { if self.blacklist.iter().any(|s| ident.name == *s) {
span_lint( span_lint(
cx, cx,
BLACKLISTED_NAME, BLACKLISTED_NAME,
ident.span, ident.span,
&format!("use of a blacklisted/placeholder name `{}`", ident.node), &format!("use of a blacklisted/placeholder name `{}`", ident.name),
); );
} }
} }

View file

@ -203,7 +203,7 @@ impl<'a, 'tcx, 'v> SuggestContext<'a, 'tcx, 'v> {
METHODS_WITH_NEGATION METHODS_WITH_NEGATION
.iter().cloned() .iter().cloned()
.flat_map(|(a, b)| vec![(a, b), (b, a)]) .flat_map(|(a, b)| vec![(a, b), (b, a)])
.find(|&(a, _)| a == path.name.as_str()) .find(|&(a, _)| a == path.ident.as_str())
.and_then(|(_, neg_method)| Some(format!("{}.{}()", self.snip(&args[0])?, neg_method))) .and_then(|(_, neg_method)| Some(format!("{}.{}()", self.snip(&args[0])?, neg_method)))
}, },
_ => None, _ => None,

View file

@ -39,10 +39,10 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for ByteCount {
fn check_expr(&mut self, cx: &LateContext, expr: &Expr) { fn check_expr(&mut self, cx: &LateContext, expr: &Expr) {
if_chain! { if_chain! {
if let ExprMethodCall(ref count, _, ref count_args) = expr.node; if let ExprMethodCall(ref count, _, ref count_args) = expr.node;
if count.name == "count"; if count.ident.name == "count";
if count_args.len() == 1; if count_args.len() == 1;
if let ExprMethodCall(ref filter, _, ref filter_args) = count_args[0].node; if let ExprMethodCall(ref filter, _, ref filter_args) = count_args[0].node;
if filter.name == "filter"; if filter.ident.name == "filter";
if filter_args.len() == 2; if filter_args.len() == 2;
if let ExprClosure(_, _, body_id, _, _) = filter_args[1].node; if let ExprClosure(_, _, body_id, _, _) = filter_args[1].node;
then { then {
@ -68,7 +68,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for ByteCount {
} }
let haystack = if let ExprMethodCall(ref path, _, ref args) = let haystack = if let ExprMethodCall(ref path, _, ref args) =
filter_args[0].node { filter_args[0].node {
let p = path.name; let p = path.ident.name;
if (p == "iter" || p == "iter_mut") && args.len() == 1 { if (p == "iter" || p == "iter_mut") && args.len() == 1 {
&args[0] &args[0]
} else { } else {
@ -104,7 +104,7 @@ fn get_path_name(expr: &Expr) -> Option<Name> {
} else { } else {
None None
}, },
ExprPath(ref qpath) => single_segment_path(qpath).map(|ps| ps.name), ExprPath(ref qpath) => single_segment_path(qpath).map(|ps| ps.ident.name),
_ => None, _ => None,
} }
} }

View file

@ -269,8 +269,8 @@ fn bindings<'a, 'tcx>(cx: &LateContext<'a, 'tcx>, pat: &Pat) -> HashMap<LocalInt
PatKind::TupleStruct(_, ref pats, _) => for pat in pats { PatKind::TupleStruct(_, ref pats, _) => for pat in pats {
bindings_impl(cx, pat, map); bindings_impl(cx, pat, map);
}, },
PatKind::Binding(_, _, ref ident, ref as_pat) => { PatKind::Binding(_, _, ident, ref as_pat) => {
if let Entry::Vacant(v) = map.entry(ident.node.as_str()) { if let Entry::Vacant(v) = map.entry(ident.as_str()) {
v.insert(cx.tables.pat_ty(pat)); v.insert(cx.tables.pat_ty(pat));
} }
if let Some(ref as_pat) = *as_pat { if let Some(ref as_pat) = *as_pat {

View file

@ -43,7 +43,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for DurationSubsec {
if match_type(cx, walk_ptrs_ty(cx.tables.expr_ty(&args[0])), &paths::DURATION); if match_type(cx, walk_ptrs_ty(cx.tables.expr_ty(&args[0])), &paths::DURATION);
if let Some((Constant::Int(divisor), _)) = constant(cx, cx.tables, right); if let Some((Constant::Int(divisor), _)) = constant(cx, cx.tables, right);
then { then {
let suggested_fn = match (method_path.name.as_str().as_ref(), divisor) { let suggested_fn = match (method_path.ident.as_str().as_ref(), divisor) {
("subsec_micros", 1_000) => "subsec_millis", ("subsec_micros", 1_000) => "subsec_millis",
("subsec_nanos", 1_000) => "subsec_micros", ("subsec_nanos", 1_000) => "subsec_micros",
("subsec_nanos", 1_000_000) => "subsec_millis", ("subsec_nanos", 1_000_000) => "subsec_millis",

View file

@ -90,7 +90,7 @@ fn check_cond<'a, 'tcx, 'b>(
if_chain! { if_chain! {
if let ExprMethodCall(ref path, _, ref params) = check.node; if let ExprMethodCall(ref path, _, ref params) = check.node;
if params.len() >= 2; if params.len() >= 2;
if path.name == "contains_key"; if path.ident.name == "contains_key";
if let ExprAddrOf(_, ref key) = params[1].node; if let ExprAddrOf(_, ref key) = params[1].node;
then { then {
let map = &params[0]; let map = &params[0];
@ -125,7 +125,7 @@ impl<'a, 'tcx, 'b> Visitor<'tcx> for InsertVisitor<'a, 'tcx, 'b> {
if_chain! { if_chain! {
if let ExprMethodCall(ref path, _, ref params) = expr.node; if let ExprMethodCall(ref path, _, ref params) = expr.node;
if params.len() == 3; if params.len() == 3;
if path.name == "insert"; if path.ident.name == "insert";
if get_item_name(self.cx, self.map) == get_item_name(self.cx, &params[0]); if get_item_name(self.cx, self.map) == get_item_name(self.cx, &params[0]);
if SpanlessEq::new(self.cx).eq_expr(self.key, &params[1]); if SpanlessEq::new(self.cx).eq_expr(self.key, &params[1]);
then { then {

View file

@ -121,7 +121,7 @@ impl LintPass for EnumVariantNames {
} }
fn var2str(var: &Variant) -> LocalInternedString { fn var2str(var: &Variant) -> LocalInternedString {
var.node.ident.name.as_str() var.node.ident.as_str()
} }
/// Returns the number of chars that match from the start /// Returns the number of chars that match from the start
@ -245,7 +245,7 @@ impl EarlyLintPass for EnumVariantNames {
} }
fn check_item(&mut self, cx: &EarlyContext, item: &Item) { fn check_item(&mut self, cx: &EarlyContext, item: &Item) {
let item_name = item.ident.name.as_str(); let item_name = item.ident.as_str();
let item_name_chars = item_name.chars().count(); let item_name_chars = item_name.chars().count();
let item_camel = to_camel_case(&item_name); let item_camel = to_camel_case(&item_name);
if !in_macro(item.span) { if !in_macro(item.span) {

View file

@ -78,7 +78,7 @@ fn check_closure(cx: &LateContext, expr: &Expr) {
// If it's a proper path, it can't be a local variable // If it's a proper path, it can't be a local variable
return; return;
} }
if p.segments[0].name != ident.node { if p.segments[0].ident.name != ident.name {
// The two idents should be the same // The two idents should be the same
return; return;
} }

View file

@ -36,12 +36,12 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for Pass {
if_chain! { if_chain! {
// match call to unwrap // match call to unwrap
if let ExprMethodCall(ref unwrap_fun, _, ref unwrap_args) = expr.node; if let ExprMethodCall(ref unwrap_fun, _, ref unwrap_args) = expr.node;
if unwrap_fun.name == "unwrap"; if unwrap_fun.ident.name == "unwrap";
// match call to write_fmt // match call to write_fmt
if unwrap_args.len() > 0; if unwrap_args.len() > 0;
if let ExprMethodCall(ref write_fun, _, ref write_args) = if let ExprMethodCall(ref write_fun, _, ref write_args) =
unwrap_args[0].node; unwrap_args[0].node;
if write_fun.name == "write_fmt"; if write_fun.ident.name == "write_fmt";
// match calls to std::io::stdout() / std::io::stderr () // match calls to std::io::stdout() / std::io::stderr ()
if write_args.len() > 0; if write_args.len() > 0;
if let ExprCall(ref dest_fun, _) = write_args[0].node; if let ExprCall(ref dest_fun, _) = write_args[0].node;

View file

@ -93,7 +93,7 @@ fn lint_impl_body<'a, 'tcx>(cx: &LateContext<'a, 'tcx>, impl_span: Span, impl_it
for impl_item in impl_items { for impl_item in impl_items {
if_chain! { if_chain! {
if impl_item.name == "from"; if impl_item.ident.name == "from";
if let ImplItemKind::Method(_, body_id) = if let ImplItemKind::Method(_, body_id) =
cx.tcx.hir.impl_item(impl_item.id).node; cx.tcx.hir.impl_item(impl_item.id).node;
then { then {

View file

@ -151,7 +151,7 @@ fn check_unformatted(expr: &Expr) -> bool {
if let ExprStruct(_, ref fields, _) = format_field.expr.node; if let ExprStruct(_, ref fields, _) = format_field.expr.node;
if let Some(align_field) = fields.iter().find(|f| f.ident.name == "width"); if let Some(align_field) = fields.iter().find(|f| f.ident.name == "width");
if let ExprPath(ref qpath) = align_field.expr.node; if let ExprPath(ref qpath) = align_field.expr.node;
if last_path_segment(qpath).name == "Implied"; if last_path_segment(qpath).ident.name == "Implied";
then { then {
return true; return true;
} }

View file

@ -56,7 +56,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for IdentityConversion {
}, },
ExprMethodCall(ref name, .., ref args) => { ExprMethodCall(ref name, .., ref args) => {
if match_trait_method(cx, e, &paths::INTO[..]) && &*name.name.as_str() == "into" { if match_trait_method(cx, e, &paths::INTO[..]) && &*name.ident.as_str() == "into" {
let a = cx.tables.expr_ty(e); let a = cx.tables.expr_ty(e);
let b = cx.tables.expr_ty(&args[0]); let b = cx.tables.expr_ty(&args[0]);
if same_tys(cx, a, b) { if same_tys(cx, a, b) {

View file

@ -143,7 +143,7 @@ fn is_infinite(cx: &LateContext, expr: &Expr) -> Finiteness {
match expr.node { match expr.node {
ExprMethodCall(ref method, _, ref args) => { ExprMethodCall(ref method, _, ref args) => {
for &(name, len, heuristic, cap) in HEURISTICS.iter() { for &(name, len, heuristic, cap) in HEURISTICS.iter() {
if method.name == name && args.len() == len { if method.ident.name == name && args.len() == len {
return (match heuristic { return (match heuristic {
Always => Infinite, Always => Infinite,
First => is_infinite(cx, &args[0]), First => is_infinite(cx, &args[0]),
@ -152,7 +152,7 @@ fn is_infinite(cx: &LateContext, expr: &Expr) -> Finiteness {
}).and(cap); }).and(cap);
} }
} }
if method.name == "flat_map" && args.len() == 2 { if method.ident.name == "flat_map" && args.len() == 2 {
if let ExprClosure(_, _, body_id, _, _) = args[1].node { if let ExprClosure(_, _, body_id, _, _) = args[1].node {
let body = cx.tcx.hir.body(body_id); let body = cx.tcx.hir.body(body_id);
return is_infinite(cx, &body.value); return is_infinite(cx, &body.value);
@ -207,16 +207,16 @@ fn complete_infinite_iter(cx: &LateContext, expr: &Expr) -> Finiteness {
match expr.node { match expr.node {
ExprMethodCall(ref method, _, ref args) => { ExprMethodCall(ref method, _, ref args) => {
for &(name, len) in COMPLETING_METHODS.iter() { for &(name, len) in COMPLETING_METHODS.iter() {
if method.name == name && args.len() == len { if method.ident.name == name && args.len() == len {
return is_infinite(cx, &args[0]); return is_infinite(cx, &args[0]);
} }
} }
for &(name, len) in POSSIBLY_COMPLETING_METHODS.iter() { for &(name, len) in POSSIBLY_COMPLETING_METHODS.iter() {
if method.name == name && args.len() == len { if method.ident.name == name && args.len() == len {
return MaybeInfinite.and(is_infinite(cx, &args[0])); return MaybeInfinite.and(is_infinite(cx, &args[0]));
} }
} }
if method.name == "last" && args.len() == 1 { if method.ident.name == "last" && args.len() == 1 {
let not_double_ended = get_trait_def_id(cx, &paths::DOUBLE_ENDED_ITERATOR) let not_double_ended = get_trait_def_id(cx, &paths::DOUBLE_ENDED_ITERATOR)
.map_or(false, |id| !implements_trait(cx, cx.tables.expr_ty(&args[0]), id, &[])); .map_or(false, |id| !implements_trait(cx, cx.tables.expr_ty(&args[0]), id, &[]));
if not_double_ended { if not_double_ended {

View file

@ -38,7 +38,7 @@ impl LintPass for Pass {
impl<'a, 'tcx> LateLintPass<'a, 'tcx> for Pass { impl<'a, 'tcx> LateLintPass<'a, 'tcx> for Pass {
fn check_trait_item(&mut self, cx: &LateContext<'a, 'tcx>, item: &'tcx TraitItem) { fn check_trait_item(&mut self, cx: &LateContext<'a, 'tcx>, item: &'tcx TraitItem) {
if let TraitItemKind::Method(_, TraitMethod::Required(_)) = item.node { if let TraitItemKind::Method(_, TraitMethod::Required(_)) = item.node {
check_attrs(cx, item.name, &item.attrs); check_attrs(cx, item.ident.name, &item.attrs);
} }
} }
} }

View file

@ -107,7 +107,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for LenZero {
fn check_trait_items(cx: &LateContext, visited_trait: &Item, trait_items: &[TraitItemRef]) { fn check_trait_items(cx: &LateContext, visited_trait: &Item, trait_items: &[TraitItemRef]) {
fn is_named_self(cx: &LateContext, item: &TraitItemRef, name: &str) -> bool { fn is_named_self(cx: &LateContext, item: &TraitItemRef, name: &str) -> bool {
item.name == name && if let AssociatedItemKind::Method { has_self } = item.kind { item.ident.name == name && if let AssociatedItemKind::Method { has_self } = item.kind {
has_self && { has_self && {
let did = cx.tcx.hir.local_def_id(item.id.node_id); let did = cx.tcx.hir.local_def_id(item.id.node_id);
cx.tcx.fn_sig(did).inputs().skip_binder().len() == 1 cx.tcx.fn_sig(did).inputs().skip_binder().len() == 1
@ -135,7 +135,7 @@ fn check_trait_items(cx: &LateContext, visited_trait: &Item, trait_items: &[Trai
.iter() .iter()
.flat_map(|&i| cx.tcx.associated_items(i)) .flat_map(|&i| cx.tcx.associated_items(i))
.any(|i| { .any(|i| {
i.kind == ty::AssociatedKind::Method && i.method_has_self_argument && i.name == "is_empty" i.kind == ty::AssociatedKind::Method && i.method_has_self_argument && i.ident.name == "is_empty"
&& cx.tcx.fn_sig(i.def_id).inputs().skip_binder().len() == 1 && cx.tcx.fn_sig(i.def_id).inputs().skip_binder().len() == 1
}); });
@ -155,7 +155,7 @@ fn check_trait_items(cx: &LateContext, visited_trait: &Item, trait_items: &[Trai
fn check_impl_items(cx: &LateContext, item: &Item, impl_items: &[ImplItemRef]) { fn check_impl_items(cx: &LateContext, item: &Item, impl_items: &[ImplItemRef]) {
fn is_named_self(cx: &LateContext, item: &ImplItemRef, name: &str) -> bool { fn is_named_self(cx: &LateContext, item: &ImplItemRef, name: &str) -> bool {
item.name == name && if let AssociatedItemKind::Method { has_self } = item.kind { item.ident.name == name && if let AssociatedItemKind::Method { has_self } = item.kind {
has_self && { has_self && {
let did = cx.tcx.hir.local_def_id(item.id.node_id); let did = cx.tcx.hir.local_def_id(item.id.node_id);
cx.tcx.fn_sig(did).inputs().skip_binder().len() == 1 cx.tcx.fn_sig(did).inputs().skip_binder().len() == 1
@ -202,7 +202,7 @@ fn check_cmp(cx: &LateContext, span: Span, method: &Expr, lit: &Expr, op: &str,
} }
} }
check_len(cx, span, method_path.name, args, lit, op, compare_to) check_len(cx, span, method_path.ident.name, args, lit, op, compare_to)
} }
} }
@ -235,7 +235,7 @@ fn has_is_empty(cx: &LateContext, expr: &Expr) -> bool {
/// Get an `AssociatedItem` and return true if it matches `is_empty(self)`. /// Get an `AssociatedItem` and return true if it matches `is_empty(self)`.
fn is_is_empty(cx: &LateContext, item: &ty::AssociatedItem) -> bool { fn is_is_empty(cx: &LateContext, item: &ty::AssociatedItem) -> bool {
if let ty::AssociatedKind::Method = item.kind { if let ty::AssociatedKind::Method = item.kind {
if item.name == "is_empty" { if item.ident.name == "is_empty" {
let sig = cx.tcx.fn_sig(item.def_id); let sig = cx.tcx.fn_sig(item.def_id);
let ty = sig.skip_binder(); let ty = sig.skip_binder();
ty.inputs().len() == 1 ty.inputs().len() == 1

View file

@ -67,7 +67,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for LetIfSeq {
if let Some(expr) = it.peek(); if let Some(expr) = it.peek();
if let hir::StmtDecl(ref decl, _) = stmt.node; if let hir::StmtDecl(ref decl, _) = stmt.node;
if let hir::DeclLocal(ref decl) = decl.node; if let hir::DeclLocal(ref decl) = decl.node;
if let hir::PatKind::Binding(mode, canonical_id, ref name, None) = decl.pat.node; if let hir::PatKind::Binding(mode, canonical_id, ident, None) = decl.pat.node;
if let hir::StmtExpr(ref if_, _) = expr.node; if let hir::StmtExpr(ref if_, _) = expr.node;
if let hir::ExprIf(ref cond, ref then, ref else_) = if_.node; if let hir::ExprIf(ref cond, ref then, ref else_) = if_.node;
if !used_in_expr(cx, canonical_id, cond); if !used_in_expr(cx, canonical_id, cond);
@ -106,7 +106,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for LetIfSeq {
let sug = format!( let sug = format!(
"let {mut}{name} = if {cond} {{{then} {value} }} else {{{else} {default} }};", "let {mut}{name} = if {cond} {{{then} {value} }} else {{{else} {default} }};",
mut=mutability, mut=mutability,
name=name.node, name=ident.name,
cond=snippet(cx, cond.span, "_"), cond=snippet(cx, cond.span, "_"),
then=if then.stmts.len() > 1 { " ..;" } else { "" }, then=if then.stmts.len() > 1 { " ..;" } else { "" },
else=if default_multi_stmts { " ..;" } else { "" }, else=if default_multi_stmts { " ..;" } else { "" },

View file

@ -126,7 +126,7 @@ fn check_fn_inner<'a, 'tcx>(
GenericArg::Type(_) => None, GenericArg::Type(_) => None,
}); });
for bound in lifetimes { for bound in lifetimes {
if bound.name.name() != "'static" && !bound.is_elided() { if bound.name.ident().name != "'static" && !bound.is_elided() {
return; return;
} }
bounds_lts.push(bound); bounds_lts.push(bound);
@ -240,7 +240,7 @@ fn allowed_lts_from(named_generics: &[GenericParam]) -> HashSet<RefLt> {
for par in named_generics.iter() { for par in named_generics.iter() {
if let GenericParamKind::Lifetime { .. } = par.kind { if let GenericParamKind::Lifetime { .. } = par.kind {
if par.bounds.is_empty() { if par.bounds.is_empty() {
allowed_lts.insert(RefLt::Named(par.name.name())); allowed_lts.insert(RefLt::Named(par.name.ident().name));
} }
} }
} }
@ -251,8 +251,8 @@ fn allowed_lts_from(named_generics: &[GenericParam]) -> HashSet<RefLt> {
fn lts_from_bounds<'a, T: Iterator<Item = &'a Lifetime>>(mut vec: Vec<RefLt>, bounds_lts: T) -> Vec<RefLt> { fn lts_from_bounds<'a, T: Iterator<Item = &'a Lifetime>>(mut vec: Vec<RefLt>, bounds_lts: T) -> Vec<RefLt> {
for lt in bounds_lts { for lt in bounds_lts {
if lt.name.name() != "'static" { if lt.name.ident().name != "'static" {
vec.push(RefLt::Named(lt.name.name())); vec.push(RefLt::Named(lt.name.ident().name));
} }
} }
@ -282,12 +282,12 @@ impl<'v, 't> RefVisitor<'v, 't> {
fn record(&mut self, lifetime: &Option<Lifetime>) { fn record(&mut self, lifetime: &Option<Lifetime>) {
if let Some(ref lt) = *lifetime { if let Some(ref lt) = *lifetime {
if lt.name.name() == "'static" { if lt.name.ident().name == "'static" {
self.lts.push(RefLt::Static); self.lts.push(RefLt::Static);
} else if lt.is_elided() { } else if lt.is_elided() {
self.lts.push(RefLt::Unnamed); self.lts.push(RefLt::Unnamed);
} else { } else {
self.lts.push(RefLt::Named(lt.name.name())); self.lts.push(RefLt::Named(lt.name.ident().name));
} }
} else { } else {
self.lts.push(RefLt::Unnamed); self.lts.push(RefLt::Unnamed);
@ -421,7 +421,7 @@ struct LifetimeChecker {
impl<'tcx> Visitor<'tcx> for LifetimeChecker { impl<'tcx> Visitor<'tcx> for LifetimeChecker {
// for lifetimes as parameters of generics // for lifetimes as parameters of generics
fn visit_lifetime(&mut self, lifetime: &'tcx Lifetime) { fn visit_lifetime(&mut self, lifetime: &'tcx Lifetime) {
self.map.remove(&lifetime.name.name()); self.map.remove(&lifetime.name.ident().name);
} }
fn visit_generic_param(&mut self, param: &'tcx GenericParam) { fn visit_generic_param(&mut self, param: &'tcx GenericParam) {
@ -442,7 +442,7 @@ impl<'tcx> Visitor<'tcx> for LifetimeChecker {
fn report_extra_lifetimes<'a, 'tcx: 'a>(cx: &LateContext<'a, 'tcx>, func: &'tcx FnDecl, generics: &'tcx Generics) { fn report_extra_lifetimes<'a, 'tcx: 'a>(cx: &LateContext<'a, 'tcx>, func: &'tcx FnDecl, generics: &'tcx Generics) {
let hs = generics.params.iter() let hs = generics.params.iter()
.filter_map(|par| match par.kind { .filter_map(|par| match par.kind {
GenericParamKind::Lifetime { .. } => Some((par.name.name(), par.span)), GenericParamKind::Lifetime { .. } => Some((par.name.ident().name, par.span)),
_ => None, _ => None,
}) })
.collect(); .collect();
@ -463,7 +463,7 @@ struct BodyLifetimeChecker {
impl<'tcx> Visitor<'tcx> for BodyLifetimeChecker { impl<'tcx> Visitor<'tcx> for BodyLifetimeChecker {
// for lifetimes as parameters of generics // for lifetimes as parameters of generics
fn visit_lifetime(&mut self, lifetime: &'tcx Lifetime) { fn visit_lifetime(&mut self, lifetime: &'tcx Lifetime) {
if lifetime.name.name() != keywords::Invalid.name() && lifetime.name.name() != "'static" { if lifetime.name.ident().name != keywords::Invalid.name() && lifetime.name.ident().name != "'static" {
self.lifetimes_used_in_body = true; self.lifetimes_used_in_body = true;
} }
} }

View file

@ -485,8 +485,8 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for Pass {
{ {
let iter_expr = &method_args[0]; let iter_expr = &method_args[0];
let lhs_constructor = last_path_segment(qpath); let lhs_constructor = last_path_segment(qpath);
if method_path.name == "next" && match_trait_method(cx, match_expr, &paths::ITERATOR) if method_path.ident.name == "next" && match_trait_method(cx, match_expr, &paths::ITERATOR)
&& lhs_constructor.name == "Some" && !is_refutable(cx, &pat_args[0]) && lhs_constructor.ident.name == "Some" && !is_refutable(cx, &pat_args[0])
&& !is_iterator_used_after_while_let(cx, iter_expr) && !is_iterator_used_after_while_let(cx, iter_expr)
&& !is_nested(cx, expr, &method_args[0]) && !is_nested(cx, expr, &method_args[0])
{ {
@ -513,7 +513,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for Pass {
fn check_stmt(&mut self, cx: &LateContext<'a, 'tcx>, stmt: &'tcx Stmt) { fn check_stmt(&mut self, cx: &LateContext<'a, 'tcx>, stmt: &'tcx Stmt) {
if let StmtSemi(ref expr, _) = stmt.node { if let StmtSemi(ref expr, _) = stmt.node {
if let ExprMethodCall(ref method, _, ref args) = expr.node { if let ExprMethodCall(ref method, _, ref args) = expr.node {
if args.len() == 1 && method.name == "collect" && match_trait_method(cx, expr, &paths::ITERATOR) { if args.len() == 1 && method.ident.name == "collect" && match_trait_method(cx, expr, &paths::ITERATOR) {
span_lint( span_lint(
cx, cx,
UNUSED_COLLECT, UNUSED_COLLECT,
@ -811,7 +811,7 @@ fn fetch_cloned_fixed_offset_var<'a, 'tcx>(
) -> Option<FixedOffsetVar> { ) -> Option<FixedOffsetVar> {
if_chain! { if_chain! {
if let ExprMethodCall(ref method, _, ref args) = expr.node; if let ExprMethodCall(ref method, _, ref args) = expr.node;
if method.name == "clone"; if method.ident.name == "clone";
if args.len() == 1; if args.len() == 1;
if let Some(arg) = args.get(0); if let Some(arg) = args.get(0);
then { then {
@ -907,7 +907,7 @@ fn detect_manual_memcpy<'a, 'tcx>(
let print_limit = |end: &Option<&Expr>, offset: Offset, var_name: &str| if let Some(end) = *end { let print_limit = |end: &Option<&Expr>, offset: Offset, var_name: &str| if let Some(end) = *end {
if_chain! { if_chain! {
if let ExprMethodCall(ref method, _, ref len_args) = end.node; if let ExprMethodCall(ref method, _, ref len_args) = end.node;
if method.name == "len"; if method.ident.name == "len";
if len_args.len() == 1; if len_args.len() == 1;
if let Some(arg) = len_args.get(0); if let Some(arg) = len_args.get(0);
if snippet(cx, arg.span, "??") == var_name; if snippet(cx, arg.span, "??") == var_name;
@ -985,7 +985,7 @@ fn check_for_loop_range<'a, 'tcx>(
}) = higher::range(cx, arg) }) = higher::range(cx, arg)
{ {
// the var must be a single name // the var must be a single name
if let PatKind::Binding(_, canonical_id, ref ident, _) = pat.node { if let PatKind::Binding(_, canonical_id, ident, _) = pat.node {
let mut visitor = VarVisitor { let mut visitor = VarVisitor {
cx, cx,
var: canonical_id, var: canonical_id,
@ -1058,13 +1058,13 @@ fn check_for_loop_range<'a, 'tcx>(
cx, cx,
NEEDLESS_RANGE_LOOP, NEEDLESS_RANGE_LOOP,
expr.span, expr.span,
&format!("the loop variable `{}` is used to index `{}`", ident.node, indexed), &format!("the loop variable `{}` is used to index `{}`", ident.name, indexed),
|db| { |db| {
multispan_sugg( multispan_sugg(
db, db,
"consider using an iterator".to_string(), "consider using an iterator".to_string(),
vec![ vec![
(pat.span, format!("({}, <item>)", ident.node)), (pat.span, format!("({}, <item>)", ident.name)),
(arg.span, format!("{}.{}().enumerate(){}{}", indexed, method, take, skip)), (arg.span, format!("{}.{}().enumerate(){}{}", indexed, method, take, skip)),
], ],
); );
@ -1081,7 +1081,7 @@ fn check_for_loop_range<'a, 'tcx>(
cx, cx,
NEEDLESS_RANGE_LOOP, NEEDLESS_RANGE_LOOP,
expr.span, expr.span,
&format!("the loop variable `{}` is only used to index `{}`.", ident.node, indexed), &format!("the loop variable `{}` is only used to index `{}`.", ident.name, indexed),
|db| { |db| {
multispan_sugg( multispan_sugg(
db, db,
@ -1100,10 +1100,10 @@ fn is_len_call(expr: &Expr, var: Name) -> bool {
if_chain! { if_chain! {
if let ExprMethodCall(ref method, _, ref len_args) = expr.node; if let ExprMethodCall(ref method, _, ref len_args) = expr.node;
if len_args.len() == 1; if len_args.len() == 1;
if method.name == "len"; if method.ident.name == "len";
if let ExprPath(QPath::Resolved(_, ref path)) = len_args[0].node; if let ExprPath(QPath::Resolved(_, ref path)) = len_args[0].node;
if path.segments.len() == 1; if path.segments.len() == 1;
if path.segments[0].name == var; if path.segments[0].ident.name == var;
then { then {
return true; return true;
} }
@ -1206,7 +1206,7 @@ fn check_for_loop_arg(cx: &LateContext, pat: &Pat, arg: &Expr, expr: &Expr) {
if let ExprMethodCall(ref method, _, ref args) = arg.node { if let ExprMethodCall(ref method, _, ref args) = arg.node {
// just the receiver, no arguments // just the receiver, no arguments
if args.len() == 1 { if args.len() == 1 {
let method_name = &*method.name.as_str(); let method_name = &*method.ident.as_str();
// check for looping over x.iter() or x.iter_mut(), could use &x or &mut x // check for looping over x.iter() or x.iter_mut(), could use &x or &mut x
if method_name == "iter" || method_name == "iter_mut" { if method_name == "iter" || method_name == "iter_mut" {
if is_ref_iterable_type(cx, &args[0]) { if is_ref_iterable_type(cx, &args[0]) {
@ -1520,9 +1520,9 @@ fn check_for_mutation(cx: &LateContext, body: &Expr, bound_ids: &[Option<NodeId>
fn pat_is_wild<'tcx>(pat: &'tcx PatKind, body: &'tcx Expr) -> bool { fn pat_is_wild<'tcx>(pat: &'tcx PatKind, body: &'tcx Expr) -> bool {
match *pat { match *pat {
PatKind::Wild => true, PatKind::Wild => true,
PatKind::Binding(_, _, ident, None) if ident.node.as_str().starts_with('_') => { PatKind::Binding(_, _, ident, None) if ident.as_str().starts_with('_') => {
let mut visitor = UsedVisitor { let mut visitor = UsedVisitor {
var: ident.node, var: ident.name,
used: false, used: false,
}; };
walk_expr(&mut visitor, body); walk_expr(&mut visitor, body);
@ -1615,7 +1615,7 @@ impl<'a, 'tcx> VarVisitor<'a, 'tcx> {
if indexed_indirectly || index_used_directly { if indexed_indirectly || index_used_directly {
if self.prefer_mutable { if self.prefer_mutable {
self.indexed_mut.insert(seqvar.segments[0].name); self.indexed_mut.insert(seqvar.segments[0].ident.name);
} }
let def = self.cx.tables.qpath_def(seqpath, seqexpr.hir_id); let def = self.cx.tables.qpath_def(seqpath, seqexpr.hir_id);
match def { match def {
@ -1626,19 +1626,19 @@ impl<'a, 'tcx> VarVisitor<'a, 'tcx> {
let parent_def_id = self.cx.tcx.hir.local_def_id(parent_id); let parent_def_id = self.cx.tcx.hir.local_def_id(parent_id);
let extent = self.cx.tcx.region_scope_tree(parent_def_id).var_scope(hir_id.local_id); let extent = self.cx.tcx.region_scope_tree(parent_def_id).var_scope(hir_id.local_id);
if indexed_indirectly { if indexed_indirectly {
self.indexed_indirectly.insert(seqvar.segments[0].name, Some(extent)); self.indexed_indirectly.insert(seqvar.segments[0].ident.name, Some(extent));
} }
if index_used_directly { if index_used_directly {
self.indexed_directly.insert(seqvar.segments[0].name, Some(extent)); self.indexed_directly.insert(seqvar.segments[0].ident.name, Some(extent));
} }
return false; // no need to walk further *on the variable* return false; // no need to walk further *on the variable*
} }
Def::Static(..) | Def::Const(..) => { Def::Static(..) | Def::Const(..) => {
if indexed_indirectly { if indexed_indirectly {
self.indexed_indirectly.insert(seqvar.segments[0].name, None); self.indexed_indirectly.insert(seqvar.segments[0].ident.name, None);
} }
if index_used_directly { if index_used_directly {
self.indexed_directly.insert(seqvar.segments[0].name, None); self.indexed_directly.insert(seqvar.segments[0].ident.name, None);
} }
return false; // no need to walk further *on the variable* return false; // no need to walk further *on the variable*
} }
@ -1656,8 +1656,8 @@ impl<'a, 'tcx> Visitor<'tcx> for VarVisitor<'a, 'tcx> {
if_chain! { if_chain! {
// a range index op // a range index op
if let ExprMethodCall(ref meth, _, ref args) = expr.node; if let ExprMethodCall(ref meth, _, ref args) = expr.node;
if (meth.name == "index" && match_trait_method(self.cx, expr, &paths::INDEX)) if (meth.ident.name == "index" && match_trait_method(self.cx, expr, &paths::INDEX))
|| (meth.name == "index_mut" && match_trait_method(self.cx, expr, &paths::INDEX_MUT)); || (meth.ident.name == "index_mut" && match_trait_method(self.cx, expr, &paths::INDEX_MUT));
if !self.check(&args[1], &args[0], expr); if !self.check(&args[1], &args[0], expr);
then { return } then { return }
} }
@ -1681,7 +1681,7 @@ impl<'a, 'tcx> Visitor<'tcx> for VarVisitor<'a, 'tcx> {
self.nonindex = true; self.nonindex = true;
} else { } else {
// not the correct variable, but still a variable // not the correct variable, but still a variable
self.referenced.insert(path.segments[0].name); self.referenced.insert(path.segments[0].ident.name);
} }
} }
} }
@ -1933,8 +1933,8 @@ impl<'a, 'tcx> Visitor<'tcx> for InitializeVisitor<'a, 'tcx> {
// Look for declarations of the variable // Look for declarations of the variable
if let DeclLocal(ref local) = decl.node { if let DeclLocal(ref local) = decl.node {
if local.pat.id == self.var_id { if local.pat.id == self.var_id {
if let PatKind::Binding(_, _, ref ident, _) = local.pat.node { if let PatKind::Binding(_, _, ident, _) = local.pat.node {
self.name = Some(ident.node); self.name = Some(ident.name);
self.state = if let Some(ref init) = local.init { self.state = if let Some(ref init) = local.init {
if is_integer_literal(init, 0) { if is_integer_literal(init, 0) {
@ -2123,7 +2123,7 @@ impl<'tcx> Visitor<'tcx> for LoopNestVisitor {
return; return;
} }
if let PatKind::Binding(_, _, span_name, _) = pat.node { if let PatKind::Binding(_, _, span_name, _) = pat.node {
if self.iterator == span_name.node { if self.iterator == span_name.name {
self.nesting = RuledOut; self.nesting = RuledOut;
return; return;
} }
@ -2140,7 +2140,7 @@ fn path_name(e: &Expr) -> Option<Name> {
if let ExprPath(QPath::Resolved(_, ref path)) = e.node { if let ExprPath(QPath::Resolved(_, ref path)) = e.node {
let segments = &path.segments; let segments = &path.segments;
if segments.len() == 1 { if segments.len() == 1 {
return Some(segments[0].name); return Some(segments[0].ident.name);
} }
}; };
None None

View file

@ -2,7 +2,7 @@ use rustc::lint::*;
use rustc::hir::*; use rustc::hir::*;
use rustc::ty; use rustc::ty;
use syntax::ast; use syntax::ast;
use crate::utils::{get_arg_name, is_adjusted, iter_input_pats, match_qpath, match_trait_method, match_type, use crate::utils::{get_arg_ident, is_adjusted, iter_input_pats, match_qpath, match_trait_method, match_type,
paths, remove_blocks, snippet, span_help_and_lint, walk_ptrs_ty, walk_ptrs_ty_depth}; paths, remove_blocks, snippet, span_help_and_lint, walk_ptrs_ty, walk_ptrs_ty_depth};
/// **What it does:** Checks for mapping `clone()` over an iterator. /// **What it does:** Checks for mapping `clone()` over an iterator.
@ -31,7 +31,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for Pass {
fn check_expr(&mut self, cx: &LateContext<'a, 'tcx>, expr: &'tcx Expr) { fn check_expr(&mut self, cx: &LateContext<'a, 'tcx>, expr: &'tcx Expr) {
// call to .map() // call to .map()
if let ExprMethodCall(ref method, _, ref args) = expr.node { if let ExprMethodCall(ref method, _, ref args) = expr.node {
if method.name == "map" && args.len() == 2 { if method.ident.name == "map" && args.len() == 2 {
match args[1].node { match args[1].node {
ExprClosure(_, ref decl, closure_eid, _, _) => { ExprClosure(_, ref decl, closure_eid, _, _) => {
let body = cx.tcx.hir.body(closure_eid); let body = cx.tcx.hir.body(closure_eid);
@ -40,7 +40,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for Pass {
// nothing special in the argument, besides reference bindings // nothing special in the argument, besides reference bindings
// (e.g. .map(|&x| x) ) // (e.g. .map(|&x| x) )
if let Some(first_arg) = iter_input_pats(decl, body).next(); if let Some(first_arg) = iter_input_pats(decl, body).next();
if let Some(arg_ident) = get_arg_name(&first_arg.pat); if let Some(arg_ident) = get_arg_ident(&first_arg.pat);
// the method is being called on a known type (option or iterator) // the method is being called on a known type (option or iterator)
if let Some(type_name) = get_type_name(cx, expr, &args[0]); if let Some(type_name) = get_type_name(cx, expr, &args[0]);
then { then {
@ -63,7 +63,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for Pass {
} }
// explicit clone() calls ( .map(|x| x.clone()) ) // explicit clone() calls ( .map(|x| x.clone()) )
else if let ExprMethodCall(ref clone_call, _, ref clone_args) = closure_expr.node { else if let ExprMethodCall(ref clone_call, _, ref clone_args) = closure_expr.node {
if clone_call.name == "clone" && if clone_call.ident.name == "clone" &&
clone_args.len() == 1 && clone_args.len() == 1 &&
match_trait_method(cx, closure_expr, &paths::CLONE_TRAIT) && match_trait_method(cx, closure_expr, &paths::CLONE_TRAIT) &&
expr_eq_name(&clone_args[0], arg_ident) expr_eq_name(&clone_args[0], arg_ident)
@ -98,12 +98,12 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for Pass {
} }
} }
fn expr_eq_name(expr: &Expr, id: ast::Name) -> bool { fn expr_eq_name(expr: &Expr, id: ast::Ident) -> bool {
match expr.node { match expr.node {
ExprPath(QPath::Resolved(None, ref path)) => { ExprPath(QPath::Resolved(None, ref path)) => {
let arg_segment = [ let arg_segment = [
PathSegment { PathSegment {
name: id, ident: id,
args: None, args: None,
infer_types: true, infer_types: true,
}, },
@ -124,7 +124,7 @@ fn get_type_name(cx: &LateContext, expr: &Expr, arg: &Expr) -> Option<&'static s
} }
} }
fn only_derefs(cx: &LateContext, expr: &Expr, id: ast::Name) -> bool { fn only_derefs(cx: &LateContext, expr: &Expr, id: ast::Ident) -> bool {
match expr.node { match expr.node {
ExprUnary(UnDeref, ref subexpr) if !is_adjusted(cx, subexpr) => only_derefs(cx, subexpr, id), ExprUnary(UnDeref, ref subexpr) if !is_adjusted(cx, subexpr) => only_derefs(cx, subexpr, id),
_ => expr_eq_name(expr, id), _ => expr_eq_name(expr, id),

View file

@ -270,7 +270,7 @@ fn check_single_match_opt_like(cx: &LateContext, ex: &Expr, arms: &[Arm], expr:
} }
print::to_string(print::NO_ANN, |s| s.print_qpath(path, false)) print::to_string(print::NO_ANN, |s| s.print_qpath(path, false))
}, },
PatKind::Binding(BindingAnnotation::Unannotated, _, ident, None) => ident.node.to_string(), PatKind::Binding(BindingAnnotation::Unannotated, _, ident, None) => ident.to_string(),
PatKind::Path(ref path) => print::to_string(print::NO_ANN, |s| s.print_qpath(path, false)), PatKind::Path(ref path) => print::to_string(print::NO_ANN, |s| s.print_qpath(path, false)),
_ => return, _ => return,
}; };
@ -552,14 +552,14 @@ fn is_ref_some_arm(arm: &Arm) -> Option<BindingAnnotation> {
if_chain! { if_chain! {
if let PatKind::TupleStruct(ref path, ref pats, _) = arm.pats[0].node; if let PatKind::TupleStruct(ref path, ref pats, _) = arm.pats[0].node;
if pats.len() == 1 && match_qpath(path, &paths::OPTION_SOME); if pats.len() == 1 && match_qpath(path, &paths::OPTION_SOME);
if let PatKind::Binding(rb, _, ref ident, _) = pats[0].node; if let PatKind::Binding(rb, _, ident, _) = pats[0].node;
if rb == BindingAnnotation::Ref || rb == BindingAnnotation::RefMut; if rb == BindingAnnotation::Ref || rb == BindingAnnotation::RefMut;
if let ExprCall(ref e, ref args) = remove_blocks(&arm.body).node; if let ExprCall(ref e, ref args) = remove_blocks(&arm.body).node;
if let ExprPath(ref some_path) = e.node; if let ExprPath(ref some_path) = e.node;
if match_qpath(some_path, &paths::OPTION_SOME) && args.len() == 1; if match_qpath(some_path, &paths::OPTION_SOME) && args.len() == 1;
if let ExprPath(ref qpath) = args[0].node; if let ExprPath(ref qpath) = args[0].node;
if let &QPath::Resolved(_, ref path2) = qpath; if let &QPath::Resolved(_, ref path2) = qpath;
if path2.segments.len() == 1 && ident.node == path2.segments[0].name; if path2.segments.len() == 1 && ident.name == path2.segments[0].ident.name;
then { then {
return Some(rb) return Some(rb)
} }

View file

@ -771,18 +771,18 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for Pass {
lint_unnecessary_fold(cx, expr, arglists[0]); lint_unnecessary_fold(cx, expr, arglists[0]);
} }
lint_or_fun_call(cx, expr, *method_span, &method_call.name.as_str(), args); lint_or_fun_call(cx, expr, *method_span, &method_call.ident.as_str(), args);
lint_expect_fun_call(cx, expr, *method_span, &method_call.name.as_str(), args); lint_expect_fun_call(cx, expr, *method_span, &method_call.ident.as_str(), args);
let self_ty = cx.tables.expr_ty_adjusted(&args[0]); let self_ty = cx.tables.expr_ty_adjusted(&args[0]);
if args.len() == 1 && method_call.name == "clone" { if args.len() == 1 && method_call.ident.name == "clone" {
lint_clone_on_copy(cx, expr, &args[0], self_ty); lint_clone_on_copy(cx, expr, &args[0], self_ty);
lint_clone_on_ref_ptr(cx, expr, &args[0]); lint_clone_on_ref_ptr(cx, expr, &args[0]);
} }
match self_ty.sty { match self_ty.sty {
ty::TyRef(_, ty, _) if ty.sty == ty::TyStr => for &(method, pos) in &PATTERN_METHODS { ty::TyRef(_, ty, _) if ty.sty == ty::TyStr => for &(method, pos) in &PATTERN_METHODS {
if method_call.name == method && args.len() > pos { if method_call.ident.name == method && args.len() > pos {
lint_single_char_pattern(cx, expr, &args[pos]); lint_single_char_pattern(cx, expr, &args[pos]);
} }
}, },
@ -806,7 +806,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for Pass {
if in_external_macro(cx, implitem.span) { if in_external_macro(cx, implitem.span) {
return; return;
} }
let name = implitem.name; let name = implitem.ident.name;
let parent = cx.tcx.hir.get_parent(implitem.id); let parent = cx.tcx.hir.get_parent(implitem.id);
let item = cx.tcx.hir.expect_item(parent); let item = cx.tcx.hir.expect_item(parent);
if_chain! { if_chain! {
@ -890,7 +890,7 @@ fn lint_or_fun_call(cx: &LateContext, expr: &hir::Expr, method_span: Span, name:
if name == "unwrap_or" { if name == "unwrap_or" {
if let hir::ExprPath(ref qpath) = fun.node { if let hir::ExprPath(ref qpath) = fun.node {
let path = &*last_path_segment(qpath).name.as_str(); let path = &*last_path_segment(qpath).ident.as_str();
if ["default", "new"].contains(&path) { if ["default", "new"].contains(&path) {
let arg_ty = cx.tables.expr_ty(arg); let arg_ty = cx.tables.expr_ty(arg);
@ -1438,7 +1438,7 @@ fn derefs_to_slice(cx: &LateContext, expr: &hir::Expr, ty: Ty) -> Option<sugg::S
} }
if let hir::ExprMethodCall(ref path, _, ref args) = expr.node { if let hir::ExprMethodCall(ref path, _, ref args) = expr.node {
if path.name == "iter" && may_slice(cx, cx.tables.expr_ty(&args[0])) { if path.ident.name == "iter" && may_slice(cx, cx.tables.expr_ty(&args[0])) {
sugg::Sugg::hir_opt(cx, &args[0]).map(|sugg| sugg.addr()) sugg::Sugg::hir_opt(cx, &args[0]).map(|sugg| sugg.addr())
} else { } else {
None None
@ -1794,7 +1794,7 @@ fn lint_chars_cmp<'a, 'tcx>(
if arg_char.len() == 1; if arg_char.len() == 1;
if let hir::ExprPath(ref qpath) = fun.node; if let hir::ExprPath(ref qpath) = fun.node;
if let Some(segment) = single_segment_path(qpath); if let Some(segment) = single_segment_path(qpath);
if segment.name == "Some"; if segment.ident.name == "Some";
then { then {
let self_ty = walk_ptrs_ty(cx.tables.expr_ty_adjusted(&args[0][0])); let self_ty = walk_ptrs_ty(cx.tables.expr_ty_adjusted(&args[0][0]));
@ -2093,7 +2093,7 @@ fn is_as_ref_or_mut_trait(ty: &hir::Ty, self_ty: &hir::Ty, generics: &hir::Gener
single_segment_ty(ty).map_or(false, |seg| { single_segment_ty(ty).map_or(false, |seg| {
generics.params.iter().any(|param| match param.kind { generics.params.iter().any(|param| match param.kind {
hir::GenericParamKind::Type { .. } => { hir::GenericParamKind::Type { .. } => {
param.name.name() == seg.name && param.bounds.iter().any(|bound| { param.name.ident().name == seg.ident.name && param.bounds.iter().any(|bound| {
if let hir::GenericBound::Trait(ref ptr, ..) = *bound { if let hir::GenericBound::Trait(ref ptr, ..) = *bound {
let path = &ptr.trait_ref.path; let path = &ptr.trait_ref.path;
match_path(path, name) && path.segments.last().map_or(false, |s| { match_path(path, name) && path.segments.last().map_or(false, |s| {
@ -2132,8 +2132,8 @@ fn is_ty(ty: &hir::Ty, self_ty: &hir::Ty) -> bool {
) => ty_path ) => ty_path
.segments .segments
.iter() .iter()
.map(|seg| seg.name) .map(|seg| seg.ident.name)
.eq(self_ty_path.segments.iter().map(|seg| seg.name)), .eq(self_ty_path.segments.iter().map(|seg| seg.ident.name)),
_ => false, _ => false,
} }
} }

View file

@ -379,7 +379,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for Pass {
} }
let binding = match expr.node { let binding = match expr.node {
ExprPath(ref qpath) => { ExprPath(ref qpath) => {
let binding = last_path_segment(qpath).name.as_str(); let binding = last_path_segment(qpath).ident.as_str();
if binding.starts_with('_') && if binding.starts_with('_') &&
!binding.starts_with("__") && !binding.starts_with("__") &&
binding != "_result" && // FIXME: #944 binding != "_result" && // FIXME: #944
@ -417,13 +417,13 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for Pass {
} }
fn check_pat(&mut self, cx: &LateContext<'a, 'tcx>, pat: &'tcx Pat) { fn check_pat(&mut self, cx: &LateContext<'a, 'tcx>, pat: &'tcx Pat) {
if let PatKind::Binding(_, _, ref ident, Some(ref right)) = pat.node { if let PatKind::Binding(_, _, ident, Some(ref right)) = pat.node {
if right.node == PatKind::Wild { if right.node == PatKind::Wild {
span_lint( span_lint(
cx, cx,
REDUNDANT_PATTERN, REDUNDANT_PATTERN,
pat.span, pat.span,
&format!("the `{} @ _` pattern can be written as just `{}`", ident.node, ident.node), &format!("the `{} @ _` pattern can be written as just `{}`", ident.name, ident.name),
); );
} }
} }
@ -433,7 +433,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for Pass {
fn check_nan(cx: &LateContext, path: &Path, expr: &Expr) { fn check_nan(cx: &LateContext, path: &Path, expr: &Expr) {
if !in_constant(cx, expr.id) { if !in_constant(cx, expr.id) {
if let Some(seg) = path.segments.last() { if let Some(seg) = path.segments.last() {
if seg.name == "NAN" { if seg.ident.name == "NAN" {
span_lint( span_lint(
cx, cx,
CMP_NAN, CMP_NAN,

View file

@ -190,7 +190,7 @@ impl EarlyLintPass for MiscEarly {
fn check_generics(&mut self, cx: &EarlyContext, gen: &Generics) { fn check_generics(&mut self, cx: &EarlyContext, gen: &Generics) {
for param in &gen.params { for param in &gen.params {
if let GenericParamKind::Type { .. } = param.kind { if let GenericParamKind::Type { .. } = param.kind {
let name = param.ident.name.as_str(); let name = param.ident.as_str();
if constants::BUILTIN_TYPES.contains(&&*name) { if constants::BUILTIN_TYPES.contains(&&*name) {
span_lint( span_lint(
cx, cx,
@ -268,7 +268,7 @@ impl EarlyLintPass for MiscEarly {
for arg in &decl.inputs { for arg in &decl.inputs {
if let PatKind::Ident(_, ident, None) = arg.pat.node { if let PatKind::Ident(_, ident, None) = arg.pat.node {
let arg_name = ident.name.to_string(); let arg_name = ident.to_string();
if arg_name.starts_with('_') { if arg_name.starts_with('_') {
if let Some(correspondence) = registered_names.get(&arg_name[1..]) { if let Some(correspondence) = registered_names.get(&arg_name[1..]) {

View file

@ -48,7 +48,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for UnnecessaryMutPassed {
let def_id = cx.tables.type_dependent_defs()[e.hir_id].def_id(); let def_id = cx.tables.type_dependent_defs()[e.hir_id].def_id();
let substs = cx.tables.node_substs(e.hir_id); let substs = cx.tables.node_substs(e.hir_id);
let method_type = cx.tcx.type_of(def_id).subst(cx.tcx, substs); let method_type = cx.tcx.type_of(def_id).subst(cx.tcx, substs);
check_arguments(cx, arguments, method_type, &path.name.as_str()) check_arguments(cx, arguments, method_type, &path.ident.as_str())
}, },
_ => (), _ => (),
} }

View file

@ -152,8 +152,8 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for NeedlessPassByValue {
// Ignore `self`s. // Ignore `self`s.
if idx == 0 { if idx == 0 {
if let PatKind::Binding(_, _, name, ..) = arg.pat.node { if let PatKind::Binding(_, _, ident, ..) = arg.pat.node {
if name.node.as_str() == "self" { if ident.as_str() == "self" {
continue; continue;
} }
} }
@ -217,7 +217,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for NeedlessPassByValue {
get_spans(cx, Some(body.id()), idx, &[("clone", ".to_owned()")]); get_spans(cx, Some(body.id()), idx, &[("clone", ".to_owned()")]);
if let TyPath(QPath::Resolved(_, ref path)) = input.node; if let TyPath(QPath::Resolved(_, ref path)) = input.node;
if let Some(elem_ty) = path.segments.iter() if let Some(elem_ty) = path.segments.iter()
.find(|seg| seg.name == "Vec") .find(|seg| seg.ident.name == "Vec")
.and_then(|ps| ps.args.as_ref()) .and_then(|ps| ps.args.as_ref())
.map(|params| params.args.iter().find_map(|arg| match arg { .map(|params| params.args.iter().find_map(|arg| match arg {
GenericArg::Type(ty) => Some(ty), GenericArg::Type(ty) => Some(ty),

View file

@ -97,7 +97,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for NewWithoutDefault {
return; return;
} }
if let hir::ImplItemKind::Method(ref sig, _) = impl_item.node { if let hir::ImplItemKind::Method(ref sig, _) = impl_item.node {
let name = impl_item.name; let name = impl_item.ident.name;
let id = impl_item.id; let id = impl_item.id;
if sig.header.constness == hir::Constness::Const { if sig.header.constness == hir::Constness::Const {
// can't be implemented by default // can't be implemented by default

View file

@ -35,7 +35,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for NonSensical {
fn check_expr(&mut self, cx: &LateContext<'a, 'tcx>, e: &'tcx Expr) { fn check_expr(&mut self, cx: &LateContext<'a, 'tcx>, e: &'tcx Expr) {
if let ExprMethodCall(ref path, _, ref arguments) = e.node { if let ExprMethodCall(ref path, _, ref arguments) = e.node {
let obj_ty = walk_ptrs_ty(cx.tables.expr_ty(&arguments[0])); let obj_ty = walk_ptrs_ty(cx.tables.expr_ty(&arguments[0]));
if path.name == "open" && match_type(cx, obj_ty, &paths::OPEN_OPTIONS) { if path.ident.name == "open" && match_type(cx, obj_ty, &paths::OPEN_OPTIONS) {
let mut options = Vec::new(); let mut options = Vec::new();
get_open_options(cx, &arguments[0], &mut options); get_open_options(cx, &arguments[0], &mut options);
check_open_options(cx, &options, e.span); check_open_options(cx, &options, e.span);
@ -87,7 +87,7 @@ fn get_open_options(cx: &LateContext, argument: &Expr, options: &mut Vec<(OpenOp
_ => Argument::Unknown, _ => Argument::Unknown,
}; };
match &*path.name.as_str() { match &*path.ident.as_str() {
"create" => { "create" => {
options.push((OpenOption::Create, argument_option)); options.push((OpenOption::Create, argument_option));
}, },

View file

@ -44,7 +44,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for Pass {
if trait_ref.path.def.def_id() == eq_trait; if trait_ref.path.def.def_id() == eq_trait;
then { then {
for impl_item in impl_items { for impl_item in impl_items {
if impl_item.name == "ne" { if impl_item.ident.name == "ne" {
span_lint(cx, span_lint(cx,
PARTIALEQ_NE_IMPL, PARTIALEQ_NE_IMPL,
impl_item.span, impl_item.span,

View file

@ -54,7 +54,7 @@ impl QuestionMarkPass {
if_chain! { if_chain! {
if let ExprIf(ref if_expr, ref body, _) = expr.node; if let ExprIf(ref if_expr, ref body, _) = expr.node;
if let ExprMethodCall(ref segment, _, ref args) = if_expr.node; if let ExprMethodCall(ref segment, _, ref args) = if_expr.node;
if segment.name == "is_none"; if segment.ident.name == "is_none";
if Self::expression_returns_none(cx, body); if Self::expression_returns_none(cx, body);
if let Some(subject) = args.get(0); if let Some(subject) = args.get(0);
if Self::is_option(cx, subject); if Self::is_option(cx, subject);

View file

@ -89,7 +89,7 @@ impl LintPass for Pass {
impl<'a, 'tcx> LateLintPass<'a, 'tcx> for Pass { impl<'a, 'tcx> LateLintPass<'a, 'tcx> for Pass {
fn check_expr(&mut self, cx: &LateContext<'a, 'tcx>, expr: &'tcx Expr) { fn check_expr(&mut self, cx: &LateContext<'a, 'tcx>, expr: &'tcx Expr) {
if let ExprMethodCall(ref path, _, ref args) = expr.node { if let ExprMethodCall(ref path, _, ref args) = expr.node {
let name = path.name.as_str(); let name = path.ident.as_str();
// Range with step_by(0). // Range with step_by(0).
if name == "step_by" && args.len() == 2 && has_step_by(cx, &args[0]) { if name == "step_by" && args.len() == 2 && has_step_by(cx, &args[0]) {
@ -108,13 +108,13 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for Pass {
if_chain! { if_chain! {
// .iter() call // .iter() call
if let ExprMethodCall(ref iter_path, _, ref iter_args ) = *iter; if let ExprMethodCall(ref iter_path, _, ref iter_args ) = *iter;
if iter_path.name == "iter"; if iter_path.ident.name == "iter";
// range expression in .zip() call: 0..x.len() // range expression in .zip() call: 0..x.len()
if let Some(higher::Range { start: Some(start), end: Some(end), .. }) = higher::range(cx, zip_arg); if let Some(higher::Range { start: Some(start), end: Some(end), .. }) = higher::range(cx, zip_arg);
if is_integer_literal(start, 0); if is_integer_literal(start, 0);
// .len() call // .len() call
if let ExprMethodCall(ref len_path, _, ref len_args) = end.node; if let ExprMethodCall(ref len_path, _, ref len_args) = end.node;
if len_path.name == "len" && len_args.len() == 1; if len_path.ident.name == "len" && len_args.len() == 1;
// .iter() and .len() called on same Path // .iter() and .len() called on same Path
if let ExprPath(QPath::Resolved(_, ref iter_path)) = iter_args[0].node; if let ExprPath(QPath::Resolved(_, ref iter_path)) = iter_args[0].node;
if let ExprPath(QPath::Resolved(_, ref len_path)) = len_args[0].node; if let ExprPath(QPath::Resolved(_, ref len_path)) = len_args[0].node;

View file

@ -114,7 +114,7 @@ impl ReturnPass {
if let Some(ref initexpr) = local.init; if let Some(ref initexpr) = local.init;
if let ast::PatKind::Ident(_, ident, _) = local.pat.node; if let ast::PatKind::Ident(_, ident, _) = local.pat.node;
if let ast::ExprKind::Path(_, ref path) = retexpr.node; if let ast::ExprKind::Path(_, ref path) = retexpr.node;
if match_path_ast(path, &[&ident.name.as_str()]); if match_path_ast(path, &[&ident.as_str()]);
if !in_external_macro(cx, initexpr.span); if !in_external_macro(cx, initexpr.span);
then { then {
span_note_and_lint(cx, span_note_and_lint(cx,

View file

@ -36,7 +36,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for Serde {
let mut seen_str = None; let mut seen_str = None;
let mut seen_string = None; let mut seen_string = None;
for item in items { for item in items {
match &*item.name.as_str() { match &*item.ident.as_str() {
"visit_str" => seen_str = Some(item.span), "visit_str" => seen_str = Some(item.span),
"visit_string" => seen_string = Some(item.span), "visit_string" => seen_string = Some(item.span),
_ => {}, _ => {},

View file

@ -100,7 +100,7 @@ fn check_fn<'a, 'tcx>(cx: &LateContext<'a, 'tcx>, decl: &'tcx FnDecl, body: &'tc
let mut bindings = Vec::new(); let mut bindings = Vec::new();
for arg in iter_input_pats(decl, body) { for arg in iter_input_pats(decl, body) {
if let PatKind::Binding(_, _, ident, _) = arg.pat.node { if let PatKind::Binding(_, _, ident, _) = arg.pat.node {
bindings.push((ident.node, ident.span)) bindings.push((ident.name, ident.span))
} }
} }
check_expr(cx, &body.value, &mut bindings); check_expr(cx, &body.value, &mut bindings);
@ -164,8 +164,8 @@ fn check_pat<'a, 'tcx>(
) { ) {
// TODO: match more stuff / destructuring // TODO: match more stuff / destructuring
match pat.node { match pat.node {
PatKind::Binding(_, _, ref ident, ref inner) => { PatKind::Binding(_, _, ident, ref inner) => {
let name = ident.node; let name = ident.name;
if is_binding(cx, pat.hir_id) { if is_binding(cx, pat.hir_id) {
let mut new_binding = true; let mut new_binding = true;
for tup in bindings.iter_mut() { for tup in bindings.iter_mut() {
@ -378,5 +378,5 @@ fn is_self_shadow(name: Name, expr: &Expr) -> bool {
} }
fn path_eq_name(name: Name, path: &Path) -> bool { fn path_eq_name(name: Name, path: &Path) -> bool {
!path.is_global() && path.segments.len() == 1 && path.segments[0].name.as_str() == name.as_str() !path.is_global() && path.segments.len() == 1 && path.segments[0].ident.as_str() == name.as_str()
} }

View file

@ -149,7 +149,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for StringLitAsBytes {
use crate::utils::{in_macro, snippet}; use crate::utils::{in_macro, snippet};
if let ExprMethodCall(ref path, _, ref args) = e.node { if let ExprMethodCall(ref path, _, ref args) = e.node {
if path.name == "as_bytes" { if path.ident.name == "as_bytes" {
if let ExprLit(ref lit) = args[0].node { if let ExprLit(ref lit) = args[0].node {
if let LitKind::Str(ref lit_content, _) = lit.node { if let LitKind::Str(ref lit_content, _) = lit.node {
if lit_content.as_str().chars().all(|c| c.is_ascii()) && !in_macro(args[0].span) { if lit_content.as_str().chars().all(|c| c.is_ascii()) && !in_macro(args[0].span) {

View file

@ -64,7 +64,7 @@ fn check_manual_swap(cx: &LateContext, block: &Block) {
if let StmtDecl(ref tmp, _) = w[0].node; if let StmtDecl(ref tmp, _) = w[0].node;
if let DeclLocal(ref tmp) = tmp.node; if let DeclLocal(ref tmp) = tmp.node;
if let Some(ref tmp_init) = tmp.init; if let Some(ref tmp_init) = tmp.init;
if let PatKind::Binding(_, _, ref tmp_name, None) = tmp.pat.node; if let PatKind::Binding(_, _, ident, None) = tmp.pat.node;
// foo() = bar(); // foo() = bar();
if let StmtSemi(ref first, _) = w[1].node; if let StmtSemi(ref first, _) = w[1].node;
@ -76,7 +76,7 @@ fn check_manual_swap(cx: &LateContext, block: &Block) {
if let ExprPath(QPath::Resolved(None, ref rhs2)) = rhs2.node; if let ExprPath(QPath::Resolved(None, ref rhs2)) = rhs2.node;
if rhs2.segments.len() == 1; if rhs2.segments.len() == 1;
if tmp_name.node.as_str() == rhs2.segments[0].name.as_str(); if ident.as_str() == rhs2.segments[0].ident.as_str();
if SpanlessEq::new(cx).ignore_fn().eq_expr(tmp_init, lhs1); if SpanlessEq::new(cx).ignore_fn().eq_expr(tmp_init, lhs1);
if SpanlessEq::new(cx).ignore_fn().eq_expr(rhs1, lhs2); if SpanlessEq::new(cx).ignore_fn().eq_expr(rhs1, lhs2);
then { then {

View file

@ -317,7 +317,7 @@ fn check_ty_rptr(cx: &LateContext, ast_ty: &hir::Ty, is_local: bool, lt: &Lifeti
let ltopt = if lt.is_elided() { let ltopt = if lt.is_elided() {
"".to_owned() "".to_owned()
} else { } else {
format!("{} ", lt.name.name().as_str()) format!("{} ", lt.name.ident().name.as_str())
}; };
let mutopt = if mut_ty.mutbl == Mutability::MutMutable { let mutopt = if mut_ty.mutbl == Mutability::MutMutable {
"mut " "mut "
@ -1993,10 +1993,10 @@ impl<'a, 'b, 'tcx: 'a + 'b> Visitor<'tcx> for ImplicitHasherConstructorVisitor<'
} }
if match_path(ty_path, &paths::HASHMAP) { if match_path(ty_path, &paths::HASHMAP) {
if method.name == "new" { if method.ident.name == "new" {
self.suggestions self.suggestions
.insert(e.span, "HashMap::default()".to_string()); .insert(e.span, "HashMap::default()".to_string());
} else if method.name == "with_capacity" { } else if method.ident.name == "with_capacity" {
self.suggestions.insert( self.suggestions.insert(
e.span, e.span,
format!( format!(
@ -2006,10 +2006,10 @@ impl<'a, 'b, 'tcx: 'a + 'b> Visitor<'tcx> for ImplicitHasherConstructorVisitor<'
); );
} }
} else if match_path(ty_path, &paths::HASHSET) { } else if match_path(ty_path, &paths::HASHSET) {
if method.name == "new" { if method.ident.name == "new" {
self.suggestions self.suggestions
.insert(e.span, "HashSet::default()".to_string()); .insert(e.span, "HashSet::default()".to_string());
} else if method.name == "with_capacity" { } else if method.ident.name == "with_capacity" {
self.suggestions.insert( self.suggestions.insert(
e.span, e.span,
format!( format!(

View file

@ -57,7 +57,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for UnusedIoAmount {
} }
}, },
hir::ExprMethodCall(ref path, _, ref args) => match &*path.name.as_str() { hir::ExprMethodCall(ref path, _, ref args) => match &*path.ident.as_str() {
"expect" | "unwrap" | "unwrap_or" | "unwrap_or_else" => { "expect" | "unwrap" | "unwrap_or" | "unwrap_or_else" => {
check_method_call(cx, &args[0], expr); check_method_call(cx, &args[0], expr);
}, },
@ -71,7 +71,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for UnusedIoAmount {
fn check_method_call(cx: &LateContext, call: &hir::Expr, expr: &hir::Expr) { fn check_method_call(cx: &LateContext, call: &hir::Expr, expr: &hir::Expr) {
if let hir::ExprMethodCall(ref path, _, _) = call.node { if let hir::ExprMethodCall(ref path, _, _) = call.node {
let symbol = &*path.name.as_str(); let symbol = &*path.ident.as_str();
if match_trait_method(cx, call, &paths::IO_READ) && symbol == "read" { if match_trait_method(cx, call, &paths::IO_READ) && symbol == "read" {
span_lint( span_lint(
cx, cx,

View file

@ -70,10 +70,10 @@ impl<'a, 'tcx: 'a> Visitor<'tcx> for UnusedLabelVisitor<'a, 'tcx> {
fn visit_expr(&mut self, expr: &'tcx hir::Expr) { fn visit_expr(&mut self, expr: &'tcx hir::Expr) {
match expr.node { match expr.node {
hir::ExprBreak(destination, _) | hir::ExprContinue(destination) => if let Some(label) = destination.label { hir::ExprBreak(destination, _) | hir::ExprContinue(destination) => if let Some(label) = destination.label {
self.labels.remove(&label.name.as_str()); self.labels.remove(&label.ident.as_str());
}, },
hir::ExprLoop(_, Some(label), _) | hir::ExprWhile(_, _, Some(label)) => { hir::ExprLoop(_, Some(label), _) | hir::ExprWhile(_, _, Some(label)) => {
self.labels.insert(label.name.as_str(), expr.span); self.labels.insert(label.ident.as_str(), expr.span);
}, },
_ => (), _ => (),
} }

View file

@ -95,7 +95,7 @@ fn collect_unwrap_info<'a, 'tcx: 'a>(
if let Expr_::ExprPath(QPath::Resolved(None, path)) = &args[0].node; if let Expr_::ExprPath(QPath::Resolved(None, path)) = &args[0].node;
let ty = cx.tables.expr_ty(&args[0]); let ty = cx.tables.expr_ty(&args[0]);
if match_type(cx, ty, &paths::OPTION) || match_type(cx, ty, &paths::RESULT); if match_type(cx, ty, &paths::OPTION) || match_type(cx, ty, &paths::RESULT);
let name = method_name.name.as_str(); let name = method_name.ident.as_str();
if ["is_some", "is_none", "is_ok", "is_err"].contains(&&*name); if ["is_some", "is_none", "is_ok", "is_err"].contains(&&*name);
then { then {
assert!(args.len() == 1); assert!(args.len() == 1);
@ -142,8 +142,8 @@ impl<'a, 'tcx: 'a> Visitor<'tcx> for UnwrappableVariablesVisitor<'a, 'tcx> {
if_chain! { if_chain! {
if let Expr_::ExprMethodCall(ref method_name, _, ref args) = expr.node; if let Expr_::ExprMethodCall(ref method_name, _, ref args) = expr.node;
if let Expr_::ExprPath(QPath::Resolved(None, ref path)) = args[0].node; if let Expr_::ExprPath(QPath::Resolved(None, ref path)) = args[0].node;
if ["unwrap", "unwrap_err"].contains(&&*method_name.name.as_str()); if ["unwrap", "unwrap_err"].contains(&&*method_name.ident.as_str());
let call_to_unwrap = method_name.name == "unwrap"; let call_to_unwrap = method_name.ident.name == "unwrap";
if let Some(unwrappable) = self.unwrappables.iter() if let Some(unwrappable) = self.unwrappables.iter()
.find(|u| u.ident.def == path.def); .find(|u| u.ident.def == path.def);
then { then {
@ -154,7 +154,7 @@ impl<'a, 'tcx: 'a> Visitor<'tcx> for UnwrappableVariablesVisitor<'a, 'tcx> {
expr.span, expr.span,
&format!("You checked before that `{}()` cannot fail. \ &format!("You checked before that `{}()` cannot fail. \
Instead of checking and unwrapping, it's better to use `if let` or `match`.", Instead of checking and unwrapping, it's better to use `if let` or `match`.",
method_name.name), method_name.ident.name),
|db| { db.span_label(unwrappable.check.span, "the check is happening here"); }, |db| { db.span_label(unwrappable.check.span, "the check is happening here"); },
); );
} else { } else {
@ -163,7 +163,7 @@ impl<'a, 'tcx: 'a> Visitor<'tcx> for UnwrappableVariablesVisitor<'a, 'tcx> {
PANICKING_UNWRAP, PANICKING_UNWRAP,
expr.span, expr.span,
&format!("This call to `{}()` will always panic.", &format!("This call to `{}()` will always panic.",
method_name.name), method_name.ident.name),
|db| { db.span_label(unwrappable.check.span, "because of this check"); }, |db| { db.span_label(unwrappable.check.span, "because of this check"); },
); );
} }

View file

@ -88,7 +88,7 @@ struct UseSelfVisitor<'a, 'tcx: 'a> {
impl<'a, 'tcx> Visitor<'tcx> for UseSelfVisitor<'a, 'tcx> { impl<'a, 'tcx> Visitor<'tcx> for UseSelfVisitor<'a, 'tcx> {
fn visit_path(&mut self, path: &'tcx Path, _id: NodeId) { fn visit_path(&mut self, path: &'tcx Path, _id: NodeId) {
if self.item_path.def == path.def && path.segments.last().expect(SEGMENTS_MSG).name != SelfType.name() { if self.item_path.def == path.def && path.segments.last().expect(SEGMENTS_MSG).ident.name != SelfType.name() {
span_lint_and_then(self.cx, USE_SELF, path.span, "unnecessary structure name repetition", |db| { span_lint_and_then(self.cx, USE_SELF, path.span, "unnecessary structure name repetition", |db| {
db.span_suggestion(path.span, "use the applicable keyword", "Self".to_owned()); db.span_suggestion(path.span, "use the applicable keyword", "Self".to_owned());
}); });

View file

@ -395,7 +395,7 @@ impl<'tcx> Visitor<'tcx> for PrintVisitor {
let obj_pat = self.next("object"); let obj_pat = self.next("object");
let field_name_pat = self.next("field_name"); let field_name_pat = self.next("field_name");
println!("Field(ref {}, ref {}) = {};", obj_pat, field_name_pat, current); println!("Field(ref {}, ref {}) = {};", obj_pat, field_name_pat, current);
println!(" if {}.node.as_str() == {:?}", field_name_pat, field_ident.name.as_str()); println!(" if {}.node.as_str() == {:?}", field_name_pat, field_ident.as_str());
self.current = obj_pat; self.current = obj_pat;
self.visit_expr(object); self.visit_expr(object);
}, },
@ -487,7 +487,7 @@ impl<'tcx> Visitor<'tcx> for PrintVisitor {
let current = format!("{}.node", self.current); let current = format!("{}.node", self.current);
match pat.node { match pat.node {
PatKind::Wild => println!("Wild = {};", current), PatKind::Wild => println!("Wild = {};", current),
PatKind::Binding(anno, _, name, ref sub) => { PatKind::Binding(anno, _, ident, ref sub) => {
let anno_pat = match anno { let anno_pat = match anno {
BindingAnnotation::Unannotated => "BindingAnnotation::Unannotated", BindingAnnotation::Unannotated => "BindingAnnotation::Unannotated",
BindingAnnotation::Mutable => "BindingAnnotation::Mutable", BindingAnnotation::Mutable => "BindingAnnotation::Mutable",
@ -503,7 +503,7 @@ impl<'tcx> Visitor<'tcx> for PrintVisitor {
} else { } else {
println!("Binding({}, _, {}, None) = {};", anno_pat, name_pat, current); println!("Binding({}, _, {}, None) = {};", anno_pat, name_pat, current);
} }
println!(" if {}.node.as_str() == \"{}\";", name_pat, name.node.as_str()); println!(" if {}.node.as_str() == \"{}\";", name_pat, ident.as_str());
} }
PatKind::Struct(ref path, ref fields, ignore) => { PatKind::Struct(ref path, ref fields, ignore) => {
let path_pat = self.next("path"); let path_pat = self.next("path");
@ -671,7 +671,7 @@ fn print_path(path: &QPath, first: &mut bool) {
} else { } else {
print!(", "); print!(", ");
} }
print!("{:?}", segment.name.as_str()); print!("{:?}", segment.ident.as_str());
}, },
QPath::TypeRelative(ref ty, ref segment) => match ty.node { QPath::TypeRelative(ref ty, ref segment) => match ty.node {
hir::Ty_::TyPath(ref inner_path) => { hir::Ty_::TyPath(ref inner_path) => {
@ -681,7 +681,7 @@ fn print_path(path: &QPath, first: &mut bool) {
} else { } else {
print!(", "); print!(", ");
} }
print!("{:?}", segment.name.as_str()); print!("{:?}", segment.ident.as_str());
}, },
ref other => print!("/* unimplemented: {:?}*/", other), ref other => print!("/* unimplemented: {:?}*/", other),
}, },

View file

@ -77,7 +77,7 @@ impl<'a, 'tcx: 'a> SpanlessEq<'a, 'tcx> {
match (&left.node, &right.node) { match (&left.node, &right.node) {
(&ExprAddrOf(l_mut, ref le), &ExprAddrOf(r_mut, ref re)) => l_mut == r_mut && self.eq_expr(le, re), (&ExprAddrOf(l_mut, ref le), &ExprAddrOf(r_mut, ref re)) => l_mut == r_mut && self.eq_expr(le, re),
(&ExprContinue(li), &ExprContinue(ri)) => { (&ExprContinue(li), &ExprContinue(ri)) => {
both(&li.label, &ri.label, |l, r| l.name.as_str() == r.name.as_str()) both(&li.label, &ri.label, |l, r| l.ident.as_str() == r.ident.as_str())
}, },
(&ExprAssign(ref ll, ref lr), &ExprAssign(ref rl, ref rr)) => self.eq_expr(ll, rl) && self.eq_expr(lr, rr), (&ExprAssign(ref ll, ref lr), &ExprAssign(ref rl, ref rr)) => self.eq_expr(ll, rl) && self.eq_expr(lr, rr),
(&ExprAssignOp(ref lo, ref ll, ref lr), &ExprAssignOp(ref ro, ref rl, ref rr)) => { (&ExprAssignOp(ref lo, ref ll, ref lr), &ExprAssignOp(ref ro, ref rl, ref rr)) => {
@ -91,7 +91,7 @@ impl<'a, 'tcx: 'a> SpanlessEq<'a, 'tcx> {
}) })
}, },
(&ExprBreak(li, ref le), &ExprBreak(ri, ref re)) => { (&ExprBreak(li, ref le), &ExprBreak(ri, ref re)) => {
both(&li.label, &ri.label, |l, r| l.name.as_str() == r.name.as_str()) both(&li.label, &ri.label, |l, r| l.ident.as_str() == r.ident.as_str())
&& both(le, re, |l, r| self.eq_expr(l, r)) && both(le, re, |l, r| self.eq_expr(l, r))
}, },
(&ExprBox(ref l), &ExprBox(ref r)) => self.eq_expr(l, r), (&ExprBox(ref l), &ExprBox(ref r)) => self.eq_expr(l, r),
@ -109,7 +109,7 @@ impl<'a, 'tcx: 'a> SpanlessEq<'a, 'tcx> {
}, },
(&ExprLit(ref l), &ExprLit(ref r)) => l.node == r.node, (&ExprLit(ref l), &ExprLit(ref r)) => l.node == r.node,
(&ExprLoop(ref lb, ref ll, ref lls), &ExprLoop(ref rb, ref rl, ref rls)) => { (&ExprLoop(ref lb, ref ll, ref lls), &ExprLoop(ref rb, ref rl, ref rls)) => {
lls == rls && self.eq_block(lb, rb) && both(ll, rl, |l, r| l.name.as_str() == r.name.as_str()) lls == rls && self.eq_block(lb, rb) && both(ll, rl, |l, r| l.ident.as_str() == r.ident.as_str())
}, },
(&ExprMatch(ref le, ref la, ref ls), &ExprMatch(ref re, ref ra, ref rs)) => { (&ExprMatch(ref le, ref la, ref ls), &ExprMatch(ref re, ref ra, ref rs)) => {
ls == rs && self.eq_expr(le, re) && over(la, ra, |l, r| { ls == rs && self.eq_expr(le, re) && over(la, ra, |l, r| {
@ -138,7 +138,7 @@ impl<'a, 'tcx: 'a> SpanlessEq<'a, 'tcx> {
(&ExprUnary(l_op, ref le), &ExprUnary(r_op, ref re)) => l_op == r_op && self.eq_expr(le, re), (&ExprUnary(l_op, ref le), &ExprUnary(r_op, ref re)) => l_op == r_op && self.eq_expr(le, re),
(&ExprArray(ref l), &ExprArray(ref r)) => self.eq_exprs(l, r), (&ExprArray(ref l), &ExprArray(ref r)) => self.eq_exprs(l, r),
(&ExprWhile(ref lc, ref lb, ref ll), &ExprWhile(ref rc, ref rb, ref rl)) => { (&ExprWhile(ref lc, ref lb, ref ll), &ExprWhile(ref rc, ref rb, ref rl)) => {
self.eq_expr(lc, rc) && self.eq_block(lb, rb) && both(ll, rl, |l, r| l.name.as_str() == r.name.as_str()) self.eq_expr(lc, rc) && self.eq_block(lb, rb) && both(ll, rl, |l, r| l.ident.as_str() == r.ident.as_str())
}, },
_ => false, _ => false,
} }
@ -172,7 +172,7 @@ impl<'a, 'tcx: 'a> SpanlessEq<'a, 'tcx> {
self.eq_qpath(lp, rp) && over(la, ra, |l, r| self.eq_pat(l, r)) && ls == rs self.eq_qpath(lp, rp) && over(la, ra, |l, r| self.eq_pat(l, r)) && ls == rs
}, },
(&PatKind::Binding(ref lb, _, ref li, ref lp), &PatKind::Binding(ref rb, _, ref ri, ref rp)) => { (&PatKind::Binding(ref lb, _, ref li, ref lp), &PatKind::Binding(ref rb, _, ref ri, ref rp)) => {
lb == rb && li.node.as_str() == ri.node.as_str() && both(lp, rp, |l, r| self.eq_pat(l, r)) lb == rb && li.name.as_str() == ri.name.as_str() && both(lp, rp, |l, r| self.eq_pat(l, r))
}, },
(&PatKind::Path(ref l), &PatKind::Path(ref r)) => self.eq_qpath(l, r), (&PatKind::Path(ref l), &PatKind::Path(ref r)) => self.eq_qpath(l, r),
(&PatKind::Lit(ref l), &PatKind::Lit(ref r)) => self.eq_expr(l, r), (&PatKind::Lit(ref l), &PatKind::Lit(ref r)) => self.eq_expr(l, r),
@ -228,7 +228,7 @@ impl<'a, 'tcx: 'a> SpanlessEq<'a, 'tcx> {
fn eq_path_segment(&mut self, left: &PathSegment, right: &PathSegment) -> bool { fn eq_path_segment(&mut self, left: &PathSegment, right: &PathSegment) -> bool {
// The == of idents doesn't work with different contexts, // The == of idents doesn't work with different contexts,
// we have to be explicit about hygiene // we have to be explicit about hygiene
if left.name.as_str() != right.name.as_str() { if left.ident.as_str() != right.ident.as_str() {
return false; return false;
} }
match (&left.args, &right.args) { match (&left.args, &right.args) {
@ -268,7 +268,7 @@ impl<'a, 'tcx: 'a> SpanlessEq<'a, 'tcx> {
} }
fn eq_type_binding(&mut self, left: &TypeBinding, right: &TypeBinding) -> bool { fn eq_type_binding(&mut self, left: &TypeBinding, right: &TypeBinding) -> bool {
left.name == right.name && self.eq_ty(&left.ty, &right.ty) left.ident.name == right.ident.name && self.eq_ty(&left.ty, &right.ty)
} }
} }
@ -356,7 +356,7 @@ impl<'a, 'tcx: 'a> SpanlessHash<'a, 'tcx> {
let c: fn(_) -> _ = ExprContinue; let c: fn(_) -> _ = ExprContinue;
c.hash(&mut self.s); c.hash(&mut self.s);
if let Some(i) = i.label { if let Some(i) = i.label {
self.hash_name(i.name); self.hash_name(i.ident.name);
} }
}, },
ExprYield(ref e) => { ExprYield(ref e) => {
@ -393,7 +393,7 @@ impl<'a, 'tcx: 'a> SpanlessHash<'a, 'tcx> {
let c: fn(_, _) -> _ = ExprBreak; let c: fn(_, _) -> _ = ExprBreak;
c.hash(&mut self.s); c.hash(&mut self.s);
if let Some(i) = i.label { if let Some(i) = i.label {
self.hash_name(i.name); self.hash_name(i.ident.name);
} }
if let Some(ref j) = *j { if let Some(ref j) = *j {
self.hash_expr(&*j); self.hash_expr(&*j);
@ -457,7 +457,7 @@ impl<'a, 'tcx: 'a> SpanlessHash<'a, 'tcx> {
c.hash(&mut self.s); c.hash(&mut self.s);
self.hash_block(b); self.hash_block(b);
if let Some(i) = *i { if let Some(i) = *i {
self.hash_name(i.name); self.hash_name(i.ident.name);
} }
}, },
ExprMatch(ref e, ref arms, ref s) => { ExprMatch(ref e, ref arms, ref s) => {
@ -478,7 +478,7 @@ impl<'a, 'tcx: 'a> SpanlessHash<'a, 'tcx> {
ExprMethodCall(ref path, ref _tys, ref args) => { ExprMethodCall(ref path, ref _tys, ref args) => {
let c: fn(_, _, _) -> _ = ExprMethodCall; let c: fn(_, _, _) -> _ = ExprMethodCall;
c.hash(&mut self.s); c.hash(&mut self.s);
self.hash_name(path.name); self.hash_name(path.ident.name);
self.hash_exprs(args); self.hash_exprs(args);
}, },
ExprRepeat(ref e, ref l_id) => { ExprRepeat(ref e, ref l_id) => {
@ -548,7 +548,7 @@ impl<'a, 'tcx: 'a> SpanlessHash<'a, 'tcx> {
self.hash_expr(cond); self.hash_expr(cond);
self.hash_block(b); self.hash_block(b);
if let Some(l) = l { if let Some(l) = l {
self.hash_name(l.name); self.hash_name(l.ident.name);
} }
}, },
} }
@ -570,7 +570,7 @@ impl<'a, 'tcx: 'a> SpanlessHash<'a, 'tcx> {
self.hash_path(path); self.hash_path(path);
}, },
QPath::TypeRelative(_, ref path) => { QPath::TypeRelative(_, ref path) => {
self.hash_name(path.name); self.hash_name(path.ident.name);
}, },
} }
// self.cx.tables.qpath_def(p, id).hash(&mut self.s); // self.cx.tables.qpath_def(p, id).hash(&mut self.s);
@ -579,7 +579,7 @@ impl<'a, 'tcx: 'a> SpanlessHash<'a, 'tcx> {
pub fn hash_path(&mut self, p: &Path) { pub fn hash_path(&mut self, p: &Path) {
p.is_global().hash(&mut self.s); p.is_global().hash(&mut self.s);
for p in &p.segments { for p in &p.segments {
self.hash_name(p.name); self.hash_name(p.ident.name);
} }
} }

View file

@ -50,7 +50,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for Pass {
if !has_attr(&item.attrs) { if !has_attr(&item.attrs) {
return; return;
} }
println!("impl item `{}`", item.name); println!("impl item `{}`", item.ident.name);
match item.vis { match item.vis {
hir::Visibility::Public => println!("public"), hir::Visibility::Public => println!("public"),
hir::Visibility::Crate(_) => println!("visible crate wide"), hir::Visibility::Crate(_) => println!("visible crate wide"),
@ -181,7 +181,7 @@ fn print_expr(cx: &LateContext, expr: &hir::Expr, indent: usize) {
}, },
hir::ExprMethodCall(ref path, _, ref args) => { hir::ExprMethodCall(ref path, _, ref args) => {
println!("{}MethodCall", ind); println!("{}MethodCall", ind);
println!("{}method name: {}", ind, path.name); println!("{}method name: {}", ind, path.ident.name);
for arg in args { for arg in args {
print_expr(cx, arg, indent + 1); print_expr(cx, arg, indent + 1);
} }
@ -268,7 +268,7 @@ fn print_expr(cx: &LateContext, expr: &hir::Expr, indent: usize) {
println!("{}rhs:", ind); println!("{}rhs:", ind);
print_expr(cx, rhs, indent + 1); print_expr(cx, rhs, indent + 1);
}, },
hir::ExprField(ref e, ref ident) => { hir::ExprField(ref e, ident) => {
println!("{}Field", ind); println!("{}Field", ind);
println!("{}field name: {}", ind, ident.name); println!("{}field name: {}", ind, ident.name);
println!("{}struct expr:", ind); println!("{}struct expr:", ind);
@ -417,10 +417,10 @@ fn print_pat(cx: &LateContext, pat: &hir::Pat, indent: usize) {
println!("{}+", ind); println!("{}+", ind);
match pat.node { match pat.node {
hir::PatKind::Wild => println!("{}Wild", ind), hir::PatKind::Wild => println!("{}Wild", ind),
hir::PatKind::Binding(ref mode, _, ref name, ref inner) => { hir::PatKind::Binding(ref mode, _, ident, ref inner) => {
println!("{}Binding", ind); println!("{}Binding", ind);
println!("{}mode: {:?}", ind, mode); println!("{}mode: {:?}", ind, mode);
println!("{}name: {}", ind, name.node); println!("{}name: {}", ind, ident.name);
if let Some(ref inner) = *inner { if let Some(ref inner) = *inner {
println!("{}inner:", ind); println!("{}inner:", ind);
print_pat(cx, inner, indent + 1); print_pat(cx, inner, indent + 1);

View file

@ -78,7 +78,7 @@ impl EarlyLintPass for Clippy {
if let ItemKind::Mod(ref paths_mod) = paths.node { if let ItemKind::Mod(ref paths_mod) = paths.node {
let mut last_name: Option<LocalInternedString> = None; let mut last_name: Option<LocalInternedString> = None;
for item in &paths_mod.items { for item in &paths_mod.items {
let name = item.ident.name.as_str(); let name = item.ident.as_str();
if let Some(ref last_name) = last_name { if let Some(ref last_name) = last_name {
if **last_name > *name { if **last_name > *name {
span_lint( span_lint(
@ -196,7 +196,7 @@ impl<'a, 'tcx: 'a> Visitor<'tcx> for LintCollector<'a, 'tcx> {
fn visit_path(&mut self, path: &'tcx Path, _: NodeId) { fn visit_path(&mut self, path: &'tcx Path, _: NodeId) {
if path.segments.len() == 1 { if path.segments.len() == 1 {
self.output.insert(path.segments[0].name); self.output.insert(path.segments[0].ident.name);
} }
} }
fn nested_visit_map<'this>(&'this mut self) -> NestedVisitorMap<'this, 'tcx> { fn nested_visit_map<'this>(&'this mut self) -> NestedVisitorMap<'this, 'tcx> {

View file

@ -175,7 +175,7 @@ pub fn match_trait_method(cx: &LateContext, expr: &Expr, path: &[&str]) -> bool
/// Check if an expression references a variable of the given name. /// Check if an expression references a variable of the given name.
pub fn match_var(expr: &Expr, var: Name) -> bool { pub fn match_var(expr: &Expr, var: Name) -> bool {
if let ExprPath(QPath::Resolved(None, ref path)) = expr.node { if let ExprPath(QPath::Resolved(None, ref path)) = expr.node {
if path.segments.len() == 1 && path.segments[0].name == var { if path.segments.len() == 1 && path.segments[0].ident.name == var {
return true; return true;
} }
} }
@ -212,7 +212,7 @@ pub fn match_qpath(path: &QPath, segments: &[&str]) -> bool {
QPath::TypeRelative(ref ty, ref segment) => match ty.node { QPath::TypeRelative(ref ty, ref segment) => match ty.node {
TyPath(ref inner_path) => { TyPath(ref inner_path) => {
!segments.is_empty() && match_qpath(inner_path, &segments[..(segments.len() - 1)]) !segments.is_empty() && match_qpath(inner_path, &segments[..(segments.len() - 1)])
&& segment.name == segments[segments.len() - 1] && segment.ident.name == segments[segments.len() - 1]
}, },
_ => false, _ => false,
}, },
@ -224,7 +224,7 @@ pub fn match_path(path: &Path, segments: &[&str]) -> bool {
.iter() .iter()
.rev() .rev()
.zip(segments.iter().rev()) .zip(segments.iter().rev())
.all(|(a, b)| a.name == *b) .all(|(a, b)| a.ident.name == *b)
} }
/// Match a `Path` against a slice of segment string literals, e.g. /// Match a `Path` against a slice of segment string literals, e.g.
@ -331,7 +331,7 @@ pub fn method_chain_args<'a>(expr: &'a Expr, methods: &[&str]) -> Option<Vec<&'a
for method_name in methods.iter().rev() { for method_name in methods.iter().rev() {
// method chains are stored last -> first // method chains are stored last -> first
if let ExprMethodCall(ref path, _, ref args) = current.node { if let ExprMethodCall(ref path, _, ref args) = current.node {
if path.name == *method_name { if path.ident.name == *method_name {
if args.iter().any(|e| in_macro(e.span)) { if args.iter().any(|e| in_macro(e.span)) {
return None; return None;
} }
@ -353,9 +353,9 @@ pub fn method_chain_args<'a>(expr: &'a Expr, methods: &[&str]) -> Option<Vec<&'a
pub fn get_item_name(cx: &LateContext, expr: &Expr) -> Option<Name> { pub fn get_item_name(cx: &LateContext, expr: &Expr) -> Option<Name> {
let parent_id = cx.tcx.hir.get_parent(expr.id); let parent_id = cx.tcx.hir.get_parent(expr.id);
match cx.tcx.hir.find(parent_id) { match cx.tcx.hir.find(parent_id) {
Some(Node::NodeItem(&Item { ref name, .. })) | Some(Node::NodeItem(&Item { ref name, .. })) => Some(*name),
Some(Node::NodeTraitItem(&TraitItem { ref name, .. })) | Some(Node::NodeTraitItem(&TraitItem { ident, .. })) |
Some(Node::NodeImplItem(&ImplItem { ref name, .. })) => Some(*name), Some(Node::NodeImplItem(&ImplItem { ident, .. })) => Some(ident.name),
_ => None, _ => None,
} }
} }
@ -363,8 +363,8 @@ pub fn get_item_name(cx: &LateContext, expr: &Expr) -> Option<Name> {
/// Get the name of a `Pat`, if any /// Get the name of a `Pat`, if any
pub fn get_pat_name(pat: &Pat) -> Option<Name> { pub fn get_pat_name(pat: &Pat) -> Option<Name> {
match pat.node { match pat.node {
PatKind::Binding(_, _, ref spname, _) => Some(spname.node), PatKind::Binding(_, _, ref spname, _) => Some(spname.name),
PatKind::Path(ref qpath) => single_segment_path(qpath).map(|ps| ps.name), PatKind::Path(ref qpath) => single_segment_path(qpath).map(|ps| ps.ident.name),
PatKind::Box(ref p) | PatKind::Ref(ref p, _) => get_pat_name(&*p), PatKind::Box(ref p) | PatKind::Ref(ref p, _) => get_pat_name(&*p),
_ => None, _ => None,
} }
@ -431,7 +431,7 @@ pub fn snippet_block<'a, 'b, T: LintContext<'b>>(cx: &T, span: Span, default: &'
pub fn last_line_of_span<'a, T: LintContext<'a>>(cx: &T, span: Span) -> Span { pub fn last_line_of_span<'a, T: LintContext<'a>>(cx: &T, span: Span) -> Span {
let file_map_and_line = cx.sess().codemap().lookup_line(span.lo()).unwrap(); let file_map_and_line = cx.sess().codemap().lookup_line(span.lo()).unwrap();
let line_no = file_map_and_line.line; let line_no = file_map_and_line.line;
let line_start = &file_map_and_line.fm.lines.clone().into_inner()[line_no]; let line_start = &file_map_and_line.fm.lines[line_no];
Span::new(*line_start, span.hi(), span.ctxt()) Span::new(*line_start, span.hi(), span.ctxt())
} }
@ -990,7 +990,7 @@ pub fn opt_def_id(def: Def) -> Option<DefId> {
pub fn is_self(slf: &Arg) -> bool { pub fn is_self(slf: &Arg) -> bool {
if let PatKind::Binding(_, _, name, _) = slf.pat.node { if let PatKind::Binding(_, _, name, _) = slf.pat.node {
name.node == keywords::SelfValue.name() name.name == keywords::SelfValue.name()
} else { } else {
false false
} }
@ -1068,12 +1068,20 @@ pub fn is_allowed(cx: &LateContext, lint: &'static Lint, id: NodeId) -> bool {
pub fn get_arg_name(pat: &Pat) -> Option<ast::Name> { pub fn get_arg_name(pat: &Pat) -> Option<ast::Name> {
match pat.node { match pat.node {
PatKind::Binding(_, _, name, None) => Some(name.node), PatKind::Binding(_, _, ident, None) => Some(ident.name),
PatKind::Ref(ref subpat, _) => get_arg_name(subpat), PatKind::Ref(ref subpat, _) => get_arg_name(subpat),
_ => None, _ => None,
} }
} }
pub fn get_arg_ident(pat: &Pat) -> Option<ast::Ident> {
match pat.node {
PatKind::Binding(_, _, ident, None) => Some(ident),
PatKind::Ref(ref subpat, _) => get_arg_ident(subpat),
_ => None,
}
}
pub fn int_bits(tcx: TyCtxt, ity: ast::IntTy) -> u64 { pub fn int_bits(tcx: TyCtxt, ity: ast::IntTy) -> u64 {
layout::Integer::from_attr(tcx, attr::IntType::SignedInt(ity)).size().bits() layout::Integer::from_attr(tcx, attr::IntType::SignedInt(ity)).size().bits()
} }

View file

@ -56,12 +56,12 @@ impl<'a, 'tcx: 'a> Visitor<'tcx> for PtrCloneVisitor<'a, 'tcx> {
} }
if let ExprMethodCall(ref seg, _, ref args) = expr.node { if let ExprMethodCall(ref seg, _, ref args) = expr.node {
if args.len() == 1 && match_var(&args[0], self.name) { if args.len() == 1 && match_var(&args[0], self.name) {
if seg.name == "capacity" { if seg.ident.name == "capacity" {
self.abort = true; self.abort = true;
return; return;
} }
for &(fn_name, suffix) in self.replace { for &(fn_name, suffix) in self.replace {
if seg.name == fn_name { if seg.ident.name == fn_name {
self.spans self.spans
.push((expr.span, snippet(self.cx, args[0].span, "_") + suffix)); .push((expr.span, snippet(self.cx, args[0].span, "_") + suffix));
return; return;

View file

@ -186,7 +186,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for Pass {
}, },
// write!() // write!()
ExprMethodCall(ref fun, _, ref args) => { ExprMethodCall(ref fun, _, ref args) => {
if fun.name == "write_fmt" { if fun.ident.name == "write_fmt" {
check_write_variants(cx, expr, args); check_write_variants(cx, expr, args);
} }
}, },
@ -471,13 +471,13 @@ pub fn check_unformatted(format_field: &Expr) -> bool {
if let ExprStruct(_, ref fields, _) = format_field.node; if let ExprStruct(_, ref fields, _) = format_field.node;
if let Some(width_field) = fields.iter().find(|f| f.ident.name == "width"); if let Some(width_field) = fields.iter().find(|f| f.ident.name == "width");
if let ExprPath(ref qpath) = width_field.expr.node; if let ExprPath(ref qpath) = width_field.expr.node;
if last_path_segment(qpath).name == "Implied"; if last_path_segment(qpath).ident.name == "Implied";
if let Some(align_field) = fields.iter().find(|f| f.ident.name == "align"); if let Some(align_field) = fields.iter().find(|f| f.ident.name == "align");
if let ExprPath(ref qpath) = align_field.expr.node; if let ExprPath(ref qpath) = align_field.expr.node;
if last_path_segment(qpath).name == "Unknown"; if last_path_segment(qpath).ident.name == "Unknown";
if let Some(precision_field) = fields.iter().find(|f| f.ident.name == "precision"); if let Some(precision_field) = fields.iter().find(|f| f.ident.name == "precision");
if let ExprPath(ref qpath_precision) = precision_field.expr.node; if let ExprPath(ref qpath_precision) = precision_field.expr.node;
if last_path_segment(qpath_precision).name == "Implied"; if last_path_segment(qpath_precision).ident.name == "Implied";
then { then {
return true; return true;
} }