Merge pull request #2880 from mati865/rustup_hir

Rustup
This commit is contained in:
Oliver Schneider 2018-06-29 10:20:19 +02:00 committed by GitHub
commit 3aee654dd1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
53 changed files with 196 additions and 187 deletions

View File

@ -617,6 +617,7 @@ All notable changes to this project will be documented in this file.
[`block_in_if_condition_expr`]: https://rust-lang-nursery.github.io/rust-clippy/master/index.html#block_in_if_condition_expr
[`block_in_if_condition_stmt`]: https://rust-lang-nursery.github.io/rust-clippy/master/index.html#block_in_if_condition_stmt
[`bool_comparison`]: https://rust-lang-nursery.github.io/rust-clippy/master/index.html#bool_comparison
[`borrow_interior_mutable_const`]: https://rust-lang-nursery.github.io/rust-clippy/master/index.html#borrow_interior_mutable_const
[`borrowed_box`]: https://rust-lang-nursery.github.io/rust-clippy/master/index.html#borrowed_box
[`box_vec`]: https://rust-lang-nursery.github.io/rust-clippy/master/index.html#box_vec
[`boxed_local`]: https://rust-lang-nursery.github.io/rust-clippy/master/index.html#boxed_local
@ -641,6 +642,7 @@ All notable changes to this project will be documented in this file.
[`crosspointer_transmute`]: https://rust-lang-nursery.github.io/rust-clippy/master/index.html#crosspointer_transmute
[`cyclomatic_complexity`]: https://rust-lang-nursery.github.io/rust-clippy/master/index.html#cyclomatic_complexity
[`decimal_literal_representation`]: https://rust-lang-nursery.github.io/rust-clippy/master/index.html#decimal_literal_representation
[`declare_interior_mutable_const`]: https://rust-lang-nursery.github.io/rust-clippy/master/index.html#declare_interior_mutable_const
[`default_trait_access`]: https://rust-lang-nursery.github.io/rust-clippy/master/index.html#default_trait_access
[`deprecated_semver`]: https://rust-lang-nursery.github.io/rust-clippy/master/index.html#deprecated_semver
[`deref_addrof`]: https://rust-lang-nursery.github.io/rust-clippy/master/index.html#deref_addrof

View File

