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

fix [undocumented_unsafe_blocks] FP with trait/impl items #12672

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

J-ZhengLi
Copy link
Member

fixes: #11709

do-over of #11813 , I was trying to fix multiple problems at once thus making that PR hard to review, also hard to maintain after so many conflicts... So, here's a new one, should be a bit simpler to review the changes.

r? @Alexendoo if you don't mind?


changelog: fix [undocumented_unsafe_blocks] FP with trait/impl items

@rustbot rustbot added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties label Apr 12, 2024
Comment on lines 733 to 750
fn hir(node: &'hir Node<'hir>) -> Option<Self> {
let (owner_id, kind, span) = match node {
Node::Item(item) => (item.owner_id, item.kind.into(), item.span),
Node::TraitItem(ti) => (ti.owner_id, ti.kind.into(), ti.span),
Node::ImplItem(ii) => (ii.owner_id, ii.kind.into(), ii.span),
_ => return None,
};
Some(Self { owner_id, kind, span })
}

fn is_const_or_static(&self) -> bool {
matches!(
self.kind,
ItemAlikeKind::Item(ItemKind::Const(..) | ItemKind::Static(..))
| ItemAlikeKind::ImplItem(hir::ImplItemKind::Const(..))
| ItemAlikeKind::TraitItem(hir::TraitItemKind::Const(..))
)
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These could be two standalone functions without the new types/macros, something like

fn item_a_like(node: &Node) -> Option<(Span, HirId)> { ... }

fn is_const_or_static_item_a_like(node: &Node) -> bool { ... }

Also worth mentioning that you can use .into() to go from an OwnerId to a HirId

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
S-waiting-on-review Status: Awaiting review from the assignee but also interested parties
Projects
None yet
Development

Successfully merging this pull request may close these issues.

undocumented_unsafe_blocks doesn't detect safety comment above associated constant
3 participants