Skip to content

Commit aeb653f

Browse files
authored
Merge pull request #2902 from mikerite/missing_inline_refactor
Remove duplication in missing_inline
2 parents d914106 + 60af4a8 commit aeb653f

File tree

1 file changed

+12
-21
lines changed

1 file changed

+12
-21
lines changed

clippy_lints/src/missing_inline.rs

Lines changed: 12 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -169,28 +169,19 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for MissingInline {
169169
};
170170

171171
let def_id = cx.tcx.hir.local_def_id(impl_item.id);
172-
match cx.tcx.associated_item(def_id).container {
173-
TraitContainer(cid) => {
174-
if let Some(n) = cx.tcx.hir.as_local_node_id(cid) {
175-
if !cx.access_levels.is_exported(n) {
176-
// If a trait is being implemented for an item, and the
177-
// trait is not exported, we don't need #[inline]
178-
return;
179-
}
180-
}
181-
},
182-
ImplContainer(cid) => {
183-
if cx.tcx.impl_trait_ref(cid).is_some() {
184-
let trait_ref = cx.tcx.impl_trait_ref(cid).unwrap();
185-
if let Some(n) = cx.tcx.hir.as_local_node_id(trait_ref.def_id) {
186-
if !cx.access_levels.is_exported(n) {
187-
// If a trait is being implemented for an item, and the
188-
// trait is not exported, we don't need #[inline]
189-
return;
190-
}
191-
}
172+
let trait_def_id = match cx.tcx.associated_item(def_id).container {
173+
TraitContainer(cid) => Some(cid),
174+
ImplContainer(cid) => cx.tcx.impl_trait_ref(cid).map(|t| t.def_id),
175+
};
176+
177+
if let Some(trait_def_id) = trait_def_id {
178+
if let Some(n) = cx.tcx.hir.as_local_node_id(trait_def_id) {
179+
if !cx.access_levels.is_exported(n) {
180+
// If a trait is being implemented for an item, and the
181+
// trait is not exported, we don't need #[inline]
182+
return;
192183
}
193-
},
184+
}
194185
}
195186

196187
check_missing_inline_attrs(cx, &impl_item.attrs, impl_item.span, desc);

0 commit comments

Comments
 (0)