Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rustup #3685

Merged
merged 3 commits into from
Jan 22, 2019
Merged

Rustup #3685

Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion clippy_lints/src/arithmetic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for Arithmetic {
}
self.const_span = Some(body_span);
},
hir::BodyOwnerKind::Fn => (),
hir::BodyOwnerKind::Fn | hir::BodyOwnerKind::Closure => (),
}
}

Expand Down
22 changes: 19 additions & 3 deletions clippy_lints/src/utils/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -64,9 +64,25 @@ pub fn differing_macro_contexts(lhs: Span, rhs: Span) -> bool {
/// ```
pub fn in_constant(cx: &LateContext<'_, '_>, id: NodeId) -> bool {
let parent_id = cx.tcx.hir().get_parent(id);
match cx.tcx.hir().body_owner_kind(parent_id) {
hir::BodyOwnerKind::Fn => false,
hir::BodyOwnerKind::Const | hir::BodyOwnerKind::Static(..) => true,
match cx.tcx.hir().get(parent_id) {
Node::Item(&Item {
node: ItemKind::Const(..),
..
})
| Node::TraitItem(&TraitItem {
node: TraitItemKind::Const(..),
..
})
| Node::ImplItem(&ImplItem {
node: ImplItemKind::Const(..),
..
})
| Node::AnonConst(_)
| Node::Item(&Item {
node: ItemKind::Static(..),
..
}) => true,
_ => false,
}
}

Expand Down