use clippy_utils::diagnostics::{span_lint, span_lint_and_then};
use rustc_ast::ast::{
- Arm, AssocItem, AssocItemKind, Attribute, Block, FnDecl, FnKind, Item, ItemKind, Local, Pat, PatKind,
+ self, Arm, AssocItem, AssocItemKind, Attribute, Block, FnDecl, Item, ItemKind, Local, Pat, PatKind,
};
use rustc_ast::visit::{walk_block, walk_expr, walk_pat, Visitor};
-use rustc_lint::{EarlyContext, EarlyLintPass};
+use rustc_lint::{EarlyContext, EarlyLintPass, LintContext};
use rustc_middle::lint::in_external_macro;
use rustc_session::{declare_tool_lint, impl_lint_pass};
use rustc_span::source_map::Span;
/// let checked_exp = something;
/// let checked_expr = something_else;
/// ```
+ #[clippy::version = "pre 1.29.0"]
pub SIMILAR_NAMES,
pedantic,
"similarly named items and bindings"
/// ```ignore
/// let (a, b, c, d, e, f, g) = (...);
/// ```
+ #[clippy::version = "pre 1.29.0"]
pub MANY_SINGLE_CHAR_NAMES,
- style,
+ pedantic,
"too many single character bindings"
}
/// let ___1 = 1;
/// let __1___2 = 11;
/// ```
+ #[clippy::version = "pre 1.29.0"]
pub JUST_UNDERSCORES_AND_DIGITS,
style,
"unclear name"
&["qpath", "path"],
&["lit", "lint"],
&["wparam", "lparam"],
+ &["iter", "item"],
];
struct SimilarNamesNameVisitor<'a, 'tcx, 'b>(&'b mut SimilarNamesLocalVisitor<'a, 'tcx>);
return;
}
for existing_name in &self.0.names {
- if allowed_to_be_similar(&interned_name, existing_name.exemptions) {
+ if allowed_to_be_similar(interned_name, existing_name.exemptions) {
continue;
}
match existing_name.len.cmp(&count) {
Ordering::Greater => {
if existing_name.len - count != 1
- || levenstein_not_1(&interned_name, &existing_name.interned.as_str())
+ || levenstein_not_1(interned_name, existing_name.interned.as_str())
{
continue;
}
},
Ordering::Less => {
if count - existing_name.len != 1
- || levenstein_not_1(&existing_name.interned.as_str(), &interned_name)
+ || levenstein_not_1(existing_name.interned.as_str(), interned_name)
{
continue;
}
return;
}
self.0.names.push(ExistingName {
- exemptions: get_exemptions(&interned_name).unwrap_or(&[]),
+ exemptions: get_exemptions(interned_name).unwrap_or(&[]),
interned: ident.name,
span: ident.span,
len: count,
impl<'a, 'tcx> Visitor<'tcx> for SimilarNamesLocalVisitor<'a, 'tcx> {
fn visit_local(&mut self, local: &'tcx Local) {
- if let Some(ref init) = local.init {
- self.apply(|this| walk_expr(this, &**init));
+ if let Some((init, els)) = &local.kind.init_else_opt() {
+ self.apply(|this| walk_expr(this, init));
+ if let Some(els) = els {
+ self.apply(|this| walk_block(this, els));
+ }
}
// add the pattern after the expression because the bindings aren't available
// yet in the init
impl EarlyLintPass for NonExpressiveNames {
fn check_item(&mut self, cx: &EarlyContext<'_>, item: &Item) {
- if in_external_macro(cx.sess, item.span) {
+ if in_external_macro(cx.sess(), item.span) {
return;
}
- if let ItemKind::Fn(box FnKind(_, ref sig, _, Some(ref blk))) = item.kind {
+ if let ItemKind::Fn(box ast::Fn {
+ ref sig,
+ body: Some(ref blk),
+ ..
+ }) = item.kind
+ {
do_check(self, cx, &item.attrs, &sig.decl, blk);
}
}
fn check_impl_item(&mut self, cx: &EarlyContext<'_>, item: &AssocItem) {
- if in_external_macro(cx.sess, item.span) {
+ if in_external_macro(cx.sess(), item.span) {
return;
}
- if let AssocItemKind::Fn(box FnKind(_, ref sig, _, Some(ref blk))) = item.kind {
+ if let AssocItemKind::Fn(box ast::Fn {
+ ref sig,
+ body: Some(ref blk),
+ ..
+ }) = item.kind
+ {
do_check(self, cx, &item.attrs, &sig.decl, blk);
}
}