Skip to content

Commit 4161823

Browse files
committed
Avoid triggering similar names on code from expansion
1 parent 04db13e commit 4161823

File tree

2 files changed

+10
-6
lines changed

2 files changed

+10
-6
lines changed

clippy_lints/src/new_without_default.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -90,8 +90,8 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for NewWithoutDefault {
9090
return;
9191
}
9292
if sig.decl.inputs.is_empty() && name == sym!(new) && cx.access_levels.is_reachable(id) {
93-
let self_did = cx.tcx.hir().local_def_id(cx.tcx.hir().get_parent_item(id));
94-
let self_ty = cx.tcx.type_of(self_did);
93+
let self_def_id = cx.tcx.hir().local_def_id(cx.tcx.hir().get_parent_item(id));
94+
let self_ty = cx.tcx.type_of(self_def_id);
9595
if_chain! {
9696
if same_tys(cx, self_ty, return_ty(cx, id));
9797
if let Some(default_trait_id) = get_trait_def_id(cx, &paths::DEFAULT_TRAIT);
@@ -112,10 +112,10 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for NewWithoutDefault {
112112
// generics
113113
if_chain! {
114114
if let Some(ref impling_types) = self.impling_types;
115-
if let Some(self_def) = cx.tcx.type_of(self_did).ty_adt_def();
116-
if let Some(self_def_id) = self_def.did.as_local();
115+
if let Some(self_def) = cx.tcx.type_of(self_def_id).ty_adt_def();
116+
if let Some(self_local_did) = self_def.did.as_local();
117117
then {
118-
let self_id = cx.tcx.hir().local_def_id_to_hir_id(self_def_id);
118+
let self_id = cx.tcx.hir().local_def_id_to_hir_id(self_local_did);
119119
if impling_types.contains(&self_id) {
120120
return;
121121
}

clippy_lints/src/non_expressive_names.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,11 @@ struct SimilarNamesNameVisitor<'a, 'tcx, 'b>(&'b mut SimilarNamesLocalVisitor<'a
132132
impl<'a, 'tcx, 'b> Visitor<'tcx> for SimilarNamesNameVisitor<'a, 'tcx, 'b> {
133133
fn visit_pat(&mut self, pat: &'tcx Pat) {
134134
match pat.kind {
135-
PatKind::Ident(_, ident, _) => self.check_ident(ident),
135+
PatKind::Ident(_, ident, _) => {
136+
if !pat.span.from_expansion() {
137+
self.check_ident(ident);
138+
}
139+
},
136140
PatKind::Struct(_, ref fields, _) => {
137141
for field in fields {
138142
if !field.is_shorthand {

0 commit comments

Comments
 (0)