Separate out a hir::Impl struct

This makes it possible to pass the `Impl` directly to functions, instead
of having to pass each of the many fields one at a time. It also
simplifies matches in many cases.
This commit is contained in:
Joshua Nelson 2020-11-22 17:46:21 -05:00
parent 9e45a23ab9
commit dfb41f4797
24 changed files with 61 additions and 69 deletions

View file

@ -423,13 +423,13 @@ fn print_item(cx: &LateContext<'_>, item: &hir::Item<'_>) {
hir::ItemKind::TraitAlias(..) => {
println!("trait alias");
},
hir::ItemKind::Impl {
hir::ItemKind::Impl(hir::Impl {
of_trait: Some(ref _trait_ref),
..
} => {
}) => {
println!("trait impl");
},
hir::ItemKind::Impl { of_trait: None, .. } => {
hir::ItemKind::Impl(hir::Impl { of_trait: None, .. }) => {
println!("impl");
},
}

View file

@ -352,11 +352,11 @@ impl<'tcx> LateLintPass<'tcx> for LintWithoutLintPass {
} else if is_expn_of(item.span, "impl_lint_pass").is_some()
|| is_expn_of(item.span, "declare_lint_pass").is_some()
{
if let hir::ItemKind::Impl {
if let hir::ItemKind::Impl(hir::Impl {
of_trait: None,
items: ref impl_item_refs,
..
} = item.kind
}) = item.kind
{
let mut collector = LintCollector {
output: &mut self.registered_lints,

View file

@ -439,8 +439,8 @@ pub fn trait_ref_of_method<'tcx>(cx: &LateContext<'tcx>, hir_id: HirId) -> Optio
if_chain! {
if parent_impl != hir::CRATE_HIR_ID;
if let hir::Node::Item(item) = cx.tcx.hir().get(parent_impl);
if let hir::ItemKind::Impl{ of_trait: trait_ref, .. } = &item.kind;
then { return trait_ref.as_ref(); }
if let hir::ItemKind::Impl(impl_) = &item.kind;
then { return impl_.of_trait.as_ref(); }
}
None
}
@ -1530,7 +1530,7 @@ pub fn is_no_std_crate(krate: &Crate<'_>) -> bool {
/// ```
pub fn is_trait_impl_item(cx: &LateContext<'_>, hir_id: HirId) -> bool {
if let Some(Node::Item(item)) = cx.tcx.hir().find(cx.tcx.hir().get_parent_node(hir_id)) {
matches!(item.kind, ItemKind::Impl { of_trait: Some(_), .. })
matches!(item.kind, ItemKind::Impl(hir::Impl { of_trait: Some(_), .. }))
} else {
false
}