@ -9,7 +9,7 @@ We are currently in the process of discussing Clippy 1.0 via the RFC process in
A collection of lints to catch common mistakes and improve your [Rust](https://github.com/rust-lang/rust) code.
[There are 270 lints included in this crate!](https://rust-lang-nursery.github.io/rust-clippy/master/index.html)
[There are 272 lints included in this crate!](https://rust-lang-nursery.github.io/rust-clippy/master/index.html)
We have a bunch of lint categories to allow you to choose how much clippy is supposed to ~~annoy~~ help you:

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) {
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) {
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 {
fn check_pat(&mut self, cx: &LateContext<'a, 'tcx>, pat: &'tcx Pat) {
if let PatKind::Binding(_, _, ref ident, _) = pat.node {
if self.blacklist.iter().any(|s| ident.node == *s) {
if let PatKind::Binding(_, _, ident, _) = pat.node {
if self.blacklist.iter().any(|s| ident.name == *s) {
span_lint(
cx,
BLACKLISTED_NAME,
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
.iter().cloned()
.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)))
},
_ => None,

View File

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

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 {
bindings_impl(cx, pat, map);
},
PatKind::Binding(_, _, ref ident, ref as_pat) => {
if let Entry::Vacant(v) = map.entry(ident.node.as_str()) {
PatKind::Binding(_, _, ident, ref as_pat) => {
if let Entry::Vacant(v) = map.entry(ident.as_str()) {
v.insert(cx.tables.pat_ty(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 let Some((Constant::Int(divisor), _)) = constant(cx, cx.tables, right);
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_nanos", 1_000) => "subsec_micros",
("subsec_nanos", 1_000_000) => "subsec_millis",

View File

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

View File

@ -121,7 +121,7 @@ impl LintPass for EnumVariantNames {
}
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
@ -245,7 +245,7 @@ impl EarlyLintPass for EnumVariantNames {
}
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_camel = to_camel_case(&item_name);
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
return;
}
if p.segments[0].name != ident.node {
if p.segments[0].ident.name != ident.name {
// The two idents should be the same
return;
}

View File

@ -36,12 +36,12 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for Pass {
if_chain! {
// match call to unwrap
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
if unwrap_args.len() > 0;
if let ExprMethodCall(ref write_fun, _, ref write_args) =
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 ()
if write_args.len() > 0;
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 {
if_chain! {
if impl_item.name == "from";
if impl_item.ident.name == "from";
if let ImplItemKind::Method(_, body_id) =
cx.tcx.hir.impl_item(impl_item.id).node;
then {

View File

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

View File

@ -56,7 +56,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for IdentityConversion {
},
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 b = cx.tables.expr_ty(&args[0]);
if same_tys(cx, a, b) {

View File

@ -143,7 +143,7 @@ fn is_infinite(cx: &LateContext, expr: &Expr) -> Finiteness {
match expr.node {
ExprMethodCall(ref method, _, ref args) => {
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 {
Always => Infinite,
First => is_infinite(cx, &args[0]),
@ -152,7 +152,7 @@ fn is_infinite(cx: &LateContext, expr: &Expr) -> Finiteness {
}).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 {
let body = cx.tcx.hir.body(body_id);
return is_infinite(cx, &body.value);
@ -207,16 +207,16 @@ fn complete_infinite_iter(cx: &LateContext, expr: &Expr) -> Finiteness {
match expr.node {
ExprMethodCall(ref method, _, ref args) => {
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]);
}
}
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]));
}
}
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)
.map_or(false, |id| !implements_trait(cx, cx.tables.expr_ty(&args[0]), id, &[]));
if not_double_ended {

View File

@ -38,7 +38,7 @@ impl LintPass for Pass {
impl<'a, 'tcx> LateLintPass<'a, 'tcx> for Pass {
fn check_trait_item(&mut self, cx: &LateContext<'a, 'tcx>, item: &'tcx TraitItem) {
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 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 && {
let did = cx.tcx.hir.local_def_id(item.id.node_id);
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()
.flat_map(|&i| cx.tcx.associated_items(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
});
@ -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 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 && {
let did = cx.tcx.hir.local_def_id(item.id.node_id);
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)`.
fn is_is_empty(cx: &LateContext, item: &ty::AssociatedItem) -> bool {
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 ty = sig.skip_binder();
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 hir::StmtDecl(ref decl, _) = stmt.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::ExprIf(ref cond, ref then, ref else_) = if_.node;
if !used_in_expr(cx, canonical_id, cond);
@ -106,7 +106,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for LetIfSeq {
let sug = format!(
"let {mut}{name} = if {cond} {{{then} {value} }} else {{{else} {default} }};",
mut=mutability,
name=name.node,
name=ident.name,
cond=snippet(cx, cond.span, "_"),
then=if then.stmts.len() > 1 { " ..;" } else { "" },
else=if default_multi_stmts { " ..;" } else { "" },

View File

@ -434,6 +434,7 @@ pub fn register_plugins(reg: &mut rustc_plugin::Registry) {
reg.register_lint_group("clippy_pedantic", vec![
attrs::INLINE_ALWAYS,
copies::MATCH_SAME_ARMS,
default_trait_access::DEFAULT_TRAIT_ACCESS,
derive::EXPL_IMPL_CLONE_ON_COPY,
doc::DOC_MARKDOWN,
empty_enum::EMPTY_ENUM,
@ -492,7 +493,6 @@ pub fn register_plugins(reg: &mut rustc_plugin::Registry) {
copies::IF_SAME_THEN_ELSE,
copies::IFS_SAME_COND,
cyclomatic_complexity::CYCLOMATIC_COMPLEXITY,
default_trait_access::DEFAULT_TRAIT_ACCESS,
derive::DERIVE_HASH_XOR_EQ,
double_comparison::DOUBLE_COMPARISONS,
double_parens::DOUBLE_PARENS,
@ -694,7 +694,6 @@ pub fn register_plugins(reg: &mut rustc_plugin::Registry) {
block_in_if_condition::BLOCK_IN_IF_CONDITION_STMT,
collapsible_if::COLLAPSIBLE_IF,
const_static_lifetime::CONST_STATIC_LIFETIME,
default_trait_access::DEFAULT_TRAIT_ACCESS,
enum_variants::ENUM_VARIANT_NAMES,
enum_variants::MODULE_INCEPTION,
eq_op::OP_REF,

View File

@ -126,7 +126,7 @@ fn check_fn_inner<'a, 'tcx>(
GenericArg::Type(_) => None,
});
for bound in lifetimes {
if bound.name.name() != "'static" && !bound.is_elided() {
if bound.name.ident().name != "'static" && !bound.is_elided() {
return;
}
bounds_lts.push(bound);
@ -240,7 +240,7 @@ fn allowed_lts_from(named_generics: &[GenericParam]) -> HashSet<RefLt> {
for par in named_generics.iter() {
if let GenericParamKind::Lifetime { .. } = par.kind {
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> {
for lt in bounds_lts {
if lt.name.name() != "'static" {
vec.push(RefLt::Named(lt.name.name()));
if lt.name.ident().name != "'static" {
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>) {
if let Some(ref lt) = *lifetime {
if lt.name.name() == "'static" {
if lt.name.ident().name == "'static" {
self.lts.push(RefLt::Static);
} else if lt.is_elided() {
self.lts.push(RefLt::Unnamed);
} else {
self.lts.push(RefLt::Named(lt.name.name()));
self.lts.push(RefLt::Named(lt.name.ident().name));
}
} else {
self.lts.push(RefLt::Unnamed);
@ -421,7 +421,7 @@ struct LifetimeChecker {
impl<'tcx> Visitor<'tcx> for LifetimeChecker {
// for lifetimes as parameters of generics
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) {
@ -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) {
let hs = generics.params.iter()
.filter_map(|par| match par.kind {
GenericParamKind::Lifetime { .. } => Some((par.name.name(), par.span)),
GenericParamKind::Lifetime { .. } => Some((par.name.ident().name, par.span)),
_ => None,
})
.collect();
@ -463,7 +463,7 @@ struct BodyLifetimeChecker {
impl<'tcx> Visitor<'tcx> for BodyLifetimeChecker {
// for lifetimes as parameters of generics
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;
}
}

View File

@ -485,8 +485,8 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for Pass {
{
let iter_expr = &method_args[0];
let lhs_constructor = last_path_segment(qpath);
if method_path.name == "next" && match_trait_method(cx, match_expr, &paths::ITERATOR)
&& lhs_constructor.name == "Some" && !is_refutable(cx, &pat_args[0])
if method_path.ident.name == "next" && match_trait_method(cx, match_expr, &paths::ITERATOR)
&& lhs_constructor.ident.name == "Some" && !is_refutable(cx, &pat_args[0])
&& !is_iterator_used_after_while_let(cx, iter_expr)
&& !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) {
if let StmtSemi(ref expr, _) = stmt.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(
cx,
UNUSED_COLLECT,
@ -811,7 +811,7 @@ fn fetch_cloned_fixed_offset_var<'a, 'tcx>(
) -> Option<FixedOffsetVar> {
if_chain! {
if let ExprMethodCall(ref method, _, ref args) = expr.node;
if method.name == "clone";
if method.ident.name == "clone";
if args.len() == 1;
if let Some(arg) = args.get(0);
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 {
if_chain! {
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 let Some(arg) = len_args.get(0);
if snippet(cx, arg.span, "??") == var_name;
@ -985,7 +985,7 @@ fn check_for_loop_range<'a, 'tcx>(
}) = higher::range(cx, arg)
{
// 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 {
cx,
var: canonical_id,
@ -1058,13 +1058,13 @@ fn check_for_loop_range<'a, 'tcx>(
cx,
NEEDLESS_RANGE_LOOP,
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| {
multispan_sugg(
db,
"consider using an iterator".to_string(),
vec![
(pat.span, format!("({}, <item>)", ident.node)),
(pat.span, format!("({}, <item>)", ident.name)),
(arg.span, format!("{}.{}().enumerate(){}{}", indexed, method, take, skip)),
],
);
@ -1081,7 +1081,7 @@ fn check_for_loop_range<'a, 'tcx>(
cx,
NEEDLESS_RANGE_LOOP,
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| {
multispan_sugg(
db,
@ -1100,10 +1100,10 @@ fn is_len_call(expr: &Expr, var: Name) -> bool {
if_chain! {
if let ExprMethodCall(ref method, _, ref len_args) = expr.node;
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 path.segments.len() == 1;
if path.segments[0].name == var;
if path.segments[0].ident.name == var;
then {
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 {
// just the receiver, no arguments
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
if method_name == "iter" || method_name == "iter_mut" {
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 {
match *pat {
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 {
var: ident.node,
var: ident.name,
used: false,
};
walk_expr(&mut visitor, body);
@ -1615,7 +1615,7 @@ impl<'a, 'tcx> VarVisitor<'a, 'tcx> {
if indexed_indirectly || index_used_directly {
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);
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 extent = self.cx.tcx.region_scope_tree(parent_def_id).var_scope(hir_id.local_id);
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 {
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*
}
Def::Static(..) | Def::Const(..) => {
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 {
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*
}
@ -1656,8 +1656,8 @@ impl<'a, 'tcx> Visitor<'tcx> for VarVisitor<'a, 'tcx> {
if_chain! {
// a range index op
if let ExprMethodCall(ref meth, _, ref args) = expr.node;
if (meth.name == "index" && match_trait_method(self.cx, expr, &paths::INDEX))
|| (meth.name == "index_mut" && match_trait_method(self.cx, expr, &paths::INDEX_MUT));
if (meth.ident.name == "index" && match_trait_method(self.cx, expr, &paths::INDEX))
|| (meth.ident.name == "index_mut" && match_trait_method(self.cx, expr, &paths::INDEX_MUT));
if !self.check(&args[1], &args[0], expr);
then { return }
}
@ -1681,7 +1681,7 @@ impl<'a, 'tcx> Visitor<'tcx> for VarVisitor<'a, 'tcx> {
self.nonindex = true;
} else {
// 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
if let DeclLocal(ref local) = decl.node {
if local.pat.id == self.var_id {
if let PatKind::Binding(_, _, ref ident, _) = local.pat.node {
self.name = Some(ident.node);
if let PatKind::Binding(_, _, ident, _) = local.pat.node {
self.name = Some(ident.name);
self.state = if let Some(ref init) = local.init {
if is_integer_literal(init, 0) {
@ -2123,7 +2123,7 @@ impl<'tcx> Visitor<'tcx> for LoopNestVisitor {
return;
}
if let PatKind::Binding(_, _, span_name, _) = pat.node {
if self.iterator == span_name.node {
if self.iterator == span_name.name {
self.nesting = RuledOut;
return;
}
@ -2140,7 +2140,7 @@ fn path_name(e: &Expr) -> Option<Name> {
if let ExprPath(QPath::Resolved(_, ref path)) = e.node {
let segments = &path.segments;
if segments.len() == 1 {
return Some(segments[0].name);
return Some(segments[0].ident.name);
}
};
None

View File

@ -2,7 +2,7 @@ use rustc::lint::*;
use rustc::hir::*;
use rustc::ty;
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};
/// **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) {
// call to .map()
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 {
ExprClosure(_, ref decl, 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
// (e.g. .map(|&x| x) )
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)
if let Some(type_name) = get_type_name(cx, expr, &args[0]);
then {
@ -63,7 +63,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for Pass {
}
// explicit clone() calls ( .map(|x| x.clone()) )
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 &&
match_trait_method(cx, closure_expr, &paths::CLONE_TRAIT) &&
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 {
ExprPath(QPath::Resolved(None, ref path)) => {
let arg_segment = [
PathSegment {
name: id,
ident: id,
args: None,
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 {
ExprUnary(UnDeref, ref subexpr) if !is_adjusted(cx, subexpr) => only_derefs(cx, subexpr, 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))
},
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)),
_ => return,
};
@ -552,14 +552,14 @@ fn is_ref_some_arm(arm: &Arm) -> Option<BindingAnnotation> {
if_chain! {
if let PatKind::TupleStruct(ref path, ref pats, _) = arm.pats[0].node;
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 let ExprCall(ref e, ref args) = remove_blocks(&arm.body).node;
if let ExprPath(ref some_path) = e.node;
if match_qpath(some_path, &paths::OPTION_SOME) && args.len() == 1;
if let ExprPath(ref qpath) = args[0].node;
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 {
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_or_fun_call(cx, expr, *method_span, &method_call.name.as_str(), args);
lint_expect_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.ident.as_str(), args);
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_ref_ptr(cx, expr, &args[0]);
}
match self_ty.sty {
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]);
}
},
@ -806,7 +806,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for Pass {
if in_external_macro(cx, implitem.span) {
return;
}
let name = implitem.name;
let name = implitem.ident.name;
let parent = cx.tcx.hir.get_parent(implitem.id);
let item = cx.tcx.hir.expect_item(parent);
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 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) {
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 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())
} else {
None
@ -1794,7 +1794,7 @@ fn lint_chars_cmp<'a, 'tcx>(
if arg_char.len() == 1;
if let hir::ExprPath(ref qpath) = fun.node;
if let Some(segment) = single_segment_path(qpath);
if segment.name == "Some";
if segment.ident.name == "Some";
then {
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| {
generics.params.iter().any(|param| match param.kind {
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 {
let path = &ptr.trait_ref.path;
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
.segments
.iter()
.map(|seg| seg.name)
.eq(self_ty_path.segments.iter().map(|seg| seg.name)),
.map(|seg| seg.ident.name)
.eq(self_ty_path.segments.iter().map(|seg| seg.ident.name)),
_ => false,
}
}

View File

@ -379,7 +379,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for Pass {
}
let binding = match expr.node {
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('_') &&
!binding.starts_with("__") &&
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) {
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 {
span_lint(
cx,
REDUNDANT_PATTERN,
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) {
if !in_constant(cx, expr.id) {
if let Some(seg) = path.segments.last() {
if seg.name == "NAN" {
if seg.ident.name == "NAN" {
span_lint(
cx,
CMP_NAN,

View File

@ -190,7 +190,7 @@ impl EarlyLintPass for MiscEarly {
fn check_generics(&mut self, cx: &EarlyContext, gen: &Generics) {
for param in &gen.params {
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) {
span_lint(
cx,
@ -268,7 +268,7 @@ impl EarlyLintPass for MiscEarly {
for arg in &decl.inputs {
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 let Some(correspondence) = registered_names.get(&arg_name[1..]) {
@ -371,8 +371,8 @@ impl MiscEarly {
let mut seen = (false, false);
for ch in src.chars() {
match ch {
'a' ... 'f' => seen.0 = true,
'A' ... 'F' => seen.1 = true,
'a' ..= 'f' => seen.0 = true,
'A' ..= 'F' => seen.1 = true,
'i' | 'u' => break, // start of suffix already
_ => ()
}

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 substs = cx.tables.node_substs(e.hir_id);
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.
if idx == 0 {
if let PatKind::Binding(_, _, name, ..) = arg.pat.node {
if name.node.as_str() == "self" {
if let PatKind::Binding(_, _, ident, ..) = arg.pat.node {
if ident.as_str() == "self" {
continue;
}
}
@ -217,7 +217,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for NeedlessPassByValue {
get_spans(cx, Some(body.id()), idx, &[("clone", ".to_owned()")]);
if let TyPath(QPath::Resolved(_, ref path)) = input.node;
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())
.map(|params| params.args.iter().find_map(|arg| match arg {
GenericArg::Type(ty) => Some(ty),

View File

@ -97,7 +97,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for NewWithoutDefault {
return;
}
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;
if sig.header.constness == hir::Constness::Const {
// can't be implemented by default

View File

@ -5,7 +5,7 @@
use rustc::lint::{LateContext, LateLintPass, Lint, LintArray, LintPass};
use rustc::hir::*;
use rustc::hir::def::Def;
use rustc::ty::{self, TyRef, TypeFlags};
use rustc::ty::{self, TypeFlags};
use rustc::ty::adjustment::Adjust;
use rustc_errors::Applicability;
use rustc_typeck::hir_ty_to_ty;

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) {
if let ExprMethodCall(ref path, _, ref arguments) = e.node {
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();
get_open_options(cx, &arguments[0], &mut options);
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,
};
match &*path.name.as_str() {
match &*path.ident.as_str() {
"create" => {
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;
then {
for impl_item in impl_items {
if impl_item.name == "ne" {
if impl_item.ident.name == "ne" {
span_lint(cx,
PARTIALEQ_NE_IMPL,
impl_item.span,

View File

@ -54,7 +54,7 @@ impl QuestionMarkPass {
if_chain! {
if let ExprIf(ref if_expr, ref body, _) = 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 let Some(subject) = args.get(0);
if Self::is_option(cx, subject);

View File

@ -89,7 +89,7 @@ impl LintPass for Pass {
impl<'a, 'tcx> LateLintPass<'a, 'tcx> for Pass {
fn check_expr(&mut self, cx: &LateContext<'a, 'tcx>, expr: &'tcx Expr) {
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).
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! {
// .iter() call
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()
if let Some(higher::Range { start: Some(start), end: Some(end), .. }) = higher::range(cx, zip_arg);
if is_integer_literal(start, 0);
// .len() call
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
if let ExprPath(QPath::Resolved(_, ref iter_path)) = iter_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 ast::PatKind::Ident(_, ident, _) = local.pat.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);
then {
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_string = None;
for item in items {
match &*item.name.as_str() {
match &*item.ident.as_str() {
"visit_str" => seen_str = 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();
for arg in iter_input_pats(decl, body) {
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);
@ -164,8 +164,8 @@ fn check_pat<'a, 'tcx>(
) {
// TODO: match more stuff / destructuring
match pat.node {
PatKind::Binding(_, _, ref ident, ref inner) => {
let name = ident.node;
PatKind::Binding(_, _, ident, ref inner) => {
let name = ident.name;
if is_binding(cx, pat.hir_id) {
let mut new_binding = true;
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 {
!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};
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 LitKind::Str(ref lit_content, _) = lit.node {
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 DeclLocal(ref tmp) = tmp.node;
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();
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 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(rhs1, lhs2);
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() {
"".to_owned()
} else {
format!("{} ", lt.name.name().as_str())
format!("{} ", lt.name.ident().name.as_str())
};
let mutopt = if mut_ty.mutbl == Mutability::MutMutable {
"mut "
@ -1993,10 +1993,10 @@ impl<'a, 'b, 'tcx: 'a + 'b> Visitor<'tcx> for ImplicitHasherConstructorVisitor<'
}
if match_path(ty_path, &paths::HASHMAP) {
if method.name == "new" {
if method.ident.name == "new" {
self.suggestions
.insert(e.span, "HashMap::default()".to_string());
} else if method.name == "with_capacity" {
} else if method.ident.name == "with_capacity" {
self.suggestions.insert(
e.span,
format!(
@ -2006,10 +2006,10 @@ impl<'a, 'b, 'tcx: 'a + 'b> Visitor<'tcx> for ImplicitHasherConstructorVisitor<'
);
}
} else if match_path(ty_path, &paths::HASHSET) {
if method.name == "new" {
if method.ident.name == "new" {
self.suggestions
.insert(e.span, "HashSet::default()".to_string());
} else if method.name == "with_capacity" {
} else if method.ident.name == "with_capacity" {
self.suggestions.insert(
e.span,
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" => {
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) {
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" {
span_lint(
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) {
match expr.node {
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)) => {
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;
let ty = cx.tables.expr_ty(&args[0]);
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);
then {
assert!(args.len() == 1);
@ -142,8 +142,8 @@ impl<'a, 'tcx: 'a> Visitor<'tcx> for UnwrappableVariablesVisitor<'a, 'tcx> {
if_chain! {
if let Expr_::ExprMethodCall(ref method_name, _, ref args) = expr.node;
if let Expr_::ExprPath(QPath::Resolved(None, ref path)) = args[0].node;
if ["unwrap", "unwrap_err"].contains(&&*method_name.name.as_str());
let call_to_unwrap = method_name.name == "unwrap";
if ["unwrap", "unwrap_err"].contains(&&*method_name.ident.as_str());
let call_to_unwrap = method_name.ident.name == "unwrap";
if let Some(unwrappable) = self.unwrappables.iter()
.find(|u| u.ident.def == path.def);
then {
@ -154,7 +154,7 @@ impl<'a, 'tcx: 'a> Visitor<'tcx> for UnwrappableVariablesVisitor<'a, 'tcx> {
expr.span,
&format!("You checked before that `{}()` cannot fail. \
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"); },
);
} else {
@ -163,7 +163,7 @@ impl<'a, 'tcx: 'a> Visitor<'tcx> for UnwrappableVariablesVisitor<'a, 'tcx> {
PANICKING_UNWRAP,
expr.span,
&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"); },
);
}

View File

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

View File

@ -77,7 +77,7 @@ impl<'a, 'tcx: 'a> SpanlessEq<'a, 'tcx> {
match (&left.node, &right.node) {
(&ExprAddrOf(l_mut, ref le), &ExprAddrOf(r_mut, ref re)) => l_mut == r_mut && self.eq_expr(le, re),
(&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),
(&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)) => {
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))
},
(&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,
(&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)) => {
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),
(&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)) => {
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,
}
@ -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
},
(&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::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 {
// The == of idents doesn't work with different contexts,
// 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;
}
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 {
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;
c.hash(&mut self.s);
if let Some(i) = i.label {
self.hash_name(i.name);
self.hash_name(i.ident.name);
}
},
ExprYield(ref e) => {
@ -393,7 +393,7 @@ impl<'a, 'tcx: 'a> SpanlessHash<'a, 'tcx> {
let c: fn(_, _) -> _ = ExprBreak;
c.hash(&mut self.s);
if let Some(i) = i.label {
self.hash_name(i.name);
self.hash_name(i.ident.name);
}
if let Some(ref j) = *j {
self.hash_expr(&*j);
@ -457,7 +457,7 @@ impl<'a, 'tcx: 'a> SpanlessHash<'a, 'tcx> {
c.hash(&mut self.s);
self.hash_block(b);
if let Some(i) = *i {
self.hash_name(i.name);
self.hash_name(i.ident.name);
}
},
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) => {
let c: fn(_, _, _) -> _ = ExprMethodCall;
c.hash(&mut self.s);
self.hash_name(path.name);
self.hash_name(path.ident.name);
self.hash_exprs(args);
},
ExprRepeat(ref e, ref l_id) => {
@ -548,7 +548,7 @@ impl<'a, 'tcx: 'a> SpanlessHash<'a, 'tcx> {
self.hash_expr(cond);
self.hash_block(b);
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);
},
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);
@ -579,7 +579,7 @@ impl<'a, 'tcx: 'a> SpanlessHash<'a, 'tcx> {
pub fn hash_path(&mut self, p: &Path) {
p.is_global().hash(&mut self.s);
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) {
return;
}
println!("impl item `{}`", item.name);
println!("impl item `{}`", item.ident.name);
match item.vis {
hir::Visibility::Public => println!("public"),
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) => {
println!("{}MethodCall", ind);
println!("{}method name: {}", ind, path.name);
println!("{}method name: {}", ind, path.ident.name);
for arg in args {
print_expr(cx, arg, indent + 1);
}
@ -268,7 +268,7 @@ fn print_expr(cx: &LateContext, expr: &hir::Expr, indent: usize) {
println!("{}rhs:", ind);
print_expr(cx, rhs, indent + 1);
},
hir::ExprField(ref e, ref ident) => {
hir::ExprField(ref e, ident) => {
println!("{}Field", ind);
println!("{}field name: {}", ind, ident.name);
println!("{}struct expr:", ind);
@ -417,10 +417,10 @@ fn print_pat(cx: &LateContext, pat: &hir::Pat, indent: usize) {
println!("{}+", ind);
match pat.node {
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!("{}mode: {:?}", ind, mode);
println!("{}name: {}", ind, name.node);
println!("{}name: {}", ind, ident.name);
if let Some(ref inner) = *inner {
println!("{}inner:", ind);
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 {
let mut last_name: Option<LocalInternedString> = None;
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 **last_name > *name {
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) {
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> {

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.
pub fn match_var(expr: &Expr, var: Name) -> bool {
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;
}
}
@ -212,7 +212,7 @@ pub fn match_qpath(path: &QPath, segments: &[&str]) -> bool {
QPath::TypeRelative(ref ty, ref segment) => match ty.node {
TyPath(ref inner_path) => {
!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,
},
@ -224,7 +224,7 @@ pub fn match_path(path: &Path, segments: &[&str]) -> bool {
.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.
@ -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() {
// method chains are stored last -> first
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)) {
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> {
let parent_id = cx.tcx.hir.get_parent(expr.id);
match cx.tcx.hir.find(parent_id) {
Some(Node::NodeItem(&Item { ref name, .. })) |
Some(Node::NodeTraitItem(&TraitItem { ref name, .. })) |
Some(Node::NodeImplItem(&ImplItem { ref name, .. })) => Some(*name),
Some(Node::NodeItem(&Item { ref name, .. })) => Some(*name),
Some(Node::NodeTraitItem(&TraitItem { ident, .. })) |
Some(Node::NodeImplItem(&ImplItem { ident, .. })) => Some(ident.name),
_ => None,
}
}
@ -363,8 +363,8 @@ pub fn get_item_name(cx: &LateContext, expr: &Expr) -> Option<Name> {
/// Get the name of a `Pat`, if any
pub fn get_pat_name(pat: &Pat) -> Option<Name> {
match pat.node {
PatKind::Binding(_, _, ref spname, _) => Some(spname.node),
PatKind::Path(ref qpath) => single_segment_path(qpath).map(|ps| ps.name),
PatKind::Binding(_, _, ref spname, _) => Some(spname.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),
_ => 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 {
let file_map_and_line = cx.sess().codemap().lookup_line(span.lo()).unwrap();
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())
}
@ -990,7 +990,7 @@ pub fn opt_def_id(def: Def) -> Option<DefId> {
pub fn is_self(slf: &Arg) -> bool {
if let PatKind::Binding(_, _, name, _) = slf.pat.node {
name.node == keywords::SelfValue.name()
name.name == keywords::SelfValue.name()
} else {
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> {
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),
_ => 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 {
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 args.len() == 1 && match_var(&args[0], self.name) {
if seg.name == "capacity" {
if seg.ident.name == "capacity" {
self.abort = true;
return;
}
for &(fn_name, suffix) in self.replace {
if seg.name == fn_name {
if seg.ident.name == fn_name {
self.spans
.push((expr.span, snippet(self.cx, args[0].span, "_") + suffix));
return;

View File

@ -186,7 +186,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for Pass {
},
// write!()
ExprMethodCall(ref fun, _, ref args) => {
if fun.name == "write_fmt" {
if fun.ident.name == "write_fmt" {
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 Some(width_field) = fields.iter().find(|f| f.ident.name == "width");
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 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 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 {
return true;
}

View File

@ -1,7 +1,7 @@
rustc 1.28.0-nightly (01cc982e9 2018-06-24)
rustc 1.28.0-nightly (e3bf634e0 2018-06-28)
binary: rustc
commit-hash: 01cc982e936120acb0424e41de14e42ba2d88c6f
commit-date: 2018-06-24
commit-hash: e3bf634e060bc2f8665878288bcea02008ca346e
commit-date: 2018-06-28
host: x86_64-unknown-linux-gnu
release: 1.28.0-nightly
LLVM version: 6.0